Pydantic Extra Types Payment
The pydantic_extra_types.payment module provides the
PaymentCardNumber data type.
Bases: str, Enum
Payment card brands supported by the PaymentCardNumber.
Bases: str
Whether to strip whitespace from the input value.
Type: bool Default: True
The minimum length of the card number.
Type: int Default: 12
The maximum length of the card number.
Type: int Default: 19
The first 6 digits of the card number.
Type: str Default: card_number[:6]
The last 4 digits of the card number.
Type: str Default: card_number[(-4):]
The brand of the card.
Type: PaymentCardBrand Default: self.validate_brand(card_number)
The masked card number.
Type: str
@classmethod
def validate(
cls,
__input_value: str,
_: core_schema.ValidationInfo,
) -> PaymentCardNumber
Validate the PaymentCardNumber instance.
PaymentCardNumber — The validated PaymentCardNumber instance.
__input_value : str
The input value to validate.
The validation info.
@classmethod
def validate_digits(cls, card_number: str) -> None
Validate that the card number is all digits.
card_number : str
The card number to validate.
PydanticCustomError— If the card number is not all digits.
@classmethod
def validate_luhn_check_digit(cls, card_number: str) -> str
Validate the payment card number. Based on the Luhn algorithm.
str — The validated card number.
card_number : str
The card number to validate.
PydanticCustomError— If the card number is not valid.
@staticmethod
def validate_brand(card_number: str) -> PaymentCardBrand
Validate length based on BIN for major brands.
PaymentCardBrand — The validated card brand.
card_number : str
The card number to validate.
PydanticCustomError— If the card number is not valid.