| 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._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_retrieve_params import ( |
| 18 |
TransactionRetrieveParams, |
| 19 |
) |
| 20 |
from stripe.tax._transaction import Transaction |
| 21 |
from stripe.tax._transaction_line_item_service import ( |
| 22 |
TransactionLineItemService, |
| 23 |
) |
| 24 |
|
| 25 |
_subservices = { |
| 26 |
"line_items": [ |
| 27 |
"stripe.tax._transaction_line_item_service", |
| 28 |
"TransactionLineItemService", |
| 29 |
], |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
class TransactionService(StripeService): |
| 34 |
line_items: "TransactionLineItemService" |
| 35 |
|
| 36 |
def __init__(self, requestor): |
| 37 |
super().__init__(requestor) |
| 38 |
|
| 39 |
def __getattr__(self, name): |
| 40 |
try: |
| 41 |
import_from, service = _subservices[name] |
| 42 |
service_class = getattr( |
| 43 |
import_module(import_from), |
| 44 |
service, |
| 45 |
) |
| 46 |
setattr( |
| 47 |
self, |
| 48 |
name, |
| 49 |
service_class(self._requestor), |
| 50 |
) |
| 51 |
return getattr(self, name) |
| 52 |
except KeyError: |
| 53 |
raise AttributeError() |
| 54 |
|
| 55 |
def retrieve( |
| 56 |
self, |
| 57 |
transaction: str, |
| 58 |
params: Optional["TransactionRetrieveParams"] = None, |
| 59 |
options: Optional["RequestOptions"] = None, |
| 60 |
) -> "Transaction": |
| 61 |
""" |
| 62 |
Retrieves a Tax Transaction object. |
| 63 |
""" |
| 64 |
return cast( |
| 65 |
"Transaction", |
| 66 |
self._request( |
| 67 |
"get", |
| 68 |
"/v1/tax/transactions/{transaction}".format( |
| 69 |
transaction=sanitize_id(transaction), |
| 70 |
), |
| 71 |
base_address="api", |
| 72 |
params=params, |
| 73 |
options=options, |
| 74 |
), |
| 75 |
) |
| 76 |
|
| 77 |
async def retrieve_async( |
| 78 |
self, |
| 79 |
transaction: str, |
| 80 |
params: Optional["TransactionRetrieveParams"] = None, |
| 81 |
options: Optional["RequestOptions"] = None, |
| 82 |
) -> "Transaction": |
| 83 |
""" |
| 84 |
Retrieves a Tax Transaction object. |
| 85 |
""" |
| 86 |
return cast( |
| 87 |
"Transaction", |
| 88 |
await self._request_async( |
| 89 |
"get", |
| 90 |
"/v1/tax/transactions/{transaction}".format( |
| 91 |
transaction=sanitize_id(transaction), |
| 92 |
), |
| 93 |
base_address="api", |
| 94 |
params=params, |
| 95 |
options=options, |
| 96 |
), |
| 97 |
) |
| 98 |
|
| 99 |
def create_from_calculation( |
| 100 |
self, |
| 101 |
params: "TransactionCreateFromCalculationParams", |
| 102 |
options: Optional["RequestOptions"] = None, |
| 103 |
) -> "Transaction": |
| 104 |
""" |
| 105 |
Creates a Tax Transaction from a calculation, if that calculation hasn't expired. Calculations expire after 90 days. |
| 106 |
""" |
| 107 |
return cast( |
| 108 |
"Transaction", |
| 109 |
self._request( |
| 110 |
"post", |
| 111 |
"/v1/tax/transactions/create_from_calculation", |
| 112 |
base_address="api", |
| 113 |
params=params, |
| 114 |
options=options, |
| 115 |
), |
| 116 |
) |
| 117 |
|
| 118 |
async def create_from_calculation_async( |
| 119 |
self, |
| 120 |
params: "TransactionCreateFromCalculationParams", |
| 121 |
options: Optional["RequestOptions"] = None, |
| 122 |
) -> "Transaction": |
| 123 |
""" |
| 124 |
Creates a Tax Transaction from a calculation, if that calculation hasn't expired. Calculations expire after 90 days. |
| 125 |
""" |
| 126 |
return cast( |
| 127 |
"Transaction", |
| 128 |
await self._request_async( |
| 129 |
"post", |
| 130 |
"/v1/tax/transactions/create_from_calculation", |
| 131 |
base_address="api", |
| 132 |
params=params, |
| 133 |
options=options, |
| 134 |
), |
| 135 |
) |
| 136 |
|
| 137 |
def create_reversal( |
| 138 |
self, |
| 139 |
params: "TransactionCreateReversalParams", |
| 140 |
options: Optional["RequestOptions"] = None, |
| 141 |
) -> "Transaction": |
| 142 |
""" |
| 143 |
Partially or fully reverses a previously created Transaction. |
| 144 |
""" |
| 145 |
return cast( |
| 146 |
"Transaction", |
| 147 |
self._request( |
| 148 |
"post", |
| 149 |
"/v1/tax/transactions/create_reversal", |
| 150 |
base_address="api", |
| 151 |
params=params, |
| 152 |
options=options, |
| 153 |
), |
| 154 |
) |
| 155 |
|
| 156 |
async def create_reversal_async( |
| 157 |
self, |
| 158 |
params: "TransactionCreateReversalParams", |
| 159 |
options: Optional["RequestOptions"] = None, |
| 160 |
) -> "Transaction": |
| 161 |
""" |
| 162 |
Partially or fully reverses a previously created Transaction. |
| 163 |
""" |
| 164 |
return cast( |
| 165 |
"Transaction", |
| 166 |
await self._request_async( |
| 167 |
"post", |
| 168 |
"/v1/tax/transactions/create_reversal", |
| 169 |
base_address="api", |
| 170 |
params=params, |
| 171 |
options=options, |
| 172 |
), |
| 173 |
) |