Coverage for polar/wallet/schemas.py: 100%
16 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
3from fastapi import Path
4from pydantic import UUID4, Field
6from polar.exceptions import ResourceNotFound
7from polar.kit.schemas import CUSTOMER_ID_EXAMPLE, IDSchema, Schema, TimestampedSchema
9WalletID = Annotated[UUID4, Path(description="The wallet ID.")]
11WalletNotFound = {
12 "description": "Wallet not found.",
13 "model": ResourceNotFound.schema(),
14}
17class WalletBase(TimestampedSchema, IDSchema):
18 customer_id: UUID4 = Field(
19 description="The ID of the customer that owns the wallet.",
20 examples=[CUSTOMER_ID_EXAMPLE],
21 )
22 balance: int = Field(
23 description="The current balance of the wallet, in cents.", examples=[50_00]
24 )
25 currency: str = Field(description="The currency of the wallet.", examples=["usd"])
28class Wallet(WalletBase):
29 """
30 A wallet represents a customer's balance in your organization.
32 They can top-up their wallet, and use the balance to pay for usage.
33 """
35 pass
38class WalletTopUpCreate(Schema):
39 """
40 Request schema to top-up a wallet.
41 """
43 amount: int = Field(
44 description="The amount to top-up the wallet by, in cents.", examples=[20_00]
45 )
46 currency: str = Field(
47 pattern="usd",
48 description=(
49 "The currency. Currently, only `usd` is supported. "
50 "It should match the wallet's currency."
51 ),
52 )