Debian Codegraph @

stripe/tax/_calculation.py

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