@@ -102,9 +102,9 @@ def index(request):
102
102
return success (request )
103
103
# else if expiration date has passed, then re-enroll
104
104
elif expiration .is_expired (matching_group_funding_source ):
105
- client . link_concession_group_funding_source ( funding_source_id = funding_source . id , group_id = group_id )
106
- analytics . returned_success ( request , group_id )
107
- return success ( request )
105
+ return _link_concession_group_funding_source (
106
+ request , eligibility , client , matching_group_funding_source , group_id
107
+ )
108
108
# else expiration date hasn't passed, so calculate re-enrollment date and show user
109
109
else :
110
110
reenrollment_date = expiration .calculate_reenrollment_date ( # noqa
@@ -115,18 +115,9 @@ def index(request):
115
115
# todo for #1921: show reenrollment_date to user
116
116
# funding source has not been linked to the group yet
117
117
else :
118
- # if eligibility_type does not supports_expiration, then just link it
119
- if not eligibility .supports_expiration :
120
- client .link_concession_group_funding_source (funding_source_id = funding_source .id , group_id = group_id )
121
- # else eligibility_type supports_expiration, so calculate expiration date from today and include in request
122
- else :
123
- expiry_date = expiration .calculate_expiry_date (matching_group_funding_source , eligibility .expiration_days )
124
- client .link_concession_group_funding_source (
125
- funding_source_id = funding_source .id , group_id = group_id , expiry_date = expiry_date
126
- )
127
-
128
- analytics .returned_success (request , eligibility .group_id )
129
- return success (request )
118
+ return _link_concession_group_funding_source (
119
+ request , eligibility , client , matching_group_funding_source , group_id
120
+ )
130
121
131
122
except HTTPError as e :
132
123
analytics .returned_error (request , str (e ))
@@ -156,6 +147,21 @@ def index(request):
156
147
return TemplateResponse (request , TEMPLATE_INDEX , context )
157
148
158
149
150
+ def _link_concession_group_funding_source (request , eligibility , client : Client , matching_group_funding_source , group_id ):
151
+ # if eligibility_type does not supports_expiration, then just link it
152
+ if not eligibility .supports_expiration :
153
+ client .link_concession_group_funding_source (funding_source_id = matching_group_funding_source .id , group_id = group_id )
154
+ # else eligibility_type supports_expiration, so calculate expiration date from today and include in request
155
+ else :
156
+ expiry_date = expiration .calculate_expiry_date (matching_group_funding_source , eligibility .expiration_days )
157
+ client .link_concession_group_funding_source (
158
+ funding_source_id = matching_group_funding_source .id , group_id = group_id , expiry_date = expiry_date
159
+ )
160
+
161
+ analytics .returned_success (request , eligibility .group_id )
162
+ return success (request )
163
+
164
+
159
165
@decorator_from_middleware (EligibleSessionRequired )
160
166
def retry (request ):
161
167
"""View handler for a recoverable failure condition."""
0 commit comments