#kshitij khanal
1 messages · Page 1 of 1 (latest)
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
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.
you can probably delete a single subscription item using https://stripe.com/docs/api/subscription_items/delete
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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.
Then you'll need to use a Schedule: https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases
i.e. configure a phase to remove the item after X amount of iterations
I am trying it out.
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
Did you try it?
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.
I would recommend at least attempting something with the API, see if it works as you need. If not, then I can help
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.
An iteration is 1 cycle accoridng to the interval on the price_xxx. So could be monthly, yearly, etc
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.
Once all phases of the Schedule are complete, the Subscription will release and continue to cycle on the normal interval
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?
It doesn't cancel the Subscription no. You told me you wanted to remove a specific item after a month
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.
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
If i update the subscription, will the removed item be available until a month he/she is subscribed to?
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
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.
Ok, and I've described how to do that
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?
No, you'd need a single Schedule. You can't have multiple Schedules controlling a single Subscription
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?
It depends on whether the Subscription is controlled by a Schedule or not
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?
Then you'd update the Schedule again to remove the phase
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?
Sounds reasonable
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.
np!
And another concern, is there any documentation of endbehavior types?
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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?
Hi! I'm taking over this thread.
Once the schedule ends, what will happen depends on this parameter: https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-end_behavior
But by default it will simply continue forever.
So the second phase could have iteration: 1, and it will continue foerver.
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
The code you shared looks correct to me.
I am a bit confused here. Does iteration: 1 mean continuing forever or for one cycle (1 month)?
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.
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.
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
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?
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
I recommend doing some tests in test mode with Test Clock to make sure everything works as expected: https://stripe.com/docs/billing/testing/test-clocks
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?
Sure. Thanks.
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 acustomer.subscription.updatedyes. But again I recommend testing this in test mode.
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)
If you have the Subscription ID, then the Subscription Schedule can be found in the Subscription itself: https://stripe.com/docs/api/subscriptions/object#subscription_object-schedule
Thanks a lot @river glacier @true perch @timber kestrel