Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- master
- beta
- private-preview
- sdk-release/**
- feature/**
tags:
Expand Down
2 changes: 1 addition & 1 deletion CODEGEN_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
baff58c9d515cdd5f5c3231d101989d588788c6f
ea0f8e8d45ce01f448d4a4c4d336d1b491ce684f
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2442
v2456
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ sends by default. If you are overriding `stripe.api_version` / `stripe_version`
[webhook endpoint](https://stripe.com/docs/webhooks#api-versions) tied to an older version,
be aware that the data you see at runtime may not match the types.

### Open and Closed Enums

Many of Stripe API enums are open, meaning Stripe may add new values even on older API versions.
To reflect this, open enum fields are typed as `Union[Literal[...], str]` rather than a plain `Literal[...]`.
This ensures the field has the correct type for both values known at SDK release time and other values that may be added later.

A small number of enums are closed, meaning Stripe guarantees no new values will be added without an API version change.

Refer to the [API Reference](https://docs.stripe.com) for the latest set of allowed values.


### Public Preview SDKs

Stripe has features in the [public preview phase](https://docs.stripe.com/release-phases) that can be accessed via versions of this package that have the `bX` suffix like `12.2.0b2`.
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ typecheck: install-test-deps install-dev-deps

# ⭐ format all code
format: install-dev-deps
ruff format . --quiet
ruff format . > /dev/null

# verify formatting, but don't modify files
format-check: install-dev-deps
ruff format . --check --quiet
ruff format . --check > /dev/null

# remove venv & build artifacts
clean:
Expand Down
4 changes: 2 additions & 2 deletions stripe/_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# File generated from our OpenAPI spec
from stripe._expandable_field import ExpandableField
from stripe._stripe_object import StripeObject
from typing import ClassVar, Optional
from typing import ClassVar, Optional, Union
from typing_extensions import Literal, TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -26,7 +26,7 @@ class Source(StripeObject):
"""
The coupon that was redeemed to create this discount.
"""
type: Literal["coupon"]
type: Union[Literal["coupon"], str]
"""
The source type of the discount.
"""
Expand Down
2 changes: 1 addition & 1 deletion stripe/_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ class WechatPay(StripeObject):
"""
The client type that the end customer will pay from
"""
setup_future_usage: Optional[Literal["none"]]
setup_future_usage: Optional[Union[Literal["none"], str]]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
4 changes: 2 additions & 2 deletions stripe/_payment_attempt_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class Card(StripeObject):
"""

card: Optional[Card]
type: Optional[Literal["card"]]
type: Optional[Union[Literal["card"], str]]
"""
funding type of the underlying payment method.
"""
Expand Down Expand Up @@ -1826,7 +1826,7 @@ class Card(StripeObject):
"""

card: Optional[Card]
type: Optional[Literal["card"]]
type: Optional[Union[Literal["card"], str]]
"""
Funding type of the underlying payment method.
"""
Expand Down
2 changes: 1 addition & 1 deletion stripe/_payment_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4417,7 +4417,7 @@ class WechatPay(StripeObject):
"""
The client type that the end customer will pay from
"""
setup_future_usage: Optional[Literal["none"]]
setup_future_usage: Optional[Union[Literal["none"], str]]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
4 changes: 2 additions & 2 deletions stripe/_payment_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class Card(StripeObject):
"""

card: Optional[Card]
type: Optional[Literal["card"]]
type: Optional[Union[Literal["card"], str]]
"""
funding type of the underlying payment method.
"""
Expand Down Expand Up @@ -1846,7 +1846,7 @@ class Card(StripeObject):
"""

card: Optional[Card]
type: Optional[Literal["card"]]
type: Optional[Union[Literal["card"], str]]
"""
Funding type of the underlying payment method.
"""
Expand Down
34 changes: 33 additions & 1 deletion stripe/_stripe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ def _refresh_from(
for k, v in values.items():
# Apply field encoding coercion (e.g. int64_string: str → int)
v = self._coerce_field_value(k, v)
inner_class = self._get_inner_class_type(k)
inner_class = self._get_union_variant_class(
k, v
) or self._get_inner_class_type(k)
is_dict = self._get_inner_class_is_beneath_dict(k)
if is_dict:
obj = {
Expand Down Expand Up @@ -682,11 +684,41 @@ def __deepcopy__(self, memo: Dict[int, Any]) -> "StripeObject":
_inner_class_dicts: ClassVar[List[str]] = []
_field_encodings: ClassVar[Dict[str, str]] = {}

# Maps a discriminated-union field to (discriminator, {value: class}). Generated
# subclasses override this; every other object keeps the empty default so the
# lookup in _update_attributes stays cheap.
_inner_class_union_variant_types: ClassVar[
Dict[str, Tuple[str, Dict[str, Type["StripeObject"]]]]
] = {}

def _get_inner_class_type(
self, field_name: str
) -> Optional[Type["StripeObject"]]:
return self._inner_class_types.get(field_name)

def _get_union_variant_class(
self, field_name: str, value: Any
) -> Optional[Type["StripeObject"]]:
"""
Returns the variant class that a discriminated union field's value should
become, based on the discriminator carried in the value itself.

Returns None rather than raising when the discriminator is absent, is not a
string, or names a variant this version of the SDK does not know about. The
caller then converts without a class, so a variant the API adds after this
release still deserializes instead of blowing up.
"""
union = self._inner_class_union_variant_types.get(field_name)
if union is None or not isinstance(value, dict):
return None

discriminator, variants = union
discriminator_value = cast(Dict[str, Any], value).get(discriminator)
if not isinstance(discriminator_value, str):
return None

return variants.get(discriminator_value)

def _get_inner_class_is_beneath_dict(self, field_name: str):
return field_name in self._inner_class_dicts

Expand Down
2 changes: 1 addition & 1 deletion stripe/_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ class Subscription(StripeObject):
"""
Unix timestamp in seconds of when the subscription status transitioned to `paused`.
"""
type: Literal["subscription"]
type: Union[Literal["subscription"], str]
"""
The type of pause.
"""
Expand Down
4 changes: 2 additions & 2 deletions stripe/checkout/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ class AfterpayClearpay(StripeObject):
"""

class Alipay(StripeObject):
setup_future_usage: Optional[Literal["none"]]
setup_future_usage: Optional[Union[Literal["none"], str]]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down Expand Up @@ -1993,7 +1993,7 @@ class WechatPay(StripeObject):
"""
The client type that the end customer will pay from
"""
setup_future_usage: Optional[Literal["none"]]
setup_future_usage: Optional[Union[Literal["none"], str]]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from stripe._stripe_response import StripeResponse
from stripe._util import get_api_mode
from stripe.v2.core._event import Event, EventNotification, RelatedObject
from typing import Any, Dict, Optional, cast
from typing import Any, Dict, Optional, Union, cast
from typing_extensions import Literal, TYPE_CHECKING, override

if TYPE_CHECKING:
Expand Down Expand Up @@ -98,7 +98,7 @@ class V2CoreAccountIncludingConfigurationCustomerCapabilityStatusUpdatedEvent(
class V2CoreAccountIncludingConfigurationCustomerCapabilityStatusUpdatedEventData(
StripeObject,
):
updated_capability: Literal["automatic_indirect_tax"]
updated_capability: Union[Literal["automatic_indirect_tax"], str]
"""
Open Enum. The capability which had its status updated.
"""
Expand Down
2 changes: 1 addition & 1 deletion stripe/params/_invoice_create_preview_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ class InvoiceCreatePreviewParamsSubscriptionDetailsPause(TypedDict):
"""
Determines how to handle debits and credits when pausing. Defaults to `pending_invoice_item`.
"""
type: NotRequired[Literal["subscription"]]
type: NotRequired["Literal['subscription']|str"]
"""
The type of pause to apply. Defaults to `subscription`.
"""
Expand Down
2 changes: 1 addition & 1 deletion stripe/params/_order_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,7 +2081,7 @@ class OrderCreateParamsPaymentSettingsPaymentMethodOptionsWechatPay(TypedDict):
"""
The client type that the end customer will pay from
"""
setup_future_usage: NotRequired[Literal["none"]]
setup_future_usage: NotRequired["Literal['none']|str"]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
2 changes: 1 addition & 1 deletion stripe/params/_order_modify_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ class OrderModifyParamsPaymentSettingsPaymentMethodOptionsWechatPay(TypedDict):
"""
The client type that the end customer will pay from
"""
setup_future_usage: NotRequired[Literal["none"]]
setup_future_usage: NotRequired["Literal['none']|str"]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
2 changes: 1 addition & 1 deletion stripe/params/_order_update_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,7 @@ class OrderUpdateParamsPaymentSettingsPaymentMethodOptionsWechatPay(TypedDict):
"""
The client type that the end customer will pay from
"""
setup_future_usage: NotRequired[Literal["none"]]
setup_future_usage: NotRequired["Literal['none']|str"]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
2 changes: 1 addition & 1 deletion stripe/params/_payment_intent_confirm_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6590,7 +6590,7 @@ class PaymentIntentConfirmParamsPaymentMethodOptionsWechatPay(TypedDict):
"""
The client type that the end customer will pay from
"""
setup_future_usage: NotRequired[Literal["none"]]
setup_future_usage: NotRequired["Literal['none']|str"]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
2 changes: 1 addition & 1 deletion stripe/params/_payment_intent_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6710,7 +6710,7 @@ class PaymentIntentCreateParamsPaymentMethodOptionsWechatPay(TypedDict):
"""
The client type that the end customer will pay from
"""
setup_future_usage: NotRequired[Literal["none"]]
setup_future_usage: NotRequired["Literal['none']|str"]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
2 changes: 1 addition & 1 deletion stripe/params/_payment_intent_modify_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6563,7 +6563,7 @@ class PaymentIntentModifyParamsPaymentMethodOptionsWechatPay(TypedDict):
"""
The client type that the end customer will pay from
"""
setup_future_usage: NotRequired[Literal["none"]]
setup_future_usage: NotRequired["Literal['none']|str"]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
2 changes: 1 addition & 1 deletion stripe/params/_payment_intent_update_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6562,7 +6562,7 @@ class PaymentIntentUpdateParamsPaymentMethodOptionsWechatPay(TypedDict):
"""
The client type that the end customer will pay from
"""
setup_future_usage: NotRequired[Literal["none"]]
setup_future_usage: NotRequired["Literal['none']|str"]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
2 changes: 1 addition & 1 deletion stripe/params/_subscription_pause_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SubscriptionPauseParams(RequestOptions):
"""
Determines how to handle debits and credits when pausing. Defaults to `pending_invoice_item`.
"""
type: NotRequired[Literal["subscription"]]
type: NotRequired["Literal['subscription']|str"]
"""
The type of pause to apply. Defaults to `subscription`.
"""
Expand Down
4 changes: 2 additions & 2 deletions stripe/params/checkout/_session_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ class SessionCreateParamsPaymentMethodOptionsAfterpayClearpay(TypedDict):


class SessionCreateParamsPaymentMethodOptionsAlipay(TypedDict):
setup_future_usage: NotRequired[Literal["none"]]
setup_future_usage: NotRequired["Literal['none']|str"]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down Expand Up @@ -2615,7 +2615,7 @@ class SessionCreateParamsPaymentMethodOptionsWechatPay(TypedDict):
"""
The client type that the end customer will pay from
"""
setup_future_usage: NotRequired[Literal["none"]]
setup_future_usage: NotRequired["Literal['none']|str"]
"""
Indicates that you intend to make future payments with this PaymentIntent's payment method.

Expand Down
2 changes: 1 addition & 1 deletion stripe/params/tax/_registration_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ class RegistrationCreateParamsCountryOptionsSrStandard(TypedDict):


class RegistrationCreateParamsCountryOptionsTh(TypedDict):
type: Literal["simplified"]
type: Union[Literal["simplified"], str]
"""
Type of registration to be created in `country`.
"""
Expand Down
6 changes: 3 additions & 3 deletions stripe/params/v2/billing/_cadence_list_params.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from typing import List
from typing import List, Union
from typing_extensions import Literal, NotRequired, TypedDict


class CadenceListParams(TypedDict):
include: NotRequired[List[Literal["settings_data"]]]
include: NotRequired[List[Union[Literal["settings_data"], str]]]
"""
Additional resource to include in the response.
"""
Expand Down Expand Up @@ -35,7 +35,7 @@ class CadenceListParamsPayer(TypedDict):
"""
The ID of the Customer object. If provided, only cadences that specifically reference the provided customer ID will be returned.
"""
type: Literal["customer"]
type: Union[Literal["customer"], str]
"""
A string identifying the type of the payer. Currently the only supported value is `customer`.
"""
4 changes: 2 additions & 2 deletions stripe/params/v2/billing/_cadence_retrieve_params.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from typing import List
from typing import List, Union
from typing_extensions import Literal, NotRequired, TypedDict


class CadenceRetrieveParams(TypedDict):
include: NotRequired[List[Literal["settings_data"]]]
include: NotRequired[List[Union[Literal["settings_data"], str]]]
"""
Additional resource to include in the response.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class CollectionSettingCreateParamsPaymentMethodOptionsCustomerBalance(
"""
Configuration for the bank transfer funding type, if the `funding_type` is set to `bank_transfer`.
"""
funding_type: NotRequired[Literal["bank_transfer"]]
funding_type: NotRequired["Literal['bank_transfer']|str"]
"""
The funding method type to be used when there are not enough funds in the customer balance. Currently the only supported value is `bank_transfer`.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class CollectionSettingUpdateParamsPaymentMethodOptionsCustomerBalance(
"""
Configuration for the bank transfer funding type, if the `funding_type` is set to `bank_transfer`.
"""
funding_type: NotRequired[Literal["bank_transfer"]]
funding_type: NotRequired["Literal['bank_transfer']|str"]
"""
The funding method type to be used when there are not enough funds in the customer balance. Currently the only supported value is `bank_transfer`.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from typing import Union
from typing_extensions import Literal, TypedDict


Expand All @@ -12,7 +13,7 @@ class MeterEventAdjustmentCreateParams(TypedDict):
"""
The name of the meter event. Corresponds with the `event_name` field on a meter.
"""
type: Literal["cancel"]
type: Union[Literal["cancel"], str]
"""
Specifies the type of cancellation. Currently supports canceling a single event.
"""
Expand Down
Loading