Reputation: 560
I am currently adding the Stripe checkout to my application. My goal is really to have at least as code as possible.
The documentation says I need to handle at least three different webhook types:
I try to avoid handling any customers in Stripe and I think it is not necessary with the checkout component.
However, I still need the user id in the webhooks to update the states accordingly.
When creating the session on the backend I'll add the field client_reference_id
.
For the state checkout.session.completed
I get this field and everything is fine.
For invoice.paid
I don't get it and I need to use subscription_data.metadata
in the session to get this data.
For invoice.payment_failed
I don't know how to get it or how to test it with the CLI because I can't add metadata and I cannot add the client_reference_id
.
Do you have an idea what the best practice here is and how I should implement that? Or should I really handle a customer in Stripe as well?
Thanks!
Upvotes: 5
Views: 3782
Reputation: 2163
There's a couple different ways you can handle this -
client_reference_id
in subscription_data.metadata
, you can still get it from the invoice.paid
and invoice.payment_failed
events by retrieving the Subscription found at subscription
on the Invoice (see api ref).client_reference_id
. When you get an invoice.paid
or invoice.payment_failed
event you would grab the Customer ID and the information in your database would allow you to tie it back to the correct client_reference_id
.Upvotes: 1