Preserve idempotency key for purchase pages' form states
What does this MR do and why?
Resolves https://gitlab.com/gitlab-org/customers-gitlab-com/-/issues/7496+.
Recently, we introduced an idempotency key to purchase pages that's sent along with purchase confirmation requests to the backend. We caught an edge case where after a failed purchase request, a user can change some form input then change them back to their original values, regenerating the idempotency key, then submitting the request again. This violates the mechanism where the idempotency key must remain the same between failed requests, so we don't duplicate subscription purchases.
This MR adds state tracking for idempotency keys, where we use the same key for the same set of form input.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Case | Screen Recording |
---|---|
Idempotency key is stored according to form fields' state | key_regeneration |
Successful purchase sends correct idempotency key | successful_purchase |
Card with insufficient funds does not regenerate idempotency key | card_with_insufficient_funds |
4xx error returned regenerates idempotency key | 422_error |
Non-4xx error returned does not regenerate idempotency key | 500_error |
How to set up and validate locally
-
Start GDK and CustomersDot.
-
Perform the following steps for the Subscription and Add-On purchase pages:
- Fill out the form, open your devtools' network tab, and click "Buy subscription".
- Check that the request
POST /subscriptions
contains anidempotency_key
parameter in the body. Note the key value. - Change a value in the form (e.g. quantity or purchase method), change it back to its original value, and click "Buy subscription" again.
- Check that the new
POST
request contains the same value foridempotency_key
.
For testing the 4xx
and non-4xx
error states, please refer to the error scenarios in this MR.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.