title: Which webhooks to look after in Stripe Checkout?
body: <p>I'm implementing subscription with <a href="https://stripe.com/docs/payments/checkout/subscriptions/starting" rel="nofollow noreferrer">Stripe Checkout</a>, but I have some questions that I couldn't get definitive answers for even from their support.</p>
  
  <p>I have following scenario:</p>
  
  <ol>
  <li>User clicks on a <code>Subscribe</code> button</li>
  <li>User gets redirected to Stripe Checkout page (along with session token)</li>
  <li>User successfully pays (and from now on is a Customer)
  
  <ul>
  <li>and here I get 14 webhook calls (each one is different <a href="https://stripe.com/docs/api/events/types" rel="nofollow noreferrer">event type</a>):
  
  <ul>
  <li><code>checkout.session.completed</code></li>
  <li><code>payment_method.attached</code></li>
  <li><code>invoice.created</code></li>
  <li><code>customer.updated</code></li>
  <li><code>customer.subscription.created</code></li>
  <li><code>customer.created</code> <em>(even though I used the same email - test mode, but still...)</em></li>
  <li><code>invoice.finalized</code></li>
  <li><code>invoice.updated</code></li>
  <li><code>invoice.payment_succeeded</code></li>
  <li><code>customer.subscription.updated</code></li>
  <li><code>charge.succeeded</code></li>
  <li><code>payment_intent.succeeded</code></li>
  <li><code>payment_intent.created</code></li>
  <li><code>invoice.updated</code></li>
  <li><em>edit: I get all of them at once because I use <a href="https://stripe.com/docs/payments/checkout/subscriptions/starting#testing-webhooks-locally" rel="nofollow noreferrer">Stripe CLI</a>'s <code>listen</code> feature 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</em></li>
  </ul></li>
  </ul></li>
  </ol>
  
  <p>Until here it all works good. My concern is that:</p>
  
  <ul>
  <li>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? <a href="https://stripe.com/docs/api/events/types#event_types-subscription_schedule.canceled" rel="nofollow noreferrer"><code>subscription_schedule.canceled</code></a> maybe?). 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.</li>
  <li>when I do another subscription payment using the very same email I get exactly the same webhooks (including <code>customer.created</code> which I think shouldn't be there) or am I missing something?</li>
  <li>is there any possibility to double-charge a Customer by accident like I read in other Stripe implementations (see: idempotency)?</li>
  <li>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.</li>
  </ul>
  
  <p>Flow that I want to achieve:</p>
  
  <ol>
  <li>User successful payment (as above in points from 1 - 3). <em>Already done!</em></li>
  <li>Register new customer in database (Firebase in this case) and log him in automatically so after payment he has instant access.</li>
  <li>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.</li>
  </ol>