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

16 statements  

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

1from typing import Annotated 1a

2 

3from fastapi import Path 1a

4from pydantic import UUID4, Field 1a

5 

6from polar.exceptions import ResourceNotFound 1a

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

8 

9WalletID = Annotated[UUID4, Path(description="The wallet ID.")] 1a

10 

11WalletNotFound = { 1a

12 "description": "Wallet not found.", 

13 "model": ResourceNotFound.schema(), 

14} 

15 

16 

17class WalletBase(TimestampedSchema, IDSchema): 1a

18 customer_id: UUID4 = Field( 1a

19 description="The ID of the customer that owns the wallet.", 

20 examples=[CUSTOMER_ID_EXAMPLE], 

21 ) 

22 balance: int = Field( 1a

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"]) 1a

26 

27 

28class Wallet(WalletBase): 1a

29 """ 

30 A wallet represents a customer's balance in your organization. 

31 

32 They can top-up their wallet, and use the balance to pay for usage. 

33 """ 

34 

35 pass 1a

36 

37 

38class WalletTopUpCreate(Schema): 1a

39 """ 

40 Request schema to top-up a wallet. 

41 """ 

42 

43 amount: int = Field( 1a

44 description="The amount to top-up the wallet by, in cents.", examples=[20_00] 

45 ) 

46 currency: str = Field( 1a

47 pattern="usd", 

48 description=( 

49 "The currency. Currently, only `usd` is supported. " 

50 "It should match the wallet's currency." 

51 ), 

52 )