Coverage for polar/integrations/stripe/schemas.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 12:42 +0000

1from enum import StrEnum 

2from typing import Literal 

3from uuid import UUID 

4 

5from polar.kit.schemas import Schema 

6 

7 

8class PaymentIntentSuccessWebhook(Schema): 

9 id: str # A payment intent id (pi_) 

10 amount: int 

11 currency: str 

12 amount_received: int 

13 customer: str | None 

14 invoice: str | None # A invoice ID (in_) 

15 latest_charge: str # A charge ID (ch_ or py_) 

16 status: str # "succeeded" 

17 receipt_email: str | None = None 

18 

19 

20class ProductType(StrEnum): 

21 pledge = "pledge" 

22 product = "product" 

23 

24 

25class PaymentIntentMetadata(Schema): 

26 """ 

27 Stripe Metadata 

28 

29 Setting a value to an empty string will remove the field from Stripe. 

30 Sending a empty metadata object will remove all metadata from Stripe. 

31 

32 This is why we always set polar_not_empty to an empty string, to prevent us from 

33 accidentally un-setting all metadata. 

34 """ 

35 

36 # Safe guards us from accidentally sending an empty metadata object 

37 polar_not_empty: str = "" 

38 

39 type: ProductType 

40 

41 

42class PledgePaymentIntentMetadata(PaymentIntentMetadata): 

43 type: Literal[ProductType.pledge] = ProductType.pledge 

44 

45 issue_id: UUID | None = None 

46 issue_title: str | None = None 

47 

48 anonymous: bool = False 

49 anonymous_email: str | None = None 

50 

51 user_id: UUID | None = None 

52 user_email: str | None = None 

53 organization_id: UUID | None = None 

54 organization_name: str | None = None 

55 

56 # Set to empty string to unset the value 

57 on_behalf_of_organization_id: UUID | Literal[""] | None = None