Debian Codegraph @

stripe/tax/_transaction.py

raw
1 # -*- coding: utf-8 -*-
2 # File generated from our OpenAPI spec
3 from stripe._api_resource import APIResource
4 from stripe._list_object import ListObject
5 from stripe._stripe_object import StripeObject
6 from stripe._util import class_method_variant, sanitize_id
7 from typing import ClassVar, Dict, List, Optional, cast, overload
8 from typing_extensions import Literal, Unpack, TYPE_CHECKING
9
10 if TYPE_CHECKING:
11 from stripe.params.tax._transaction_create_from_calculation_params import (
12 TransactionCreateFromCalculationParams,
13 )
14 from stripe.params.tax._transaction_create_reversal_params import (
15 TransactionCreateReversalParams,
16 )
17 from stripe.params.tax._transaction_list_line_items_params import (
18 TransactionListLineItemsParams,
19 )
20 from stripe.params.tax._transaction_retrieve_params import (
21 TransactionRetrieveParams,
22 )
23 from stripe.tax._transaction_line_item import TransactionLineItem
24
25
26 class Transaction(APIResource["Transaction"]):
27 """
28 A Tax Transaction records the tax collected from or refunded to your customer.
29
30 Related guide: [Calculate tax in your custom payment flow](https://docs.stripe.com/tax/custom#tax-transaction)
31 """
32
33 OBJECT_NAME: ClassVar[Literal["tax.transaction"]] = "tax.transaction"
34
35 class CustomerDetails(StripeObject):
36 class Address(StripeObject):
37 city: Optional[str]
38 """
39 City, district, suburb, town, or village.
40 """
41 country: str
42 """
43 Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
44 """
45 line1: Optional[str]
46 """
47 Address line 1, such as the street, PO Box, or company name.
48 """
49 line2: Optional[str]
50 """
51 Address line 2, such as the apartment, suite, unit, or building.
52 """
53 postal_code: Optional[str]
54 """
55 ZIP or postal code.
56 """
57 state: Optional[str]
58 """
59 State/province as an [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) subdivision code, without country prefix, such as "NY" or "TX".
60 """
61
62 class TaxId(StripeObject):
63 type: Literal[
64 "ad_nrt",
65 "ae_trn",
66 "al_tin",
67 "am_tin",
68 "ao_tin",
69 "ar_cuit",
70 "au_abn",
71 "au_arn",
72 "aw_tin",
73 "az_tin",
74 "ba_tin",
75 "bb_tin",
76 "bd_bin",
77 "bf_ifu",
78 "bg_uic",
79 "bh_vat",
80 "bj_ifu",
81 "bo_tin",
82 "br_cnpj",
83 "br_cpf",
84 "bs_tin",
85 "by_tin",
86 "ca_bn",
87 "ca_gst_hst",
88 "ca_pst_bc",
89 "ca_pst_mb",
90 "ca_pst_sk",
91 "ca_qst",
92 "cd_nif",
93 "ch_uid",
94 "ch_vat",
95 "cl_tin",
96 "cm_niu",
97 "cn_tin",
98 "co_nit",
99 "cr_tin",
100 "cv_nif",
101 "de_stn",
102 "do_rcn",
103 "ec_ruc",
104 "eg_tin",
105 "es_cif",
106 "et_tin",
107 "eu_oss_vat",
108 "eu_vat",
109 "gb_vat",
110 "ge_vat",
111 "gn_nif",
112 "hk_br",
113 "hr_oib",
114 "hu_tin",
115 "id_npwp",
116 "il_vat",
117 "in_gst",
118 "is_vat",
119 "jp_cn",
120 "jp_rn",
121 "jp_trn",
122 "ke_pin",
123 "kg_tin",
124 "kh_tin",
125 "kr_brn",
126 "kz_bin",
127 "la_tin",
128 "li_uid",
129 "li_vat",
130 "lk_vat",
131 "ma_vat",
132 "md_vat",
133 "me_pib",
134 "mk_vat",
135 "mr_nif",
136 "mx_rfc",
137 "my_frp",
138 "my_itn",
139 "my_sst",
140 "ng_tin",
141 "no_vat",
142 "no_voec",
143 "np_pan",
144 "nz_gst",
145 "om_vat",
146 "pe_ruc",
147 "ph_tin",
148 "pl_nip",
149 "ro_tin",
150 "rs_pib",
151 "ru_inn",
152 "ru_kpp",
153 "sa_vat",
154 "sg_gst",
155 "sg_uen",
156 "si_tin",
157 "sn_ninea",
158 "sr_fin",
159 "sv_nit",
160 "th_vat",
161 "tj_tin",
162 "tr_tin",
163 "tw_vat",
164 "tz_vat",
165 "ua_vat",
166 "ug_tin",
167 "unknown",
168 "us_ein",
169 "uy_ruc",
170 "uz_tin",
171 "uz_vat",
172 "ve_rif",
173 "vn_tin",
174 "za_vat",
175 "zm_tin",
176 "zw_tin",
177 ]
178 """
179 The type of the tax ID, one of `ad_nrt`, `ar_cuit`, `eu_vat`, `bo_tin`, `br_cnpj`, `br_cpf`, `cn_tin`, `co_nit`, `cr_tin`, `do_rcn`, `ec_ruc`, `eu_oss_vat`, `hr_oib`, `pe_ruc`, `ro_tin`, `rs_pib`, `sv_nit`, `uy_ruc`, `ve_rif`, `vn_tin`, `gb_vat`, `nz_gst`, `au_abn`, `au_arn`, `in_gst`, `no_vat`, `no_voec`, `za_vat`, `ch_vat`, `mx_rfc`, `sg_uen`, `ru_inn`, `ru_kpp`, `ca_bn`, `hk_br`, `es_cif`, `pl_nip`, `tw_vat`, `th_vat`, `jp_cn`, `jp_rn`, `jp_trn`, `li_uid`, `li_vat`, `lk_vat`, `my_itn`, `us_ein`, `kr_brn`, `ca_qst`, `ca_gst_hst`, `ca_pst_bc`, `ca_pst_mb`, `ca_pst_sk`, `my_sst`, `sg_gst`, `ae_trn`, `cl_tin`, `sa_vat`, `id_npwp`, `my_frp`, `il_vat`, `ge_vat`, `ua_vat`, `is_vat`, `bg_uic`, `hu_tin`, `si_tin`, `ke_pin`, `tr_tin`, `eg_tin`, `ph_tin`, `al_tin`, `bh_vat`, `kz_bin`, `ng_tin`, `om_vat`, `de_stn`, `ch_uid`, `tz_vat`, `uz_vat`, `uz_tin`, `md_vat`, `ma_vat`, `by_tin`, `ao_tin`, `bs_tin`, `bb_tin`, `cd_nif`, `mr_nif`, `me_pib`, `zw_tin`, `ba_tin`, `gn_nif`, `mk_vat`, `sr_fin`, `sn_ninea`, `am_tin`, `np_pan`, `tj_tin`, `ug_tin`, `zm_tin`, `kh_tin`, `aw_tin`, `az_tin`, `bd_bin`, `bj_ifu`, `et_tin`, `kg_tin`, `la_tin`, `cm_niu`, `cv_nif`, `bf_ifu`, or `unknown`
180 """
181 value: str
182 """
183 The value of the tax ID.
184 """
185
186 address: Optional[Address]
187 """
188 The customer's postal address (for example, home or business location).
189 """
190 address_source: Optional[Literal["billing", "shipping"]]
191 """
192 The type of customer address provided.
193 """
194 ip_address: Optional[str]
195 """
196 The customer's IP address (IPv4 or IPv6).
197 """
198 tax_ids: List[TaxId]
199 """
200 The customer's tax IDs (for example, EU VAT numbers).
201 """
202 taxability_override: Literal[
203 "customer_exempt", "none", "reverse_charge"
204 ]
205 """
206 The taxability override used for taxation.
207 """
208 _inner_class_types = {"address": Address, "tax_ids": TaxId}
209
210 class Reversal(StripeObject):
211 original_transaction: Optional[str]
212 """
213 The `id` of the reversed `Transaction` object.
214 """
215
216 class ShipFromDetails(StripeObject):
217 class Address(StripeObject):
218 city: Optional[str]
219 """
220 City, district, suburb, town, or village.
221 """
222 country: str
223 """
224 Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
225 """
226 line1: Optional[str]
227 """
228 Address line 1, such as the street, PO Box, or company name.
229 """
230 line2: Optional[str]
231 """
232 Address line 2, such as the apartment, suite, unit, or building.
233 """
234 postal_code: Optional[str]
235 """
236 ZIP or postal code.
237 """
238 state: Optional[str]
239 """
240 State/province as an [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) subdivision code, without country prefix, such as "NY" or "TX".
241 """
242
243 address: Address
244 _inner_class_types = {"address": Address}
245
246 class ShippingCost(StripeObject):
247 class TaxBreakdown(StripeObject):
248 class Jurisdiction(StripeObject):
249 country: str
250 """
251 Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
252 """
253 display_name: str
254 """
255 A human-readable name for the jurisdiction imposing the tax.
256 """
257 level: Literal[
258 "city", "country", "county", "district", "state"
259 ]
260 """
261 Indicates the level of the jurisdiction imposing the tax.
262 """
263 state: Optional[str]
264 """
265 [ISO 3166-2 subdivision code](https://en.wikipedia.org/wiki/ISO_3166-2), without country prefix. For example, "NY" for New York, United States.
266 """
267
268 class TaxRateDetails(StripeObject):
269 display_name: str
270 """
271 A localized display name for tax type, intended to be human-readable. For example, "Local Sales and Use Tax", "Value-added tax (VAT)", or "Umsatzsteuer (USt.)".
272 """
273 percentage_decimal: str
274 """
275 The tax rate percentage as a string. For example, 8.5% is represented as "8.5".
276 """
277 tax_type: Literal[
278 "amusement_tax",
279 "communications_tax",
280 "gst",
281 "hst",
282 "igst",
283 "jct",
284 "lease_tax",
285 "pst",
286 "qst",
287 "retail_delivery_fee",
288 "rst",
289 "sales_tax",
290 "service_tax",
291 "vat",
292 ]
293 """
294 The tax type, such as `vat` or `sales_tax`.
295 """
296
297 amount: int
298 """
299 The amount of tax, in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal).
300 """
301 jurisdiction: Jurisdiction
302 sourcing: Literal["destination", "origin"]
303 """
304 Indicates whether the jurisdiction was determined by the origin (merchant's address) or destination (customer's address).
305 """
306 tax_rate_details: Optional[TaxRateDetails]
307 """
308 Details regarding the rate for this tax. This field will be `null` when the tax is not imposed, for example if the product is exempt from tax.
309 """
310 taxability_reason: Literal[
311 "customer_exempt",
312 "not_collecting",
313 "not_subject_to_tax",
314 "not_supported",
315 "portion_product_exempt",
316 "portion_reduced_rated",
317 "portion_standard_rated",
318 "product_exempt",
319 "product_exempt_holiday",
320 "proportionally_rated",
321 "reduced_rated",
322 "reverse_charge",
323 "standard_rated",
324 "taxable_basis_reduced",
325 "zero_rated",
326 ]
327 """
328 The reasoning behind this tax, for example, if the product is tax exempt. The possible values for this field may be extended as new tax rules are supported.
329 """
330 taxable_amount: int
331 """
332 The amount on which tax is calculated, in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal).
333 """
334 _inner_class_types = {
335 "jurisdiction": Jurisdiction,
336 "tax_rate_details": TaxRateDetails,
337 }
338
339 amount: int
340 """
341 The shipping amount in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal). If `tax_behavior=inclusive`, then this amount includes taxes. Otherwise, taxes were calculated on top of this amount.
342 """
343 amount_tax: int
344 """
345 The amount of tax calculated for shipping, in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal).
346 """
347 shipping_rate: Optional[str]
348 """
349 The ID of an existing [ShippingRate](https://docs.stripe.com/api/shipping_rates/object).
350 """
351 tax_behavior: Literal["exclusive", "inclusive"]
352 """
353 Specifies whether the `amount` includes taxes. If `tax_behavior=inclusive`, then the amount includes taxes.
354 """
355 tax_breakdown: Optional[List[TaxBreakdown]]
356 """
357 Detailed account of taxes relevant to shipping cost. (It is not populated for the transaction resource object and will be removed in the next API version.)
358 """
359 tax_code: str
360 """
361 The [tax code](https://docs.stripe.com/tax/tax-categories) ID used for shipping.
362 """
363 _inner_class_types = {"tax_breakdown": TaxBreakdown}
364
365 created: int
366 """
367 Time at which the object was created. Measured in seconds since the Unix epoch.
368 """
369 currency: str
370 """
371 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).
372 """
373 customer: Optional[str]
374 """
375 The ID of an existing [Customer](https://docs.stripe.com/api/customers/object) used for the resource.
376 """
377 customer_details: CustomerDetails
378 id: str
379 """
380 Unique identifier for the transaction.
381 """
382 line_items: Optional[ListObject["TransactionLineItem"]]
383 """
384 The tax collected or refunded, by line item.
385 """
386 livemode: bool
387 """
388 Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
389 """
390 metadata: Optional[Dict[str, str]]
391 """
392 Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
393 """
394 object: Literal["tax.transaction"]
395 """
396 String representing the object's type. Objects of the same type share the same value.
397 """
398 posted_at: int
399 """
400 The Unix timestamp representing when the tax liability is assumed or reduced.
401 """
402 reference: str
403 """
404 A custom unique identifier, such as 'myOrder_123'.
405 """
406 reversal: Optional[Reversal]
407 """
408 If `type=reversal`, contains information about what was reversed.
409 """
410 ship_from_details: Optional[ShipFromDetails]
411 """
412 The details of the ship from location, such as the address.
413 """
414 shipping_cost: Optional[ShippingCost]
415 """
416 The shipping cost details for the transaction.
417 """
418 tax_date: int
419 """
420 Timestamp of date at which the tax rules and rates in effect applies for the calculation.
421 """
422 type: Literal["reversal", "transaction"]
423 """
424 If `reversal`, this transaction reverses an earlier transaction.
425 """
426
427 @classmethod
428 def create_from_calculation(
429 cls, **params: Unpack["TransactionCreateFromCalculationParams"]
430 ) -> "Transaction":
431 """
432 Creates a Tax Transaction from a calculation, if that calculation hasn't expired. Calculations expire after 90 days.
433 """
434 return cast(
435 "Transaction",
436 cls._static_request(
437 "post",
438 "/v1/tax/transactions/create_from_calculation",
439 params=params,
440 ),
441 )
442
443 @classmethod
444 async def create_from_calculation_async(
445 cls, **params: Unpack["TransactionCreateFromCalculationParams"]
446 ) -> "Transaction":
447 """
448 Creates a Tax Transaction from a calculation, if that calculation hasn't expired. Calculations expire after 90 days.
449 """
450 return cast(
451 "Transaction",
452 await cls._static_request_async(
453 "post",
454 "/v1/tax/transactions/create_from_calculation",
455 params=params,
456 ),
457 )
458
459 @classmethod
460 def create_reversal(
461 cls, **params: Unpack["TransactionCreateReversalParams"]
462 ) -> "Transaction":
463 """
464 Partially or fully reverses a previously created Transaction.
465 """
466 return cast(
467 "Transaction",
468 cls._static_request(
469 "post",
470 "/v1/tax/transactions/create_reversal",
471 params=params,
472 ),
473 )
474
475 @classmethod
476 async def create_reversal_async(
477 cls, **params: Unpack["TransactionCreateReversalParams"]
478 ) -> "Transaction":
479 """
480 Partially or fully reverses a previously created Transaction.
481 """
482 return cast(
483 "Transaction",
484 await cls._static_request_async(
485 "post",
486 "/v1/tax/transactions/create_reversal",
487 params=params,
488 ),
489 )
490
491 @classmethod
492 def _cls_list_line_items(
493 cls,
494 transaction: str,
495 **params: Unpack["TransactionListLineItemsParams"],
496 ) -> ListObject["TransactionLineItem"]:
497 """
498 Retrieves the line items of a committed standalone transaction as a collection.
499 """
500 return cast(
501 ListObject["TransactionLineItem"],
502 cls._static_request(
503 "get",
504 "/v1/tax/transactions/{transaction}/line_items".format(
505 transaction=sanitize_id(transaction)
506 ),
507 params=params,
508 ),
509 )
510
511 @overload
512 @staticmethod
513 def list_line_items(
514 transaction: str, **params: Unpack["TransactionListLineItemsParams"]
515 ) -> ListObject["TransactionLineItem"]:
516 """
517 Retrieves the line items of a committed standalone transaction as a collection.
518 """
519 ...
520
521 @overload
522 def list_line_items(
523 self, **params: Unpack["TransactionListLineItemsParams"]
524 ) -> ListObject["TransactionLineItem"]:
525 """
526 Retrieves the line items of a committed standalone transaction as a collection.
527 """
528 ...
529
530 @class_method_variant("_cls_list_line_items")
531 def list_line_items( # pyright: ignore[reportGeneralTypeIssues]
532 self, **params: Unpack["TransactionListLineItemsParams"]
533 ) -> ListObject["TransactionLineItem"]:
534 """
535 Retrieves the line items of a committed standalone transaction as a collection.
536 """
537 return cast(
538 ListObject["TransactionLineItem"],
539 self._request(
540 "get",
541 "/v1/tax/transactions/{transaction}/line_items".format(
542 transaction=sanitize_id(self.get("id"))
543 ),
544 params=params,
545 ),
546 )
547
548 @classmethod
549 async def _cls_list_line_items_async(
550 cls,
551 transaction: str,
552 **params: Unpack["TransactionListLineItemsParams"],
553 ) -> ListObject["TransactionLineItem"]:
554 """
555 Retrieves the line items of a committed standalone transaction as a collection.
556 """
557 return cast(
558 ListObject["TransactionLineItem"],
559 await cls._static_request_async(
560 "get",
561 "/v1/tax/transactions/{transaction}/line_items".format(
562 transaction=sanitize_id(transaction)
563 ),
564 params=params,
565 ),
566 )
567
568 @overload
569 @staticmethod
570 async def list_line_items_async(
571 transaction: str, **params: Unpack["TransactionListLineItemsParams"]
572 ) -> ListObject["TransactionLineItem"]:
573 """
574 Retrieves the line items of a committed standalone transaction as a collection.
575 """
576 ...
577
578 @overload
579 async def list_line_items_async(
580 self, **params: Unpack["TransactionListLineItemsParams"]
581 ) -> ListObject["TransactionLineItem"]:
582 """
583 Retrieves the line items of a committed standalone transaction as a collection.
584 """
585 ...
586
587 @class_method_variant("_cls_list_line_items_async")
588 async def list_line_items_async( # pyright: ignore[reportGeneralTypeIssues]
589 self, **params: Unpack["TransactionListLineItemsParams"]
590 ) -> ListObject["TransactionLineItem"]:
591 """
592 Retrieves the line items of a committed standalone transaction as a collection.
593 """
594 return cast(
595 ListObject["TransactionLineItem"],
596 await self._request_async(
597 "get",
598 "/v1/tax/transactions/{transaction}/line_items".format(
599 transaction=sanitize_id(self.get("id"))
600 ),
601 params=params,
602 ),
603 )
604
605 @classmethod
606 def retrieve(
607 cls, id: str, **params: Unpack["TransactionRetrieveParams"]
608 ) -> "Transaction":
609 """
610 Retrieves a Tax Transaction object.
611 """
612 instance = cls(id, **params)
613 instance.refresh()
614 return instance
615
616 @classmethod
617 async def retrieve_async(
618 cls, id: str, **params: Unpack["TransactionRetrieveParams"]
619 ) -> "Transaction":
620 """
621 Retrieves a Tax Transaction object.
622 """
623 instance = cls(id, **params)
624 await instance.refresh_async()
625 return instance
626
627 _inner_class_types = {
628 "customer_details": CustomerDetails,
629 "reversal": Reversal,
630 "ship_from_details": ShipFromDetails,
631 "shipping_cost": ShippingCost,
632 }