stripe-firebase-extensions icon indicating copy to clipboard operation
stripe-firebase-extensions copied to clipboard

Refunded state

Open dancixx opened this issue 4 years ago • 10 comments

Hi guys.

This is not actually a bug but maybe later can be a feature request. So the main question is that how can I detect on saved invoices and payments the refunded state? Is there a listener for this event in this package?

dancixx avatar Nov 26 '21 07:11 dancixx

The Charge Object in the Payment Intent Object already has a refunded boolean flag - only it is not updated on a refund. We need to revoke the user's authorisation if the payment has been refunded - what are the options?

Spitzbua avatar Oct 21 '22 15:10 Spitzbua

Bumping this. Is there a way to tell if a payment in the Payments sub-collection was refunded? Adding these events to the webhook doesn't appear to be enough - none of the Firebase Cloud Functions handle updating the corresponding payment document to reflect the refunded change.

I assume the change would be made in the insertPaymentRecord function, belonging to the handleWebhookEvents webhook handler function. Similar to how changes to existing subscriptions update the document, I would think that refund events on Stripe could be used to update the existing payment document.

https://github.com/invertase/stripe-firebase-extensions/blob/24591c4bc1aabd723271c9aecbe7182d530ed9bb/firestore-stripe-payments/functions/src/index.ts#L637

joshkautz avatar Sep 13 '23 16:09 joshkautz

I'd be happy to start on adding a Pull Request with the changes, since I'd definitely use a feature of this nature, but I'm not sure if that's a Stripe anti-pattern or goes against the intended usage. I'd be interested in hearing what folks at Invertase think about that matter. Dare I tag someone - @dackers86 ? If that sounds like something reasonable to add, I'd be happy to do some work on it, but don't wanna go down a rabbit hole if that's just not a good route. To be clear, my ultimate goal is to pick up on refunds to single-payment product purchases. Is this silly?

joshkautz avatar Sep 13 '23 16:09 joshkautz

This sounds very useful feature. Perhaps we could update the Firestore payment document in Firestore based by adding the necessary web-hook event to the following:

https://github.com/invertase/stripe-firebase-extensions/blob/9ab8170a70535137a37cd3f328ae78ed42520fff/firestore-stripe-payments/functions/src/index.ts#L729

Api reference: https://stripe.com/docs/api/charges/object#charge_object-refunded.

A PR may also provide additional context from the community on how best to use this property in Firestore.

dackers86 avatar Sep 13 '23 17:09 dackers86

Sounds good, thanks for the reply, I'll get cooking on this in the near future here. Cheers 👍

joshkautz avatar Sep 13 '23 22:09 joshkautz