| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# File generated from our OpenAPI spec |
| 3 |
from stripe._stripe_service import StripeService |
| 4 |
from stripe._util import sanitize_id |
| 5 |
from typing import Optional, cast |
| 6 |
from importlib import import_module |
| 7 |
from typing_extensions import TYPE_CHECKING |
| 8 |
|
| 9 |
if TYPE_CHECKING: |
| 10 |
from stripe._request_options import RequestOptions |
| 11 |
from stripe.params.tax._calculation_create_params import ( |
| 12 |
CalculationCreateParams, |
| 13 |
) |
| 14 |
from stripe.params.tax._calculation_retrieve_params import ( |
| 15 |
CalculationRetrieveParams, |
| 16 |
) |
| 17 |
from stripe.tax._calculation import Calculation |
| 18 |
from stripe.tax._calculation_line_item_service import ( |
| 19 |
CalculationLineItemService, |
| 20 |
) |
| 21 |
|
| 22 |
_subservices = { |
| 23 |
"line_items": [ |
| 24 |
"stripe.tax._calculation_line_item_service", |
| 25 |
"CalculationLineItemService", |
| 26 |
], |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
class CalculationService(StripeService): |
| 31 |
line_items: "CalculationLineItemService" |
| 32 |
|
| 33 |
def __init__(self, requestor): |
| 34 |
super().__init__(requestor) |
| 35 |
|
| 36 |
def __getattr__(self, name): |
| 37 |
try: |
| 38 |
import_from, service = _subservices[name] |
| 39 |
service_class = getattr( |
| 40 |
import_module(import_from), |
| 41 |
service, |
| 42 |
) |
| 43 |
setattr( |
| 44 |
self, |
| 45 |
name, |
| 46 |
service_class(self._requestor), |
| 47 |
) |
| 48 |
return getattr(self, name) |
| 49 |
except KeyError: |
| 50 |
raise AttributeError() |
| 51 |
|
| 52 |
def retrieve( |
| 53 |
self, |
| 54 |
calculation: str, |
| 55 |
params: Optional["CalculationRetrieveParams"] = None, |
| 56 |
options: Optional["RequestOptions"] = None, |
| 57 |
) -> "Calculation": |
| 58 |
""" |
| 59 |
Retrieves a Tax Calculation object, if the calculation hasn't expired. |
| 60 |
""" |
| 61 |
return cast( |
| 62 |
"Calculation", |
| 63 |
self._request( |
| 64 |
"get", |
| 65 |
"/v1/tax/calculations/{calculation}".format( |
| 66 |
calculation=sanitize_id(calculation), |
| 67 |
), |
| 68 |
base_address="api", |
| 69 |
params=params, |
| 70 |
options=options, |
| 71 |
), |
| 72 |
) |
| 73 |
|
| 74 |
async def retrieve_async( |
| 75 |
self, |
| 76 |
calculation: str, |
| 77 |
params: Optional["CalculationRetrieveParams"] = None, |
| 78 |
options: Optional["RequestOptions"] = None, |
| 79 |
) -> "Calculation": |
| 80 |
""" |
| 81 |
Retrieves a Tax Calculation object, if the calculation hasn't expired. |
| 82 |
""" |
| 83 |
return cast( |
| 84 |
"Calculation", |
| 85 |
await self._request_async( |
| 86 |
"get", |
| 87 |
"/v1/tax/calculations/{calculation}".format( |
| 88 |
calculation=sanitize_id(calculation), |
| 89 |
), |
| 90 |
base_address="api", |
| 91 |
params=params, |
| 92 |
options=options, |
| 93 |
), |
| 94 |
) |
| 95 |
|
| 96 |
def create( |
| 97 |
self, |
| 98 |
params: "CalculationCreateParams", |
| 99 |
options: Optional["RequestOptions"] = None, |
| 100 |
) -> "Calculation": |
| 101 |
""" |
| 102 |
Calculates tax based on the input and returns a Tax Calculation object. |
| 103 |
""" |
| 104 |
return cast( |
| 105 |
"Calculation", |
| 106 |
self._request( |
| 107 |
"post", |
| 108 |
"/v1/tax/calculations", |
| 109 |
base_address="api", |
| 110 |
params=params, |
| 111 |
options=options, |
| 112 |
), |
| 113 |
) |
| 114 |
|
| 115 |
async def create_async( |
| 116 |
self, |
| 117 |
params: "CalculationCreateParams", |
| 118 |
options: Optional["RequestOptions"] = None, |
| 119 |
) -> "Calculation": |
| 120 |
""" |
| 121 |
Calculates tax based on the input and returns a Tax Calculation object. |
| 122 |
""" |
| 123 |
return cast( |
| 124 |
"Calculation", |
| 125 |
await self._request_async( |
| 126 |
"post", |
| 127 |
"/v1/tax/calculations", |
| 128 |
base_address="api", |
| 129 |
params=params, |
| 130 |
options=options, |
| 131 |
), |
| 132 |
) |