github.com/stripe/stripe-go/v76@v76.25.0/invoiceitem.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 invoice item, removing it from an invoice. Deleting invoice items is only possible when they're not attached to invoices, or if it's attached to a draft invoice. 12 type InvoiceItemParams struct { 13 Params `form:"*"` 14 // The integer amount in cents (or local equivalent) of the charge to be applied to the upcoming invoice. If you want to apply a credit to the customer's account, pass a negative amount. 15 Amount *int64 `form:"amount"` 16 // 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). 17 Currency *string `form:"currency"` 18 // The ID of the customer who will be billed when this invoice item is billed. 19 Customer *string `form:"customer"` 20 // An arbitrary string which you can attach to the invoice item. The description is displayed in the invoice for easy tracking. 21 Description *string `form:"description"` 22 // Controls whether discounts apply to this invoice item. Defaults to false for prorations or negative invoice items, and true for all other invoice items. Cannot be set to true for prorations. 23 Discountable *bool `form:"discountable"` 24 // The coupons, promotion codes & existing discounts which apply to the invoice item or invoice line item. Item discounts are applied before invoice discounts. Pass an empty string to remove previously-defined discounts. 25 Discounts []*InvoiceItemDiscountParams `form:"discounts"` 26 // Specifies which fields in the response should be expanded. 27 Expand []*string `form:"expand"` 28 // The ID of an existing invoice to add this invoice item to. When left blank, the invoice item will be added to the next upcoming scheduled invoice. This is useful when adding invoice items in response to an invoice.created webhook. You can only add invoice items to draft invoices and there is a maximum of 250 items per invoice. 29 Invoice *string `form:"invoice"` 30 // 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`. 31 Metadata map[string]string `form:"metadata"` 32 // The period associated with this invoice item. When set to different values, the period will be rendered on the invoice. If you have [Stripe Revenue Recognition](https://stripe.com/docs/revenue-recognition) enabled, the period will be used to recognize and defer revenue. See the [Revenue Recognition documentation](https://stripe.com/docs/revenue-recognition/methodology/subscriptions-and-invoicing) for details. 33 Period *InvoiceItemPeriodParams `form:"period"` 34 // The ID of the price object. 35 Price *string `form:"price"` 36 // Data used to generate a new [Price](https://stripe.com/docs/api/prices) object inline. 37 PriceData *InvoiceItemPriceDataParams `form:"price_data"` 38 // Non-negative integer. The quantity of units for the invoice item. 39 Quantity *int64 `form:"quantity"` 40 // The ID of a subscription to add this invoice item to. When left blank, the invoice item will be be added to the next upcoming scheduled invoice. When set, scheduled invoices for subscriptions other than the specified subscription will ignore the invoice item. Use this when you want to express that an invoice item has been accrued within the context of a particular subscription. 41 Subscription *string `form:"subscription"` 42 // 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. 43 TaxBehavior *string `form:"tax_behavior"` 44 // A [tax code](https://stripe.com/docs/tax/tax-categories) ID. 45 TaxCode *string `form:"tax_code"` 46 // The tax rates which apply to the invoice item. When set, the `default_tax_rates` on the invoice do not apply to this invoice item. Pass an empty string to remove previously-defined tax rates. 47 TaxRates []*string `form:"tax_rates"` 48 // The integer unit amount in cents (or local equivalent) of the charge to be applied to the upcoming invoice. This unit_amount will be multiplied by the quantity to get the full amount. If you want to apply a credit to the customer's account, pass a negative unit_amount. 49 UnitAmount *int64 `form:"unit_amount"` 50 // 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. 51 UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"` 52 } 53 54 // AddExpand appends a new field to expand. 55 func (p *InvoiceItemParams) AddExpand(f string) { 56 p.Expand = append(p.Expand, &f) 57 } 58 59 // AddMetadata adds a new key-value pair to the Metadata. 60 func (p *InvoiceItemParams) AddMetadata(key string, value string) { 61 if p.Metadata == nil { 62 p.Metadata = make(map[string]string) 63 } 64 65 p.Metadata[key] = value 66 } 67 68 // The coupons, promotion codes & existing discounts which apply to the invoice item or invoice line item. Item discounts are applied before invoice discounts. Pass an empty string to remove previously-defined discounts. 69 type InvoiceItemDiscountParams struct { 70 // ID of the coupon to create a new discount for. 71 Coupon *string `form:"coupon"` 72 // ID of an existing discount on the object (or one of its ancestors) to reuse. 73 Discount *string `form:"discount"` 74 // ID of the promotion code to create a new discount for. 75 PromotionCode *string `form:"promotion_code"` 76 } 77 78 // The period associated with this invoice item. When set to different values, the period will be rendered on the invoice. If you have [Stripe Revenue Recognition](https://stripe.com/docs/revenue-recognition) enabled, the period will be used to recognize and defer revenue. See the [Revenue Recognition documentation](https://stripe.com/docs/revenue-recognition/methodology/subscriptions-and-invoicing) for details. 79 type InvoiceItemPeriodParams struct { 80 // The end of the period, which must be greater than or equal to the start. This value is inclusive. 81 End *int64 `form:"end"` 82 // The start of the period. This value is inclusive. 83 Start *int64 `form:"start"` 84 } 85 86 // Data used to generate a new [Price](https://stripe.com/docs/api/prices) object inline. 87 type InvoiceItemPriceDataParams struct { 88 // 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). 89 Currency *string `form:"currency"` 90 // The ID of the product that this price will belong to. 91 Product *string `form:"product"` 92 // 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. 93 TaxBehavior *string `form:"tax_behavior"` 94 // A positive integer in cents (or local equivalent) (or 0 for a free price) representing how much to charge. 95 UnitAmount *int64 `form:"unit_amount"` 96 // 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. 97 UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"` 98 } 99 100 // Returns a list of your invoice items. Invoice items are returned sorted by creation date, with the most recently created invoice items appearing first. 101 type InvoiceItemListParams struct { 102 ListParams `form:"*"` 103 // Only return invoice items that were created during the given date interval. 104 Created *int64 `form:"created"` 105 // Only return invoice items that were created during the given date interval. 106 CreatedRange *RangeQueryParams `form:"created"` 107 // The identifier of the customer whose invoice items to return. If none is provided, all invoice items will be returned. 108 Customer *string `form:"customer"` 109 // Specifies which fields in the response should be expanded. 110 Expand []*string `form:"expand"` 111 // Only return invoice items belonging to this invoice. If none is provided, all invoice items will be returned. If specifying an invoice, no customer identifier is needed. 112 Invoice *string `form:"invoice"` 113 // Set to `true` to only show pending invoice items, which are not yet attached to any invoices. Set to `false` to only show invoice items already attached to invoices. If unspecified, no filter is applied. 114 Pending *bool `form:"pending"` 115 } 116 117 // AddExpand appends a new field to expand. 118 func (p *InvoiceItemListParams) AddExpand(f string) { 119 p.Expand = append(p.Expand, &f) 120 } 121 122 // Invoice Items represent the component lines of an [invoice](https://stripe.com/docs/api/invoices). An invoice item is added to an 123 // invoice by creating or updating it with an `invoice` field, at which point it will be included as 124 // [an invoice line item](https://stripe.com/docs/api/invoices/line_item) within 125 // [invoice.lines](https://stripe.com/docs/api/invoices/object#invoice_object-lines). 126 // 127 // Invoice Items can be created before you are ready to actually send the invoice. This can be particularly useful when combined 128 // with a [subscription](https://stripe.com/docs/api/subscriptions). Sometimes you want to add a charge or credit to a customer, but actually charge 129 // or credit the customer's card only at the end of a regular billing cycle. This is useful for combining several charges 130 // (to minimize per-transaction fees), or for having Stripe tabulate your usage-based billing totals. 131 // 132 // Related guides: [Integrate with the Invoicing API](https://stripe.com/docs/invoicing/integration), [Subscription Invoices](https://stripe.com/docs/billing/invoices/subscription#adding-upcoming-invoice-items). 133 type InvoiceItem struct { 134 APIResource 135 // Amount (in the `currency` specified) of the invoice item. This should always be equal to `unit_amount * quantity`. 136 Amount int64 `json:"amount"` 137 // 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). 138 Currency Currency `json:"currency"` 139 // The ID of the customer who will be billed when this invoice item is billed. 140 Customer *Customer `json:"customer"` 141 // Time at which the object was created. Measured in seconds since the Unix epoch. 142 Date int64 `json:"date"` 143 Deleted bool `json:"deleted"` 144 // An arbitrary string attached to the object. Often useful for displaying to users. 145 Description string `json:"description"` 146 // If true, discounts will apply to this invoice item. Always false for prorations. 147 Discountable bool `json:"discountable"` 148 // The discounts which apply to the invoice item. Item discounts are applied before invoice discounts. Use `expand[]=discounts` to expand each discount. 149 Discounts []*Discount `json:"discounts"` 150 // Unique identifier for the object. 151 ID string `json:"id"` 152 // The ID of the invoice this invoice item belongs to. 153 Invoice *Invoice `json:"invoice"` 154 // Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. 155 Livemode bool `json:"livemode"` 156 // 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. 157 Metadata map[string]string `json:"metadata"` 158 // String representing the object's type. Objects of the same type share the same value. 159 Object string `json:"object"` 160 Period *Period `json:"period"` 161 // If the invoice item is a proration, the plan of the subscription that the proration was computed for. 162 Plan *Plan `json:"plan"` 163 // The price of the invoice item. 164 Price *Price `json:"price"` 165 // Whether the invoice item was created automatically as a proration adjustment when the customer switched plans. 166 Proration bool `json:"proration"` 167 // Quantity of units for the invoice item. If the invoice item is a proration, the quantity of the subscription that the proration was computed for. 168 Quantity int64 `json:"quantity"` 169 // The subscription that this invoice item has been created for, if any. 170 Subscription *Subscription `json:"subscription"` 171 // The subscription item that this invoice item has been created for, if any. 172 SubscriptionItem string `json:"subscription_item"` 173 // The tax rates which apply to the invoice item. When set, the `default_tax_rates` on the invoice do not apply to this invoice item. 174 TaxRates []*TaxRate `json:"tax_rates"` 175 // ID of the test clock this invoice item belongs to. 176 TestClock *TestHelpersTestClock `json:"test_clock"` 177 // Unit amount (in the `currency` specified) of the invoice item. 178 UnitAmount int64 `json:"unit_amount"` 179 // Same as `unit_amount`, but contains a decimal value with at most 12 decimal places. 180 UnitAmountDecimal float64 `json:"unit_amount_decimal,string"` 181 } 182 183 // InvoiceItemList is a list of InvoiceItems as retrieved from a list endpoint. 184 type InvoiceItemList struct { 185 APIResource 186 ListMeta 187 Data []*InvoiceItem `json:"data"` 188 } 189 190 // UnmarshalJSON handles deserialization of an InvoiceItem. 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 (i *InvoiceItem) UnmarshalJSON(data []byte) error { 194 if id, ok := ParseID(data); ok { 195 i.ID = id 196 return nil 197 } 198 199 type invoiceItem InvoiceItem 200 var v invoiceItem 201 if err := json.Unmarshal(data, &v); err != nil { 202 return err 203 } 204 205 *i = InvoiceItem(v) 206 return nil 207 }