1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
|
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._invoice_line_item import InvoiceLineItem
from stripe._list_object import ListObject
from stripe._request_options import RequestOptions
from stripe._stripe_service import StripeService
from stripe._util import sanitize_id
from typing import Dict, List, cast
from typing_extensions import Literal, NotRequired, TypedDict
class InvoiceLineItemService(StripeService):
class ListParams(TypedDict):
ending_before: NotRequired[str]
"""
A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
limit: NotRequired[int]
"""
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
"""
starting_after: NotRequired[str]
"""
A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
"""
class UpdateParams(TypedDict):
amount: NotRequired[int]
"""
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.
"""
description: NotRequired[str]
"""
An arbitrary string which you can attach to the invoice item. The description is displayed in the invoice for easy tracking.
"""
discountable: NotRequired[bool]
"""
Controls whether discounts apply to this line item. Defaults to false for prorations or negative line items, and true for all other line items. Cannot be set to true for prorations.
"""
discounts: NotRequired[
"Literal['']|List[InvoiceLineItemService.UpdateParamsDiscount]"
]
"""
The coupons, promotion codes & existing discounts which apply to the line item. Item discounts are applied before invoice discounts. Pass an empty string to remove previously-defined discounts.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
metadata: NotRequired["Literal['']|Dict[str, str]"]
"""
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`. For [type=subscription](https://stripe.com/docs/api/invoices/line_item#invoice_line_item_object-type) line items, the incoming metadata specified on the request is directly used to set this value, in contrast to [type=invoiceitem](api/invoices/line_item#invoice_line_item_object-type) line items, where any existing metadata on the invoice line is merged with the incoming data.
"""
period: NotRequired["InvoiceLineItemService.UpdateParamsPeriod"]
"""
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.
"""
price_data: NotRequired["InvoiceLineItemService.UpdateParamsPriceData"]
"""
Data used to generate a new [Price](https://stripe.com/docs/api/prices) object inline.
"""
pricing: NotRequired["InvoiceLineItemService.UpdateParamsPricing"]
"""
The pricing information for the invoice item.
"""
quantity: NotRequired[int]
"""
Non-negative integer. The quantity of units for the line item.
"""
tax_amounts: NotRequired[
"Literal['']|List[InvoiceLineItemService.UpdateParamsTaxAmount]"
]
"""
A list of up to 10 tax amounts for this line item. This can be useful if you calculate taxes on your own or use a third-party to calculate them. You cannot set tax amounts if any line item has [tax_rates](https://stripe.com/docs/api/invoices/line_item#invoice_line_item_object-tax_rates) or if the invoice has [default_tax_rates](https://stripe.com/docs/api/invoices/object#invoice_object-default_tax_rates) or uses [automatic tax](https://stripe.com/docs/tax/invoicing). Pass an empty string to remove previously defined tax amounts.
"""
tax_rates: NotRequired["Literal['']|List[str]"]
"""
The tax rates which apply to the line item. When set, the `default_tax_rates` on the invoice do not apply to this line item. Pass an empty string to remove previously-defined tax rates.
"""
class UpdateParamsDiscount(TypedDict):
coupon: NotRequired[str]
"""
ID of the coupon to create a new discount for.
"""
discount: NotRequired[str]
"""
ID of an existing discount on the object (or one of its ancestors) to reuse.
"""
promotion_code: NotRequired[str]
"""
ID of the promotion code to create a new discount for.
"""
class UpdateParamsPeriod(TypedDict):
end: int
"""
The end of the period, which must be greater than or equal to the start. This value is inclusive.
"""
start: int
"""
The start of the period. This value is inclusive.
"""
class UpdateParamsPriceData(TypedDict):
currency: str
"""
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).
"""
product: NotRequired[str]
"""
The ID of the [Product](https://docs.stripe.com/api/products) that this [Price](https://docs.stripe.com/api/prices) will belong to. One of `product` or `product_data` is required.
"""
product_data: NotRequired[
"InvoiceLineItemService.UpdateParamsPriceDataProductData"
]
"""
Data used to generate a new [Product](https://docs.stripe.com/api/products) object inline. One of `product` or `product_data` is required.
"""
tax_behavior: NotRequired[
Literal["exclusive", "inclusive", "unspecified"]
]
"""
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.
"""
unit_amount: NotRequired[int]
"""
A non-negative integer in cents (or local equivalent) representing how much to charge. One of `unit_amount` or `unit_amount_decimal` is required.
"""
unit_amount_decimal: NotRequired[str]
"""
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.
"""
class UpdateParamsPriceDataProductData(TypedDict):
description: NotRequired[str]
"""
The product's description, meant to be displayable to the customer. Use this field to optionally store a long form explanation of the product being sold for your own rendering purposes.
"""
images: NotRequired[List[str]]
"""
A list of up to 8 URLs of images for this product, meant to be displayable to the customer.
"""
metadata: NotRequired[Dict[str, str]]
"""
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`.
"""
name: str
"""
The product's name, meant to be displayable to the customer.
"""
tax_code: NotRequired[str]
"""
A [tax code](https://stripe.com/docs/tax/tax-categories) ID.
"""
class UpdateParamsPricing(TypedDict):
price: NotRequired[str]
"""
The ID of the price object.
"""
class UpdateParamsTaxAmount(TypedDict):
amount: int
"""
The amount, in cents (or local equivalent), of the tax.
"""
tax_rate_data: (
"InvoiceLineItemService.UpdateParamsTaxAmountTaxRateData"
)
"""
Data to find or create a TaxRate object.
Stripe automatically creates or reuses a TaxRate object for each tax amount. If the `tax_rate_data` exactly matches a previous value, Stripe will reuse the TaxRate object. TaxRate objects created automatically by Stripe are immediately archived, do not appear in the line item's `tax_rates`, and cannot be directly added to invoices, payments, or line items.
"""
taxability_reason: NotRequired[
Literal[
"customer_exempt",
"not_collecting",
"not_subject_to_tax",
"not_supported",
"portion_product_exempt",
"portion_reduced_rated",
"portion_standard_rated",
"product_exempt",
"product_exempt_holiday",
"proportionally_rated",
"reduced_rated",
"reverse_charge",
"standard_rated",
"taxable_basis_reduced",
"zero_rated",
]
]
"""
The reasoning behind this tax, for example, if the product is tax exempt.
"""
taxable_amount: int
"""
The amount on which tax is calculated, in cents (or local equivalent).
"""
class UpdateParamsTaxAmountTaxRateData(TypedDict):
country: NotRequired[str]
"""
Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
"""
description: NotRequired[str]
"""
An arbitrary string attached to the tax rate for your internal use only. It will not be visible to your customers.
"""
display_name: str
"""
The display name of the tax rate, which will be shown to users.
"""
inclusive: bool
"""
This specifies if the tax rate is inclusive or exclusive.
"""
jurisdiction: NotRequired[str]
"""
The jurisdiction for the tax rate. You can use this label field for tax reporting purposes. It also appears on your customer's invoice.
"""
jurisdiction_level: NotRequired[
Literal[
"city", "country", "county", "district", "multiple", "state"
]
]
"""
The level of the jurisdiction that imposes this tax rate.
"""
percentage: float
"""
The statutory tax rate percent. This field accepts decimal values between 0 and 100 inclusive with at most 4 decimal places. To accommodate fixed-amount taxes, set the percentage to zero. Stripe will not display zero percentages on the invoice unless the `amount` of the tax is also zero.
"""
state: NotRequired[str]
"""
[ISO 3166-2 subdivision code](https://en.wikipedia.org/wiki/ISO_3166-2:US), without country prefix. For example, "NY" for New York, United States.
"""
tax_type: NotRequired[
Literal[
"amusement_tax",
"communications_tax",
"gst",
"hst",
"igst",
"jct",
"lease_tax",
"pst",
"qst",
"retail_delivery_fee",
"rst",
"sales_tax",
"service_tax",
"vat",
]
]
"""
The high-level tax type, such as `vat` or `sales_tax`.
"""
def list(
self,
invoice: str,
params: "InvoiceLineItemService.ListParams" = {},
options: RequestOptions = {},
) -> ListObject[InvoiceLineItem]:
"""
When retrieving an invoice, you'll get a lines property containing the total count of line items and the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items.
"""
return cast(
ListObject[InvoiceLineItem],
self._request(
"get",
"/v1/invoices/{invoice}/lines".format(
invoice=sanitize_id(invoice),
),
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
invoice: str,
params: "InvoiceLineItemService.ListParams" = {},
options: RequestOptions = {},
) -> ListObject[InvoiceLineItem]:
"""
When retrieving an invoice, you'll get a lines property containing the total count of line items and the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items.
"""
return cast(
ListObject[InvoiceLineItem],
await self._request_async(
"get",
"/v1/invoices/{invoice}/lines".format(
invoice=sanitize_id(invoice),
),
base_address="api",
params=params,
options=options,
),
)
def update(
self,
invoice: str,
line_item_id: str,
params: "InvoiceLineItemService.UpdateParams" = {},
options: RequestOptions = {},
) -> InvoiceLineItem:
"""
Updates an invoice's line item. Some fields, such as tax_amounts, only live on the invoice line item,
so they can only be updated through this endpoint. Other fields, such as amount, live on both the invoice
item and the invoice line item, so updates on this endpoint will propagate to the invoice item as well.
Updating an invoice's line item is only possible before the invoice is finalized.
"""
return cast(
InvoiceLineItem,
self._request(
"post",
"/v1/invoices/{invoice}/lines/{line_item_id}".format(
invoice=sanitize_id(invoice),
line_item_id=sanitize_id(line_item_id),
),
base_address="api",
params=params,
options=options,
),
)
async def update_async(
self,
invoice: str,
line_item_id: str,
params: "InvoiceLineItemService.UpdateParams" = {},
options: RequestOptions = {},
) -> InvoiceLineItem:
"""
Updates an invoice's line item. Some fields, such as tax_amounts, only live on the invoice line item,
so they can only be updated through this endpoint. Other fields, such as amount, live on both the invoice
item and the invoice line item, so updates on this endpoint will propagate to the invoice item as well.
Updating an invoice's line item is only possible before the invoice is finalized.
"""
return cast(
InvoiceLineItem,
await self._request_async(
"post",
"/v1/invoices/{invoice}/lines/{line_item_id}".format(
invoice=sanitize_id(invoice),
line_item_id=sanitize_id(line_item_id),
),
base_address="api",
params=params,
options=options,
),
)
|