#Crawl
1 messages ยท Page 1 of 1 (latest)
Hello ๐
We have a doc here that covers subscription related events thoroughly
https://stripe.com/docs/billing/subscriptions/webhooks
I'd recommend going through it and picking the ones that are right for your integration
for reference, I'm asking about the code event.type
customer.subscription.updated - is this equal to subscription closed after payment fail + subscription changes + resumed ?
Yes, it has a subscription object in the payload so you can look at its status and check what changes were made
Ok perfect, so if I have those, I'm fully covered for all scenarios for a basic monthly saas product? Or I'm missing something ?
customer.subscription.resumed
customer.subscription.updated
customer.subscription.deleted
payment_intent.succeeded
For exemple, if a payment fail do I have a
customer.subscription.updated or
customer.subscription.deleted
Or do I need invoice code too?
invoice.payment_succeeded
invoice.payment_failed
invoice.payment_succeeded
Or I have the payment failure in
customer.subscription.paused
It depends on your integration to be honest ๐
I just want to know if user have an ongoing subscription
and update my db to true or false based on that
nothing complex
if user pay for the first time then it's true thanks to payment_intent.succeeded
But now I want to know if user cancel, payment fail, pause the sub, etc..
But now I want to know if user cancel, payment fail, pause the sub, etc..
If user cancels, you'd seecustomer.subscription.deleted
If the payment fails, you'd see invoice.payment_failed
If they pause the sub, you'd see customer.subscription.updated
For the payment fail, does stripe try to do the payment again in auto ?
and does this also fire the customer.subscription.updated ?
Also with stripe cli, how do I trigger a customer.subscription.resumed
Hi there ๐ taking over, as my colleague needs to step away
Give me a few minutes to get caught up.
This will depend on your retry setting in the dashboard: https://dashboard.stripe.com/settings/billing/automatic
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Unfortunately I don't think the CLI has the option to trigger customer.subscription.resumed
Ok so when you say, after multiple retry it cancel the subscription
this mean customer.subscription.deleted ??
Ok so if a subcription is resumed, this is a payment_intent.succeeded ??
Correct
Perfect, so no need to watch out for payment fail
as when the payment attempt fail more than 3 times, the sub is canceled
I personally would still listen for payment failures, but customer.subscription.deleted will fire after all payment attempts fail, so that part is totally up to you
And in customer.subscription.updated where can I see if it's paused ?
Or resumed ?
Here's my object
{
id: 'sub_1N8V66LM4GHVXwuAFv21ZcyD',
object: 'subscription',
application: null,
application_fee_percent: null,
automatic_tax: { enabled: false },
billing_cycle_anchor: 1684271274,
billing_thresholds: null,
cancel_at: null,
cancel_at_period_end: false,
canceled_at: null,
cancellation_details: { comment: null, feedback: null, reason: null },
collection_method: 'charge_automatically',
created: 1684271274,
currency: 'usd',
current_period_end: 1686949674,
current_period_start: 1684271274,
customer: 'cus_NuJjpjmS565KT8',
days_until_due: null,
default_payment_method: null,
default_source: null,
default_tax_rates: [],
description: null,
discount: null,
ended_at: null,
items: {
object: 'list',
data: [ [Object] ],
has_more: false,
total_count: 1,
url: '/v1/subscription_items?subscription=sub_1N8V66LM4GHVXwuAFv21ZcyD'
},
latest_invoice: 'in_1N8V66LM4GHVXwuAYlIKFrK2',
livemode: false,
metadata: { foo: 'bar' },
next_pending_invoice_item_invoice: null,
on_behalf_of: null,
pause_collection: null,
payment_settings: {
payment_method_options: null,
payment_method_types: null,
save_default_payment_method: 'off'
},
pending_invoice_item_interval: null,
pending_setup_intent: null,
pending_update: null,
plan: {
id: 'plan_NuJj3mWjokkm7Y',
object: 'plan',
active: true,
aggregate_usage: null,
amount: 2000,
amount_decimal: '2000',
billing_scheme: 'per_unit',
created: 1684271273,
currency: 'usd',
interval: 'month',
interval_count: 1,
livemode: false,
metadata: {},
nickname: null,
product: 'prod_NuJjDhcCxs1uP2',
tiers_mode: null,
transform_usage: null,
trial_period_days: null,
usage_type: 'licensed'
},
quantity: 1,
schedule: null,
start_date: 1684271274,
status: 'active',
test_clock: null,
transfer_data: null,
trial_end: null,
trial_settings: { end_behavior: { missing_payment_method: 'create_invoice' } },
trial_start: null
}```
You would want to listen for customer.subscription.paused for pauses: https://stripe.com/docs/billing/subscriptions/webhooks#events
Same for customer.subscription.resumed
Oh I see
So now I've got
payment_intent.succeeded -> set true
customer.subscription.paused -> set false
customer.subscription.resumed -> set true
customer.subscription.deleted -> set false
(knowing that customer.subscription.resumed
will trigger payment_intent.succeeded
right ? )
and a payment fail after 3 attempt will trigger customer.subscription.deleted -> set false
Events don't trigger other events, but yes: payment_intent.succeeded will fire when a payment is made on a paused subscription
correct correct, will be sent at the same time I meant
Can you confirm this last one too ?
If you have it set in the dashboard to delete the subscription, then yes
It's seems like it's the default setting
I also have a question, so when a customer is deleted,
the subscription is also deleted right ?
and when a subcription is canceld, is it received when the subcription is canceled ?
What if I cancel but want to have the ongoing sub until my end date
You wouldn't cancel until your end date in that case
So you mean when a subcription is cancel, I do receive my cancel webhook
And I need to manage the dates in my logic ? Stripe dont have this logic ?
And how can a user resume a subscription in the billing portal ?
I don't understand what you mean
Let's do one question at a time please. It makes it a lot easier to ensure nothing gets overlooked
Question one :
When user click on cancel subscription in billing portal for exemple
o receive my cancel webhook customer.subscription.deleted right away ?
Or it's sent when the time of the subcription is finished ?
It's sent immediately
ok I understand
Question 2 :
And how can a user resume a subscription? in the billing portal ?
(Preferably no code)
or checkout again
If it is paused, I believe they can resume in the Billing Portal, but let me confirm
I believe once it is canceled, you would need to send them back to Checkout to creat a new subscription: https://stripe.com/docs/customer-management/configure-portal
ok that make sense
the only thing I'm missing is how can I manage the date of the end of the subscription when user cancel
What do you mean by "manage"?
I mean I want to keep the subscription ongoing until the end of the the subcription
does this work ? with this api call
const subscription = stripe.subscriptions.update(subscriptionId, { cancel_at_period_end: true });
yup!