Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining checkout.session.completed and invoice.payment_succeeded

My basic setup is creating a session and completing a payment with a Stripe webhook sent when checkout.session.complete is true.

But to be able to update the current_period_end in my database, I have to use a webhook for when invoice.payment_succeeded is true.

This works together, but, I have a problem!

Problem: When a user subscribes for the first time, Stripe sends a webhook of both checkout.session.complete and invoice.payment_succeeded.

I want to receive only the checkout.session.complete when a user first subscribes, so is it possible to prevent the invoice.payment_succeeded from being sent the first time / when checkout.session.complete is sent?

like image 969
Casper Hansen Avatar asked Dec 05 '25 05:12

Casper Hansen


1 Answers

The invoice object has the attribute billing_reason. If the invoice.payment_succeeded webhook event is triggered by creating a new subscription, the value of billing_reason will be "subscription_create".

like image 185
heartmo Avatar answered Dec 10 '25 20:12

heartmo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!