Payment
The pydantic_extra_types.payment
module provides the
PaymentCardNumber
data type.
PaymentCardBrand ¶
PaymentCardNumber ¶
PaymentCardNumber(card_number)
Bases: str
Source code in pydantic_extra_types/payment.py
44 45 46 47 48 49 50 51 |
|
strip_whitespace
class-attribute
¶
strip_whitespace: bool = True
Whether to strip whitespace from the input value.
brand
instance-attribute
¶
brand: PaymentCardBrand = self.validate_brand(card_number)
The brand of the card.
validate
classmethod
¶
validate(__input_value, _)
Validate the PaymentCardNumber
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__input_value |
str
|
The input value to validate. |
required |
_ |
core_schema.ValidationInfo
|
The validation info. |
required |
Returns:
Type | Description |
---|---|
PaymentCardNumber
|
The validated |
Source code in pydantic_extra_types/payment.py
62 63 64 65 66 67 68 69 70 71 72 73 |
|
validate_digits
classmethod
¶
validate_digits(card_number)
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
81 82 83 84 85 86 87 88 89 90 91 92 |
|
validate_luhn_check_digit
classmethod
¶
validate_luhn_check_digit(card_number)
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
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
validate_brand
staticmethod
¶
validate_brand(card_number)
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
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|