I'm implementing subscription with Stripe Checkout, but I have some questions that I couldn't get definitive answers for even from their support.
I have following scenario:
- User clicks on a
Subscribebutton - User gets redirected to Stripe Checkout page (along with session token)
- User successfully pays (and from now on is a Customer)
- and here I get 14 webhook calls (each one is different event type):
checkout.session.completedpayment_method.attachedinvoice.createdcustomer.updatedcustomer.subscription.createdcustomer.created(even though I used the same email - test mode, but still...)invoice.finalizedinvoice.updatedinvoice.payment_succeededcustomer.subscription.updatedcharge.succeededpayment_intent.succeededpayment_intent.createdinvoice.updated- edit: I get all of them at once because I use Stripe CLI's
listenfeature and it probably shows all calls which normally wouldn't happen because they have to be defined in dashboard event by event. For instance if I create invoice in the dashboard and pay it then if no webhook is defined explicitly then my server won't know about anything
- and here I get 14 webhook calls (each one is different event type):
Until here it all works good. My concern is that:
- if a Customer will be charged next month which webhook should I listen to? I need to differentiate between first-time Customer (because I create new account for that user) and existing Customer that I just need to note in database that this user is still active (or listen for event of subscription cancellation?
subscription_schedule.canceledmaybe?). One idea is to just listen to successful payment and upon that check if customer exists in database - if he does just update, if not then create account. - when I do another subscription payment using the very same email I get exactly the same webhooks (including
customer.createdwhich I think shouldn't be there) or am I missing something? - is there any possibility to double-charge a Customer by accident like I read in other Stripe implementations (see: idempotency)?
- what are other things to take into account while implementing Stripe Checkout? I feel like their instructions are not reassuring that I've done everything that is considered good practice.
Flow that I want to achieve:
- User successful payment (as above in points from 1 - 3). Already done!
- Register new customer in database (Firebase in this case) and log him in automatically so after payment he has instant access.
- As long as customer's card is charged he has access. While he cancels or card has no insufficient funds I need to have my server notified about this to downgrade access.