#coding-lover_api

1 messages · Page 1 of 1 (latest)

neat canyonBOT
#

đź‘‹ Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

đź”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1361673526909604062

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

restive widget
#

Hi, let me help you with this.

#

Do all of your Subscriptions start with a trial?

ivory mist
#

yes

restive widget
ivory mist
#

how to do in cli

#

if subscription is cancelled or cancelled due to non payment after trial, Is it possible to reactive it or need to create new one?

restive widget
#

You can see examples in all languages here:

restive widget
ivory mist
#

so I need to pause subscription instead of cancelling

#

const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [
{
price: price.id,
},
],
payment_behavior: 'default_incomplete',
trial_period_days: 60,
trial_settings: {
end_behavior: {
missing_payment_method: 'cancel',
},
},
});

#

Currently I'm doing this

restive widget
#

No, you can't pause Subscriptions with Stripe. There's a feature that pauses payments - meaning you offer your product for free.

ivory mist
#

after trial if user want to get subscription I need to create new one?

#

After 2 months customer unable to pay and his subscription cancelled so he need to subscribe to new one instead of reactive new one?

#

there is a method in stripe docs stripe.subscriptions.resume

#

Copilot suggest me this
async function reactivateSubscription(subscriptionId) {
try {
const subscription = await stripe.subscriptions.retrieve(subscriptionId);

let updatedSubscription;
if (subscription.status === 'canceled') {
  // Reactivate a canceled subscription
  updatedSubscription = await stripe.subscriptions.update(subscriptionId, {
    cancel_at_period_end: false,
    collection_method: 'charge_automatically',
    items: [
      {
        id: subscription.items.data[0].id,
        price: subscription.items.data[0].price.id,
      },
    ],
  });
} else if (subscription.cancel_at_period_end) {
  // Remove pending cancellation
  updatedSubscription = await stripe.subscriptions.update(subscriptionId, {
    cancel_at_period_end: false,
  });
}

console.log('Reactivated subscription:', updatedSubscription.id);
return updatedSubscription;

} catch (error) {
console.error('Error reactivating subscription:', error);
}
}

restive widget
ivory mist
#

ok

neat canyonBOT
ivory mist
#

Hello @gritty forge

gritty forge
ivory mist
#

from stripe docs
You can sign customers up for a free trial of a subscription without collecting their payment details in the Dashboard, the API, and Checkout. When you create the subscription, you can specify whether to cancel or pause the subscription if the customer didn’t provide a payment method during the trial period. To cancel or pause the subscription, set the trial_settings.end_behavior.missing_payment_method parameter when you create or update the subscription:

#

Pause subscription-If the free trial subscription ends without a payment method, it pauses and doesn’t cycle until it’s resumed. When a subscription is paused, it doesn’t generate invoices (unlike when a subscription’s payment collection is paused). When your customer adds their payment method after the subscription has paused, you can resume the same subscription. The subscription can remain paused indefinitely. Set missing_payment_method=pause to pause the subscription when it reaches the end of a trial without an available payment method.

gritty forge
#

Where are you finding that, exactly?

ivory mist
#

?

gritty forge
#

Ok, got it. Thanks.

#

And what are you having trouble with about this?

ivory mist
#

I don't have trouble now when I read docs

#

Vanya says subscription cannot paused so I'm confused

gritty forge
#

I think it would be more precise to say it cannot be paused directly/explicitly, only indirectly by this one mechanism

#

A subscription can only enter a paused status when a trial ends without a payment method. A paused subscription doesn’t generate invoices and can be resumed after your customer adds their payment method. The paused status is different from pausing collection, which still generates invoices and leaves the subscription’s status unchanged.
https://docs.stripe.com/api/subscriptions/object#subscription_object-status

#

This is because it never really starts collecting in the first place, so that can be deferred

#

In these cases you need to collect a payment method from your customer (and set it as the customer or subscription default) to begin colleting payment

ivory mist
#

so how to resume pause subscription?
with this api
stripe.subscriptions.resume?

gritty forge
#

Attach a payment method, as far as i can tell

#

Have you tried that?

#

Do you have an example test subscription ID (eg, sub_12345) you're trying to finish setting up?