#cnguyen - Subscriptions
1 messages ยท Page 1 of 1 (latest)
Hi again my Rubeus โค๏ธ ๐
If a Subscription is canceled/deleted you get customer.subscription.deleted: https://stripe.com/docs/api/events/types#event_types-customer.subscription.deleted
I want to update a user property when his subscription is over. For example, if I cancel it. Or it arrived at the end of his period. Or when we try to resubscribe automatically with the Smart retries, then it doesn't work anymore
OK. So it's the end when we "cancel now", or when it's "cancel at" and even when at the end of the Stripe "Smart Retries" system ?
Sorry, not sure I understand... I think there are several different questions there?
So it's the end when we "cancel now"
Yeah, if you cancel a Subscription immediately you'll get customer.subscription.deleted immediately.
when it's "cancel at"
If you've specified a cancel date/time in the future you'll get the customer.subscription.deleted at/near the specified cancelation time.
at the end of the Stripe "Smart Retries" system
This depends on the settings in your Dashboard related to how the Subscription is treated when retries end.
For the Smart Retries, we just setup the number of times. But I thought that at the end of X times, if it doesn't work, the subscription was canceled. No ?
Nope, it depends on what you have configured here:
If you have that set to cancel the Subscription then you will get customer.subscription.deleted, but if you have it set to something else you won't get that event.
mmm ok thank you. I suppose that there is a hook when we mark the subscription as unpaid
@pulsar chasm I see that @viscid stag go to sleep ๐ Maybe you have the answer here ?
Ah sorry about that! I didn't realize you had asked another question
It's me. I have to add the "?" ^^sorry
No you don't have to add a "?" - i just read it to fast (sorry again)!
Yes, when a subscription get's updated to be unpaid, you'll get a customer.subscription.updated event that reflectes that
ok and I have to check the status of the event response I suppose
to check if status == unpaid
Yup! You can check the event for the status, and you can also check that the status has changed by verifying if status in included in previous_attributes of the webhook event. If it's not there, that means the status has not changed
When the status wil be "unpaid", there is always a previous_attributes no ? Previous_attributes = previous status ?
Let me clarify - Yes, when the status transitions to "unpaid" the event will have data[previous_attributes][status]: <THE_OLD_STATUS> and the event object will have status: unpaid.
A subscription can have various updates not related to the subscription, so if you specifically want to check for a status update that's when you would check if previous_attributes[status] is set. For example, when a subscription renews it's current_period_start and current_period_end will be updated, but that customer.subscription.updated event will not change the status
@pulsar chasm And I have another question: I want to check if the user has an active subscription, do you think that the best is :
- to expand the subscription with stripe.customer.retrieve and check if there is active subscription ?
- make a stripe.subscriptions.list with status 'active' and check the data.length?
And in stripe.subscriptions.list, can I add multiple status ? Like 'active' or 'trialing'
Personally, I'd go with listing subscriptions, passing in customer and the whatever statuses you want, and then checking the length
I don't believe you can pass in multiple statuses though
So the 2nd option
But I have to launch it twice if I need to know the the user has a subscription
Or set to 'all' status and check by myself
yeah, if you want to check for both trialing and active subscriptions may be better to pass in all
Because I think that the "customer expand subscription" doesn't return all the subscription. Right? I don't know which filter it is
It'll list all their current subscriptions, so I believe it excludes any canceled/incomplete_expired ones. But we also don't really recommend going that route because it could have performance issues
ok
So it's like to check with status to "all" and filter it by removing canceled/incomplete_expired
yup!
ok tthhaannkkkssssss