Asynchronous Stripe refund fails to update the payment amount
When a charge is asynchronous like SEPA
and that a refund is done before the succeed of the charge, Stripe may sent the webhooks in this order charge.refund.updated
, charge.succeeded
and finally payment_intent.succeeded
(if there is a payment intent).
The problem is that the payment_intent.suceeded
webhook update the payment amount with the payment_intent.amount_received
but this field is never updated (even if there are refunds).
Also the charge.amount_refunded
is updated even if the refund is still pending. According to Stripe support this is because the fund has leaved Stripe but there may be failure later. In this case we will receive a charge.refund.updated
with the status failed
. But no events for the charge, so we need to update the payment using the stripe.charge
instance.
Ref: https://discord.com/channels/841573134531821608/1253363519856840737