For order https://admin.luxuryescapes.com/purchases/8e254fcc-de48-40e8-9e2f-cbeb4919a75d
There's 2 stripe payments:
- $5,072 => covers $2323 in flights and $2749 for package
- $130 => covers airport lounge add-on
- Through our admin portal, someone refunded the full $2749 for the package.
- Payment service looked at the stripe payments and said "ok, we can refund $2749 by refunding the full $130 payment, plus $2619 of the $5072 payment". (This is a bug we can fix - it should have taken the whole $2749 from the $5072 payment!)
- The first refund (for $130) goes through stripe successfully, and is recorded in our DB correctly. 1 second later, the second refund (for $2749) goes through stripe successfully, but due to unique constraint, our DB fails to record it (note: different transaction keys from admin portal wouldn't have fixed this particular issue, since we weren't trying to refund multiple items)
- Sai cancels the $130 add-on. Sai manually records two -$65 manual payments, presumably because he couldn't actually refund the add-on (because it had already been refunded!) Sai: I think these manual deductions are a mistake since the add-on was already inadvertently / accidentally refunded by our bug)
- Customer is at this point $130 short of a full refund (ignoring flights). Due to confusion over bug, we're trying to refund the full $2749 for the package, because we have no record of it in our admin portal - and it keeps erroring. (But remember, the $2749 has already been refunded - split across the two payments)
- I figure out that the refund error is "Refund amount ($2,749.00) is greater than unrefunded amount on charge ($2,453.00)" and report to Sai.
Sai refunds $2,453 (ie, the total money left in the $5,072 payment)Edit: Sai does a proper stripe refund for -$296 and records a manual refund for -$2453. See Sai's comment below. So, we're all good for this order now - you can ignore the paragraph below. Just need to fix the bugs at the end.
So: $2749 (full package price) less $130 (accidental add-on refund amount due to bug) = $2,619, was refunded in step 2) from the full $5,072 payment (for package + flights). This leaves only 5072 - 2619 = $2,453 left on that large payment, which effectively represents the amount of "flights + $130 of the package price that was refunded from the add-on transaction rather than this package/flights transaction". But we then refunded that whole amount. I think what we should have done is just refunded $130 to complete the package refund portion, and leave the flights un-refunded.
- The entire amount of all payments in the order have been refunded, including the flights payments. But, flights are not cancelled.
- We have two manual payments for -$65 in our admin portal that shouldn't be there.
- Fix the bug in step 2) up top, where it split the $2749 refund across two payments.
- Fix bug in step 3) where it fails to save in our DB due to unique constraint
- Sai to decide if we undo the manual -$65 payments
Neither of those fixes are necessarily simple. Should I pick them up now? They are causing issues in a number of areas (particularly the second bug)
🔥 Great investigation