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

15 statements  

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

1from datetime import datetime 

2from typing import Annotated 

3 

4from pydantic import UUID4, Field, HttpUrl 

5from pydantic.aliases import AliasChoices 

6 

7from polar.customer.schemas.customer import Customer 

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

9 

10 

11class CustomerSessionCreateBase(Schema): 

12 return_url: Annotated[ 

13 HttpUrl | None, 

14 Field( 

15 description=( 

16 "When set, a back button will be shown in the customer portal " 

17 "to return to this URL." 

18 ), 

19 examples=["https://example.com/account"], 

20 ), 

21 ] = None 

22 

23 

24class CustomerSessionCustomerIDCreate(CustomerSessionCreateBase): 

25 """ 

26 Schema for creating a customer session using a customer ID. 

27 """ 

28 

29 customer_id: UUID4 = Field( 

30 description="ID of the customer to create a session for." 

31 ) 

32 

33 

34class CustomerSessionCustomerExternalIDCreate(CustomerSessionCreateBase): 

35 """ 

36 Schema for creating a customer session using an external customer ID. 

37 """ 

38 

39 external_customer_id: str = Field( 

40 description="External ID of the customer to create a session for.", 

41 validation_alias=AliasChoices("external_customer_id", "customer_external_id"), 

42 ) 

43 

44 

45CustomerSessionCreate = ( 

46 CustomerSessionCustomerIDCreate | CustomerSessionCustomerExternalIDCreate 

47) 

48 

49 

50class CustomerSession(IDSchema, TimestampedSchema): 

51 """ 

52 A customer session that can be used to authenticate as a customer. 

53 """ 

54 

55 token: str = Field(validation_alias="raw_token") 

56 expires_at: datetime 

57 return_url: str | None 

58 customer_portal_url: str 

59 customer_id: UUID4 

60 customer: Customer