schema.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 | None
  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 = None
  77. class StripeEventRequest(BaseModel):
  78. id: str | None = None
  79. idempotency_key: str | None = None
  80. class StripeEvent(BaseModel):
  81. id: str
  82. object: str = "event"
  83. api_version: str
  84. created: int
  85. data: EventData
  86. livemode: bool
  87. pending_webhooks: int
  88. request: StripeEventRequest
  89. type: str
  90. class AutomaticTax(BaseModel):
  91. enabled: bool
  92. liability: str | None = None
  93. status: str | None = None
  94. class CustomText(BaseModel):
  95. shipping_address: str | None = None
  96. submit: str | None = None
  97. class InvoiceData(BaseModel):
  98. account_tax_ids: list[str] | None = None
  99. custom_fields: list[str] | None = None
  100. description: str | None = None
  101. footer: str | None = None
  102. issuer: str | None = None
  103. metadata: dict[str, str]
  104. rendering_options: str | None = None
  105. class InvoiceCreation(BaseModel):
  106. enabled: bool
  107. invoice_data: InvoiceData
  108. class PhoneNumberCollection(BaseModel):
  109. enabled: bool
  110. class TotalDetails(BaseModel):
  111. amount_discount: int
  112. amount_shipping: int
  113. amount_tax: int
  114. class Session(BaseModel):
  115. id: str
  116. object: str
  117. after_expiration: str | None = None
  118. allow_promotion_codes: str | None = None
  119. amount_subtotal: int
  120. amount_total: int
  121. automatic_tax: AutomaticTax
  122. billing_address_collection: str | None = None
  123. cancel_url: str | None = None
  124. client_reference_id: str | None = None
  125. consent: str | None = None
  126. consent_collection: str | None = None
  127. created: int
  128. currency: str
  129. custom_fields: list
  130. custom_text: CustomText
  131. customer: str | None = None
  132. customer_creation: str
  133. customer_details: str | None = None
  134. customer_email: str | None = None
  135. expires_at: int
  136. invoice: str | None = None
  137. invoice_creation: InvoiceCreation | None
  138. livemode: bool
  139. locale: str | None = None
  140. metadata: dict[str, str]
  141. mode: str
  142. payment_intent: str | None = None
  143. payment_link: str | None = None
  144. payment_method_collection: str
  145. payment_method_options: dict
  146. payment_method_types: list[str]
  147. payment_status: str
  148. phone_number_collection: PhoneNumberCollection
  149. recovered_from: str | None = None
  150. setup_intent: str | None = None
  151. shipping_address_collection: str | None = None
  152. shipping_cost: str | None = None
  153. shipping_details: str | None = None
  154. shipping_options: list
  155. status: str
  156. submit_type: str | None = None
  157. subscription: str | None = None
  158. success_url: str
  159. total_details: TotalDetails
  160. url: str
  161. class PortalSession(BaseModel):
  162. id: str
  163. object: Literal["billing_portal.session"]
  164. configuration: str
  165. created: int
  166. customer: str
  167. flow: str | None = None
  168. livemode: bool
  169. locale: str | None = None
  170. on_behalf_of: str | None = None
  171. return_url: str
  172. url: str