When the UPI attempts run out
Each payment on our orchestration checkout allows only so many UPI attempts. After a reload mid-payment, the page didn't always respect that. Four cases, one decision at the door, and the one I broke on the way.
A payment on our orchestration checkout, the one that routes each payment to a processor by rules, allows a limited number of UPI attempts. That limit lives on the server. The page has to respect it too, or a customer gets offered something that can only fail.
It mostly did. The gap was the reload.
The bug
When the checkout loads, the session response can carry interim information about a UPI payment already under way, including how many attempts remain. The old code had one rule: if that information exists, show the UPI screen.
So a customer with no attempts left could reload the page mid-payment, land on a UPI screen, start another attempt, and fail at the server, instead of being told up front that UPI was no longer available for this payment.
Four cases, decided once
Two questions decide what the customer should see: are there attempts left? and is a UPI payment already in progress? That’s four cases, and I handled all of them in one place, the moment the session response arrives:
- No attempts left, nothing in progress: close any open drawers, stop checking for UPI status, and disable UPI with the reason “Exceeded maximum attempts for UPI payment”. Card and other methods still work.
- No attempts left, a payment in progress: keep showing that payment so the customer can still approve it in their UPI app, but disable the UPI ID field so they can’t start another.
- Attempts left, a payment in progress: show it exactly as before. A reload just picks up where they left off.
- Attempts left, nothing in progress: nothing changes.
The same check runs after a UPI payment starts. On the web intent flow only the UPI ID field is disabled; otherwise the whole method is. The UPI ID field also got a proper disabled state in the form, so the form itself knows it’s locked.
The case I broke
The first version handled the limit correctly, and stopped showing in-progress payments that still had attempts left: the “nothing should change” case. It was caught and fixed the next day, along with a second fix to read the remaining attempts from the right place in the response.
The lesson is boring and true: the case you didn’t mean to change deserves a test as much as the one you did.
One more thing: formatting
The main change also reformatted whole files from two-space to four-space indentation. About 150 changed lines ended up buried in a diff of roughly 2,000. That’s hard to review, and it hides exactly the kind of regression above. Formatting belongs in its own commit.
What I learned
- Decide once, at the door. Four cases handled in one place, at load, beat scattered checks in each screen, and the rules become readable.
- Don’t take away a payment that’s already moving. If the last attempt is with the customer’s UPI app, let them approve it. Only block starting another.
- Test the unchanged path. Regressions live where you weren’t looking.
- Keep formatting out of logic changes. Reviewers can only catch what they can see.