#Crawl

1 messages ยท Page 1 of 1 (latest)

narrow ridgeBOT
upper star
gilded pawn
#

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 ?

upper star
#

Yes, it has a subscription object in the payload so you can look at its status and check what changes were made

gilded pawn
#

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

upper star
#

It depends on your integration to be honest ๐Ÿ™‚

narrow ridgeBOT
gilded pawn
#

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..

upper star
#

But now I want to know if user cancel, payment fail, pause the sub, etc..
If user cancels, you'd see customer.subscription.deleted

If the payment fails, you'd see invoice.payment_failed

If they pause the sub, you'd see customer.subscription.updated

gilded pawn
gilded pawn
sharp shuttle
#

Hi there ๐Ÿ‘‹ taking over, as my colleague needs to step away

Give me a few minutes to get caught up.

sharp shuttle
sharp shuttle
gilded pawn
gilded pawn
sharp shuttle
#

Correct

gilded pawn
#

Perfect, so no need to watch out for payment fail
as when the payment attempt fail more than 3 times, the sub is canceled

sharp shuttle
#

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

gilded pawn
#

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
}```
sharp shuttle
#

Same for customer.subscription.resumed

gilded pawn
#

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

sharp shuttle
#

Events don't trigger other events, but yes: payment_intent.succeeded will fire when a payment is made on a paused subscription

gilded pawn
#

correct correct, will be sent at the same time I meant

gilded pawn
sharp shuttle
#

If you have it set in the dashboard to delete the subscription, then yes

gilded pawn
gilded pawn
sharp shuttle
#

You wouldn't cancel until your end date in that case

gilded pawn
#

And how can a user resume a subscription in the billing portal ?

sharp shuttle
#

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

gilded pawn
#

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 ?

sharp shuttle
#

It's sent immediately

gilded pawn
#

Question 2 :
And how can a user resume a subscription? in the billing portal ?
(Preferably no code)

#

or checkout again

sharp shuttle
#

If it is paused, I believe they can resume in the Billing Portal, but let me confirm

gilded pawn
#

the only thing I'm missing is how can I manage the date of the end of the subscription when user cancel

sharp shuttle
#

What do you mean by "manage"?

gilded pawn
#

does this work ? with this api call

const subscription = stripe.subscriptions.update(subscriptionId, { cancel_at_period_end: true });

sharp shuttle
#

yup!

gilded pawn
#

ok perfect

#

So here, it will not cancel the suscription right away and send a webhook when the end is reached