I've seen this similar question, but it did not answer the question asked.
I can't understand how to manage re-occurring subscription.
I did a test and the following events were fired after a successful Stripe Checkout test payment:
charge.succeededcheckout.session.completedpayment_method.attachedinvoice.createdcustomer.subscription.createdinvoice.updatedcustomer.subscription.updatedinvoice.finalizedinvoice.paid
My issue is that both checkout.session.completed and invoice.paid is getting fired. I understand that session can be completed in the following cases
- failure
- cancel
- start of a trial
- successful start
Stripe docs says this:
The minimum event types to monitor:
EVENT NAMEDESCRIPTIONcheckout.session.completedSent when a customer clicks the Pay or Subscribe button in Checkout, informing you of a new purchase. invoice.paidSent each billing interval when a payment succeeds. invoice.payment_failedSent each billing interval if there is an issue with your customer’s payment method.
And in the code part:
For
checkout.session.completed:# You should provision the subscription and save the customer ID to your database.
For
invoice.paid:# Continue to provision the subscription as payments continue to be made.
So then I thought there was surely a way to identify that checkout.session.completed and invoice.paid would be related to each other, but then the problem is that checkout.session.completed does not contain any Invoice id and the invoice.paid does not contain an id for the CheckoutSession where it was created from.
How do I give users only one month of subscription, instead of 2? Does Stripe even keep track of the end of the subscription?
Because in the tracking section here, it says:
- ...
- Your site receives an invoice.paid event.
- Your webhook endpoint finds the customer for whom payment was just made.
- Your webhook endpoint updates the customer’s current_period_end timestamp in your database to the appropriate date in the future (plus a day or two for leeway).
So this page ignore the checkout.session.completed endpoint entirely and relies on invoice.paid only, which supposedly may only arrive hours later than the session completed. (I can't find the link on this.)