Coverage for polar/customer_portal/schemas/customer.py: 100%
21 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 typing import Annotated, Literal
3from pydantic import UUID4, AfterValidator, Discriminator, TypeAdapter
5from polar.kit.address import Address, AddressInput
6from polar.kit.http import get_safe_return_url
7from polar.kit.schemas import (
8 ClassName,
9 EmptyStrToNoneValidator,
10 IDSchema,
11 MergeJSONSchema,
12 Schema,
13 SetSchemaReference,
14 TimestampedSchema,
15)
16from polar.kit.tax import TaxID
17from polar.payment_method.schemas import PaymentMethodCard, PaymentMethodGeneric
20class CustomerPortalOAuthAccount(Schema):
21 account_id: str
22 account_username: str | None
25class CustomerPortalCustomer(IDSchema, TimestampedSchema):
26 email: str
27 email_verified: bool
28 name: str | None
29 billing_name: str | None
30 billing_address: Address | None
31 tax_id: TaxID | None
32 oauth_accounts: dict[str, CustomerPortalOAuthAccount]
33 default_payment_method_id: UUID4 | None = None
36class CustomerPortalCustomerUpdate(Schema):
37 billing_name: Annotated[str | None, EmptyStrToNoneValidator] = None
38 billing_address: AddressInput | None = None
39 tax_id: Annotated[str | None, EmptyStrToNoneValidator] = None
42CustomerPaymentMethod = Annotated[
43 PaymentMethodCard | PaymentMethodGeneric,
44 SetSchemaReference("CustomerPaymentMethod"),
45 MergeJSONSchema({"title": "CustomerPaymentMethod"}),
46 ClassName("CustomerPaymentMethod"),
47]
49CustomerPaymentMethodTypeAdapter: TypeAdapter[CustomerPaymentMethod] = TypeAdapter(
50 CustomerPaymentMethod
51)
54class CustomerPaymentMethodCreate(Schema):
55 confirmation_token_id: str
56 set_default: bool
57 return_url: Annotated[str, AfterValidator(get_safe_return_url)]
60class CustomerPaymentMethodCreateSucceededResponse(Schema):
61 status: Literal["succeeded"]
62 payment_method: CustomerPaymentMethod
65class CustomerPaymentMethodCreateRequiresActionResponse(Schema):
66 status: Literal["requires_action"]
67 client_secret: str
70CustomerPaymentMethodCreateResponse = Annotated[
71 CustomerPaymentMethodCreateSucceededResponse
72 | CustomerPaymentMethodCreateRequiresActionResponse,
73 Discriminator("status"),
74 SetSchemaReference("CustomerPaymentMethodCreateResponse"),
75 MergeJSONSchema({"title": "CustomerPaymentMethodCreateResponse"}),
76]
79class CustomerPaymentMethodConfirm(Schema):
80 setup_intent_id: str
81 set_default: bool