#WpgJetsFan13-schedule-subscription
1 messages ยท Page 1 of 1 (latest)
hello, can you explain in detail what you're trying to do?
it would help to understand like:
1/ what Subscription your CheckoutSession is creating e.g. $5/month
2/ what you want to change it to, using a SubscriptionSchedule? like "$2/month first two months, then $10/month after" etc
$5/month for 12 months
I don't want to change anything, I just want it to end after 12 months
unit_amount: 500,
currency: 'cad',
recurring: {
interval: 'month',
interval_count: 1
},
product: product.id
but how do I make it end after 12 months
ah I see, so "create Subscription using Checkout for $5/month, then use SubSchedule to cancel it after 12 months", right?
that's what I'm trying to do
ok looking
but if I create subscriptionschedule from existing subscription id, then I can't set phases
and the phase items is where I can set 'iterations'
tried to add it like this, when I receive the customer.subscription.created webhook:
const schedule = await client.subscriptionSchedules.create({
from_subscription: event.data.object.id
});
await client.subscriptionSchedules.update(schedule.id, {
phases: [
{
items: [
{
price: 'price_1LcDjeCT5ZiUAGNjrR4VLL9o',
quantity: 1
}
],
iterations: 12,
start_date: Math.floor(Date.now()/1000)
}
]
});
Response:
StripeInvalidRequestError: You can not modify the start date of the current phase.
Without start_date set, it also gave me an error saying I needed to set the start_date to anchor the subscription
I wonder if it's as simple as just setting an end date?
nvm, you can't set that. I think maybe I just have to listen to a webhook for payment and then count down in my database from 12
there is a way to do this with SubSchedules, still looking
just spinning up a quick sample
nice
ah I think I have what you need
when you update the SubSchedule, you need to pass start_date as the subscription.start_date , you're setting it to "now" which is different from the Subscription's start_date
and also, specify end_behavior: "release"
await client.subscriptionSchedules.update(schedule.id, {
phases: [
{
items: [
{
price: 'price_1LcDjeCT5ZiUAGNjrR4VLL9o',
quantity: 1
}
],
iterations: 12,
start_date: event.data.object.start_date
// see line above
}
],
end_behavior: "release",
// see line above
});
try that, log out the SubscriptionSchedule object and look at its current_phase.end_date which should end in a year from your start date
thanks, I'll try that out.
I still get the same error: StripeInvalidRequestError: You can not modify the start date of the current phase.
can you share the request ID for the request you made? From https://dashboard.stripe.com/test/logs/
I'll have to make the request again hang on
req_9i7KXWT6MiK4Kx
I wonder if I just set the cancel_at to a future date 1 year from now with subscriptions.update, if that would work
๐ Hopping in since @visual summit has to head out soon - give me a minute to catch up
actually, I think it worked, what @visual summit suggested. I just had a relic in my code that messed it up
๐ good to hear!
yup, it created the timestamp for 1 year from now. nice! Thanks! So glad I convinced my boss to switch to Stripe from Square, you guys are far more helpful