Reputation: 3688
When using Checkout Subscriptions, the Stripe documentation states that the minimum event types to monitor are:
checkout.session.completed
- When you receive a checkout.session.completed event, you can provision the subscription.invoice.paid
- Sent each billing interval when a payment succeeds.invoice.payment_failed
-Sent each billing interval if there is an issue with your customer’s payment method.When you receive a checkout.session.completed event, you can provision the subscription. Continue to provision each month (if billing monthly) as you receive invoice.paid events. If you receive an invoice.payment_failed event, notify your customer and send them to the customer portal to update their payment method.
https://stripe.com/docs/billing/subscriptions/checkout#provision-and-monitor
However, I am still confused about invoice.paid
and invoice.payment_failed
events and Laravel Cashier:
Do I need to make handlers for these two events?
I'm asking this because Cashier already handles customer.subscription.updated
and customer.subscription.deleted
events and, if I understood well (correct me if I'm wrong):
customer.subscription.updated
and the subscription will continue being 'active'
: $user->subscribed('default')
will be true
(in subscriptions
table stripe_status
will remain active
).customer.subscription.updated
event will be triggered/sent and Cashier will change the subscription's status (to canceled
or incomplete
?) and $user->subscribed('default')
will be false
, right?If so, then I see no reason why I should make handlers for invoice.paid
and invoice.payment_failed
events. I will know if the payment (renewal of the subscription) was successful because customer.subscription.updated
event will be triggered/sent and Cashier will update thestripe_status
in subscriptions
table.
Or I'm wrong and it won’t work that way? If I didn't understand well, then I guess that customer.subscription.updated
event will not be triggered/sent at all, or it will but it will not contain information if the payment (renewal of the subscription) was successful or not (and if it failed, then in handler method for the invoice.payment_failed
event I will have to update the stripe_status
(in subscriptions
table) to canceled
or incomplete
?
Upvotes: 0
Views: 1400
Reputation: 5847
Whether the subscription gets deleted or not after a failed invoice payment is up to your subscription settings: https://dashboard.stripe.com/settings/billing/automatic
As such it's possible to get a invoice.payment_failed
event and not have the subscription be cancelled.
Since those events are very different it's safest to listen to all of them and handle accordingly. customer.subscription.updated
and invoice.paid
are also very different, the former will fire whenever any update to the subscription is made (e.g. if you update the metadata) whereas the latter will only fire specifically when an invoice payment succeeds.
It's ultimately up to you, but to ensure that you don't miss any important events you should consider listening to all the aforementioned events.
Upvotes: 1