Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe subscription events webhooks are not clear

Say I am letting customers subscribe to a service, as I see it there are 2 events that I need to know about :

  1. The current charge succeeded or failed, so I can congratulate him for joining in.
  2. every next charge (every month) succeeded or failed.

Stripe have too many events, and it's hard to know which one of them to listen to :

invoice.paid - "Occurs whenever an invoice payment attempt succeeds"

charge.succeeded - "occures when a new charge was created" (so what's the difference??)

invoice.payment_succeeded - "Occurs whenever an invoice payment attempt succeeds."

customer.subscription.created - "Occurs whenever a customer is signed up for a new plan."

Now I am aware that a few events can happen for a single API call, but,

What should a developer listen to in order to know that his user successfully subscribed, or failed ? how invoice.paid is different than charge.succeeded ? and how invoice.payment_succeeded is different from those ?

It is too messy, I just need to get a yes or no. I read the API https://stripe.com/docs/api/events/types

like image 222
raniran Avatar asked Oct 04 '20 17:10

raniran


People also ask

Does Stripe retry Webhooks?

In test mode, Stripe retries three times over a few hours. Webhooks can be manually retried after this time in the Dashboard, and you can also query for missed events to reconcile the data over any time period.

What happens when a Stripe subscription fails?

Failed paymentsThe subscription's status remains active as long as automatic payments succeed. If automatic payment fails, the subscription updates to past_due and Stripe attempts to recover payment based on your retry rules.

What is a stripe webhook?

Let’s say you’ve registered to receive the checkout.session.completed event and a customer clicks the “Pay” button in your app or website. A webhook between Stripe and your app tells your app whether the customer’s payment is successful or not.

How do I handle stripe events?

Add logic to handle Stripe events. For subscriptions, these include payment failures and subscription state changes (like moving from trial to an active state). Test your webhook endpoint to confirm that it’s working as expected. For more details about setting up and using incoming webhooks, read the guide.

What happens when a stripe Subscription renews?

When the subscription renews, Stripe bills the customer and tries to collect payment by either automatically charging the payment method on file, or emailing the invoice to customers. Stripe notifies your site of the invoice status through webhooks: A few days prior to renewal, your site receives an invoice.upcoming event at the webhook endpoint.

How do I get notifications from stripe?

Stripe sends notifications to your app using webhooks. Webhooks are especially important for subscriptions, where most activity occurs asynchronously. Add logic to handle Stripe events. For subscriptions, these include payment failures and subscription state changes (like moving from trial to an active state).


1 Answers

It comes down to what you want to listen for.

charge.succeeded will trigger when an invoice is successfully paid, but it'll also trigger for one-off payments.

invoice.paid will trigger when an invoice is paid but will also trigger if you mark the invoice as paid out of band (e.g. someone pays you in cash)

invoice.payment_succeeded is the same as invoice.paid, but won't trigger if you mark the invoice as paid out of band. If you don't anticipate ever accepting out of band payments, then consider using this event.

customer.subscription.created will trigger when a new subscription is created, which isn't the same as the first invoice being paid (e.g. you can create a subscription with a trial period that won't trigger an invoice paid event immediately).

If your business only works with subscriptions (and not one-off payments) and you don't particularly care about the invoice data, use charge.succeeded. If you use both then it's useful to listen to both events to distinguish between the two.

In your case, you probably only want to listen to invoice.payment_succeeded. When you get the invoice, look at the billing_reason field: https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason

If it's set to subscription_create, then send your congratulatory email. If it's subscription_cycle, then it's because the subscription entered a new billing cycle and the payment succeeded.

like image 79
Paul Asjes Avatar answered Oct 19 '22 02:10

Paul Asjes