#kshitij khanal

1 messages · Page 1 of 1 (latest)

terse irisBOT
timber kestrel
#

hello, if i understand your question correctly, you want to remove one of the line items from your Subscription?

#

you don't need Subscription Schedules for that if you want to update your Subscription immediately

honest trench
#

I don't know if the subscription has only one item or multiple items. Normally, I was unsubscribing when i had only one line item. Now, i want to unsubscribe if only one line item is present and want to delete an item at the end if mulitple items are subscribed to a subscription.

#

I used below code,
await this.stripe.subscriptions.update(stripeSubscriptionId, {
cancel_at_period_end: true,
});
for unsubscribing when the subscription had only one item.

Now, as we can have mulitple items as well, i just want to unsubscribe for one item.

terse irisBOT
timber kestrel
honest trench
#

If i remove the item, will the item be eligible for that 1 month it was previously subscribed to?

#

I don't want it to be canceled immediately. I want it to be canceled after a month.
something like,
cancel_at_period_end: true,

#

I want to achieve,
await this.stripe.subscriptions.update(stripeSubscriptionId, {
cancel_at_period_end: true,
});

this behavior for that one item.

true perch
#

i.e. configure a phase to remove the item after X amount of iterations

honest trench
#

I am trying it out.

honest trench
#

const schedule = await this.stripe.subscriptionSchedules.create({
from_subscription: stripeSubscriptionId,
end_behavior: 'release',
phases: [
{
items: [
{ price: '{{PRICE_DIGITAL}}', quantity: 1 },
],
iterations: 1,
}
],
});

Suppose I have, PRICE_PRINT and PRICE_DIGITAL as lineitems in my subscription previously. Now, i want the item PRICE_DIGITAL to be canceled after a month, but make PRICE_PRINT subscribed as it was in my subscription plan. Will the above do what i want?

#

@true perch

true perch
#

Did you try it?

honest trench
#

nope, i am wondering the behavior of this, if this fulfils what i am trying to achieve. I am new to stripe, need to look for how i can test it now instead of a month as part of testing.

true perch
#

I would recommend at least attempting something with the API, see if it works as you need. If not, then I can help

honest trench
#

Sure, I am assuming that the iteration 1 means 1 month from the date i was subscribed to earlier.

I will contact after trying it out.

true perch
#

An iteration is 1 cycle accoridng to the interval on the price_xxx. So could be monthly, yearly, etc

honest trench
#

Ok, I am assuming if the cycle is of 1 month, then the cycle starts from the date when i was subscribed to not when i am scheduling.

await this.stripe.subscriptionSchedules.create({
from_subscription: stripeSubscriptionId,
end_behavior: 'release',
phases: [
{
items: [{ price: priceId }],
iterations: 1,
},
],
});

I will test it out and let you know

#

And, how can i resume subscription forever?

#

await this.stripe.subscriptions.update(stripeSubscriptionId, {
cancel_at_period_end: false,
});

I want the behavior something like this for that item on resubscription.

true perch
#

Once all phases of the Schedule are complete, the Subscription will release and continue to cycle on the normal interval

honest trench
#

I am again confused. I have two scenarios, canceling subscription forever after a month and resuming subscription forever.

#

above code cancel the subscription after a month?

true perch
#

It doesn't cancel the Subscription no. You told me you wanted to remove a specific item after a month

honest trench
#

Yes i want to cancel the subscription for that one item only but the date being something similar to cancel_at_period_end: true.
And i want to be able to resubscribe to that subscription item again forever.

I want these two scenarios to achieve.

true perch
#

You can't 'cancel the subscription for that one item only'. If you cancel the Subscription, that will apply to all items

#

If you have a single Subscription with multiple items, and one of those items should be 'cancelled' (removed) then you'd update the Subscription to remove the item

honest trench
#

If i update the subscription, will the removed item be available until a month he/she is subscribed to?

true perch
#

No, if you update the Subscription directly it will be removed immediately. Which is why I originally recommended a Schedule as you can schedule those updates at specific times

honest trench
#

My simple requirement is that. I have 3 items. I can subscribe them one by one in a different stripe session or in a single stripe session with 2 or 3 line items.
I should be able to unsubscribe and resubscribe any one of them regardless of how the items were subsribed (in different stripe session or a single stripe session).

#

And i was using below to unsubscribe,
await this.stripe.subscriptions.update(stripeSubscriptionId, {
cancel_at_period_end: true,
});
when i used to subscribe one by one.

#

Now i need the same behavior for one of them even if i subscribe 3 items in a single session.

true perch
#

Ok, and I've described how to do that

honest trench
#

I am assuming,
await this.stripe.subscriptionSchedules.create({
from_subscription: stripeSubscriptionId,
end_behavior: 'release',
phases: [
{
items: [{ price: priceId }],
iterations: 1,
},
],
});

and

await this.stripe.subscriptionSchedules.create({
from_subscription: stripeSubscriptionId,
end_behavior: 'renew',
phases: [
{
items: [{ price: priceId }],
iterations: 1,
},
],
});

will do the work? for unsubsribing and resubscribing one of the item.
Or am i passing wrong values in end_behavior and iterations?

true perch
#

No, you'd need a single Schedule. You can't have multiple Schedules controlling a single Subscription

honest trench
#

Suppose the user wants to unsubscribe an item today, and after 4 days, he decides to resubsribe it, then how can i handle this scenario?

true perch
#

It depends on whether the Subscription is controlled by a Schedule or not

honest trench
#

Lets say that he bought a bundle of 3 items in a single session. Today, he unsubscribed one of the item. So, i handle with subscriptionSchedule so that the item will be available for him until the period_end of the month.
Again, if he wants to resubscribe, then how should i handle it?

true perch
#

Then you'd update the Schedule again to remove the phase

honest trench
#

So, seems like I should first fetch the schedules related to the subscription. Check if any schedule is already made and then decide to update if already scheduled otherwise create if already not scheduled?

true perch
#

Sounds reasonable

honest trench
#

Seems like I need to handle a lot of things in my side, if multiple items are present in a subscription. I need to check for each item and do likewise.
It would be great if stripe library provided partial update for subscription schedule so that I worry only about my current item on my side.

#

For now, I will handle by fetching the schedules first.

#

Thanks a ton. Your help means a lot to me. Will catch you later if something doesn't work out on stripe.

true perch
#

np!

honest trench
#

And another concern, is there any documentation of endbehavior types?

true perch
#

API reference explains them:

Behavior of the subscription schedule and underlying subscription when it ends. Possible values are release or cancel with the default being release. release will end the subscription schedule and keep the underlying subscription running.cancel will end the subscription schedule and cancel the underlying subscription.
https://stripe.com/docs/api/subscription_schedules/object#subscription_schedule_object-end_behavior

terse irisBOT
honest trench
#

await this.stripe.subscriptionSchedules.create({
from_subscription: stripeSubscriptionId,
end_behavior: 'release',
phases: [
{
items: [{ price: priceId1 }, { price: priceId2 }, { price: priceId3 }],
iterations: 1,
},
{
items: [{ price: priceId1 }, { price: priceId2 }],
iterations: 11,
},
],
});

Seems like the second phase runs for the next 11 months. Now, what about next year? I want the second phase to run forver. Or can i simply put something like iterations: 99999999999 instead of 11?

river glacier
#

Hi! I'm taking over this thread.

#

But by default it will simply continue forever.

#

So the second phase could have iteration: 1, and it will continue foerver.

honest trench
#

My requirement is that:
I already have 3 line items in a monthly subscription in a single session.
I want one of them to unsubscribe. To achieve this, i was suggested to use schedules.

Can you update the above code for me? I am considering priceIds for the items as: priceId1, priceId2 and priceId3. I want priceId3 to be canceled at the end of the period but continue subscription for other items

#

@river glacier

river glacier
#

The code you shared looks correct to me.

honest trench
river glacier
#

In your example you have two phases:

  • The first pahse is for one iteration
  • The second phase is 11 iteration
    But once the schedule reach the end of the last phase, it will simply continue forever.
honest trench
#

That means all the items that were originally subscribed to for a monthly package, will be subscribed again after that period (12 months).
I don't want that to happen. I want the item with priceId3 to be unsubscribed forever after first month.

river glacier
#

No, sorry if I'm not clear.

#
  • The first pahse is for one iteration, with 3 prices
  • The second phase is 11 iteration, with 2 prices
  • Then the subscription will continue forever with 2 prices
honest trench
#

Even regardless of the original subscription having 3 items subscribed, the subscription will continue for the items present in the last phase of the schedule.
That means keeping iteration = 1 in second phase,

await this.stripe.subscriptionSchedules.create({
from_subscription: stripeSubscriptionId,
end_behavior: 'release',
phases: [
{
items: [{ price: priceId1 }, { price: priceId2 }, { price: priceId3 }],
iterations: 1,
},
{
items: [{ price: priceId1 }, { price: priceId2 }],
iterations: 1,
},
],
});

will do the work for me? priceId3 will be subscribed for first month only and other items will be subscribed forever?

river glacier
#

Even regardless of the original subscription having 3 items subscribed, the subscription will continue for the items present in the last phase of the schedule.
Yes exactly.

#

That means keeping iteration = 1 in second phase,
You can yes, it wouldn't change anything

#

will do the work for me? priceId3 will be subscribed for first month only and other items will be subscribed forever?
Correct

honest trench
#

Ok, i got it. I am also assuming that the webhook will be called after the end of first cycle of the schedule for that item saying that the item is canceled?

river glacier
#

Ok, i got it. I am also assuming that the webhook will be called after the end of first cycle of the schedule for that item saying that the item is canceled?
I guess you'll get a customer.subscription.updated yes. But again I recommend testing this in test mode.

honest trench
#

I have to modify the schedule in between. Please send me the link of the docs to retrieve the schedule for that particular subsriptionId (not schedulesubscriptionId)

river glacier
terse irisBOT
honest trench
#

Thanks a lot @river glacier @true perch @timber kestrel