Handle payment_intent.failed event#246
Conversation
Codecov Report
@@ Coverage Diff @@
## master #246 +/- ##
==========================================
+ Coverage 98.12% 98.16% +0.03%
==========================================
Files 23 23
Lines 426 435 +9
==========================================
+ Hits 418 427 +9
Misses 8 8
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
| payment.failure!.tap do | ||
| SolidusStripe::LogEntries.payment_log( | ||
| payment, | ||
| success: true, |
There was a problem hiding this comment.
Oh, you're right. Changed! Thanks for pointing out.
I also added another commit to test the success value for both handlers in the subscriber class.
bd2ba34 to
3d27136
Compare
A `payment_intent.failed` event is published [1] when a payment intent can't be captured from Stripe. After we check #185, the webhook could also be triggered by an action from the backend, so we need to do nothing if the payment is already failed. Closes #179 [1] - https://stripe.com/docs/payments/payment-intents/verifying-status#webhooks
056978f to
5f8ccf3
Compare
| # @param event [SolidusStripe::Webhook::Event] | ||
| def fail_payment(event) | ||
| payment = extract_payment_from_event(event) | ||
| return if payment.failed? |
There was a problem hiding this comment.
| return if payment.failed? | |
| return if !payment.can_failure? |
I'd say that checking more generally if we can transition to failed is more generic and safe. You could be on a state (like checkout) where payment is not failed but doing the transition will raise an error. Same goes for the complete! event of the same file.
There was a problem hiding this comment.
Thanks for your suggestion, @loicginoux. If Solidus payment is in the :checkout state, but we're already getting a payment_intent.payment_failed webhook, that's probably an abnormal situation. I think it's better to be stricter so we can't detect any failure in our integration.
Summary
A
payment_intent.failedevent is published when a payment intent can't be captured from Stripe.After we check #185, the webhook could also be triggered by an action from the backend, so we need to do nothing if the payment is already failed.
Closes #179
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: