#Jonas Reif-subs-schedule
1 messages · Page 1 of 1 (latest)
You'd have a schedule with a phases field that mirrors the 3 month schedule you want, and then set end_behaviour: 'cancel'
So first I have to create a schedule like this:
subscription = "our created subscription"
schedule = Stripe::SubscriptionSchedule.create({
from_subscription: subscription.id
})
And then in a next api call I update this like
Stripe::SubscriptionSchedule.update(
schedule.id,
{
phases: [
{
items: [
{
price: subscription.price.id,
quantity: 1,
},
],
iterations: 3,
},
],
},
)
```
Is that correct like this?
OOO, why must you create a subscription initially then the schedule?
You're missing end_behavior: https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-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.
ah sorry
Stripe::SubscriptionSchedule.update(
schedule.id,
{
end_behavior: 'cancel'
phases: [
{
items: [
{
price: subscription.price.id,
quantity: 1,
},
],
iterations: 3,
},
],
},
)
```
Because we are using stripe checkout and there you cannot create Subscription Schedules
That looks good. Have you tested it with clocks? https://stripe.com/docs/billing/testing/test-clocks
Thanks for the clocks link. Never tried it but will try it now...
Helps test these real world scenarios in warp speed 😄
This thread has been archived. If you need help with anything else please ask in #dev-help or contact Stripe Support: https://support.stripe.com/contact
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
Hi again,
Thanks for reopening...
I tried to create the schedule from the subscription.
As response I get following:
So there is already a "phase" with an enddate.
When I now call:
Stripe::SubscriptionSchedule.update(
schedule.id,
{
end_behavior: 'cancel',
phases: [
{
items: [
{
price: subscription.price.id,
quantity: 1,
},
],
iterations: 3,
},
],
},
)
Then I get following error:
{
"error": {
"message": "The subscription schedule update is missing at least one phase with a `start_date` to anchor end dates to.",
"type": "invalid_request_error"
}
}
What am I doing wrong?
I also tried to add a star_date to this phase, but then I get
((Status 400) (Request req_xNdMpo0mZT4PNK) You can not modify the start date of the current phase.
I believe you need to pass current and future phases while updating the schedule
https://stripe.com/docs/billing/subscriptions/subscription-schedules#updating
As far as I know I don't think you can make much changes to the current phase except for ending it.
Let's step back a bit, what are you actually trying to do/update?
ok.
We have a Stripe Checkout for a monthly subscription. Whenever a user make a subscription we want to end it automatically after 3 month (It should be a kind of installment payment)
First idea was to use cancel_at.
So whenever we get a webhook that the subscription was created, we set the cancel_at date to 3 month from now.
But the problem is by using the cancel_at the user is still able to cancel the the subscription after e.g. 1 month in the customer portal. And the user also does not see the "cancel_at" date in the customer portal... (we have also normal subscriptions, so hiding the cancel button completly is also not an option)
Thats how the customer portal looks like:
So even the subscription is cancelled you see a "Cancel" button and that the subscription will be renewed in one month....
Thats why the second idea was to use the Subscription Schedule.
So whenever the user is making the subscription we want to create a Subscription Schedule to cancel the subscription after 3 month
So the main question is:
How could I generate such a Subscription Schedule which cancels the subscription after 3 month from an existing subscription
Hope its clearer now? 🙂
Hello, hanzo had to step out but I can help here. Does a subscription on a schedule have a clearer UI in the portal? I would think that it would also not show the cancel date there
Hi Pompey,
I dont know. Thats what I also want to try.
But at least the cancel button is not there (according to docs)
Gotcha. Looking in to how to do this for an existing subscription
Thanks
So to create a schedule from an existing subscription, you pass from_subscription='sub_123'
https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription
And to get it to cancel after three months, you would want to set the subscription's end_behavior to cancel and update the first phrase of the subscription to only last 3 iterations 'iterations': 12,
So I think you'd need to make one API call to create the schedule from the subscription and one to update the schedule to add the cancelation info
Yes I think thats what we already have discussed above:
First API call would be:
subscription = "our created subscription"
schedule = Stripe::SubscriptionSchedule.create({
from_subscription: subscription.id
})
But how does the second api call look like?
You would be setting the end_behavior and passing in a modified version of your one phase to the phases parameter. My test code is in Python but here is what that looks like if it gives you a better idea:
phase = schedule.phases.data[0]
phase.iterations = 3
schedule = stripe.SubscriptionSchedule.modify(
schedule.id,
end_behavior='cancel'
phases=[
phase
]
)```
You don't actually need to re-use the same phase object, I just like to as it makes things easier
ok thanks.
I will try it now 🙂
Ok thats the final code:
schedule = Stripe::SubscriptionSchedule.create({
from_subscription: request.result.subscription[:external_id]
})
phase = schedule.phases[0]
phase.end_date = nil
phase.iterations = 3
Stripe::SubscriptionSchedule.update(
schedule.id,
{
end_behavior: "cancel",
phases: [
phase.to_hash
]
}
)
The cancel button is gone.
But I think still a missleading translation😦
What does the translation say?
Unfortunately I don't think you can customize that string. You can update the description on your subscription but that text might not be prominent enough to communicate what you are looking to communicate
Sth like
"Company XY has specified/set an update of your plan for the 24. September 2022."
mhm let me check that
I'm still trying it out