#sveba-subscription-schedule
1 messages ยท Page 1 of 1 (latest)
Hello ๐
Just so that I'm clear, are you trying to migrate existing subscriptions to a schedule or just trying to create a new subscription that is attached to a schedule?
my project is still in development, there is no existing subscriptions. I'm just trying to change my code so it works with subscription schedules
Gotcha. How are you creating the SubscriptionSchedules exactly? There wouldn't be a subscription ID until the schedule kicks in
const schedule = await stripe.subscriptionSchedules.create(
{
customer: customer.id,
start_date: "now",
end_behavior: "release",
phases: _initialPrice
? [
{
items: [{ price: _initialPrice }],
iterations: 1,
},
{
items: [{ price: _recurringPrice }],
},
]
: [
{
items: [{ price: _recurringPrice }],
},
],
},
{
stripeAccount: stripeAccountId,
}
);
I was getting a subscription id by calling schedule.subscription
I thought if I maybe expand the subscription schedule with "latest_invoice.payment_intent" then I could use the subscription id to get the subscription which would allowed me to get the client secret, but it throw an error "This property cannot be expanded (latest_invoice)."
you'd also likely need to expand the subscription too
can you share the code that you're currently using to expand?
here's how I expand it
const schedule = await stripe.subscriptionSchedules.create(
{
customer: customer.id,
start_date: "now",
end_behavior: "release",
expand: ["latest_invoice.payment_intent"],
phases: _initialPrice
? [
{
items: [{ price: _initialPrice }],
iterations: 1,
},
{
items: [{ price: _recurringPrice }],
},
]
: [
{
items: [{ price: _recurringPrice }],
},
],
},
{
stripeAccount: stripeAccountId,
}
);
but I'm only create the subscription schedule, not subscription. not sure how can I expand it then
ah okay, mostly need to change this to expand: ["subscription.latest_invoice.payment_intent"]
ohh I can I'll try it right now and will let you know, thanks
I did what you said, but subscription.latest_invoice.payment_intent is null right now
can you share the invoice id?
in_1LXmhrPqGmcXJ4PgywR5EFYs
seems like the invoice is still in draft state
that's why there isn't a payment intent there
how could i then get a client secret to send over to frontend?
Apologies for the delay. Invoices are auto-advanced to open state after 1 hour window. Or else, you can call the API to finalize the invoice and that would create a PaymentIntent
https://stripe.com/docs/api/invoices/finalize
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Thank you