| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# File generated from our OpenAPI spec |
| 3 |
from stripe._createable_api_resource import CreateableAPIResource |
| 4 |
from stripe._expandable_field import ExpandableField |
| 5 |
from stripe._list_object import ListObject |
| 6 |
from stripe._listable_api_resource import ListableAPIResource |
| 7 |
from stripe._stripe_object import StripeObject |
| 8 |
from stripe._updateable_api_resource import UpdateableAPIResource |
| 9 |
from stripe._util import class_method_variant, sanitize_id |
| 10 |
from typing import ClassVar, Dict, List, Optional, cast, overload |
| 11 |
from typing_extensions import Literal, Unpack, TYPE_CHECKING |
| 12 |
|
| 13 |
if TYPE_CHECKING: |
| 14 |
from stripe._customer import Customer |
| 15 |
from stripe.params.billing._credit_grant_create_params import ( |
| 16 |
CreditGrantCreateParams, |
| 17 |
) |
| 18 |
from stripe.params.billing._credit_grant_expire_params import ( |
| 19 |
CreditGrantExpireParams, |
| 20 |
) |
| 21 |
from stripe.params.billing._credit_grant_list_params import ( |
| 22 |
CreditGrantListParams, |
| 23 |
) |
| 24 |
from stripe.params.billing._credit_grant_modify_params import ( |
| 25 |
CreditGrantModifyParams, |
| 26 |
) |
| 27 |
from stripe.params.billing._credit_grant_retrieve_params import ( |
| 28 |
CreditGrantRetrieveParams, |
| 29 |
) |
| 30 |
from stripe.params.billing._credit_grant_void_grant_params import ( |
| 31 |
CreditGrantVoidGrantParams, |
| 32 |
) |
| 33 |
from stripe.test_helpers._test_clock import TestClock |
| 34 |
|
| 35 |
|
| 36 |
class CreditGrant( |
| 37 |
CreateableAPIResource["CreditGrant"], |
| 38 |
ListableAPIResource["CreditGrant"], |
| 39 |
UpdateableAPIResource["CreditGrant"], |
| 40 |
): |
| 41 |
""" |
| 42 |
A credit grant is an API resource that documents the allocation of some billing credits to a customer. |
| 43 |
|
| 44 |
Related guide: [Billing credits](https://docs.stripe.com/billing/subscriptions/usage-based/billing-credits) |
| 45 |
""" |
| 46 |
|
| 47 |
OBJECT_NAME: ClassVar[Literal["billing.credit_grant"]] = ( |
| 48 |
"billing.credit_grant" |
| 49 |
) |
| 50 |
|
| 51 |
class Amount(StripeObject): |
| 52 |
class Monetary(StripeObject): |
| 53 |
currency: str |
| 54 |
""" |
| 55 |
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). |
| 56 |
""" |
| 57 |
value: int |
| 58 |
""" |
| 59 |
A positive integer representing the amount. |
| 60 |
""" |
| 61 |
|
| 62 |
monetary: Optional[Monetary] |
| 63 |
""" |
| 64 |
The monetary amount. |
| 65 |
""" |
| 66 |
type: Literal["monetary"] |
| 67 |
""" |
| 68 |
The type of this amount. We currently only support `monetary` billing credits. |
| 69 |
""" |
| 70 |
_inner_class_types = {"monetary": Monetary} |
| 71 |
|
| 72 |
class ApplicabilityConfig(StripeObject): |
| 73 |
class Scope(StripeObject): |
| 74 |
class Price(StripeObject): |
| 75 |
id: Optional[str] |
| 76 |
""" |
| 77 |
Unique identifier for the object. |
| 78 |
""" |
| 79 |
|
| 80 |
price_type: Optional[Literal["metered"]] |
| 81 |
""" |
| 82 |
The price type that credit grants can apply to. We currently only support the `metered` price type. This refers to prices that have a [Billing Meter](https://docs.stripe.com/api/billing/meter) attached to them. Cannot be used in combination with `prices`. |
| 83 |
""" |
| 84 |
prices: Optional[List[Price]] |
| 85 |
""" |
| 86 |
The prices that credit grants can apply to. We currently only support `metered` prices. This refers to prices that have a [Billing Meter](https://docs.stripe.com/api/billing/meter) attached to them. Cannot be used in combination with `price_type`. |
| 87 |
""" |
| 88 |
_inner_class_types = {"prices": Price} |
| 89 |
|
| 90 |
scope: Scope |
| 91 |
_inner_class_types = {"scope": Scope} |
| 92 |
|
| 93 |
amount: Amount |
| 94 |
applicability_config: ApplicabilityConfig |
| 95 |
category: Literal["paid", "promotional"] |
| 96 |
""" |
| 97 |
The category of this credit grant. This is for tracking purposes and isn't displayed to the customer. |
| 98 |
""" |
| 99 |
created: int |
| 100 |
""" |
| 101 |
Time at which the object was created. Measured in seconds since the Unix epoch. |
| 102 |
""" |
| 103 |
customer: ExpandableField["Customer"] |
| 104 |
""" |
| 105 |
ID of the customer receiving the billing credits. |
| 106 |
""" |
| 107 |
customer_account: Optional[str] |
| 108 |
""" |
| 109 |
ID of the account representing the customer receiving the billing credits |
| 110 |
""" |
| 111 |
effective_at: Optional[int] |
| 112 |
""" |
| 113 |
The time when the billing credits become effective-when they're eligible for use. |
| 114 |
""" |
| 115 |
expires_at: Optional[int] |
| 116 |
""" |
| 117 |
The time when the billing credits expire. If not present, the billing credits don't expire. |
| 118 |
""" |
| 119 |
id: str |
| 120 |
""" |
| 121 |
Unique identifier for the object. |
| 122 |
""" |
| 123 |
livemode: bool |
| 124 |
""" |
| 125 |
Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. |
| 126 |
""" |
| 127 |
metadata: Dict[str, str] |
| 128 |
""" |
| 129 |
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. |
| 130 |
""" |
| 131 |
name: Optional[str] |
| 132 |
""" |
| 133 |
A descriptive name shown in dashboard. |
| 134 |
""" |
| 135 |
object: Literal["billing.credit_grant"] |
| 136 |
""" |
| 137 |
String representing the object's type. Objects of the same type share the same value. |
| 138 |
""" |
| 139 |
priority: Optional[int] |
| 140 |
""" |
| 141 |
The priority for applying this credit grant. The highest priority is 0 and the lowest is 100. |
| 142 |
""" |
| 143 |
test_clock: Optional[ExpandableField["TestClock"]] |
| 144 |
""" |
| 145 |
ID of the test clock this credit grant belongs to. |
| 146 |
""" |
| 147 |
updated: int |
| 148 |
""" |
| 149 |
Time at which the object was last updated. Measured in seconds since the Unix epoch. |
| 150 |
""" |
| 151 |
voided_at: Optional[int] |
| 152 |
""" |
| 153 |
The time when this credit grant was voided. If not present, the credit grant hasn't been voided. |
| 154 |
""" |
| 155 |
|
| 156 |
@classmethod |
| 157 |
def create( |
| 158 |
cls, **params: Unpack["CreditGrantCreateParams"] |
| 159 |
) -> "CreditGrant": |
| 160 |
""" |
| 161 |
Creates a credit grant. |
| 162 |
""" |
| 163 |
return cast( |
| 164 |
"CreditGrant", |
| 165 |
cls._static_request( |
| 166 |
"post", |
| 167 |
cls.class_url(), |
| 168 |
params=params, |
| 169 |
), |
| 170 |
) |
| 171 |
|
| 172 |
@classmethod |
| 173 |
async def create_async( |
| 174 |
cls, **params: Unpack["CreditGrantCreateParams"] |
| 175 |
) -> "CreditGrant": |
| 176 |
""" |
| 177 |
Creates a credit grant. |
| 178 |
""" |
| 179 |
return cast( |
| 180 |
"CreditGrant", |
| 181 |
await cls._static_request_async( |
| 182 |
"post", |
| 183 |
cls.class_url(), |
| 184 |
params=params, |
| 185 |
), |
| 186 |
) |
| 187 |
|
| 188 |
@classmethod |
| 189 |
def _cls_expire( |
| 190 |
cls, id: str, **params: Unpack["CreditGrantExpireParams"] |
| 191 |
) -> "CreditGrant": |
| 192 |
""" |
| 193 |
Expires a credit grant. |
| 194 |
""" |
| 195 |
return cast( |
| 196 |
"CreditGrant", |
| 197 |
cls._static_request( |
| 198 |
"post", |
| 199 |
"/v1/billing/credit_grants/{id}/expire".format( |
| 200 |
id=sanitize_id(id) |
| 201 |
), |
| 202 |
params=params, |
| 203 |
), |
| 204 |
) |
| 205 |
|
| 206 |
@overload |
| 207 |
@staticmethod |
| 208 |
def expire( |
| 209 |
id: str, **params: Unpack["CreditGrantExpireParams"] |
| 210 |
) -> "CreditGrant": |
| 211 |
""" |
| 212 |
Expires a credit grant. |
| 213 |
""" |
| 214 |
... |
| 215 |
|
| 216 |
@overload |
| 217 |
def expire( |
| 218 |
self, **params: Unpack["CreditGrantExpireParams"] |
| 219 |
) -> "CreditGrant": |
| 220 |
""" |
| 221 |
Expires a credit grant. |
| 222 |
""" |
| 223 |
... |
| 224 |
|
| 225 |
@class_method_variant("_cls_expire") |
| 226 |
def expire( # pyright: ignore[reportGeneralTypeIssues] |
| 227 |
self, **params: Unpack["CreditGrantExpireParams"] |
| 228 |
) -> "CreditGrant": |
| 229 |
""" |
| 230 |
Expires a credit grant. |
| 231 |
""" |
| 232 |
return cast( |
| 233 |
"CreditGrant", |
| 234 |
self._request( |
| 235 |
"post", |
| 236 |
"/v1/billing/credit_grants/{id}/expire".format( |
| 237 |
id=sanitize_id(self.get("id")) |
| 238 |
), |
| 239 |
params=params, |
| 240 |
), |
| 241 |
) |
| 242 |
|
| 243 |
@classmethod |
| 244 |
async def _cls_expire_async( |
| 245 |
cls, id: str, **params: Unpack["CreditGrantExpireParams"] |
| 246 |
) -> "CreditGrant": |
| 247 |
""" |
| 248 |
Expires a credit grant. |
| 249 |
""" |
| 250 |
return cast( |
| 251 |
"CreditGrant", |
| 252 |
await cls._static_request_async( |
| 253 |
"post", |
| 254 |
"/v1/billing/credit_grants/{id}/expire".format( |
| 255 |
id=sanitize_id(id) |
| 256 |
), |
| 257 |
params=params, |
| 258 |
), |
| 259 |
) |
| 260 |
|
| 261 |
@overload |
| 262 |
@staticmethod |
| 263 |
async def expire_async( |
| 264 |
id: str, **params: Unpack["CreditGrantExpireParams"] |
| 265 |
) -> "CreditGrant": |
| 266 |
""" |
| 267 |
Expires a credit grant. |
| 268 |
""" |
| 269 |
... |
| 270 |
|
| 271 |
@overload |
| 272 |
async def expire_async( |
| 273 |
self, **params: Unpack["CreditGrantExpireParams"] |
| 274 |
) -> "CreditGrant": |
| 275 |
""" |
| 276 |
Expires a credit grant. |
| 277 |
""" |
| 278 |
... |
| 279 |
|
| 280 |
@class_method_variant("_cls_expire_async") |
| 281 |
async def expire_async( # pyright: ignore[reportGeneralTypeIssues] |
| 282 |
self, **params: Unpack["CreditGrantExpireParams"] |
| 283 |
) -> "CreditGrant": |
| 284 |
""" |
| 285 |
Expires a credit grant. |
| 286 |
""" |
| 287 |
return cast( |
| 288 |
"CreditGrant", |
| 289 |
await self._request_async( |
| 290 |
"post", |
| 291 |
"/v1/billing/credit_grants/{id}/expire".format( |
| 292 |
id=sanitize_id(self.get("id")) |
| 293 |
), |
| 294 |
params=params, |
| 295 |
), |
| 296 |
) |
| 297 |
|
| 298 |
@classmethod |
| 299 |
def list( |
| 300 |
cls, **params: Unpack["CreditGrantListParams"] |
| 301 |
) -> ListObject["CreditGrant"]: |
| 302 |
""" |
| 303 |
Retrieve a list of credit grants. |
| 304 |
""" |
| 305 |
result = cls._static_request( |
| 306 |
"get", |
| 307 |
cls.class_url(), |
| 308 |
params=params, |
| 309 |
) |
| 310 |
if not isinstance(result, ListObject): |
| 311 |
raise TypeError( |
| 312 |
"Expected list object from API, got %s" |
| 313 |
% (type(result).__name__) |
| 314 |
) |
| 315 |
|
| 316 |
return result |
| 317 |
|
| 318 |
@classmethod |
| 319 |
async def list_async( |
| 320 |
cls, **params: Unpack["CreditGrantListParams"] |
| 321 |
) -> ListObject["CreditGrant"]: |
| 322 |
""" |
| 323 |
Retrieve a list of credit grants. |
| 324 |
""" |
| 325 |
result = await cls._static_request_async( |
| 326 |
"get", |
| 327 |
cls.class_url(), |
| 328 |
params=params, |
| 329 |
) |
| 330 |
if not isinstance(result, ListObject): |
| 331 |
raise TypeError( |
| 332 |
"Expected list object from API, got %s" |
| 333 |
% (type(result).__name__) |
| 334 |
) |
| 335 |
|
| 336 |
return result |
| 337 |
|
| 338 |
@classmethod |
| 339 |
def modify( |
| 340 |
cls, id: str, **params: Unpack["CreditGrantModifyParams"] |
| 341 |
) -> "CreditGrant": |
| 342 |
""" |
| 343 |
Updates a credit grant. |
| 344 |
""" |
| 345 |
url = "%s/%s" % (cls.class_url(), sanitize_id(id)) |
| 346 |
return cast( |
| 347 |
"CreditGrant", |
| 348 |
cls._static_request( |
| 349 |
"post", |
| 350 |
url, |
| 351 |
params=params, |
| 352 |
), |
| 353 |
) |
| 354 |
|
| 355 |
@classmethod |
| 356 |
async def modify_async( |
| 357 |
cls, id: str, **params: Unpack["CreditGrantModifyParams"] |
| 358 |
) -> "CreditGrant": |
| 359 |
""" |
| 360 |
Updates a credit grant. |
| 361 |
""" |
| 362 |
url = "%s/%s" % (cls.class_url(), sanitize_id(id)) |
| 363 |
return cast( |
| 364 |
"CreditGrant", |
| 365 |
await cls._static_request_async( |
| 366 |
"post", |
| 367 |
url, |
| 368 |
params=params, |
| 369 |
), |
| 370 |
) |
| 371 |
|
| 372 |
@classmethod |
| 373 |
def retrieve( |
| 374 |
cls, id: str, **params: Unpack["CreditGrantRetrieveParams"] |
| 375 |
) -> "CreditGrant": |
| 376 |
""" |
| 377 |
Retrieves a credit grant. |
| 378 |
""" |
| 379 |
instance = cls(id, **params) |
| 380 |
instance.refresh() |
| 381 |
return instance |
| 382 |
|
| 383 |
@classmethod |
| 384 |
async def retrieve_async( |
| 385 |
cls, id: str, **params: Unpack["CreditGrantRetrieveParams"] |
| 386 |
) -> "CreditGrant": |
| 387 |
""" |
| 388 |
Retrieves a credit grant. |
| 389 |
""" |
| 390 |
instance = cls(id, **params) |
| 391 |
await instance.refresh_async() |
| 392 |
return instance |
| 393 |
|
| 394 |
@classmethod |
| 395 |
def _cls_void_grant( |
| 396 |
cls, id: str, **params: Unpack["CreditGrantVoidGrantParams"] |
| 397 |
) -> "CreditGrant": |
| 398 |
""" |
| 399 |
Voids a credit grant. |
| 400 |
""" |
| 401 |
return cast( |
| 402 |
"CreditGrant", |
| 403 |
cls._static_request( |
| 404 |
"post", |
| 405 |
"/v1/billing/credit_grants/{id}/void".format( |
| 406 |
id=sanitize_id(id) |
| 407 |
), |
| 408 |
params=params, |
| 409 |
), |
| 410 |
) |
| 411 |
|
| 412 |
@overload |
| 413 |
@staticmethod |
| 414 |
def void_grant( |
| 415 |
id: str, **params: Unpack["CreditGrantVoidGrantParams"] |
| 416 |
) -> "CreditGrant": |
| 417 |
""" |
| 418 |
Voids a credit grant. |
| 419 |
""" |
| 420 |
... |
| 421 |
|
| 422 |
@overload |
| 423 |
def void_grant( |
| 424 |
self, **params: Unpack["CreditGrantVoidGrantParams"] |
| 425 |
) -> "CreditGrant": |
| 426 |
""" |
| 427 |
Voids a credit grant. |
| 428 |
""" |
| 429 |
... |
| 430 |
|
| 431 |
@class_method_variant("_cls_void_grant") |
| 432 |
def void_grant( # pyright: ignore[reportGeneralTypeIssues] |
| 433 |
self, **params: Unpack["CreditGrantVoidGrantParams"] |
| 434 |
) -> "CreditGrant": |
| 435 |
""" |
| 436 |
Voids a credit grant. |
| 437 |
""" |
| 438 |
return cast( |
| 439 |
"CreditGrant", |
| 440 |
self._request( |
| 441 |
"post", |
| 442 |
"/v1/billing/credit_grants/{id}/void".format( |
| 443 |
id=sanitize_id(self.get("id")) |
| 444 |
), |
| 445 |
params=params, |
| 446 |
), |
| 447 |
) |
| 448 |
|
| 449 |
@classmethod |
| 450 |
async def _cls_void_grant_async( |
| 451 |
cls, id: str, **params: Unpack["CreditGrantVoidGrantParams"] |
| 452 |
) -> "CreditGrant": |
| 453 |
""" |
| 454 |
Voids a credit grant. |
| 455 |
""" |
| 456 |
return cast( |
| 457 |
"CreditGrant", |
| 458 |
await cls._static_request_async( |
| 459 |
"post", |
| 460 |
"/v1/billing/credit_grants/{id}/void".format( |
| 461 |
id=sanitize_id(id) |
| 462 |
), |
| 463 |
params=params, |
| 464 |
), |
| 465 |
) |
| 466 |
|
| 467 |
@overload |
| 468 |
@staticmethod |
| 469 |
async def void_grant_async( |
| 470 |
id: str, **params: Unpack["CreditGrantVoidGrantParams"] |
| 471 |
) -> "CreditGrant": |
| 472 |
""" |
| 473 |
Voids a credit grant. |
| 474 |
""" |
| 475 |
... |
| 476 |
|
| 477 |
@overload |
| 478 |
async def void_grant_async( |
| 479 |
self, **params: Unpack["CreditGrantVoidGrantParams"] |
| 480 |
) -> "CreditGrant": |
| 481 |
""" |
| 482 |
Voids a credit grant. |
| 483 |
""" |
| 484 |
... |
| 485 |
|
| 486 |
@class_method_variant("_cls_void_grant_async") |
| 487 |
async def void_grant_async( # pyright: ignore[reportGeneralTypeIssues] |
| 488 |
self, **params: Unpack["CreditGrantVoidGrantParams"] |
| 489 |
) -> "CreditGrant": |
| 490 |
""" |
| 491 |
Voids a credit grant. |
| 492 |
""" |
| 493 |
return cast( |
| 494 |
"CreditGrant", |
| 495 |
await self._request_async( |
| 496 |
"post", |
| 497 |
"/v1/billing/credit_grants/{id}/void".format( |
| 498 |
id=sanitize_id(self.get("id")) |
| 499 |
), |
| 500 |
params=params, |
| 501 |
), |
| 502 |
) |
| 503 |
|
| 504 |
_inner_class_types = { |
| 505 |
"amount": Amount, |
| 506 |
"applicability_config": ApplicabilityConfig, |
| 507 |
} |