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
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
1from datetime import datetime
2from typing import Annotated
4from pydantic import UUID4, Field, HttpUrl
5from pydantic.aliases import AliasChoices
7from polar.customer.schemas.customer import Customer
8from polar.kit.schemas import IDSchema, Schema, TimestampedSchema
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
24class CustomerSessionCustomerIDCreate(CustomerSessionCreateBase):
25 """
26 Schema for creating a customer session using a customer ID.
27 """
29 customer_id: UUID4 = Field(
30 description="ID of the customer to create a session for."
31 )
34class CustomerSessionCustomerExternalIDCreate(CustomerSessionCreateBase):
35 """
36 Schema for creating a customer session using an external customer ID.
37 """
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 )
45CustomerSessionCreate = (
46 CustomerSessionCustomerIDCreate | CustomerSessionCustomerExternalIDCreate
47)
50class CustomerSession(IDSchema, TimestampedSchema):
51 """
52 A customer session that can be used to authenticate as a customer.
53 """
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