Payment
The pydantic_extra_types.payment module provides the
PaymentCardNumber data type.
PaymentCardBrand ¶
PaymentCardNumber ¶
PaymentCardNumber(card_number: str)
Bases: str
Source code in pydantic_extra_types/payment.py
51 52 53 54 55 56 57 58 | |
strip_whitespace
class-attribute
¶
strip_whitespace: bool = True
Whether to strip whitespace from the input value.
brand
instance-attribute
¶
brand: PaymentCardBrand = validate_brand(card_number)
The brand of the card.
validate
classmethod
¶
validate(
__input_value: str, _: ValidationInfo
) -> PaymentCardNumber
Validate the PaymentCardNumber instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__input_value
|
str
|
The input value to validate. |
required |
_
|
ValidationInfo
|
The validation info. |
required |
Returns:
| Type | Description |
|---|---|
PaymentCardNumber
|
The validated |
Source code in pydantic_extra_types/payment.py
69 70 71 72 73 74 75 76 77 78 79 80 | |
validate_digits
classmethod
¶
validate_digits(card_number: str) -> None
Validate that the card number is all digits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
card_number
|
str
|
The card number to validate. |
required |
Raises:
| Type | Description |
|---|---|
PydanticCustomError
|
If the card number is not all digits. |
Source code in pydantic_extra_types/payment.py
88 89 90 91 92 93 94 95 96 97 98 99 | |
validate_luhn_check_digit
classmethod
¶
Validate the payment card number. Based on the Luhn algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
card_number
|
str
|
The card number to validate. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The validated card number. |
Raises:
| Type | Description |
|---|---|
PydanticCustomError
|
If the card number is not valid. |
Source code in pydantic_extra_types/payment.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
validate_brand
staticmethod
¶
validate_brand(card_number: str) -> PaymentCardBrand
Validate length based on BIN for major brands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
card_number
|
str
|
The card number to validate. |
required |
Returns:
| Type | Description |
|---|---|
PaymentCardBrand
|
The validated card brand. |
Raises:
| Type | Description |
|---|---|
PydanticCustomError
|
If the card number is not valid. |
Source code in pydantic_extra_types/payment.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |