#Egon
1 messages · Page 1 of 1 (latest)
Hi there, checkout.session.completed event is fired when your customer has completed the checkout session, it doesn't necessary mean that the payment is succeeded.
I'd suggest you to listen to invoice.paid event instead
I would like to enable the subscription for the user once checkout has completed (regardless of the payment succeeding). Then on failure, I would like to disable it.
Then you'll run into issue that you just described.
My question is in case of the payment failing, how soon the invoice.payment_failed is sent to avoid the situation described above.
So you're telling me there is no reliable way of enabling subscriptions right after checkout? The integration guide gave me the impression it should be possible: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=checkout#provision-and-monitor
The problem here is that your system needs time to provision the subscription and unable to handle the invoice.payment_failed event which may occurs after checkout.session.completed, and that's why I suggest you to only provision subscription when invoice.paid event occurs, which is mutually inclusive with invoice.payment_failed.
The question is which is generally faster, my system only needs about +- 1 second to provision the subscription.
Another solution would be to check if the payment failed in the checkout session completed event itself, but it seems that's not really possible: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_status
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Please refer to the best practices https://stripe.com/docs/webhooks/best-practices#event-ordering
Stripe does not guarantee delivery of events in the order in which they are generated.
I'd strongly suggest you to listen to invoice.paid so that you can avoid this problem, and don't need to spend extra effort to fix the problem.
Fair, although I don't think my customers will be happy if they have to wait for the subscription to become active.
Alternatively you can implement an event queue in your system, so that it can still process the invoice.payment_failed event after finishing the provision task.
Yeah, that's a good idea. Will probably end up doing that. Thanks for your time!