Casper Hansen
Casper Hansen

Reputation: 543

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?

Upvotes: 4

Views: 863

Answers (2)

Rajesh Gadhvi
Rajesh Gadhvi

Reputation: 1

Set "meta_data" to the type of cusotmer depending on customer found on stripe or not thorugh api search. This will help to compare when you receive the payment.

Upvotes: 0

heartmo
heartmo

Reputation: 582

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".

Upvotes: 1

Related Questions