schema.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. from typing import Generic, Literal, TypeVar
  2. from pydantic import BaseModel, Field
  3. T = TypeVar("T")
  4. class StripeListResponse(BaseModel, Generic[T]):
  5. object: Literal["list"]
  6. url: str
  7. has_more: bool
  8. data: list[T]
  9. class Product(BaseModel):
  10. object: Literal["product"]
  11. id: str
  12. active: bool
  13. attributes: list
  14. created: int
  15. default_price: str | None
  16. description: str | None
  17. images: list[str]
  18. livemode: bool
  19. marketing_features: list
  20. metadata: dict[str, str]
  21. name: str
  22. statement_descriptor: str | None
  23. tax_code: str | None
  24. type: str
  25. unit_label: str | None
  26. updated: int
  27. url: str | None
  28. class Customer(BaseModel):
  29. object: Literal["customer"]
  30. id: str
  31. email: str
  32. metadata: dict[str, str] | None
  33. name: str | None
  34. class Price(BaseModel):
  35. object: Literal["price"]
  36. id: str
  37. active: bool
  38. billing_scheme: str | None
  39. created: int
  40. currency: str
  41. livemode: bool
  42. lookup_key: str | None
  43. nickname: str | None
  44. product: str | dict | None
  45. recurring: dict | None
  46. tax_behavior: str | None
  47. tiers_mode: str | None
  48. type: str
  49. unit_amount: int | None
  50. unit_amount_decimal: str | None
  51. metadata: dict[str, str] | None
  52. PriceListResponse = StripeListResponse[Price]
  53. class ProductExpandedPrice(Product):
  54. default_price: Price | None
  55. ProductExpandedPriceListResponse = StripeListResponse[ProductExpandedPrice]
  56. class Items(BaseModel):
  57. object: Literal["list"]
  58. data: list[dict]
  59. class Subscription(BaseModel):
  60. object: Literal["subscription"]
  61. id: str
  62. customer: str | dict | None # Can be a string ID or a nested Customer object
  63. items: Items
  64. created: int
  65. current_period_end: int
  66. current_period_start: int
  67. status: str
  68. livemode: bool
  69. metadata: dict[str, str] | None
  70. cancel_at_period_end: bool
  71. class SubscriptionExpandCustomer(Subscription):
  72. customer: Customer
  73. SubscriptionExpandCustomerResponse = StripeListResponse[SubscriptionExpandCustomer]
  74. class EventData(BaseModel):
  75. object: Product | Price | Subscription = Field(discriminator="object")
  76. previous_attributes: dict | None
  77. class StripeEvent(BaseModel):
  78. id: str
  79. object: str = "event"
  80. api_version: str
  81. created: int
  82. data: EventData
  83. livemode: bool
  84. pending_webhooks: int
  85. request: dict
  86. type: str
  87. class AutomaticTax(BaseModel):
  88. enabled: bool
  89. liability: str | None = None
  90. status: str | None = None
  91. class CustomText(BaseModel):
  92. shipping_address: str | None = None
  93. submit: str | None = None
  94. class InvoiceData(BaseModel):
  95. account_tax_ids: list[str] | None = None
  96. custom_fields: list[str] | None = None
  97. description: str | None = None
  98. footer: str | None = None
  99. issuer: str | None = None
  100. metadata: dict[str, str]
  101. rendering_options: str | None = None
  102. class InvoiceCreation(BaseModel):
  103. enabled: bool
  104. invoice_data: InvoiceData
  105. class PhoneNumberCollection(BaseModel):
  106. enabled: bool
  107. class TotalDetails(BaseModel):
  108. amount_discount: int
  109. amount_shipping: int
  110. amount_tax: int
  111. class Session(BaseModel):
  112. id: str
  113. object: str
  114. after_expiration: str | None = None
  115. allow_promotion_codes: str | None = None
  116. amount_subtotal: int
  117. amount_total: int
  118. automatic_tax: AutomaticTax
  119. billing_address_collection: str | None = None
  120. cancel_url: str | None = None
  121. client_reference_id: str | None = None
  122. consent: str | None = None
  123. consent_collection: str | None = None
  124. created: int
  125. currency: str
  126. custom_fields: list
  127. custom_text: CustomText
  128. customer: str | None = None
  129. customer_creation: str
  130. customer_details: str | None = None
  131. customer_email: str | None = None
  132. expires_at: int
  133. invoice: str | None = None
  134. invoice_creation: InvoiceCreation | None
  135. livemode: bool
  136. locale: str | None = None
  137. metadata: dict[str, str]
  138. mode: str
  139. payment_intent: str | None = None
  140. payment_link: str | None = None
  141. payment_method_collection: str
  142. payment_method_options: dict
  143. payment_method_types: list[str]
  144. payment_status: str
  145. phone_number_collection: PhoneNumberCollection
  146. recovered_from: str | None = None
  147. setup_intent: str | None = None
  148. shipping_address_collection: str | None = None
  149. shipping_cost: str | None = None
  150. shipping_details: str | None = None
  151. shipping_options: list
  152. status: str
  153. submit_type: str | None = None
  154. subscription: str | None = None
  155. success_url: str
  156. total_details: TotalDetails
  157. url: str
  158. class PortalSession(BaseModel):
  159. id: str
  160. object: Literal["billing_portal.session"]
  161. configuration: str
  162. created: int
  163. customer: str
  164. flow: str | None = None
  165. livemode: bool
  166. locale: str | None = None
  167. on_behalf_of: str | None = None
  168. return_url: str
  169. url: str