Skip to content

Instantly share code, notes, and snippets.

@joshuapaling
Last active May 7, 2020 04:39
Show Gist options
  • Save joshuapaling/0c9f0755c835f51724005a0c666ac596 to your computer and use it in GitHub Desktop.
Save joshuapaling/0c9f0755c835f51724005a0c666ac596 to your computer and use it in GitHub Desktop.

For order https://admin.luxuryescapes.com/purchases/8e254fcc-de48-40e8-9e2f-cbeb4919a75d

There's 2 stripe payments:

  1. $5,072 => covers $2323 in flights and $2749 for package
  2. $130 => covers airport lounge add-on

Refund steps taken were:

  1. Through our admin portal, someone refunded the full $2749 for the package.
  2. 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!)
  3. 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)
  4. 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)
  5. 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)
  6. 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.
  7. 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.

So I think were we are now is:

  1. The entire amount of all payments in the order have been refunded, including the flights payments. But, flights are not cancelled.
  2. We have two manual payments for -$65 in our admin portal that shouldn't be there.

Next steps for us:

  1. Fix the bug in step 2) up top, where it split the $2749 refund across two payments.
  2. Fix bug in step 3) where it fails to save in our DB due to unique constraint
  3. 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)

@joshuacullenlux
Copy link

🔥 Great investigation

@saivannemreddy
Copy link

Joss, I have not refunded any money for the Flights (accidentally $166)
From a total payment of $5072, I refunded a total of $2619 + $296 = 2915 (Bummer, that is 2915-2749 = 166 more than what I should have, but that will be adjusted when they do the flights refund if they do at all)
image

While the add-ons is a different stripe transaction which has been refunded in Stripe but no Accounting data in AP, which is required for reflecting in the reports. So I have added the manual refund entries to adjust vendor payments and no additional money refunds to the customer:
image
Hope this makes sense

@joshuapaling
Copy link
Author

Ah yep that makes sense - I didn't notice the -$2453 was a manual refund. All good Sai 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment