#ajivrajani_code
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1265424104547287071
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there
Hi! ๐
Here's what I did to create a subscription schedule:
schedule, err := sc.sClient.SubscriptionSchedules.New(&stripe.SubscriptionScheduleParams{
FromSubscription: stripe.String(req.SubscriptionID),
})
if err != nil {
return nil, errors.Wrapf(err, "creating new subscription schedule for subscriptionID: %s", req.SubscriptionID)
}
// Update the schedule with new phase
params := &stripe.SubscriptionScheduleParams{
Phases: []*stripe.SubscriptionSchedulePhaseParams{
// Phase 0: this is the existing subscription phase. But what about other subscription properties?
{
Items: []*stripe.SubscriptionSchedulePhaseItemParams{
{
Price: stripe.String(schedule.Phases[0].Items[0].Price.ID),
Quantity: stripe.Int64(schedule.Phases[0].Items[0].Quantity),
},
},
StartDate: stripe.Int64(schedule.Phases[0].StartDate),
EndDate: stripe.Int64(schedule.Phases[0].EndDate),
},
// Phase 1: this is the new schedule phase
{
Items: []*stripe.SubscriptionSchedulePhaseItemParams{
{
Price: stripe.String(req.PriceID),
// the quantity of the new phase remains the same as the ongoing subscription
Quantity: stripe.Int64(schedule.Phases[0].Items[0].Quantity),
},
},
},
},
}
No, not exactly. You'll need to split this up into two requests: Create a Schedule from an existing Subscription, then update the newly-created Schedule to add a second phase
Right - that's exactly what I did ^
Which properties are you referring to exactly? Can you share the Subscription ID or the Schedule ID?
When I "update" the newly created subscription, I am required to "build" phase 0 (pertaining to ongoing subscription) once again.
Right, since you need to pass any current and future phases when updating a Schedule
What about properties like "collect tax automatically", "collection methods" that were set on the original subscription? Will they be lost when I "redefine" this phase 0?
Do you have a Subscription ID I can review? I'll test on my end with a similarly-created Subscription
Sure! Give me a minute please, I will re-create that subscription and share the ID with you
SubscriptionID: sub_1PfqbeIp6MB4p4mql98YWvMb
Note: Tax collection = true, payment method = send_invoice and I've set a custom footer description on the subscription
In my phase [1], I want to change the priceID only
Wrong thread?
@celest violet Please refrain from chatting in others' threads. You'll need to talk to our support team about this: https://support.stripe.com/contact/
I'm sorry, I was just looking for the answer because I contacted the support team and did not receive any response
We can't assist with account status issues in this Discord channel. I recommend waiting on a response from support or contacting them again
@dire condor I see you created this via the Dashboard. Was this just for testing purposes or do you intend to create these via the Dashboard in live mode?
Ah, this was only for testing purpose. Do you need me to create one using the API?
Everything is API driven in the live mode. Curious though - should that make any difference?
It shouldn't but just wanted to make sure we're testing in the same way
Gotcha. For now let's stick to dashboards if you don't mind - that way I can create/edit the subscriptions quickly.
@celest violet looks like you're in the wrong place, this thread is for someone else's question.
- If you have your own thread please chat there.
- If you have a question or a followup to a closed thread use one of the buttons in https://discord.com/channels/841573134531821608/842637025524842496 to get help (we don't reopen closed threads).
Note that posting inappropriate messages in other people's threads is against the rules. No worries if this was just an honest mistake, but anyone who violates the rules multiple times will be removed from this server.
I'm sorry
Sorry, still testing this out
I'll need to test via the API. Creating a Schedule and adding a phase via the Dashboard keeps all previously-configured properties on the original Subscription so this isn't necessarily the best test
Hmm I see. Makes sense, thank you. Let me know if you need any help from me. Appreciate your help ๐
I am guessing you are going to test this using a similar API call - #1265424104547287071 message?
yep!
Another question @queen compass :
Let's say I created the subscription -> created a new schedule with phase 0 and phase 1.
Now let's I want to update the quantity of ongoing subscription from 10 to 20.
Can I do that with subscription update API? Or do I need to call a combination of subscription update + schedule update APIs so that the phases (that will kick after a year) will also have quantity = 20 (updated amount)?
I've asked two separate questions. We can talk about this one after we figure out the first part.
Okay, it's sufficient to pass just the Price on the first/current phase and the second phase when updating the Schedule. The previously-set automatic tax and collection method remain unchanged on the Subscription
You'll want to do something like this: https://docs.stripe.com/billing/subscriptions/subscription-schedules/use-cases#changing-subscriptions
Ah okay, so similar to what I originally mentioned - that's good news. Thanks for confirming!
As for your other question
Once a Subscription is managed by a Schedule, you should only update the Schedule going forward. You can update quantity on a phase
So IIUC, if I want to update the quantity on an ongoing subscription immediately, I will have to iterate through all the phases of the attached schedule and update their quantities. Is that right?
update the quantity on an ongoing subscription immediately
What do you mean by this exactly? Let's say a customer is upgrading from a quantity of 1 to a quantity of 10. If their Subscription is already managed by a Schedule and that Schedule has multiple phases that still use a quantity of 1, you will need to update the Schedule and ensure that each phase uses a quantity of 10 instead
I meant I want to update the quantity now as opposed to scheduling this quantity update
Gotcha. So here's what the updates implementation can look like:
On getting an update request for a subscription from customer:
// Get subscription from Stripe
// Check if it has a schedule
// If yes:
// Update the subscription quantity of _every_ phase in this schedule
// If no:
// Update the ongoing subscription quantity
Does that sound reasonable?
I think so. I recommend testing this in test mode + the API, as well as working with test clocks to see the phases in action: https://docs.stripe.com/billing/testing/test-clocks/api-advanced-usage
I wish this was simplified under the hood where I would just need to update the ongoing subscription ๐ Oh well - that would defeat the purpose of a schedule I guess. Thanks for your help and patience today, I really appreciate it.
I will test this and start a new thread if needed.
Have a wonderful rest of your day!