Skip to content

Commit b37c193

Browse files
committed
fix(in-person): redirect to index on tokenize cancel
instead of keeping the user in an endless loop of redirects from the auto-redirect on the Switchio enrollment index, when a user cancels tokenization in the Switchio gateway by clicking "Back", send them to the admin index this is similar to how the "Cancel" button for Littlepay works
1 parent 1b8ac24 commit b37c193

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

benefits/in_person/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,11 @@ def get_context_data(self, **kwargs):
216216
}
217217
)
218218
return context
219+
220+
def get(self, request, *args, **kwargs):
221+
if request.GET.get("error") == "canceled":
222+
# the user clicked the "Back" button on the Switchio tokenization gateway
223+
# send them back to the Admin index, similar to the Littlepay cancel button
224+
return redirect(routes.ADMIN_INDEX)
225+
226+
return super().get(request, *args, **kwargs)

tests/pytest/in_person/test_views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,11 @@ def test_get_context_data__post_tokenize(self, view: views.SwitchioEnrollmentInd
285285
context = view.get_context_data()
286286

287287
assert context["loading_message"] == "Registering this contactless card for reduced fares..."
288+
289+
def test_get__cancel_tokenize(self, view: views.SwitchioEnrollmentIndexView, app_request):
290+
app_request.GET = {"error": "canceled"}
291+
292+
response = view.get(app_request)
293+
294+
assert response.status_code == 302
295+
assert response.url == reverse(routes.ADMIN_INDEX)

0 commit comments

Comments
 (0)