#Pål
1 messages · Page 1 of 1 (latest)
To schedule a change in the next billing cycle, the steps will be:
- Create a subscription schedule from existing subscription: https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription
- Update the subscription schedule that includes the current phase in phase 0 and new changes in next phase for next billing cycle
For phase 0, do I need to copy all the fields from SubscriptionSchedulePhase to SubscriptionSchedulePhaseParams or will it merge fields from the new phase 0?
A snippet
params := stripe.SubscriptionScheduleParams{
Params: stripe.Params{
Context: ctx,
},
Phases: []*stripe.SubscriptionSchedulePhaseParams{
{
// Should I manually map these fields to the existing phase 0?
AddInvoiceItems: []*stripe.SubscriptionSchedulePhaseAddInvoiceItemParams{},
ApplicationFeePercent: new(float64),
AutomaticTax: &stripe.SubscriptionSchedulePhaseAutomaticTaxParams{},
BillingCycleAnchor: new(string),
BillingThresholds: &stripe.SubscriptionBillingThresholdsParams{},
CollectionMethod: new(string),
Coupon: new(string),
Currency: new(string),
DefaultPaymentMethod: new(string),
DefaultTaxRates: []*string{},
Description: new(string),
EndDate: new(int64),
EndDateNow: new(bool),
InvoiceSettings: &stripe.SubscriptionSchedulePhaseInvoiceSettingsParams{},
Items: []*stripe.SubscriptionSchedulePhaseItemParams{},
Iterations: new(int64),
Metadata: map[string]string{},
OnBehalfOf: new(string),
ProrationBehavior: new(string),
StartDate: new(int64),
},
{
AutomaticTax: &stripe.SubscriptionSchedulePhaseAutomaticTaxParams{
Enabled: stripe.Bool(true),
},
Items: []*stripe.SubscriptionSchedulePhaseItemParams{
{
Price: &priceID,
},
},
},
},
}
You can copy the phase 0 and set in the update subscription schedule api if everything keeps the same
Yes, that makes sense. The only issue is that these are two different types (SubscriptionSchedulePhase and SubscriptionSchedulePhaseParams). Copying fields one by one seems error-prone.
Not understanding the issue
Use case:
I have a lot of subscriptions. I want to add a phase for each subscription starting at the end of the current period.
To do this I'm using the update schedule API (https://stripe.com/docs/api/subscription_schedules/update). How do I best add a second phase, leaving the first phase unchanged?
You need to pass in all existing phases when updating a Sub Schedule, otherwise their omission is taken as a request to remove them
I understand, but in the go SDK it's not possible to pass a phase from an existing subscription schedule because the types and fields does not match. See this example: https://go.dev/play/p/vdnzJdE7-Sj
I can raise a feature request in the SDK repo if this is not supported
I'm not very familiar with Go, but can you not 'cast' types. So you'd pass your existing phase as the SubscriptionSchedulePhaseParams type?
You could approach it that way in TS for example
I can't cast the type, no. This issue is specific to the go SDK. I'll create a feature request in the SDK repo 😉
Yeah that sounds like a good next step. Sorry I couldn't be more help
No problem, I still learned something. Thanks for your help!