| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# File generated from our OpenAPI spec |
| 3 |
from stripe._expandable_field import ExpandableField |
| 4 |
from stripe._list_object import ListObject |
| 5 |
from stripe._listable_api_resource import ListableAPIResource |
| 6 |
from stripe._stripe_object import StripeObject |
| 7 |
from typing import ClassVar, Optional |
| 8 |
from typing_extensions import Literal, Unpack, TYPE_CHECKING |
| 9 |
|
| 10 |
if TYPE_CHECKING: |
| 11 |
from stripe._invoice import Invoice |
| 12 |
from stripe.billing._credit_grant import CreditGrant |
| 13 |
from stripe.params.billing._credit_balance_transaction_list_params import ( |
| 14 |
CreditBalanceTransactionListParams, |
| 15 |
) |
| 16 |
from stripe.params.billing._credit_balance_transaction_retrieve_params import ( |
| 17 |
CreditBalanceTransactionRetrieveParams, |
| 18 |
) |
| 19 |
from stripe.test_helpers._test_clock import TestClock |
| 20 |
|
| 21 |
|
| 22 |
class CreditBalanceTransaction( |
| 23 |
ListableAPIResource["CreditBalanceTransaction"] |
| 24 |
): |
| 25 |
""" |
| 26 |
A credit balance transaction is a resource representing a transaction (either a credit or a debit) against an existing credit grant. |
| 27 |
""" |
| 28 |
|
| 29 |
OBJECT_NAME: ClassVar[Literal["billing.credit_balance_transaction"]] = ( |
| 30 |
"billing.credit_balance_transaction" |
| 31 |
) |
| 32 |
|
| 33 |
class Credit(StripeObject): |
| 34 |
class Amount(StripeObject): |
| 35 |
class Monetary(StripeObject): |
| 36 |
currency: str |
| 37 |
""" |
| 38 |
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). |
| 39 |
""" |
| 40 |
value: int |
| 41 |
""" |
| 42 |
A positive integer representing the amount. |
| 43 |
""" |
| 44 |
|
| 45 |
monetary: Optional[Monetary] |
| 46 |
""" |
| 47 |
The monetary amount. |
| 48 |
""" |
| 49 |
type: Literal["monetary"] |
| 50 |
""" |
| 51 |
The type of this amount. We currently only support `monetary` billing credits. |
| 52 |
""" |
| 53 |
_inner_class_types = {"monetary": Monetary} |
| 54 |
|
| 55 |
class CreditsApplicationInvoiceVoided(StripeObject): |
| 56 |
invoice: ExpandableField["Invoice"] |
| 57 |
""" |
| 58 |
The invoice to which the reinstated billing credits were originally applied. |
| 59 |
""" |
| 60 |
invoice_line_item: str |
| 61 |
""" |
| 62 |
The invoice line item to which the reinstated billing credits were originally applied. |
| 63 |
""" |
| 64 |
|
| 65 |
amount: Amount |
| 66 |
credits_application_invoice_voided: Optional[ |
| 67 |
CreditsApplicationInvoiceVoided |
| 68 |
] |
| 69 |
""" |
| 70 |
Details of the invoice to which the reinstated credits were originally applied. Only present if `type` is `credits_application_invoice_voided`. |
| 71 |
""" |
| 72 |
type: Literal["credits_application_invoice_voided", "credits_granted"] |
| 73 |
""" |
| 74 |
The type of credit transaction. |
| 75 |
""" |
| 76 |
_inner_class_types = { |
| 77 |
"amount": Amount, |
| 78 |
"credits_application_invoice_voided": CreditsApplicationInvoiceVoided, |
| 79 |
} |
| 80 |
|
| 81 |
class Debit(StripeObject): |
| 82 |
class Amount(StripeObject): |
| 83 |
class Monetary(StripeObject): |
| 84 |
currency: str |
| 85 |
""" |
| 86 |
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). |
| 87 |
""" |
| 88 |
value: int |
| 89 |
""" |
| 90 |
A positive integer representing the amount. |
| 91 |
""" |
| 92 |
|
| 93 |
monetary: Optional[Monetary] |
| 94 |
""" |
| 95 |
The monetary amount. |
| 96 |
""" |
| 97 |
type: Literal["monetary"] |
| 98 |
""" |
| 99 |
The type of this amount. We currently only support `monetary` billing credits. |
| 100 |
""" |
| 101 |
_inner_class_types = {"monetary": Monetary} |
| 102 |
|
| 103 |
class CreditsApplied(StripeObject): |
| 104 |
invoice: ExpandableField["Invoice"] |
| 105 |
""" |
| 106 |
The invoice to which the billing credits were applied. |
| 107 |
""" |
| 108 |
invoice_line_item: str |
| 109 |
""" |
| 110 |
The invoice line item to which the billing credits were applied. |
| 111 |
""" |
| 112 |
|
| 113 |
amount: Amount |
| 114 |
credits_applied: Optional[CreditsApplied] |
| 115 |
""" |
| 116 |
Details of how the billing credits were applied to an invoice. Only present if `type` is `credits_applied`. |
| 117 |
""" |
| 118 |
type: Literal["credits_applied", "credits_expired", "credits_voided"] |
| 119 |
""" |
| 120 |
The type of debit transaction. |
| 121 |
""" |
| 122 |
_inner_class_types = { |
| 123 |
"amount": Amount, |
| 124 |
"credits_applied": CreditsApplied, |
| 125 |
} |
| 126 |
|
| 127 |
created: int |
| 128 |
""" |
| 129 |
Time at which the object was created. Measured in seconds since the Unix epoch. |
| 130 |
""" |
| 131 |
credit: Optional[Credit] |
| 132 |
""" |
| 133 |
Credit details for this credit balance transaction. Only present if type is `credit`. |
| 134 |
""" |
| 135 |
credit_grant: ExpandableField["CreditGrant"] |
| 136 |
""" |
| 137 |
The credit grant associated with this credit balance transaction. |
| 138 |
""" |
| 139 |
debit: Optional[Debit] |
| 140 |
""" |
| 141 |
Debit details for this credit balance transaction. Only present if type is `debit`. |
| 142 |
""" |
| 143 |
effective_at: int |
| 144 |
""" |
| 145 |
The effective time of this credit balance transaction. |
| 146 |
""" |
| 147 |
id: str |
| 148 |
""" |
| 149 |
Unique identifier for the object. |
| 150 |
""" |
| 151 |
livemode: bool |
| 152 |
""" |
| 153 |
Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. |
| 154 |
""" |
| 155 |
object: Literal["billing.credit_balance_transaction"] |
| 156 |
""" |
| 157 |
String representing the object's type. Objects of the same type share the same value. |
| 158 |
""" |
| 159 |
test_clock: Optional[ExpandableField["TestClock"]] |
| 160 |
""" |
| 161 |
ID of the test clock this credit balance transaction belongs to. |
| 162 |
""" |
| 163 |
type: Optional[Literal["credit", "debit"]] |
| 164 |
""" |
| 165 |
The type of credit balance transaction (credit or debit). |
| 166 |
""" |
| 167 |
|
| 168 |
@classmethod |
| 169 |
def list( |
| 170 |
cls, **params: Unpack["CreditBalanceTransactionListParams"] |
| 171 |
) -> ListObject["CreditBalanceTransaction"]: |
| 172 |
""" |
| 173 |
Retrieve a list of credit balance transactions. |
| 174 |
""" |
| 175 |
result = cls._static_request( |
| 176 |
"get", |
| 177 |
cls.class_url(), |
| 178 |
params=params, |
| 179 |
) |
| 180 |
if not isinstance(result, ListObject): |
| 181 |
raise TypeError( |
| 182 |
"Expected list object from API, got %s" |
| 183 |
% (type(result).__name__) |
| 184 |
) |
| 185 |
|
| 186 |
return result |
| 187 |
|
| 188 |
@classmethod |
| 189 |
async def list_async( |
| 190 |
cls, **params: Unpack["CreditBalanceTransactionListParams"] |
| 191 |
) -> ListObject["CreditBalanceTransaction"]: |
| 192 |
""" |
| 193 |
Retrieve a list of credit balance transactions. |
| 194 |
""" |
| 195 |
result = await cls._static_request_async( |
| 196 |
"get", |
| 197 |
cls.class_url(), |
| 198 |
params=params, |
| 199 |
) |
| 200 |
if not isinstance(result, ListObject): |
| 201 |
raise TypeError( |
| 202 |
"Expected list object from API, got %s" |
| 203 |
% (type(result).__name__) |
| 204 |
) |
| 205 |
|
| 206 |
return result |
| 207 |
|
| 208 |
@classmethod |
| 209 |
def retrieve( |
| 210 |
cls, |
| 211 |
id: str, |
| 212 |
**params: Unpack["CreditBalanceTransactionRetrieveParams"], |
| 213 |
) -> "CreditBalanceTransaction": |
| 214 |
""" |
| 215 |
Retrieves a credit balance transaction. |
| 216 |
""" |
| 217 |
instance = cls(id, **params) |
| 218 |
instance.refresh() |
| 219 |
return instance |
| 220 |
|
| 221 |
@classmethod |
| 222 |
async def retrieve_async( |
| 223 |
cls, |
| 224 |
id: str, |
| 225 |
**params: Unpack["CreditBalanceTransactionRetrieveParams"], |
| 226 |
) -> "CreditBalanceTransaction": |
| 227 |
""" |
| 228 |
Retrieves a credit balance transaction. |
| 229 |
""" |
| 230 |
instance = cls(id, **params) |
| 231 |
await instance.refresh_async() |
| 232 |
return instance |
| 233 |
|
| 234 |
_inner_class_types = {"credit": Credit, "debit": Debit} |