Does the customer.subscription.updated event occur when a subscription is updated?

I am confused by the fact that the Stripe documentation assumes that the customer.subscription.updated event does not fire if I believe that it should:

  • The Stripe subscription object has the current_period_start and current_period_end properties, which will be updated whenever the client successfully pays for the subscription invoice ( https://stripe.com/docs/api#subscriptions )
  • The documentation for the customer.subscription.updated event indicates that it ...

    Occurs when a subscription changes. Examples are a transition from one plan to another or a transition from a trial to an active one.

    ... that would mean that the event would be raised if the values โ€‹โ€‹of current_period_start and current_period_end change, but this is not confirmed if this is so or not in this case.

    However, this third-party web page indicates that it does not occur upon a successful update ( https://www.masteringmodernpayments.com/stripe-webhook-event-cheatsheet#8 ).

  • But raising an event just makes sense ...

  • And, of course, if applications are needed only to control one type of event (i.e., customer.subscription.updated ), this will greatly simplify the program code without requiring the monitoring of invoice.payment_succeeded , invoice.created and charge.succeeded .
  • However, the documentation for the subscription life cycle ( https://stripe.com/docs/subscriptions/lifecycle ) absolutely does not mention the customer.subscription.updated event at all.

It seems strange that such a corresponding event does not occur when it should be. The documentation also doesn't really say when the current_period_end and current_period_start values โ€‹โ€‹are updated, which limits their usefulness.

So, in my application after receiving the invoice.payment_succeeded event, how can my program code determine when the subscription period for the client will end?

+5
source share
2 answers

I have confirmed that customer.subscription.updated is called when the payment period ends .

To do this, I intercepted all the websites that occur at the end of the period (FYI: I used the AWS Lambda function, which receives events from the AWS API Gateway, and then puts the events in the SQS queue :))

I agree that the Stripe documentation for the customer.subscription.updated event can be clearer and can cover this use case by saying ....

Occurs when a subscription changes. Examples include when the billing period ends and a new billing period begins, when switching from one plan to another, or switching from a trial to an active one.

(FYI: I would completely ignore the cheatsheet site. They only make a passing link to customer.subscription.updated . In step 8 they describe the (poor) use case of โ€œCreate a client with a plan without a trial processโ€, Do not create a customer.subscription.updated event , because this event occurs only when the subscription is updated, and not when it is created. Where are they referenced by customer.subscription.updated in the context of step 12 "Invoice attempt failed")

In defense of the Stripes documentation regarding the subscription life cycle, he says: โ€œThe following figure shows the life cycle of the most important events that occur,โ€ and I would say that customer.subscription.updated not an important event in the context of creating invoices making payments.

Some information on how Stripe handles the end of a period:

  • In my test, Stripe raised the customer.subscription.updated event about 2 minutes after the timestamp in the current_period_end property in the subscription. An event has two data objects associated with it. The first is a subscription with new values โ€‹โ€‹on it. The second object is previousAttributes with the two previous values current_period_start and current_period_end .

  • Two events were generated simultaneously: customer.subscription.updated and invoice.created (it was an invoice for the period just passed).

  • About an hour after creating the account, three events were created: invoice.payment_succeeded , charge.succeeded and invoice.updated .

How do you feel about the transfer of the billing period compared to the payment status of the invoice, really depends on you and very much depends on the type of your application. This is the beauty of the Stripe API (and it's beautiful).

In my case, I relate to the transfer of the billing period separately to the payment status of the invoice. My application takes care of when the billing period overflows and makes updates for use based on this, but any payment failures generate alerts and are processed offline.

In the end, you can use customer.subscription.updated to find out when the billing period has changed.

+5
source

customer.subscription.updated fired when current_period_start and current_period_end change. They represent the billing period .

When invoice.payment_succeeded occurs, there you must update the information on your side (for example: the subscription period): https://stripe.com/docs/subscriptions/guide#step-3-sync-with-your-site

Also more detailed information here: https://support.stripe.com/questions/what-events-can-i-see-when-a-subscription-is-renewed

0
source

Source: https://habr.com/ru/post/1258011/


All Articles