05/31 Fix template
This commit is contained in:
+18
-3
@@ -36,11 +36,23 @@ def callback():
|
|||||||
if not data:
|
if not data:
|
||||||
return jsonify({'error': 'No data'}), 400
|
return jsonify({'error': 'No data'}), 400
|
||||||
|
|
||||||
|
# Teller Connect onSuccess payload:
|
||||||
|
# { accessToken, user: {id}, enrollment: {id, institution: {name}} }
|
||||||
|
# accessToken is top-level, enrollment.id is nested
|
||||||
|
access_token = data.get('accessToken', '')
|
||||||
enrollment_data = data.get('enrollment', {})
|
enrollment_data = data.get('enrollment', {})
|
||||||
enrollment_id = enrollment_data.get('id', '')
|
enrollment_id = enrollment_data.get('id', '')
|
||||||
access_token = enrollment_data.get('accessToken', '')
|
|
||||||
|
# Also handle if client wraps it: { enrollment: { accessToken, id, ... } }
|
||||||
|
if not access_token and isinstance(enrollment_data, dict):
|
||||||
|
access_token = enrollment_data.get('accessToken', '')
|
||||||
|
if not enrollment_id and isinstance(enrollment_data, dict):
|
||||||
|
enrollment_id = enrollment_data.get('id', '')
|
||||||
|
|
||||||
|
log.info(f'[teller] callback received: enrollment_id={enrollment_id!r} token_present={bool(access_token)}')
|
||||||
|
|
||||||
if not enrollment_id or not access_token:
|
if not enrollment_id or not access_token:
|
||||||
|
log.error(f'[teller] missing data. Keys received: {list(data.keys())}')
|
||||||
return jsonify({'error': 'Missing enrollment data'}), 400
|
return jsonify({'error': 'Missing enrollment data'}), 400
|
||||||
|
|
||||||
# Upsert enrollment
|
# Upsert enrollment
|
||||||
@@ -76,8 +88,11 @@ def callback():
|
|||||||
institution_name=institution_name,
|
institution_name=institution_name,
|
||||||
))
|
))
|
||||||
|
|
||||||
enrollment.institution_name = institution_name
|
# institution.name from enrollment object (not from account loop)
|
||||||
enrollment.user_id = enrollment_data.get('user', {}).get('id', '')
|
if not institution_name:
|
||||||
|
institution_name = enrollment_data.get('institution', {}).get('name', '')
|
||||||
|
enrollment.institution_name = institution_name or enrollment.institution_name
|
||||||
|
enrollment.user_id = data.get('user', {}).get('id', '') or enrollment_data.get('user', {}).get('id', '')
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return jsonify({'status': 'ok', 'redirect': url_for('teller.map_accounts', enrollment_id=enrollment_id)})
|
return jsonify({'status': 'ok', 'redirect': url_for('teller.map_accounts', enrollment_id=enrollment_id)})
|
||||||
|
|||||||
@@ -147,7 +147,8 @@ function initTellerConnect(btn) {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-CSRFToken': CSRF,
|
'X-CSRFToken': CSRF,
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ enrollment: enrollment }),
|
// Send full Teller payload: { accessToken, user, enrollment }
|
||||||
|
body: JSON.stringify(enrollment),
|
||||||
})
|
})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
|||||||
Reference in New Issue
Block a user