update orders
This commit is contained in:
@@ -60,53 +60,25 @@ else:
|
||||
return field_schema
|
||||
|
||||
|
||||
class PaymentCardValidation:
|
||||
"""
|
||||
>>> class CreditCard(BaseModel):
|
||||
... exp: PaymentCardValidation
|
||||
|
||||
|
||||
>>> CreditCard(exp='20/23')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
pydantic_core._pydantic_core.ValidationError: 1 validation error for CreditCard
|
||||
...
|
||||
|
||||
>>> CreditCard(exp='12/23')
|
||||
CreditCard(exp=datetime.date(2023, 12, 1))
|
||||
|
||||
>>> CreditCard(exp='12/2024')
|
||||
CreditCard(exp=datetime.date(2024, 12, 1))
|
||||
|
||||
>>> CreditCard(exp='2024-12-02')
|
||||
CreditCard(exp=datetime.date(2024, 12, 2))
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def __get_pydantic_core_schema__(
|
||||
cls, _source: type[Any], _handler: GetCoreSchemaHandler
|
||||
) -> CoreSchema:
|
||||
return core_schema.no_info_after_validator_function(
|
||||
cls._validate, core_schema.str_schema()
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _validate(cls, __input_value: str) -> date:
|
||||
if '/' in __input_value:
|
||||
month, year = __input_value.split('/')
|
||||
return date(int(f'20{year[-2:]}'), int(month), 1)
|
||||
|
||||
try:
|
||||
return date.fromisoformat(__input_value)
|
||||
except Exception:
|
||||
raise ValueError('Invalid card expiration date.')
|
||||
|
||||
|
||||
class CreditCard(BaseModel):
|
||||
name: NameStr
|
||||
"""
|
||||
>>> cc = CreditCard(
|
||||
... holder_name='Mike Shinoda',
|
||||
... number='4111111111111111',
|
||||
... cvv='123',
|
||||
... exp_month='01',
|
||||
... exp_year='2026'
|
||||
... )
|
||||
>>> str(cc.number.brand)
|
||||
'Visa'
|
||||
>>> cc
|
||||
CreditCard(holder_name='Mike Shinoda', number='4111111111111111', cvv='123', exp_month='01', exp_year='2026')
|
||||
"""
|
||||
holder_name: NameStr
|
||||
number: PaymentCardNumber
|
||||
cvv: str = Field(..., min_length=3)
|
||||
exp: PaymentCardValidation
|
||||
exp_month: str = Field(..., pattern=r'^\d{2}$')
|
||||
exp_year: str = Field(..., pattern=r'^\d{4}$')
|
||||
|
||||
@property
|
||||
def brand(self) -> str:
|
||||
@@ -118,12 +90,12 @@ class CreditCard(BaseModel):
|
||||
|
||||
@property
|
||||
def first_name(self) -> str:
|
||||
first_name, _ = self.name.split(' ', 1)
|
||||
first_name, _ = self.holder_name.split(' ', 1)
|
||||
return first_name
|
||||
|
||||
@property
|
||||
def last_name(self) -> str:
|
||||
_, last_name = self.name.split(' ', 1)
|
||||
_, last_name = self.holder_name.split(' ', 1)
|
||||
return last_name
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "layercake"
|
||||
version = "0.11.4"
|
||||
version = "0.12.0"
|
||||
description = "Packages shared dependencies to optimize deployment and ensure consistency across functions."
|
||||
readme = "README.md"
|
||||
authors = [
|
||||
|
||||
2
layercake/uv.lock
generated
2
layercake/uv.lock
generated
@@ -824,7 +824,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "layercake"
|
||||
version = "0.11.2"
|
||||
version = "0.12.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "arnparse" },
|
||||
|
||||
Reference in New Issue
Block a user