github.com/stripe/stripe-go/v76@v76.25.0/subscriptionschedule.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 package stripe 8 9 import ( 10 "encoding/json" 11 "github.com/stripe/stripe-go/v76/form" 12 ) 13 14 // Possible values are `phase_start` or `automatic`. If `phase_start` then billing cycle anchor of the subscription is set to the start of the phase when entering the phase. If `automatic` then the billing cycle anchor is automatically modified as needed when entering the phase. For more information, see the billing cycle [documentation](https://stripe.com/docs/billing/subscriptions/billing-cycle). 15 type SubscriptionScheduleDefaultSettingsBillingCycleAnchor string 16 17 // List of values that SubscriptionScheduleDefaultSettingsBillingCycleAnchor can take 18 const ( 19 SubscriptionScheduleDefaultSettingsBillingCycleAnchorAutomatic SubscriptionScheduleDefaultSettingsBillingCycleAnchor = "automatic" 20 SubscriptionScheduleDefaultSettingsBillingCycleAnchorPhaseStart SubscriptionScheduleDefaultSettingsBillingCycleAnchor = "phase_start" 21 ) 22 23 // Type of the account referenced. 24 type SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuerType string 25 26 // List of values that SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuerType can take 27 const ( 28 SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuerTypeAccount SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuerType = "account" 29 SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuerTypeSelf SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuerType = "self" 30 ) 31 32 // Behavior of the subscription schedule and underlying subscription when it ends. Possible values are `release` or `cancel` with the default being `release`. `release` will end the subscription schedule and keep the underlying subscription running. `cancel` will end the subscription schedule and cancel the underlying subscription. 33 type SubscriptionScheduleEndBehavior string 34 35 // List of values that SubscriptionScheduleEndBehavior can take 36 const ( 37 SubscriptionScheduleEndBehaviorCancel SubscriptionScheduleEndBehavior = "cancel" 38 SubscriptionScheduleEndBehaviorNone SubscriptionScheduleEndBehavior = "none" 39 SubscriptionScheduleEndBehaviorRelease SubscriptionScheduleEndBehavior = "release" 40 SubscriptionScheduleEndBehaviorRenew SubscriptionScheduleEndBehavior = "renew" 41 ) 42 43 // Possible values are `phase_start` or `automatic`. If `phase_start` then billing cycle anchor of the subscription is set to the start of the phase when entering the phase. If `automatic` then the billing cycle anchor is automatically modified as needed when entering the phase. For more information, see the billing cycle [documentation](https://stripe.com/docs/billing/subscriptions/billing-cycle). 44 type SubscriptionSchedulePhaseBillingCycleAnchor string 45 46 // List of values that SubscriptionSchedulePhaseBillingCycleAnchor can take 47 const ( 48 SubscriptionSchedulePhaseBillingCycleAnchorAutomatic SubscriptionSchedulePhaseBillingCycleAnchor = "automatic" 49 SubscriptionSchedulePhaseBillingCycleAnchorPhaseStart SubscriptionSchedulePhaseBillingCycleAnchor = "phase_start" 50 ) 51 52 // Type of the account referenced. 53 type SubscriptionSchedulePhaseInvoiceSettingsIssuerType string 54 55 // List of values that SubscriptionSchedulePhaseInvoiceSettingsIssuerType can take 56 const ( 57 SubscriptionSchedulePhaseInvoiceSettingsIssuerTypeAccount SubscriptionSchedulePhaseInvoiceSettingsIssuerType = "account" 58 SubscriptionSchedulePhaseInvoiceSettingsIssuerTypeSelf SubscriptionSchedulePhaseInvoiceSettingsIssuerType = "self" 59 ) 60 61 // If the subscription schedule will prorate when transitioning to this phase. Possible values are `create_prorations` and `none`. 62 type SubscriptionSchedulePhaseProrationBehavior string 63 64 // List of values that SubscriptionSchedulePhaseProrationBehavior can take 65 const ( 66 SubscriptionSchedulePhaseProrationBehaviorAlwaysInvoice SubscriptionSchedulePhaseProrationBehavior = "always_invoice" 67 SubscriptionSchedulePhaseProrationBehaviorCreateProrations SubscriptionSchedulePhaseProrationBehavior = "create_prorations" 68 SubscriptionSchedulePhaseProrationBehaviorNone SubscriptionSchedulePhaseProrationBehavior = "none" 69 ) 70 71 // The present status of the subscription schedule. Possible values are `not_started`, `active`, `completed`, `released`, and `canceled`. You can read more about the different states in our [behavior guide](https://stripe.com/docs/billing/subscriptions/subscription-schedules). 72 type SubscriptionScheduleStatus string 73 74 // List of values that SubscriptionScheduleStatus can take 75 const ( 76 SubscriptionScheduleStatusActive SubscriptionScheduleStatus = "active" 77 SubscriptionScheduleStatusCanceled SubscriptionScheduleStatus = "canceled" 78 SubscriptionScheduleStatusCompleted SubscriptionScheduleStatus = "completed" 79 SubscriptionScheduleStatusNotStarted SubscriptionScheduleStatus = "not_started" 80 SubscriptionScheduleStatusReleased SubscriptionScheduleStatus = "released" 81 ) 82 83 // Retrieves the list of your subscription schedules. 84 type SubscriptionScheduleListParams struct { 85 ListParams `form:"*"` 86 // Only return subscription schedules that were created canceled the given date interval. 87 CanceledAt *int64 `form:"canceled_at"` 88 // Only return subscription schedules that were created canceled the given date interval. 89 CanceledAtRange *RangeQueryParams `form:"canceled_at"` 90 // Only return subscription schedules that completed during the given date interval. 91 CompletedAt *int64 `form:"completed_at"` 92 // Only return subscription schedules that completed during the given date interval. 93 CompletedAtRange *RangeQueryParams `form:"completed_at"` 94 // Only return subscription schedules that were created during the given date interval. 95 Created *int64 `form:"created"` 96 // Only return subscription schedules that were created during the given date interval. 97 CreatedRange *RangeQueryParams `form:"created"` 98 // Only return subscription schedules for the given customer. 99 Customer *string `form:"customer"` 100 // Specifies which fields in the response should be expanded. 101 Expand []*string `form:"expand"` 102 // Only return subscription schedules that were released during the given date interval. 103 ReleasedAt *int64 `form:"released_at"` 104 // Only return subscription schedules that were released during the given date interval. 105 ReleasedAtRange *RangeQueryParams `form:"released_at"` 106 // Only return subscription schedules that have not started yet. 107 Scheduled *bool `form:"scheduled"` 108 } 109 110 // AddExpand appends a new field to expand. 111 func (p *SubscriptionScheduleListParams) AddExpand(f string) { 112 p.Expand = append(p.Expand, &f) 113 } 114 115 // The connected account that issues the invoice. The invoice is presented with the branding and support information of the specified account. 116 type SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuerParams struct { 117 // The connected account being referenced when `type` is `account`. 118 Account *string `form:"account"` 119 // Type of the account referenced in the request. 120 Type *string `form:"type"` 121 } 122 123 // All invoices will be billed using the specified settings. 124 type SubscriptionScheduleDefaultSettingsInvoiceSettingsParams struct { 125 // The account tax IDs associated with the subscription schedule. Will be set on invoices generated by the subscription schedule. 126 AccountTaxIDs []*string `form:"account_tax_ids"` 127 // Number of days within which a customer must pay invoices generated by this subscription schedule. This value will be `null` for subscription schedules where `collection_method=charge_automatically`. 128 DaysUntilDue *int64 `form:"days_until_due"` 129 // The connected account that issues the invoice. The invoice is presented with the branding and support information of the specified account. 130 Issuer *SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuerParams `form:"issuer"` 131 } 132 133 // Object representing the subscription schedule's default settings. 134 type SubscriptionScheduleDefaultSettingsParams struct { 135 Params `form:"*"` 136 // A non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice total that will be transferred to the application owner's Stripe account. The request must be made by a platform account on a connected account in order to set an application fee percentage. For more information, see the application fees [documentation](https://stripe.com/docs/connect/subscriptions#collecting-fees-on-subscriptions). 137 ApplicationFeePercent *float64 `form:"application_fee_percent,high_precision"` 138 // Default settings for automatic tax computation. 139 AutomaticTax *SubscriptionAutomaticTaxParams `form:"automatic_tax"` 140 // Can be set to `phase_start` to set the anchor to the start of the phase or `automatic` to automatically change it if needed. Cannot be set to `phase_start` if this phase specifies a trial. For more information, see the billing cycle [documentation](https://stripe.com/docs/billing/subscriptions/billing-cycle). 141 BillingCycleAnchor *string `form:"billing_cycle_anchor"` 142 // Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period. Pass an empty string to remove previously-defined thresholds. 143 BillingThresholds *SubscriptionBillingThresholdsParams `form:"billing_thresholds"` 144 // Either `charge_automatically`, or `send_invoice`. When charging automatically, Stripe will attempt to pay the underlying subscription at the end of each billing cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`. Defaults to `charge_automatically` on creation. 145 CollectionMethod *string `form:"collection_method"` 146 // ID of the default payment method for the subscription schedule. It must belong to the customer associated with the subscription schedule. If not set, invoices will use the default payment method in the customer's invoice settings. 147 DefaultPaymentMethod *string `form:"default_payment_method"` 148 // Subscription description, meant to be displayable to the customer. Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces and certain local payment methods UIs. 149 Description *string `form:"description"` 150 // All invoices will be billed using the specified settings. 151 InvoiceSettings *SubscriptionScheduleDefaultSettingsInvoiceSettingsParams `form:"invoice_settings"` 152 // The account on behalf of which to charge, for each of the associated subscription's invoices. 153 OnBehalfOf *string `form:"on_behalf_of"` 154 // The data with which to automatically create a Transfer for each of the associated subscription's invoices. 155 TransferData *SubscriptionTransferDataParams `form:"transfer_data"` 156 } 157 158 // The coupons to redeem into discounts for the item. 159 type SubscriptionSchedulePhaseAddInvoiceItemDiscountParams struct { 160 // ID of the coupon to create a new discount for. 161 Coupon *string `form:"coupon"` 162 // ID of an existing discount on the object (or one of its ancestors) to reuse. 163 Discount *string `form:"discount"` 164 // ID of the promotion code to create a new discount for. 165 PromotionCode *string `form:"promotion_code"` 166 } 167 168 // A list of prices and quantities that will generate invoice items appended to the next invoice for this phase. You may pass up to 20 items. 169 type SubscriptionSchedulePhaseAddInvoiceItemParams struct { 170 // The coupons to redeem into discounts for the item. 171 Discounts []*SubscriptionSchedulePhaseAddInvoiceItemDiscountParams `form:"discounts"` 172 // The ID of the price object. 173 Price *string `form:"price"` 174 // Data used to generate a new [Price](https://stripe.com/docs/api/prices) object inline. 175 PriceData *InvoiceItemPriceDataParams `form:"price_data"` 176 // Quantity for this item. Defaults to 1. 177 Quantity *int64 `form:"quantity"` 178 // The tax rates which apply to the item. When set, the `default_tax_rates` do not apply to this item. 179 TaxRates []*string `form:"tax_rates"` 180 } 181 182 // The account that's liable for tax. If set, the business address and tax registrations required to perform the tax calculation are loaded from this account. The tax transaction is returned in the report of the connected account. 183 type SubscriptionSchedulePhaseAutomaticTaxLiabilityParams struct { 184 // The connected account being referenced when `type` is `account`. 185 Account *string `form:"account"` 186 // Type of the account referenced in the request. 187 Type *string `form:"type"` 188 } 189 190 // Automatic tax settings for this phase. 191 type SubscriptionSchedulePhaseAutomaticTaxParams struct { 192 // Enabled automatic tax calculation which will automatically compute tax rates on all invoices generated by the subscription. 193 Enabled *bool `form:"enabled"` 194 // The account that's liable for tax. If set, the business address and tax registrations required to perform the tax calculation are loaded from this account. The tax transaction is returned in the report of the connected account. 195 Liability *SubscriptionSchedulePhaseAutomaticTaxLiabilityParams `form:"liability"` 196 } 197 198 // The coupons to redeem into discounts for the schedule phase. If not specified, inherits the discount from the subscription's customer. Pass an empty string to avoid inheriting any discounts. 199 type SubscriptionSchedulePhaseDiscountParams struct { 200 // ID of the coupon to create a new discount for. 201 Coupon *string `form:"coupon"` 202 // ID of an existing discount on the object (or one of its ancestors) to reuse. 203 Discount *string `form:"discount"` 204 // ID of the promotion code to create a new discount for. 205 PromotionCode *string `form:"promotion_code"` 206 } 207 208 // The connected account that issues the invoice. The invoice is presented with the branding and support information of the specified account. 209 type SubscriptionSchedulePhaseInvoiceSettingsIssuerParams struct { 210 // The connected account being referenced when `type` is `account`. 211 Account *string `form:"account"` 212 // Type of the account referenced in the request. 213 Type *string `form:"type"` 214 } 215 216 // All invoices will be billed using the specified settings. 217 type SubscriptionSchedulePhaseInvoiceSettingsParams struct { 218 // The account tax IDs associated with this phase of the subscription schedule. Will be set on invoices generated by this phase of the subscription schedule. 219 AccountTaxIDs []*string `form:"account_tax_ids"` 220 // Number of days within which a customer must pay invoices generated by this subscription schedule. This value will be `null` for subscription schedules where `billing=charge_automatically`. 221 DaysUntilDue *int64 `form:"days_until_due"` 222 // The connected account that issues the invoice. The invoice is presented with the branding and support information of the specified account. 223 Issuer *SubscriptionSchedulePhaseInvoiceSettingsIssuerParams `form:"issuer"` 224 } 225 226 // The coupons to redeem into discounts for the subscription item. 227 type SubscriptionSchedulePhaseItemDiscountParams struct { 228 // ID of the coupon to create a new discount for. 229 Coupon *string `form:"coupon"` 230 // ID of an existing discount on the object (or one of its ancestors) to reuse. 231 Discount *string `form:"discount"` 232 // ID of the promotion code to create a new discount for. 233 PromotionCode *string `form:"promotion_code"` 234 } 235 236 // List of configuration items, each with an attached price, to apply during this phase of the subscription schedule. 237 type SubscriptionSchedulePhaseItemParams struct { 238 // Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period. When updating, pass an empty string to remove previously-defined thresholds. 239 BillingThresholds *SubscriptionItemBillingThresholdsParams `form:"billing_thresholds"` 240 // The coupons to redeem into discounts for the subscription item. 241 Discounts []*SubscriptionSchedulePhaseItemDiscountParams `form:"discounts"` 242 // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to a configuration item. Metadata on a configuration item will update the underlying subscription item's `metadata` when the phase is entered, adding new keys and replacing existing keys. Individual keys in the subscription item's `metadata` can be unset by posting an empty value to them in the configuration item's `metadata`. To unset all keys in the subscription item's `metadata`, update the subscription item directly or unset every key individually from the configuration item's `metadata`. 243 Metadata map[string]string `form:"metadata"` 244 // The plan ID to subscribe to. You may specify the same ID in `plan` and `price`. 245 Plan *string `form:"plan"` 246 // The ID of the price object. 247 Price *string `form:"price"` 248 // Data used to generate a new [Price](https://stripe.com/docs/api/prices) object inline. 249 PriceData *SubscriptionItemPriceDataParams `form:"price_data"` 250 // Quantity for the given price. Can be set only if the price's `usage_type` is `licensed` and not `metered`. 251 Quantity *int64 `form:"quantity"` 252 // A list of [Tax Rate](https://stripe.com/docs/api/tax_rates) ids. These Tax Rates will override the [`default_tax_rates`](https://stripe.com/docs/api/subscriptions/create#create_subscription-default_tax_rates) on the Subscription. When updating, pass an empty string to remove previously-defined tax rates. 253 TaxRates []*string `form:"tax_rates"` 254 } 255 256 // AddMetadata adds a new key-value pair to the Metadata. 257 func (p *SubscriptionSchedulePhaseItemParams) AddMetadata(key string, value string) { 258 if p.Metadata == nil { 259 p.Metadata = make(map[string]string) 260 } 261 262 p.Metadata[key] = value 263 } 264 265 // List representing phases of the subscription schedule. Each phase can be customized to have different durations, plans, and coupons. If there are multiple phases, the `end_date` of one phase will always equal the `start_date` of the next phase. 266 type SubscriptionSchedulePhaseParams struct { 267 // A list of prices and quantities that will generate invoice items appended to the next invoice for this phase. You may pass up to 20 items. 268 AddInvoiceItems []*SubscriptionSchedulePhaseAddInvoiceItemParams `form:"add_invoice_items"` 269 // A non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice total that will be transferred to the application owner's Stripe account. The request must be made by a platform account on a connected account in order to set an application fee percentage. For more information, see the application fees [documentation](https://stripe.com/docs/connect/subscriptions#collecting-fees-on-subscriptions). 270 ApplicationFeePercent *float64 `form:"application_fee_percent"` 271 // Automatic tax settings for this phase. 272 AutomaticTax *SubscriptionSchedulePhaseAutomaticTaxParams `form:"automatic_tax"` 273 // Can be set to `phase_start` to set the anchor to the start of the phase or `automatic` to automatically change it if needed. Cannot be set to `phase_start` if this phase specifies a trial. For more information, see the billing cycle [documentation](https://stripe.com/docs/billing/subscriptions/billing-cycle). 274 BillingCycleAnchor *string `form:"billing_cycle_anchor"` 275 // Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period. Pass an empty string to remove previously-defined thresholds. 276 BillingThresholds *SubscriptionBillingThresholdsParams `form:"billing_thresholds"` 277 // Either `charge_automatically`, or `send_invoice`. When charging automatically, Stripe will attempt to pay the underlying subscription at the end of each billing cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`. Defaults to `charge_automatically` on creation. 278 CollectionMethod *string `form:"collection_method"` 279 // The ID of the coupon to apply to this phase of the subscription schedule. This field has been deprecated and will be removed in a future API version. Use `discounts` instead. 280 Coupon *string `form:"coupon"` 281 // Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies). 282 Currency *string `form:"currency"` 283 // ID of the default payment method for the subscription schedule. It must belong to the customer associated with the subscription schedule. If not set, invoices will use the default payment method in the customer's invoice settings. 284 DefaultPaymentMethod *string `form:"default_payment_method"` 285 // A list of [Tax Rate](https://stripe.com/docs/api/tax_rates) ids. These Tax Rates will set the Subscription's [`default_tax_rates`](https://stripe.com/docs/api/subscriptions/create#create_subscription-default_tax_rates), which means they will be the Invoice's [`default_tax_rates`](https://stripe.com/docs/api/invoices/create#create_invoice-default_tax_rates) for any Invoices issued by the Subscription during this Phase. 286 DefaultTaxRates []*string `form:"default_tax_rates"` 287 // Subscription description, meant to be displayable to the customer. Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces and certain local payment methods UIs. 288 Description *string `form:"description"` 289 // The coupons to redeem into discounts for the schedule phase. If not specified, inherits the discount from the subscription's customer. Pass an empty string to avoid inheriting any discounts. 290 Discounts []*SubscriptionSchedulePhaseDiscountParams `form:"discounts"` 291 // The date at which this phase of the subscription schedule ends. If set, `iterations` must not be set. 292 EndDate *int64 `form:"end_date"` 293 EndDateNow *bool `form:"-"` // See custom AppendTo 294 // All invoices will be billed using the specified settings. 295 InvoiceSettings *SubscriptionSchedulePhaseInvoiceSettingsParams `form:"invoice_settings"` 296 // List of configuration items, each with an attached price, to apply during this phase of the subscription schedule. 297 Items []*SubscriptionSchedulePhaseItemParams `form:"items"` 298 // Integer representing the multiplier applied to the price interval. For example, `iterations=2` applied to a price with `interval=month` and `interval_count=3` results in a phase of duration `2 * 3 months = 6 months`. If set, `end_date` must not be set. 299 Iterations *int64 `form:"iterations"` 300 // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to a phase. Metadata on a schedule's phase will update the underlying subscription's `metadata` when the phase is entered, adding new keys and replacing existing keys in the subscription's `metadata`. Individual keys in the subscription's `metadata` can be unset by posting an empty value to them in the phase's `metadata`. To unset all keys in the subscription's `metadata`, update the subscription directly or unset every key individually from the phase's `metadata`. 301 Metadata map[string]string `form:"metadata"` 302 // The account on behalf of which to charge, for each of the associated subscription's invoices. 303 OnBehalfOf *string `form:"on_behalf_of"` 304 // Whether the subscription schedule will create [prorations](https://stripe.com/docs/billing/subscriptions/prorations) when transitioning to this phase. The default value is `create_prorations`. This setting controls prorations when a phase is started asynchronously and it is persisted as a field on the phase. It's different from the request-level [proration_behavior](https://stripe.com/docs/api/subscription_schedules/update#update_subscription_schedule-proration_behavior) parameter which controls what happens if the update request affects the billing configuration of the current phase. 305 ProrationBehavior *string `form:"proration_behavior"` 306 // The date at which this phase of the subscription schedule starts or `now`. Must be set on the first phase. 307 StartDate *int64 `form:"start_date"` 308 StartDateNow *bool `form:"-"` // See custom AppendTo 309 // The data with which to automatically create a Transfer for each of the associated subscription's invoices. 310 TransferData *SubscriptionTransferDataParams `form:"transfer_data"` 311 // If set to true the entire phase is counted as a trial and the customer will not be charged for any fees. 312 Trial *bool `form:"trial"` 313 // Sets the phase to trialing from the start date to this date. Must be before the phase end date, can not be combined with `trial` 314 TrialEnd *int64 `form:"trial_end"` 315 TrialEndNow *bool `form:"-"` // See custom AppendTo 316 } 317 318 // AddMetadata adds a new key-value pair to the Metadata. 319 func (p *SubscriptionSchedulePhaseParams) AddMetadata(key string, value string) { 320 if p.Metadata == nil { 321 p.Metadata = make(map[string]string) 322 } 323 324 p.Metadata[key] = value 325 } 326 327 // AppendTo implements custom encoding logic for SubscriptionSchedulePhaseParams. 328 func (p *SubscriptionSchedulePhaseParams) AppendTo(body *form.Values, keyParts []string) { 329 if BoolValue(p.EndDateNow) { 330 body.Add(form.FormatKey(append(keyParts, "end_date")), "now") 331 } 332 if BoolValue(p.TrialEndNow) { 333 body.Add(form.FormatKey(append(keyParts, "trial_end")), "now") 334 } 335 if BoolValue(p.StartDateNow) { 336 body.Add(form.FormatKey(append(keyParts, "start_date")), "now") 337 } 338 } 339 340 // Creates a new subscription schedule object. Each customer can have up to 500 active or scheduled subscriptions. 341 type SubscriptionScheduleParams struct { 342 Params `form:"*"` 343 // The identifier of the customer to create the subscription schedule for. 344 Customer *string `form:"customer"` 345 // Object representing the subscription schedule's default settings. 346 DefaultSettings *SubscriptionScheduleDefaultSettingsParams `form:"default_settings"` 347 // Behavior of the subscription schedule and underlying subscription when it ends. Possible values are `release` or `cancel` with the default being `release`. `release` will end the subscription schedule and keep the underlying subscription running. `cancel` will end the subscription schedule and cancel the underlying subscription. 348 EndBehavior *string `form:"end_behavior"` 349 // Specifies which fields in the response should be expanded. 350 Expand []*string `form:"expand"` 351 // Migrate an existing subscription to be managed by a subscription schedule. If this parameter is set, a subscription schedule will be created using the subscription's item(s), set to auto-renew using the subscription's interval. When using this parameter, other parameters (such as phase values) cannot be set. To create a subscription schedule with other modifications, we recommend making two separate API calls. 352 FromSubscription *string `form:"from_subscription"` 353 // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. 354 Metadata map[string]string `form:"metadata"` 355 // List representing phases of the subscription schedule. Each phase can be customized to have different durations, plans, and coupons. If there are multiple phases, the `end_date` of one phase will always equal the `start_date` of the next phase. Note that past phases can be omitted. 356 Phases []*SubscriptionSchedulePhaseParams `form:"phases"` 357 // If the update changes the current phase, indicates whether the changes should be prorated. The default value is `create_prorations`. 358 ProrationBehavior *string `form:"proration_behavior"` 359 // When the subscription schedule starts. We recommend using `now` so that it starts the subscription immediately. You can also use a Unix timestamp to backdate the subscription so that it starts on a past date, or set a future date for the subscription to start on. 360 StartDate *int64 `form:"start_date"` 361 StartDateNow *bool `form:"-"` // See custom AppendTo 362 } 363 364 // AddExpand appends a new field to expand. 365 func (p *SubscriptionScheduleParams) AddExpand(f string) { 366 p.Expand = append(p.Expand, &f) 367 } 368 369 // AddMetadata adds a new key-value pair to the Metadata. 370 func (p *SubscriptionScheduleParams) AddMetadata(key string, value string) { 371 if p.Metadata == nil { 372 p.Metadata = make(map[string]string) 373 } 374 375 p.Metadata[key] = value 376 } 377 378 // AppendTo implements custom encoding logic for SubscriptionScheduleParams. 379 func (p *SubscriptionScheduleParams) AppendTo(body *form.Values, keyParts []string) { 380 if BoolValue(p.StartDateNow) { 381 body.Add(form.FormatKey(append(keyParts, "start_date")), "now") 382 } 383 } 384 385 // Cancels a subscription schedule and its associated subscription immediately (if the subscription schedule has an active subscription). A subscription schedule can only be canceled if its status is not_started or active. 386 type SubscriptionScheduleCancelParams struct { 387 Params `form:"*"` 388 // Specifies which fields in the response should be expanded. 389 Expand []*string `form:"expand"` 390 // If the subscription schedule is `active`, indicates if a final invoice will be generated that contains any un-invoiced metered usage and new/pending proration invoice items. Defaults to `true`. 391 InvoiceNow *bool `form:"invoice_now"` 392 // If the subscription schedule is `active`, indicates if the cancellation should be prorated. Defaults to `true`. 393 Prorate *bool `form:"prorate"` 394 } 395 396 // AddExpand appends a new field to expand. 397 func (p *SubscriptionScheduleCancelParams) AddExpand(f string) { 398 p.Expand = append(p.Expand, &f) 399 } 400 401 // Releases the subscription schedule immediately, which will stop scheduling of its phases, but leave any existing subscription in place. A schedule can only be released if its status is not_started or active. If the subscription schedule is currently associated with a subscription, releasing it will remove its subscription property and set the subscription's ID to the released_subscription property. 402 type SubscriptionScheduleReleaseParams struct { 403 Params `form:"*"` 404 // Specifies which fields in the response should be expanded. 405 Expand []*string `form:"expand"` 406 // Keep any cancellation on the subscription that the schedule has set 407 PreserveCancelDate *bool `form:"preserve_cancel_date"` 408 } 409 410 // AddExpand appends a new field to expand. 411 func (p *SubscriptionScheduleReleaseParams) AddExpand(f string) { 412 p.Expand = append(p.Expand, &f) 413 } 414 415 // Object representing the start and end dates for the current phase of the subscription schedule, if it is `active`. 416 type SubscriptionScheduleCurrentPhase struct { 417 // The end of this phase of the subscription schedule. 418 EndDate int64 `json:"end_date"` 419 // The start of this phase of the subscription schedule. 420 StartDate int64 `json:"start_date"` 421 } 422 type SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuer struct { 423 // The connected account being referenced when `type` is `account`. 424 Account *Account `json:"account"` 425 // Type of the account referenced. 426 Type SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuerType `json:"type"` 427 } 428 type SubscriptionScheduleDefaultSettingsInvoiceSettings struct { 429 // The account tax IDs associated with the subscription schedule. Will be set on invoices generated by the subscription schedule. 430 AccountTaxIDs []*TaxID `json:"account_tax_ids"` 431 // Number of days within which a customer must pay invoices generated by this subscription schedule. This value will be `null` for subscription schedules where `billing=charge_automatically`. 432 DaysUntilDue int64 `json:"days_until_due"` 433 Issuer *SubscriptionScheduleDefaultSettingsInvoiceSettingsIssuer `json:"issuer"` 434 } 435 type SubscriptionScheduleDefaultSettings struct { 436 // A non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice total that will be transferred to the application owner's Stripe account during this phase of the schedule. 437 ApplicationFeePercent float64 `json:"application_fee_percent"` 438 AutomaticTax *SubscriptionAutomaticTax `json:"automatic_tax"` 439 // Possible values are `phase_start` or `automatic`. If `phase_start` then billing cycle anchor of the subscription is set to the start of the phase when entering the phase. If `automatic` then the billing cycle anchor is automatically modified as needed when entering the phase. For more information, see the billing cycle [documentation](https://stripe.com/docs/billing/subscriptions/billing-cycle). 440 BillingCycleAnchor SubscriptionScheduleDefaultSettingsBillingCycleAnchor `json:"billing_cycle_anchor"` 441 // Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period 442 BillingThresholds *SubscriptionBillingThresholds `json:"billing_thresholds"` 443 // Either `charge_automatically`, or `send_invoice`. When charging automatically, Stripe will attempt to pay the underlying subscription at the end of each billing cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`. 444 CollectionMethod *SubscriptionCollectionMethod `json:"collection_method"` 445 // ID of the default payment method for the subscription schedule. If not set, invoices will use the default payment method in the customer's invoice settings. 446 DefaultPaymentMethod *PaymentMethod `json:"default_payment_method"` 447 // Subscription description, meant to be displayable to the customer. Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces and certain local payment methods UIs. 448 Description string `json:"description"` 449 InvoiceSettings *SubscriptionScheduleDefaultSettingsInvoiceSettings `json:"invoice_settings"` 450 // The account (if any) the charge was made on behalf of for charges associated with the schedule's subscription. See the Connect documentation for details. 451 OnBehalfOf *Account `json:"on_behalf_of"` 452 // The account (if any) the associated subscription's payments will be attributed to for tax reporting, and where funds from each payment will be transferred to for each of the subscription's invoices. 453 TransferData *SubscriptionTransferData `json:"transfer_data"` 454 } 455 456 // The stackable discounts that will be applied to the item. 457 type SubscriptionSchedulePhaseAddInvoiceItemDiscount struct { 458 // ID of the coupon to create a new discount for. 459 Coupon *Coupon `json:"coupon"` 460 // ID of an existing discount on the object (or one of its ancestors) to reuse. 461 Discount *Discount `json:"discount"` 462 // ID of the promotion code to create a new discount for. 463 PromotionCode *PromotionCode `json:"promotion_code"` 464 } 465 466 // A list of prices and quantities that will generate invoice items appended to the next invoice for this phase. 467 type SubscriptionSchedulePhaseAddInvoiceItem struct { 468 // The stackable discounts that will be applied to the item. 469 Discounts []*SubscriptionSchedulePhaseAddInvoiceItemDiscount `json:"discounts"` 470 // ID of the price used to generate the invoice item. 471 Price *Price `json:"price"` 472 // The quantity of the invoice item. 473 Quantity int64 `json:"quantity"` 474 // The tax rates which apply to the item. When set, the `default_tax_rates` do not apply to this item. 475 TaxRates []*TaxRate `json:"tax_rates"` 476 } 477 478 // The stackable discounts that will be applied to the subscription on this phase. Subscription item discounts are applied before subscription discounts. 479 type SubscriptionSchedulePhaseDiscount struct { 480 // ID of the coupon to create a new discount for. 481 Coupon *Coupon `json:"coupon"` 482 // ID of an existing discount on the object (or one of its ancestors) to reuse. 483 Discount *Discount `json:"discount"` 484 // ID of the promotion code to create a new discount for. 485 PromotionCode *PromotionCode `json:"promotion_code"` 486 } 487 488 // The connected account that issues the invoice. The invoice is presented with the branding and support information of the specified account. 489 type SubscriptionSchedulePhaseInvoiceSettingsIssuer struct { 490 // The connected account being referenced when `type` is `account`. 491 Account *Account `json:"account"` 492 // Type of the account referenced. 493 Type SubscriptionSchedulePhaseInvoiceSettingsIssuerType `json:"type"` 494 } 495 496 // The invoice settings applicable during this phase. 497 type SubscriptionSchedulePhaseInvoiceSettings struct { 498 // The account tax IDs associated with this phase of the subscription schedule. Will be set on invoices generated by this phase of the subscription schedule. 499 AccountTaxIDs []*TaxID `json:"account_tax_ids"` 500 // Number of days within which a customer must pay invoices generated by this subscription schedule. This value will be `null` for subscription schedules where `billing=charge_automatically`. 501 DaysUntilDue int64 `json:"days_until_due"` 502 // The connected account that issues the invoice. The invoice is presented with the branding and support information of the specified account. 503 Issuer *SubscriptionSchedulePhaseInvoiceSettingsIssuer `json:"issuer"` 504 } 505 506 // The discounts applied to the subscription item. Subscription item discounts are applied before subscription discounts. Use `expand[]=discounts` to expand each discount. 507 type SubscriptionSchedulePhaseItemDiscount struct { 508 // ID of the coupon to create a new discount for. 509 Coupon *Coupon `json:"coupon"` 510 // ID of an existing discount on the object (or one of its ancestors) to reuse. 511 Discount *Discount `json:"discount"` 512 // ID of the promotion code to create a new discount for. 513 PromotionCode *PromotionCode `json:"promotion_code"` 514 } 515 516 // Subscription items to configure the subscription to during this phase of the subscription schedule. 517 type SubscriptionSchedulePhaseItem struct { 518 // Define thresholds at which an invoice will be sent, and the related subscription advanced to a new billing period 519 BillingThresholds *SubscriptionItemBillingThresholds `json:"billing_thresholds"` 520 // The discounts applied to the subscription item. Subscription item discounts are applied before subscription discounts. Use `expand[]=discounts` to expand each discount. 521 Discounts []*SubscriptionSchedulePhaseItemDiscount `json:"discounts"` 522 // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an item. Metadata on this item will update the underlying subscription item's `metadata` when the phase is entered. 523 Metadata map[string]string `json:"metadata"` 524 // ID of the plan to which the customer should be subscribed. 525 Plan *Plan `json:"plan"` 526 // ID of the price to which the customer should be subscribed. 527 Price *Price `json:"price"` 528 // Quantity of the plan to which the customer should be subscribed. 529 Quantity int64 `json:"quantity"` 530 // The tax rates which apply to this `phase_item`. When set, the `default_tax_rates` on the phase do not apply to this `phase_item`. 531 TaxRates []*TaxRate `json:"tax_rates"` 532 } 533 534 // Configuration for the subscription schedule's phases. 535 type SubscriptionSchedulePhase struct { 536 // A list of prices and quantities that will generate invoice items appended to the next invoice for this phase. 537 AddInvoiceItems []*SubscriptionSchedulePhaseAddInvoiceItem `json:"add_invoice_items"` 538 // A non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice total that will be transferred to the application owner's Stripe account during this phase of the schedule. 539 ApplicationFeePercent float64 `json:"application_fee_percent"` 540 AutomaticTax *SubscriptionAutomaticTax `json:"automatic_tax"` 541 // Possible values are `phase_start` or `automatic`. If `phase_start` then billing cycle anchor of the subscription is set to the start of the phase when entering the phase. If `automatic` then the billing cycle anchor is automatically modified as needed when entering the phase. For more information, see the billing cycle [documentation](https://stripe.com/docs/billing/subscriptions/billing-cycle). 542 BillingCycleAnchor SubscriptionSchedulePhaseBillingCycleAnchor `json:"billing_cycle_anchor"` 543 // Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period 544 BillingThresholds *SubscriptionBillingThresholds `json:"billing_thresholds"` 545 // Either `charge_automatically`, or `send_invoice`. When charging automatically, Stripe will attempt to pay the underlying subscription at the end of each billing cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`. 546 CollectionMethod *SubscriptionCollectionMethod `json:"collection_method"` 547 // ID of the coupon to use during this phase of the subscription schedule. 548 Coupon *Coupon `json:"coupon"` 549 // Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies). 550 Currency Currency `json:"currency"` 551 // ID of the default payment method for the subscription schedule. It must belong to the customer associated with the subscription schedule. If not set, invoices will use the default payment method in the customer's invoice settings. 552 DefaultPaymentMethod *PaymentMethod `json:"default_payment_method"` 553 // The default tax rates to apply to the subscription during this phase of the subscription schedule. 554 DefaultTaxRates []*TaxRate `json:"default_tax_rates"` 555 // Subscription description, meant to be displayable to the customer. Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces and certain local payment methods UIs. 556 Description string `json:"description"` 557 // The stackable discounts that will be applied to the subscription on this phase. Subscription item discounts are applied before subscription discounts. 558 Discounts []*SubscriptionSchedulePhaseDiscount `json:"discounts"` 559 // The end of this phase of the subscription schedule. 560 EndDate int64 `json:"end_date"` 561 // The invoice settings applicable during this phase. 562 InvoiceSettings *SubscriptionSchedulePhaseInvoiceSettings `json:"invoice_settings"` 563 // Subscription items to configure the subscription to during this phase of the subscription schedule. 564 Items []*SubscriptionSchedulePhaseItem `json:"items"` 565 // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to a phase. Metadata on a schedule's phase will update the underlying subscription's `metadata` when the phase is entered. Updating the underlying subscription's `metadata` directly will not affect the current phase's `metadata`. 566 Metadata map[string]string `json:"metadata"` 567 // The account (if any) the charge was made on behalf of for charges associated with the schedule's subscription. See the Connect documentation for details. 568 OnBehalfOf *Account `json:"on_behalf_of"` 569 // If the subscription schedule will prorate when transitioning to this phase. Possible values are `create_prorations` and `none`. 570 ProrationBehavior SubscriptionSchedulePhaseProrationBehavior `json:"proration_behavior"` 571 // The start of this phase of the subscription schedule. 572 StartDate int64 `json:"start_date"` 573 // The account (if any) the associated subscription's payments will be attributed to for tax reporting, and where funds from each payment will be transferred to for each of the subscription's invoices. 574 TransferData *SubscriptionTransferData `json:"transfer_data"` 575 // When the trial ends within the phase. 576 TrialEnd int64 `json:"trial_end"` 577 } 578 579 // A subscription schedule allows you to create and manage the lifecycle of a subscription by predefining expected changes. 580 // 581 // Related guide: [Subscription schedules](https://stripe.com/docs/billing/subscriptions/subscription-schedules) 582 type SubscriptionSchedule struct { 583 APIResource 584 // ID of the Connect Application that created the schedule. 585 Application *Application `json:"application"` 586 // Time at which the subscription schedule was canceled. Measured in seconds since the Unix epoch. 587 CanceledAt int64 `json:"canceled_at"` 588 // Time at which the subscription schedule was completed. Measured in seconds since the Unix epoch. 589 CompletedAt int64 `json:"completed_at"` 590 // Time at which the object was created. Measured in seconds since the Unix epoch. 591 Created int64 `json:"created"` 592 // Object representing the start and end dates for the current phase of the subscription schedule, if it is `active`. 593 CurrentPhase *SubscriptionScheduleCurrentPhase `json:"current_phase"` 594 // ID of the customer who owns the subscription schedule. 595 Customer *Customer `json:"customer"` 596 DefaultSettings *SubscriptionScheduleDefaultSettings `json:"default_settings"` 597 // Behavior of the subscription schedule and underlying subscription when it ends. Possible values are `release` or `cancel` with the default being `release`. `release` will end the subscription schedule and keep the underlying subscription running. `cancel` will end the subscription schedule and cancel the underlying subscription. 598 EndBehavior SubscriptionScheduleEndBehavior `json:"end_behavior"` 599 // Unique identifier for the object. 600 ID string `json:"id"` 601 // Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. 602 Livemode bool `json:"livemode"` 603 // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. 604 Metadata map[string]string `json:"metadata"` 605 // String representing the object's type. Objects of the same type share the same value. 606 Object string `json:"object"` 607 // Configuration for the subscription schedule's phases. 608 Phases []*SubscriptionSchedulePhase `json:"phases"` 609 // Time at which the subscription schedule was released. Measured in seconds since the Unix epoch. 610 ReleasedAt int64 `json:"released_at"` 611 // ID of the subscription once managed by the subscription schedule (if it is released). 612 ReleasedSubscription *Subscription `json:"released_subscription"` 613 // The present status of the subscription schedule. Possible values are `not_started`, `active`, `completed`, `released`, and `canceled`. You can read more about the different states in our [behavior guide](https://stripe.com/docs/billing/subscriptions/subscription-schedules). 614 Status SubscriptionScheduleStatus `json:"status"` 615 // ID of the subscription managed by the subscription schedule. 616 Subscription *Subscription `json:"subscription"` 617 // ID of the test clock this subscription schedule belongs to. 618 TestClock *TestHelpersTestClock `json:"test_clock"` 619 } 620 621 // SubscriptionScheduleList is a list of SubscriptionSchedules as retrieved from a list endpoint. 622 type SubscriptionScheduleList struct { 623 APIResource 624 ListMeta 625 Data []*SubscriptionSchedule `json:"data"` 626 } 627 628 // UnmarshalJSON handles deserialization of a SubscriptionSchedule. 629 // This custom unmarshaling is needed because the resulting 630 // property may be an id or the full struct if it was expanded. 631 func (s *SubscriptionSchedule) UnmarshalJSON(data []byte) error { 632 if id, ok := ParseID(data); ok { 633 s.ID = id 634 return nil 635 } 636 637 type subscriptionSchedule SubscriptionSchedule 638 var v subscriptionSchedule 639 if err := json.Unmarshal(data, &v); err != nil { 640 return err 641 } 642 643 *s = SubscriptionSchedule(v) 644 return nil 645 }