github.com/stripe/stripe-go/v76@v76.25.0/subscriptionitem.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 package stripe 8 9 import "encoding/json" 10 11 // Deletes an item from the subscription. Removing a subscription item from a subscription will not cancel the subscription. 12 type SubscriptionItemParams struct { 13 Params `form:"*"` 14 // 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. 15 BillingThresholds *SubscriptionItemBillingThresholdsParams `form:"billing_thresholds"` 16 // Delete all usage for the given subscription item. Allowed only when the current plan's `usage_type` is `metered`. 17 ClearUsage *bool `form:"clear_usage"` 18 // The coupons to redeem into discounts for the subscription item. 19 Discounts []*SubscriptionItemDiscountParams `form:"discounts"` 20 // Specifies which fields in the response should be expanded. 21 Expand []*string `form:"expand"` 22 // 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`. 23 Metadata map[string]string `form:"metadata"` 24 // Only supported on update 25 // Indicates if a customer is on or off-session while an invoice payment is attempted. 26 OffSession *bool `form:"off_session"` 27 // Use `allow_incomplete` to transition the subscription to `status=past_due` if a payment is required but cannot be paid. This allows you to manage scenarios where additional user actions are needed to pay a subscription's invoice. For example, SCA regulation may require 3DS authentication to complete payment. See the [SCA Migration Guide](https://stripe.com/docs/billing/migration/strong-customer-authentication) for Billing to learn more. This is the default behavior. 28 // 29 // Use `default_incomplete` to transition the subscription to `status=past_due` when payment is required and await explicit confirmation of the invoice's payment intent. This allows simpler management of scenarios where additional user actions are needed to pay a subscription's invoice. Such as failed payments, [SCA regulation](https://stripe.com/docs/billing/migration/strong-customer-authentication), or collecting a mandate for a bank debit payment method. 30 // 31 // Use `pending_if_incomplete` to update the subscription using [pending updates](https://stripe.com/docs/billing/subscriptions/pending-updates). When you use `pending_if_incomplete` you can only pass the parameters [supported by pending updates](https://stripe.com/docs/billing/pending-updates-reference#supported-attributes). 32 // 33 // Use `error_if_incomplete` if you want Stripe to return an HTTP 402 status code if a subscription's invoice cannot be paid. For example, if a payment method requires 3DS authentication due to SCA regulation and further user action is needed, this parameter does not update the subscription and returns an error instead. This was the default behavior for API versions prior to 2019-03-14. See the [changelog](https://stripe.com/docs/upgrades#2019-03-14) to learn more. 34 PaymentBehavior *string `form:"payment_behavior"` 35 // The identifier of the new plan for this subscription item. 36 Plan *string `form:"plan"` 37 // The ID of the price object. When changing a subscription item's price, `quantity` is set to 1 unless a `quantity` parameter is provided. 38 Price *string `form:"price"` 39 // Data used to generate a new [Price](https://stripe.com/docs/api/prices) object inline. 40 PriceData *SubscriptionItemPriceDataParams `form:"price_data"` 41 // Determines how to handle [prorations](https://stripe.com/docs/billing/subscriptions/prorations) when the billing cycle changes (e.g., when switching plans, resetting `billing_cycle_anchor=now`, or starting a trial), or if an item's `quantity` changes. The default value is `create_prorations`. 42 ProrationBehavior *string `form:"proration_behavior"` 43 // If set, the proration will be calculated as though the subscription was updated at the given time. This can be used to apply the same proration that was previewed with the [upcoming invoice](https://stripe.com/docs/api#retrieve_customer_invoice) endpoint. 44 ProrationDate *int64 `form:"proration_date"` 45 // The quantity you'd like to apply to the subscription item you're creating. 46 Quantity *int64 `form:"quantity"` 47 // The identifier of the subscription to modify. 48 Subscription *string `form:"subscription"` 49 // 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. 50 TaxRates []*string `form:"tax_rates"` 51 } 52 53 // AddExpand appends a new field to expand. 54 func (p *SubscriptionItemParams) AddExpand(f string) { 55 p.Expand = append(p.Expand, &f) 56 } 57 58 // AddMetadata adds a new key-value pair to the Metadata. 59 func (p *SubscriptionItemParams) AddMetadata(key string, value string) { 60 if p.Metadata == nil { 61 p.Metadata = make(map[string]string) 62 } 63 64 p.Metadata[key] = value 65 } 66 67 // 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. 68 type SubscriptionItemBillingThresholdsParams struct { 69 // Number of units that meets the billing threshold to advance the subscription to a new billing period (e.g., it takes 10 $5 units to meet a $50 [monetary threshold](https://stripe.com/docs/api/subscriptions/update#update_subscription-billing_thresholds-amount_gte)) 70 UsageGTE *int64 `form:"usage_gte"` 71 } 72 73 // The coupons to redeem into discounts for the subscription item. 74 type SubscriptionItemDiscountParams struct { 75 // ID of the coupon to create a new discount for. 76 Coupon *string `form:"coupon"` 77 // ID of an existing discount on the object (or one of its ancestors) to reuse. 78 Discount *string `form:"discount"` 79 // ID of the promotion code to create a new discount for. 80 PromotionCode *string `form:"promotion_code"` 81 } 82 83 // The recurring components of a price such as `interval` and `interval_count`. 84 type SubscriptionItemPriceDataRecurringParams struct { 85 // Specifies billing frequency. Either `day`, `week`, `month` or `year`. 86 Interval *string `form:"interval"` 87 // The number of intervals between subscription billings. For example, `interval=month` and `interval_count=3` bills every 3 months. Maximum of three years interval allowed (3 years, 36 months, or 156 weeks). 88 IntervalCount *int64 `form:"interval_count"` 89 } 90 91 // Data used to generate a new [Price](https://stripe.com/docs/api/prices) object inline. 92 type SubscriptionItemPriceDataParams struct { 93 // 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). 94 Currency *string `form:"currency"` 95 // The ID of the product that this price will belong to. 96 Product *string `form:"product"` 97 // The recurring components of a price such as `interval` and `interval_count`. 98 Recurring *SubscriptionItemPriceDataRecurringParams `form:"recurring"` 99 // Only required if a [default tax behavior](https://stripe.com/docs/tax/products-prices-tax-categories-tax-behavior#setting-a-default-tax-behavior-(recommended)) was not provided in the Stripe Tax settings. Specifies whether the price is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. Once specified as either `inclusive` or `exclusive`, it cannot be changed. 100 TaxBehavior *string `form:"tax_behavior"` 101 // A positive integer in cents (or local equivalent) (or 0 for a free price) representing how much to charge. 102 UnitAmount *int64 `form:"unit_amount"` 103 // Same as `unit_amount`, but accepts a decimal value in cents (or local equivalent) with at most 12 decimal places. Only one of `unit_amount` and `unit_amount_decimal` can be set. 104 UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"` 105 } 106 107 // Returns a list of your subscription items for a given subscription. 108 type SubscriptionItemListParams struct { 109 ListParams `form:"*"` 110 // Specifies which fields in the response should be expanded. 111 Expand []*string `form:"expand"` 112 // The ID of the subscription whose items will be retrieved. 113 Subscription *string `form:"subscription"` 114 } 115 116 // AddExpand appends a new field to expand. 117 func (p *SubscriptionItemListParams) AddExpand(f string) { 118 p.Expand = append(p.Expand, &f) 119 } 120 121 // For the specified subscription item, returns a list of summary objects. Each object in the list provides usage information that's been summarized from multiple usage records and over a subscription billing period (e.g., 15 usage records in the month of September). 122 // 123 // The list is sorted in reverse-chronological order (newest first). The first list item represents the most current usage period that hasn't ended yet. Since new usage records can still be added, the returned summary information for the subscription item's ID should be seen as unstable until the subscription billing period ends. 124 type SubscriptionItemUsageRecordSummariesParams struct { 125 ListParams `form:"*"` 126 SubscriptionItem *string `form:"-"` // Included in URL 127 // Specifies which fields in the response should be expanded. 128 Expand []*string `form:"expand"` 129 } 130 131 // AddExpand appends a new field to expand. 132 func (p *SubscriptionItemUsageRecordSummariesParams) AddExpand(f string) { 133 p.Expand = append(p.Expand, &f) 134 } 135 136 // Define thresholds at which an invoice will be sent, and the related subscription advanced to a new billing period 137 type SubscriptionItemBillingThresholds struct { 138 // Usage threshold that triggers the subscription to create an invoice 139 UsageGTE int64 `json:"usage_gte"` 140 } 141 142 // Subscription items allow you to create customer subscriptions with more than 143 // one plan, making it easy to represent complex billing relationships. 144 type SubscriptionItem struct { 145 APIResource 146 // Define thresholds at which an invoice will be sent, and the related subscription advanced to a new billing period 147 BillingThresholds *SubscriptionItemBillingThresholds `json:"billing_thresholds"` 148 // Time at which the object was created. Measured in seconds since the Unix epoch. 149 Created int64 `json:"created"` 150 Deleted bool `json:"deleted"` 151 // The discounts applied to the subscription item. Subscription item discounts are applied before subscription discounts. Use `expand[]=discounts` to expand each discount. 152 Discounts []*Discount `json:"discounts"` 153 // Unique identifier for the object. 154 ID string `json:"id"` 155 // 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. 156 Metadata map[string]string `json:"metadata"` 157 // String representing the object's type. Objects of the same type share the same value. 158 Object string `json:"object"` 159 // You can now model subscriptions more flexibly using the [Prices API](https://stripe.com/docs/api#prices). It replaces the Plans API and is backwards compatible to simplify your migration. 160 // 161 // Plans define the base price, currency, and billing cycle for recurring purchases of products. 162 // [Products](https://stripe.com/docs/api#products) help you track inventory or provisioning, and plans help you track pricing. Different physical goods or levels of service should be represented by products, and pricing options should be represented by plans. This approach lets you change prices without having to change your provisioning scheme. 163 // 164 // For example, you might have a single "gold" product that has plans for $10/month, $100/year, €9/month, and €90/year. 165 // 166 // Related guides: [Set up a subscription](https://stripe.com/docs/billing/subscriptions/set-up-subscription) and more about [products and prices](https://stripe.com/docs/products-prices/overview). 167 Plan *Plan `json:"plan"` 168 // Prices define the unit cost, currency, and (optional) billing cycle for both recurring and one-time purchases of products. 169 // [Products](https://stripe.com/docs/api#products) help you track inventory or provisioning, and prices help you track payment terms. Different physical goods or levels of service should be represented by products, and pricing options should be represented by prices. This approach lets you change prices without having to change your provisioning scheme. 170 // 171 // For example, you might have a single "gold" product that has prices for $10/month, $100/year, and €9 once. 172 // 173 // Related guides: [Set up a subscription](https://stripe.com/docs/billing/subscriptions/set-up-subscription), [create an invoice](https://stripe.com/docs/billing/invoices/create), and more about [products and prices](https://stripe.com/docs/products-prices/overview). 174 Price *Price `json:"price"` 175 // The [quantity](https://stripe.com/docs/subscriptions/quantities) of the plan to which the customer should be subscribed. 176 Quantity int64 `json:"quantity"` 177 // The `subscription` this `subscription_item` belongs to. 178 Subscription string `json:"subscription"` 179 // The tax rates which apply to this `subscription_item`. When set, the `default_tax_rates` on the subscription do not apply to this `subscription_item`. 180 TaxRates []*TaxRate `json:"tax_rates"` 181 } 182 183 // SubscriptionItemList is a list of SubscriptionItems as retrieved from a list endpoint. 184 type SubscriptionItemList struct { 185 APIResource 186 ListMeta 187 Data []*SubscriptionItem `json:"data"` 188 } 189 190 // UnmarshalJSON handles deserialization of a SubscriptionItem. 191 // This custom unmarshaling is needed because the resulting 192 // property may be an id or the full struct if it was expanded. 193 func (s *SubscriptionItem) UnmarshalJSON(data []byte) error { 194 if id, ok := ParseID(data); ok { 195 s.ID = id 196 return nil 197 } 198 199 type subscriptionItem SubscriptionItem 200 var v subscriptionItem 201 if err := json.Unmarshal(data, &v); err != nil { 202 return err 203 } 204 205 *s = SubscriptionItem(v) 206 return nil 207 }