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

20 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 17:15 +0000

1from datetime import datetime 1a

2from typing import Annotated 1a

3 

4from pydantic import UUID4, Field, HttpUrl 1a

5from pydantic.aliases import AliasChoices 1a

6 

7from polar.customer.schemas.customer import Customer 1a

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

9 

10 

11class CustomerSessionCreateBase(Schema): 1a

12 return_url: Annotated[ 1a

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): 1a

25 """ 

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

27 """ 

28 

29 customer_id: UUID4 = Field( 1a

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

31 ) 

32 

33 

34class CustomerSessionCustomerExternalIDCreate(CustomerSessionCreateBase): 1a

35 """ 

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

37 """ 

38 

39 external_customer_id: str = Field( 1a

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 = ( 1a

46 CustomerSessionCustomerIDCreate | CustomerSessionCustomerExternalIDCreate 

47) 

48 

49 

50class CustomerSession(IDSchema, TimestampedSchema): 1a

51 """ 

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

53 """ 

54 

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

56 expires_at: datetime 1a

57 return_url: str | None 1a

58 customer_portal_url: str 1a

59 customer_id: UUID4 1a

60 customer: Customer 1a