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

31 statements  

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

1from enum import StrEnum 1a

2from typing import Literal 1a

3from uuid import UUID 1a

4 

5from polar.kit.schemas import Schema 1a

6 

7 

8class PaymentIntentSuccessWebhook(Schema): 1a

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

10 amount: int 1a

11 currency: str 1a

12 amount_received: int 1a

13 customer: str | None 1a

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

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

16 status: str # "succeeded" 1a

17 receipt_email: str | None = None 1a

18 

19 

20class ProductType(StrEnum): 1a

21 pledge = "pledge" 1a

22 product = "product" 1a

23 

24 

25class PaymentIntentMetadata(Schema): 1a

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 = "" 1a

38 

39 type: ProductType 1a

40 

41 

42class PledgePaymentIntentMetadata(PaymentIntentMetadata): 1a

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

44 

45 issue_id: UUID | None = None 1a

46 issue_title: str | None = None 1a

47 

48 anonymous: bool = False 1a

49 anonymous_email: str | None = None 1a

50 

51 user_id: UUID | None = None 1a

52 user_email: str | None = None 1a

53 organization_id: UUID | None = None 1a

54 organization_name: str | None = None 1a

55 

56 # Set to empty string to unset the value 

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