Coverage for polar/payment_method/schemas.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 12:42 +0000

1from typing import Literal 

2 

3from pydantic import UUID4, AliasPath, Field, TypeAdapter 

4 

5from polar.enums import PaymentProcessor 

6from polar.kit.schemas import IDSchema, Schema, TimestampedSchema 

7 

8 

9class PaymentMethodBase(TimestampedSchema, IDSchema): 

10 processor: PaymentProcessor 

11 customer_id: UUID4 

12 

13 

14class PaymentMethodGeneric(PaymentMethodBase): 

15 type: str 

16 

17 

18class PaymentMethodCardMetadata(Schema): 

19 brand: str 

20 last4: str 

21 exp_month: int 

22 exp_year: int 

23 wallet: str | None = Field( 

24 default=None, validation_alias=AliasPath("wallet", "type") 

25 ) 

26 

27 

28class PaymentMethodCard(PaymentMethodBase): 

29 type: Literal["card"] 

30 method_metadata: PaymentMethodCardMetadata 

31 

32 

33PaymentMethod = PaymentMethodCard | PaymentMethodGeneric 

34PaymentMethodTypeAdapter: TypeAdapter[PaymentMethod] = TypeAdapter(PaymentMethod)