dodopayments 1.51.1__py3-none-any.whl → 1.56.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. dodopayments/__init__.py +5 -1
  2. dodopayments/_base_client.py +12 -12
  3. dodopayments/_client.py +52 -14
  4. dodopayments/_compat.py +48 -48
  5. dodopayments/_exceptions.py +4 -0
  6. dodopayments/_models.py +50 -44
  7. dodopayments/_qs.py +7 -7
  8. dodopayments/_streaming.py +4 -6
  9. dodopayments/_types.py +18 -11
  10. dodopayments/_utils/__init__.py +8 -2
  11. dodopayments/_utils/_compat.py +45 -0
  12. dodopayments/_utils/_datetime_parse.py +136 -0
  13. dodopayments/_utils/_transform.py +13 -3
  14. dodopayments/_utils/_typing.py +1 -1
  15. dodopayments/_utils/_utils.py +5 -6
  16. dodopayments/_version.py +1 -1
  17. dodopayments/resources/__init__.py +28 -0
  18. dodopayments/resources/addons.py +29 -29
  19. dodopayments/resources/brands.py +29 -29
  20. dodopayments/resources/checkout_sessions.py +110 -27
  21. dodopayments/resources/customers/__init__.py +14 -0
  22. dodopayments/resources/customers/customer_portal.py +5 -5
  23. dodopayments/resources/customers/customers.py +53 -21
  24. dodopayments/resources/customers/wallets/__init__.py +33 -0
  25. dodopayments/resources/customers/wallets/ledger_entries.py +318 -0
  26. dodopayments/resources/customers/wallets/wallets.py +191 -0
  27. dodopayments/resources/discounts.py +44 -44
  28. dodopayments/resources/disputes.py +19 -19
  29. dodopayments/resources/invoices/payments.py +83 -3
  30. dodopayments/resources/license_key_instances.py +13 -13
  31. dodopayments/resources/license_keys.py +23 -23
  32. dodopayments/resources/licenses.py +14 -14
  33. dodopayments/resources/meters.py +554 -0
  34. dodopayments/resources/misc.py +3 -3
  35. dodopayments/resources/payments.py +49 -41
  36. dodopayments/resources/payouts.py +26 -7
  37. dodopayments/resources/products/images.py +5 -5
  38. dodopayments/resources/products/products.py +82 -82
  39. dodopayments/resources/refunds.py +39 -30
  40. dodopayments/resources/subscriptions.py +316 -73
  41. dodopayments/resources/usage_events.py +597 -0
  42. dodopayments/resources/webhooks/headers.py +5 -5
  43. dodopayments/resources/webhooks/webhooks.py +119 -44
  44. dodopayments/types/__init__.py +48 -0
  45. dodopayments/types/add_meter_to_price.py +29 -0
  46. dodopayments/types/add_meter_to_price_param.py +30 -0
  47. dodopayments/types/checkout_session_create_params.py +6 -0
  48. dodopayments/types/checkout_session_status.py +35 -0
  49. dodopayments/types/customer_limited_details.py +5 -0
  50. dodopayments/types/customers/__init__.py +2 -0
  51. dodopayments/types/customers/customer_wallet.py +20 -0
  52. dodopayments/types/customers/wallet_list_response.py +15 -0
  53. dodopayments/types/customers/wallets/__init__.py +7 -0
  54. dodopayments/types/customers/wallets/customer_wallet_transaction.py +38 -0
  55. dodopayments/types/customers/wallets/ledger_entry_create_params.py +25 -0
  56. dodopayments/types/customers/wallets/ledger_entry_list_params.py +18 -0
  57. dodopayments/types/discount_create_params.py +3 -2
  58. dodopayments/types/discount_update_params.py +3 -2
  59. dodopayments/types/dispute_accepted_webhook_event.py +29 -0
  60. dodopayments/types/dispute_accepted_webhook_event1.py +29 -0
  61. dodopayments/types/dispute_cancelled_webhook_event.py +29 -0
  62. dodopayments/types/dispute_cancelled_webhook_event1.py +29 -0
  63. dodopayments/types/dispute_challenged_webhook_event.py +29 -0
  64. dodopayments/types/dispute_challenged_webhook_event1.py +29 -0
  65. dodopayments/types/dispute_expired_webhook_event.py +29 -0
  66. dodopayments/types/dispute_expired_webhook_event1.py +29 -0
  67. dodopayments/types/dispute_lost_webhook_event.py +29 -0
  68. dodopayments/types/dispute_lost_webhook_event1.py +29 -0
  69. dodopayments/types/dispute_opened_webhook_event.py +29 -0
  70. dodopayments/types/dispute_opened_webhook_event1.py +29 -0
  71. dodopayments/types/dispute_won_webhook_event.py +29 -0
  72. dodopayments/types/dispute_won_webhook_event1.py +29 -0
  73. dodopayments/types/event.py +26 -0
  74. dodopayments/types/event_input_param.py +38 -0
  75. dodopayments/types/license_activate_response.py +40 -0
  76. dodopayments/types/license_key_created_webhook_event.py +29 -0
  77. dodopayments/types/license_key_created_webhook_event1.py +29 -0
  78. dodopayments/types/meter.py +40 -0
  79. dodopayments/types/meter_aggregation.py +16 -0
  80. dodopayments/types/meter_aggregation_param.py +16 -0
  81. dodopayments/types/meter_create_params.py +31 -0
  82. dodopayments/types/meter_filter.py +131 -0
  83. dodopayments/types/meter_filter_param.py +143 -0
  84. dodopayments/types/meter_list_params.py +18 -0
  85. dodopayments/types/new_customer_param.py +7 -1
  86. dodopayments/types/payment.py +37 -2
  87. dodopayments/types/payment_cancelled_webhook_event.py +29 -0
  88. dodopayments/types/payment_cancelled_webhook_event1.py +29 -0
  89. dodopayments/types/payment_create_params.py +3 -0
  90. dodopayments/types/payment_failed_webhook_event.py +29 -0
  91. dodopayments/types/payment_failed_webhook_event1.py +29 -0
  92. dodopayments/types/payment_method_types.py +1 -0
  93. dodopayments/types/payment_processing_webhook_event.py +29 -0
  94. dodopayments/types/payment_processing_webhook_event1.py +29 -0
  95. dodopayments/types/payment_succeeded_webhook_event.py +29 -0
  96. dodopayments/types/payment_succeeded_webhook_event1.py +29 -0
  97. dodopayments/types/payout_list_params.py +11 -1
  98. dodopayments/types/price.py +52 -5
  99. dodopayments/types/price_param.py +52 -5
  100. dodopayments/types/product_create_params.py +3 -2
  101. dodopayments/types/product_update_params.py +4 -3
  102. dodopayments/types/refund.py +8 -1
  103. dodopayments/types/refund_create_params.py +4 -1
  104. dodopayments/types/refund_failed_webhook_event.py +29 -0
  105. dodopayments/types/refund_failed_webhook_event1.py +29 -0
  106. dodopayments/types/refund_list_response.py +39 -0
  107. dodopayments/types/refund_succeeded_webhook_event.py +29 -0
  108. dodopayments/types/refund_succeeded_webhook_event1.py +29 -0
  109. dodopayments/types/subscription.py +23 -1
  110. dodopayments/types/subscription_active_webhook_event.py +29 -0
  111. dodopayments/types/subscription_active_webhook_event1.py +29 -0
  112. dodopayments/types/subscription_cancelled_webhook_event.py +29 -0
  113. dodopayments/types/subscription_cancelled_webhook_event1.py +29 -0
  114. dodopayments/types/subscription_charge_params.py +12 -1
  115. dodopayments/types/subscription_create_params.py +3 -0
  116. dodopayments/types/subscription_expired_webhook_event.py +29 -0
  117. dodopayments/types/subscription_expired_webhook_event1.py +29 -0
  118. dodopayments/types/subscription_failed_webhook_event.py +29 -0
  119. dodopayments/types/subscription_failed_webhook_event1.py +29 -0
  120. dodopayments/types/subscription_list_response.py +3 -0
  121. dodopayments/types/subscription_on_hold_webhook_event.py +29 -0
  122. dodopayments/types/subscription_on_hold_webhook_event1.py +29 -0
  123. dodopayments/types/subscription_plan_changed_webhook_event.py +29 -0
  124. dodopayments/types/subscription_plan_changed_webhook_event1.py +29 -0
  125. dodopayments/types/subscription_renewed_webhook_event.py +29 -0
  126. dodopayments/types/subscription_renewed_webhook_event1.py +29 -0
  127. dodopayments/types/subscription_retrieve_usage_history_params.py +28 -0
  128. dodopayments/types/subscription_retrieve_usage_history_response.py +46 -0
  129. dodopayments/types/subscription_update_params.py +2 -0
  130. dodopayments/types/unsafe_unwrap_webhook_event.py +52 -0
  131. dodopayments/types/unwrap_webhook_event.py +52 -0
  132. dodopayments/types/usage_event_ingest_params.py +15 -0
  133. dodopayments/types/usage_event_ingest_response.py +9 -0
  134. dodopayments/types/usage_event_list_params.py +42 -0
  135. {dodopayments-1.51.1.dist-info → dodopayments-1.56.5.dist-info}/METADATA +6 -4
  136. dodopayments-1.56.5.dist-info/RECORD +239 -0
  137. dodopayments-1.51.1.dist-info/RECORD +0 -163
  138. {dodopayments-1.51.1.dist-info → dodopayments-1.56.5.dist-info}/WHEEL +0 -0
  139. {dodopayments-1.51.1.dist-info → dodopayments-1.56.5.dist-info}/licenses/LICENSE +0 -0
@@ -16,8 +16,9 @@ from ..types import (
16
16
  subscription_create_params,
17
17
  subscription_update_params,
18
18
  subscription_change_plan_params,
19
+ subscription_retrieve_usage_history_params,
19
20
  )
20
- from .._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
21
+ from .._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given
21
22
  from .._utils import maybe_transform, async_maybe_transform
22
23
  from .._compat import cached_property
23
24
  from .._resource import SyncAPIResource, AsyncAPIResource
@@ -40,6 +41,7 @@ from ..types.subscription_list_response import SubscriptionListResponse
40
41
  from ..types.on_demand_subscription_param import OnDemandSubscriptionParam
41
42
  from ..types.subscription_charge_response import SubscriptionChargeResponse
42
43
  from ..types.subscription_create_response import SubscriptionCreateResponse
44
+ from ..types.subscription_retrieve_usage_history_response import SubscriptionRetrieveUsageHistoryResponse
43
45
 
44
46
  __all__ = ["SubscriptionsResource", "AsyncSubscriptionsResource"]
45
47
 
@@ -71,23 +73,24 @@ class SubscriptionsResource(SyncAPIResource):
71
73
  customer: CustomerRequestParam,
72
74
  product_id: str,
73
75
  quantity: int,
74
- addons: Optional[Iterable[AttachAddonParam]] | NotGiven = NOT_GIVEN,
75
- allowed_payment_method_types: Optional[List[PaymentMethodTypes]] | NotGiven = NOT_GIVEN,
76
- billing_currency: Optional[Currency] | NotGiven = NOT_GIVEN,
77
- discount_code: Optional[str] | NotGiven = NOT_GIVEN,
78
- metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
79
- on_demand: Optional[OnDemandSubscriptionParam] | NotGiven = NOT_GIVEN,
80
- payment_link: Optional[bool] | NotGiven = NOT_GIVEN,
81
- return_url: Optional[str] | NotGiven = NOT_GIVEN,
82
- show_saved_payment_methods: bool | NotGiven = NOT_GIVEN,
83
- tax_id: Optional[str] | NotGiven = NOT_GIVEN,
84
- trial_period_days: Optional[int] | NotGiven = NOT_GIVEN,
76
+ addons: Optional[Iterable[AttachAddonParam]] | Omit = omit,
77
+ allowed_payment_method_types: Optional[List[PaymentMethodTypes]] | Omit = omit,
78
+ billing_currency: Optional[Currency] | Omit = omit,
79
+ discount_code: Optional[str] | Omit = omit,
80
+ force_3ds: Optional[bool] | Omit = omit,
81
+ metadata: Dict[str, str] | Omit = omit,
82
+ on_demand: Optional[OnDemandSubscriptionParam] | Omit = omit,
83
+ payment_link: Optional[bool] | Omit = omit,
84
+ return_url: Optional[str] | Omit = omit,
85
+ show_saved_payment_methods: bool | Omit = omit,
86
+ tax_id: Optional[str] | Omit = omit,
87
+ trial_period_days: Optional[int] | Omit = omit,
85
88
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
86
89
  # The extra values given here take precedence over values defined on the client or passed to this method.
87
90
  extra_headers: Headers | None = None,
88
91
  extra_query: Query | None = None,
89
92
  extra_body: Body | None = None,
90
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
93
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
91
94
  ) -> SubscriptionCreateResponse:
92
95
  """
93
96
  Args:
@@ -113,6 +116,8 @@ class SubscriptionsResource(SyncAPIResource):
113
116
 
114
117
  discount_code: Discount Code to apply to the subscription
115
118
 
119
+ force_3ds: Override merchant default 3DS behaviour for this subscription
120
+
116
121
  metadata: Additional metadata for the subscription Defaults to empty if not specified
117
122
 
118
123
  payment_link: If true, generates a payment link. Defaults to false if not specified.
@@ -147,6 +152,7 @@ class SubscriptionsResource(SyncAPIResource):
147
152
  "allowed_payment_method_types": allowed_payment_method_types,
148
153
  "billing_currency": billing_currency,
149
154
  "discount_code": discount_code,
155
+ "force_3ds": force_3ds,
150
156
  "metadata": metadata,
151
157
  "on_demand": on_demand,
152
158
  "payment_link": payment_link,
@@ -172,7 +178,7 @@ class SubscriptionsResource(SyncAPIResource):
172
178
  extra_headers: Headers | None = None,
173
179
  extra_query: Query | None = None,
174
180
  extra_body: Body | None = None,
175
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
181
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
176
182
  ) -> Subscription:
177
183
  """
178
184
  Args:
@@ -198,19 +204,20 @@ class SubscriptionsResource(SyncAPIResource):
198
204
  self,
199
205
  subscription_id: str,
200
206
  *,
201
- billing: Optional[BillingAddressParam] | NotGiven = NOT_GIVEN,
202
- cancel_at_next_billing_date: Optional[bool] | NotGiven = NOT_GIVEN,
203
- disable_on_demand: Optional[subscription_update_params.DisableOnDemand] | NotGiven = NOT_GIVEN,
204
- metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
205
- next_billing_date: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
206
- status: Optional[SubscriptionStatus] | NotGiven = NOT_GIVEN,
207
- tax_id: Optional[str] | NotGiven = NOT_GIVEN,
207
+ billing: Optional[BillingAddressParam] | Omit = omit,
208
+ cancel_at_next_billing_date: Optional[bool] | Omit = omit,
209
+ customer_name: Optional[str] | Omit = omit,
210
+ disable_on_demand: Optional[subscription_update_params.DisableOnDemand] | Omit = omit,
211
+ metadata: Optional[Dict[str, str]] | Omit = omit,
212
+ next_billing_date: Union[str, datetime, None] | Omit = omit,
213
+ status: Optional[SubscriptionStatus] | Omit = omit,
214
+ tax_id: Optional[str] | Omit = omit,
208
215
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
209
216
  # The extra values given here take precedence over values defined on the client or passed to this method.
210
217
  extra_headers: Headers | None = None,
211
218
  extra_query: Query | None = None,
212
219
  extra_body: Body | None = None,
213
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
220
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
214
221
  ) -> Subscription:
215
222
  """
216
223
  Args:
@@ -232,6 +239,7 @@ class SubscriptionsResource(SyncAPIResource):
232
239
  {
233
240
  "billing": billing,
234
241
  "cancel_at_next_billing_date": cancel_at_next_billing_date,
242
+ "customer_name": customer_name,
235
243
  "disable_on_demand": disable_on_demand,
236
244
  "metadata": metadata,
237
245
  "next_billing_date": next_billing_date,
@@ -249,19 +257,19 @@ class SubscriptionsResource(SyncAPIResource):
249
257
  def list(
250
258
  self,
251
259
  *,
252
- brand_id: str | NotGiven = NOT_GIVEN,
253
- created_at_gte: Union[str, datetime] | NotGiven = NOT_GIVEN,
254
- created_at_lte: Union[str, datetime] | NotGiven = NOT_GIVEN,
255
- customer_id: str | NotGiven = NOT_GIVEN,
256
- page_number: int | NotGiven = NOT_GIVEN,
257
- page_size: int | NotGiven = NOT_GIVEN,
258
- status: Literal["pending", "active", "on_hold", "cancelled", "failed", "expired"] | NotGiven = NOT_GIVEN,
260
+ brand_id: str | Omit = omit,
261
+ created_at_gte: Union[str, datetime] | Omit = omit,
262
+ created_at_lte: Union[str, datetime] | Omit = omit,
263
+ customer_id: str | Omit = omit,
264
+ page_number: int | Omit = omit,
265
+ page_size: int | Omit = omit,
266
+ status: Literal["pending", "active", "on_hold", "cancelled", "failed", "expired"] | Omit = omit,
259
267
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
260
268
  # The extra values given here take precedence over values defined on the client or passed to this method.
261
269
  extra_headers: Headers | None = None,
262
270
  extra_query: Query | None = None,
263
271
  extra_body: Body | None = None,
264
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
272
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
265
273
  ) -> SyncDefaultPageNumberPagination[SubscriptionListResponse]:
266
274
  """
267
275
  Args:
@@ -318,13 +326,13 @@ class SubscriptionsResource(SyncAPIResource):
318
326
  product_id: str,
319
327
  proration_billing_mode: Literal["prorated_immediately", "full_immediately", "difference_immediately"],
320
328
  quantity: int,
321
- addons: Optional[Iterable[AttachAddonParam]] | NotGiven = NOT_GIVEN,
329
+ addons: Optional[Iterable[AttachAddonParam]] | Omit = omit,
322
330
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
323
331
  # The extra values given here take precedence over values defined on the client or passed to this method.
324
332
  extra_headers: Headers | None = None,
325
333
  extra_query: Query | None = None,
326
334
  extra_body: Body | None = None,
327
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
335
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
328
336
  ) -> None:
329
337
  """
330
338
  Args:
@@ -370,16 +378,17 @@ class SubscriptionsResource(SyncAPIResource):
370
378
  subscription_id: str,
371
379
  *,
372
380
  product_price: int,
373
- adaptive_currency_fees_inclusive: Optional[bool] | NotGiven = NOT_GIVEN,
374
- metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
375
- product_currency: Optional[Currency] | NotGiven = NOT_GIVEN,
376
- product_description: Optional[str] | NotGiven = NOT_GIVEN,
381
+ adaptive_currency_fees_inclusive: Optional[bool] | Omit = omit,
382
+ customer_balance_config: Optional[subscription_charge_params.CustomerBalanceConfig] | Omit = omit,
383
+ metadata: Optional[Dict[str, str]] | Omit = omit,
384
+ product_currency: Optional[Currency] | Omit = omit,
385
+ product_description: Optional[str] | Omit = omit,
377
386
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
378
387
  # The extra values given here take precedence over values defined on the client or passed to this method.
379
388
  extra_headers: Headers | None = None,
380
389
  extra_query: Query | None = None,
381
390
  extra_body: Body | None = None,
382
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
391
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
383
392
  ) -> SubscriptionChargeResponse:
384
393
  """Args:
385
394
  product_price: The product price.
@@ -391,6 +400,8 @@ class SubscriptionsResource(SyncAPIResource):
391
400
  added on top (false). This field is ignored if adaptive pricing is not enabled
392
401
  for the business.
393
402
 
403
+ customer_balance_config: Specify how customer balance is used for the payment
404
+
394
405
  metadata: Metadata for the payment. If not passed, the metadata of the subscription will
395
406
  be taken
396
407
 
@@ -416,6 +427,7 @@ class SubscriptionsResource(SyncAPIResource):
416
427
  {
417
428
  "product_price": product_price,
418
429
  "adaptive_currency_fees_inclusive": adaptive_currency_fees_inclusive,
430
+ "customer_balance_config": customer_balance_config,
419
431
  "metadata": metadata,
420
432
  "product_currency": product_currency,
421
433
  "product_description": product_description,
@@ -428,6 +440,109 @@ class SubscriptionsResource(SyncAPIResource):
428
440
  cast_to=SubscriptionChargeResponse,
429
441
  )
430
442
 
443
+ def retrieve_usage_history(
444
+ self,
445
+ subscription_id: str,
446
+ *,
447
+ end_date: Union[str, datetime, None] | Omit = omit,
448
+ meter_id: Optional[str] | Omit = omit,
449
+ page_number: Optional[int] | Omit = omit,
450
+ page_size: Optional[int] | Omit = omit,
451
+ start_date: Union[str, datetime, None] | Omit = omit,
452
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
453
+ # The extra values given here take precedence over values defined on the client or passed to this method.
454
+ extra_headers: Headers | None = None,
455
+ extra_query: Query | None = None,
456
+ extra_body: Body | None = None,
457
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
458
+ ) -> SyncDefaultPageNumberPagination[SubscriptionRetrieveUsageHistoryResponse]:
459
+ """
460
+ Get detailed usage history for a subscription that includes usage-based billing
461
+ (metered components). This endpoint provides insights into customer usage
462
+ patterns and billing calculations over time.
463
+
464
+ ## What You'll Get:
465
+
466
+ - **Billing periods**: Each item represents a billing cycle with start and end
467
+ dates
468
+ - **Meter usage**: Detailed breakdown of usage for each meter configured on the
469
+ subscription
470
+ - **Usage calculations**: Total units consumed, free threshold units, and
471
+ chargeable units
472
+ - **Historical tracking**: Complete audit trail of usage-based charges
473
+
474
+ ## Use Cases:
475
+
476
+ - **Customer support**: Investigate billing questions and usage discrepancies
477
+ - **Usage analytics**: Analyze customer consumption patterns over time
478
+ - **Billing transparency**: Provide customers with detailed usage breakdowns
479
+ - **Revenue optimization**: Identify usage trends to optimize pricing strategies
480
+
481
+ ## Filtering Options:
482
+
483
+ - **Date range filtering**: Get usage history for specific time periods
484
+ - **Meter-specific filtering**: Focus on usage for a particular meter
485
+ - **Pagination**: Navigate through large usage histories efficiently
486
+
487
+ ## Important Notes:
488
+
489
+ - Only returns data for subscriptions with usage-based (metered) components
490
+ - Usage history is organized by billing periods (subscription cycles)
491
+ - Free threshold units are calculated and displayed separately from chargeable
492
+ units
493
+ - Historical data is preserved even if meter configurations change
494
+
495
+ ## Example Query Patterns:
496
+
497
+ - Get last 3 months:
498
+ `?start_date=2024-01-01T00:00:00Z&end_date=2024-03-31T23:59:59Z`
499
+ - Filter by meter: `?meter_id=mtr_api_requests`
500
+ - Paginate results: `?page_size=20&page_number=1`
501
+ - Recent usage: `?start_date=2024-03-01T00:00:00Z` (from March 1st to now)
502
+
503
+ Args:
504
+ end_date: Filter by end date (inclusive)
505
+
506
+ meter_id: Filter by specific meter ID
507
+
508
+ page_number: Page number (default: 0)
509
+
510
+ page_size: Page size (default: 10, max: 100)
511
+
512
+ start_date: Filter by start date (inclusive)
513
+
514
+ extra_headers: Send extra headers
515
+
516
+ extra_query: Add additional query parameters to the request
517
+
518
+ extra_body: Add additional JSON properties to the request
519
+
520
+ timeout: Override the client-level default timeout for this request, in seconds
521
+ """
522
+ if not subscription_id:
523
+ raise ValueError(f"Expected a non-empty value for `subscription_id` but received {subscription_id!r}")
524
+ return self._get_api_list(
525
+ f"/subscriptions/{subscription_id}/usage-history",
526
+ page=SyncDefaultPageNumberPagination[SubscriptionRetrieveUsageHistoryResponse],
527
+ options=make_request_options(
528
+ extra_headers=extra_headers,
529
+ extra_query=extra_query,
530
+ extra_body=extra_body,
531
+ timeout=timeout,
532
+ query=maybe_transform(
533
+ {
534
+ "end_date": end_date,
535
+ "meter_id": meter_id,
536
+ "page_number": page_number,
537
+ "page_size": page_size,
538
+ "start_date": start_date,
539
+ },
540
+ subscription_retrieve_usage_history_params.SubscriptionRetrieveUsageHistoryParams,
541
+ ),
542
+ ),
543
+ model=SubscriptionRetrieveUsageHistoryResponse,
544
+ )
545
+
431
546
 
432
547
  class AsyncSubscriptionsResource(AsyncAPIResource):
433
548
  @cached_property
@@ -456,23 +571,24 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
456
571
  customer: CustomerRequestParam,
457
572
  product_id: str,
458
573
  quantity: int,
459
- addons: Optional[Iterable[AttachAddonParam]] | NotGiven = NOT_GIVEN,
460
- allowed_payment_method_types: Optional[List[PaymentMethodTypes]] | NotGiven = NOT_GIVEN,
461
- billing_currency: Optional[Currency] | NotGiven = NOT_GIVEN,
462
- discount_code: Optional[str] | NotGiven = NOT_GIVEN,
463
- metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
464
- on_demand: Optional[OnDemandSubscriptionParam] | NotGiven = NOT_GIVEN,
465
- payment_link: Optional[bool] | NotGiven = NOT_GIVEN,
466
- return_url: Optional[str] | NotGiven = NOT_GIVEN,
467
- show_saved_payment_methods: bool | NotGiven = NOT_GIVEN,
468
- tax_id: Optional[str] | NotGiven = NOT_GIVEN,
469
- trial_period_days: Optional[int] | NotGiven = NOT_GIVEN,
574
+ addons: Optional[Iterable[AttachAddonParam]] | Omit = omit,
575
+ allowed_payment_method_types: Optional[List[PaymentMethodTypes]] | Omit = omit,
576
+ billing_currency: Optional[Currency] | Omit = omit,
577
+ discount_code: Optional[str] | Omit = omit,
578
+ force_3ds: Optional[bool] | Omit = omit,
579
+ metadata: Dict[str, str] | Omit = omit,
580
+ on_demand: Optional[OnDemandSubscriptionParam] | Omit = omit,
581
+ payment_link: Optional[bool] | Omit = omit,
582
+ return_url: Optional[str] | Omit = omit,
583
+ show_saved_payment_methods: bool | Omit = omit,
584
+ tax_id: Optional[str] | Omit = omit,
585
+ trial_period_days: Optional[int] | Omit = omit,
470
586
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
471
587
  # The extra values given here take precedence over values defined on the client or passed to this method.
472
588
  extra_headers: Headers | None = None,
473
589
  extra_query: Query | None = None,
474
590
  extra_body: Body | None = None,
475
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
591
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
476
592
  ) -> SubscriptionCreateResponse:
477
593
  """
478
594
  Args:
@@ -498,6 +614,8 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
498
614
 
499
615
  discount_code: Discount Code to apply to the subscription
500
616
 
617
+ force_3ds: Override merchant default 3DS behaviour for this subscription
618
+
501
619
  metadata: Additional metadata for the subscription Defaults to empty if not specified
502
620
 
503
621
  payment_link: If true, generates a payment link. Defaults to false if not specified.
@@ -532,6 +650,7 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
532
650
  "allowed_payment_method_types": allowed_payment_method_types,
533
651
  "billing_currency": billing_currency,
534
652
  "discount_code": discount_code,
653
+ "force_3ds": force_3ds,
535
654
  "metadata": metadata,
536
655
  "on_demand": on_demand,
537
656
  "payment_link": payment_link,
@@ -557,7 +676,7 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
557
676
  extra_headers: Headers | None = None,
558
677
  extra_query: Query | None = None,
559
678
  extra_body: Body | None = None,
560
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
679
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
561
680
  ) -> Subscription:
562
681
  """
563
682
  Args:
@@ -583,19 +702,20 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
583
702
  self,
584
703
  subscription_id: str,
585
704
  *,
586
- billing: Optional[BillingAddressParam] | NotGiven = NOT_GIVEN,
587
- cancel_at_next_billing_date: Optional[bool] | NotGiven = NOT_GIVEN,
588
- disable_on_demand: Optional[subscription_update_params.DisableOnDemand] | NotGiven = NOT_GIVEN,
589
- metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
590
- next_billing_date: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
591
- status: Optional[SubscriptionStatus] | NotGiven = NOT_GIVEN,
592
- tax_id: Optional[str] | NotGiven = NOT_GIVEN,
705
+ billing: Optional[BillingAddressParam] | Omit = omit,
706
+ cancel_at_next_billing_date: Optional[bool] | Omit = omit,
707
+ customer_name: Optional[str] | Omit = omit,
708
+ disable_on_demand: Optional[subscription_update_params.DisableOnDemand] | Omit = omit,
709
+ metadata: Optional[Dict[str, str]] | Omit = omit,
710
+ next_billing_date: Union[str, datetime, None] | Omit = omit,
711
+ status: Optional[SubscriptionStatus] | Omit = omit,
712
+ tax_id: Optional[str] | Omit = omit,
593
713
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
594
714
  # The extra values given here take precedence over values defined on the client or passed to this method.
595
715
  extra_headers: Headers | None = None,
596
716
  extra_query: Query | None = None,
597
717
  extra_body: Body | None = None,
598
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
718
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
599
719
  ) -> Subscription:
600
720
  """
601
721
  Args:
@@ -617,6 +737,7 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
617
737
  {
618
738
  "billing": billing,
619
739
  "cancel_at_next_billing_date": cancel_at_next_billing_date,
740
+ "customer_name": customer_name,
620
741
  "disable_on_demand": disable_on_demand,
621
742
  "metadata": metadata,
622
743
  "next_billing_date": next_billing_date,
@@ -634,19 +755,19 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
634
755
  def list(
635
756
  self,
636
757
  *,
637
- brand_id: str | NotGiven = NOT_GIVEN,
638
- created_at_gte: Union[str, datetime] | NotGiven = NOT_GIVEN,
639
- created_at_lte: Union[str, datetime] | NotGiven = NOT_GIVEN,
640
- customer_id: str | NotGiven = NOT_GIVEN,
641
- page_number: int | NotGiven = NOT_GIVEN,
642
- page_size: int | NotGiven = NOT_GIVEN,
643
- status: Literal["pending", "active", "on_hold", "cancelled", "failed", "expired"] | NotGiven = NOT_GIVEN,
758
+ brand_id: str | Omit = omit,
759
+ created_at_gte: Union[str, datetime] | Omit = omit,
760
+ created_at_lte: Union[str, datetime] | Omit = omit,
761
+ customer_id: str | Omit = omit,
762
+ page_number: int | Omit = omit,
763
+ page_size: int | Omit = omit,
764
+ status: Literal["pending", "active", "on_hold", "cancelled", "failed", "expired"] | Omit = omit,
644
765
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
645
766
  # The extra values given here take precedence over values defined on the client or passed to this method.
646
767
  extra_headers: Headers | None = None,
647
768
  extra_query: Query | None = None,
648
769
  extra_body: Body | None = None,
649
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
770
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
650
771
  ) -> AsyncPaginator[SubscriptionListResponse, AsyncDefaultPageNumberPagination[SubscriptionListResponse]]:
651
772
  """
652
773
  Args:
@@ -703,13 +824,13 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
703
824
  product_id: str,
704
825
  proration_billing_mode: Literal["prorated_immediately", "full_immediately", "difference_immediately"],
705
826
  quantity: int,
706
- addons: Optional[Iterable[AttachAddonParam]] | NotGiven = NOT_GIVEN,
827
+ addons: Optional[Iterable[AttachAddonParam]] | Omit = omit,
707
828
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
708
829
  # The extra values given here take precedence over values defined on the client or passed to this method.
709
830
  extra_headers: Headers | None = None,
710
831
  extra_query: Query | None = None,
711
832
  extra_body: Body | None = None,
712
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
833
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
713
834
  ) -> None:
714
835
  """
715
836
  Args:
@@ -755,16 +876,17 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
755
876
  subscription_id: str,
756
877
  *,
757
878
  product_price: int,
758
- adaptive_currency_fees_inclusive: Optional[bool] | NotGiven = NOT_GIVEN,
759
- metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
760
- product_currency: Optional[Currency] | NotGiven = NOT_GIVEN,
761
- product_description: Optional[str] | NotGiven = NOT_GIVEN,
879
+ adaptive_currency_fees_inclusive: Optional[bool] | Omit = omit,
880
+ customer_balance_config: Optional[subscription_charge_params.CustomerBalanceConfig] | Omit = omit,
881
+ metadata: Optional[Dict[str, str]] | Omit = omit,
882
+ product_currency: Optional[Currency] | Omit = omit,
883
+ product_description: Optional[str] | Omit = omit,
762
884
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
763
885
  # The extra values given here take precedence over values defined on the client or passed to this method.
764
886
  extra_headers: Headers | None = None,
765
887
  extra_query: Query | None = None,
766
888
  extra_body: Body | None = None,
767
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
889
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
768
890
  ) -> SubscriptionChargeResponse:
769
891
  """Args:
770
892
  product_price: The product price.
@@ -776,6 +898,8 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
776
898
  added on top (false). This field is ignored if adaptive pricing is not enabled
777
899
  for the business.
778
900
 
901
+ customer_balance_config: Specify how customer balance is used for the payment
902
+
779
903
  metadata: Metadata for the payment. If not passed, the metadata of the subscription will
780
904
  be taken
781
905
 
@@ -801,6 +925,7 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
801
925
  {
802
926
  "product_price": product_price,
803
927
  "adaptive_currency_fees_inclusive": adaptive_currency_fees_inclusive,
928
+ "customer_balance_config": customer_balance_config,
804
929
  "metadata": metadata,
805
930
  "product_currency": product_currency,
806
931
  "product_description": product_description,
@@ -813,6 +938,112 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
813
938
  cast_to=SubscriptionChargeResponse,
814
939
  )
815
940
 
941
+ def retrieve_usage_history(
942
+ self,
943
+ subscription_id: str,
944
+ *,
945
+ end_date: Union[str, datetime, None] | Omit = omit,
946
+ meter_id: Optional[str] | Omit = omit,
947
+ page_number: Optional[int] | Omit = omit,
948
+ page_size: Optional[int] | Omit = omit,
949
+ start_date: Union[str, datetime, None] | Omit = omit,
950
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
951
+ # The extra values given here take precedence over values defined on the client or passed to this method.
952
+ extra_headers: Headers | None = None,
953
+ extra_query: Query | None = None,
954
+ extra_body: Body | None = None,
955
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
956
+ ) -> AsyncPaginator[
957
+ SubscriptionRetrieveUsageHistoryResponse,
958
+ AsyncDefaultPageNumberPagination[SubscriptionRetrieveUsageHistoryResponse],
959
+ ]:
960
+ """
961
+ Get detailed usage history for a subscription that includes usage-based billing
962
+ (metered components). This endpoint provides insights into customer usage
963
+ patterns and billing calculations over time.
964
+
965
+ ## What You'll Get:
966
+
967
+ - **Billing periods**: Each item represents a billing cycle with start and end
968
+ dates
969
+ - **Meter usage**: Detailed breakdown of usage for each meter configured on the
970
+ subscription
971
+ - **Usage calculations**: Total units consumed, free threshold units, and
972
+ chargeable units
973
+ - **Historical tracking**: Complete audit trail of usage-based charges
974
+
975
+ ## Use Cases:
976
+
977
+ - **Customer support**: Investigate billing questions and usage discrepancies
978
+ - **Usage analytics**: Analyze customer consumption patterns over time
979
+ - **Billing transparency**: Provide customers with detailed usage breakdowns
980
+ - **Revenue optimization**: Identify usage trends to optimize pricing strategies
981
+
982
+ ## Filtering Options:
983
+
984
+ - **Date range filtering**: Get usage history for specific time periods
985
+ - **Meter-specific filtering**: Focus on usage for a particular meter
986
+ - **Pagination**: Navigate through large usage histories efficiently
987
+
988
+ ## Important Notes:
989
+
990
+ - Only returns data for subscriptions with usage-based (metered) components
991
+ - Usage history is organized by billing periods (subscription cycles)
992
+ - Free threshold units are calculated and displayed separately from chargeable
993
+ units
994
+ - Historical data is preserved even if meter configurations change
995
+
996
+ ## Example Query Patterns:
997
+
998
+ - Get last 3 months:
999
+ `?start_date=2024-01-01T00:00:00Z&end_date=2024-03-31T23:59:59Z`
1000
+ - Filter by meter: `?meter_id=mtr_api_requests`
1001
+ - Paginate results: `?page_size=20&page_number=1`
1002
+ - Recent usage: `?start_date=2024-03-01T00:00:00Z` (from March 1st to now)
1003
+
1004
+ Args:
1005
+ end_date: Filter by end date (inclusive)
1006
+
1007
+ meter_id: Filter by specific meter ID
1008
+
1009
+ page_number: Page number (default: 0)
1010
+
1011
+ page_size: Page size (default: 10, max: 100)
1012
+
1013
+ start_date: Filter by start date (inclusive)
1014
+
1015
+ extra_headers: Send extra headers
1016
+
1017
+ extra_query: Add additional query parameters to the request
1018
+
1019
+ extra_body: Add additional JSON properties to the request
1020
+
1021
+ timeout: Override the client-level default timeout for this request, in seconds
1022
+ """
1023
+ if not subscription_id:
1024
+ raise ValueError(f"Expected a non-empty value for `subscription_id` but received {subscription_id!r}")
1025
+ return self._get_api_list(
1026
+ f"/subscriptions/{subscription_id}/usage-history",
1027
+ page=AsyncDefaultPageNumberPagination[SubscriptionRetrieveUsageHistoryResponse],
1028
+ options=make_request_options(
1029
+ extra_headers=extra_headers,
1030
+ extra_query=extra_query,
1031
+ extra_body=extra_body,
1032
+ timeout=timeout,
1033
+ query=maybe_transform(
1034
+ {
1035
+ "end_date": end_date,
1036
+ "meter_id": meter_id,
1037
+ "page_number": page_number,
1038
+ "page_size": page_size,
1039
+ "start_date": start_date,
1040
+ },
1041
+ subscription_retrieve_usage_history_params.SubscriptionRetrieveUsageHistoryParams,
1042
+ ),
1043
+ ),
1044
+ model=SubscriptionRetrieveUsageHistoryResponse,
1045
+ )
1046
+
816
1047
 
817
1048
  class SubscriptionsResourceWithRawResponse:
818
1049
  def __init__(self, subscriptions: SubscriptionsResource) -> None:
@@ -836,6 +1067,9 @@ class SubscriptionsResourceWithRawResponse:
836
1067
  self.charge = to_raw_response_wrapper(
837
1068
  subscriptions.charge,
838
1069
  )
1070
+ self.retrieve_usage_history = to_raw_response_wrapper(
1071
+ subscriptions.retrieve_usage_history,
1072
+ )
839
1073
 
840
1074
 
841
1075
  class AsyncSubscriptionsResourceWithRawResponse:
@@ -860,6 +1094,9 @@ class AsyncSubscriptionsResourceWithRawResponse:
860
1094
  self.charge = async_to_raw_response_wrapper(
861
1095
  subscriptions.charge,
862
1096
  )
1097
+ self.retrieve_usage_history = async_to_raw_response_wrapper(
1098
+ subscriptions.retrieve_usage_history,
1099
+ )
863
1100
 
864
1101
 
865
1102
  class SubscriptionsResourceWithStreamingResponse:
@@ -884,6 +1121,9 @@ class SubscriptionsResourceWithStreamingResponse:
884
1121
  self.charge = to_streamed_response_wrapper(
885
1122
  subscriptions.charge,
886
1123
  )
1124
+ self.retrieve_usage_history = to_streamed_response_wrapper(
1125
+ subscriptions.retrieve_usage_history,
1126
+ )
887
1127
 
888
1128
 
889
1129
  class AsyncSubscriptionsResourceWithStreamingResponse:
@@ -908,3 +1148,6 @@ class AsyncSubscriptionsResourceWithStreamingResponse:
908
1148
  self.charge = async_to_streamed_response_wrapper(
909
1149
  subscriptions.charge,
910
1150
  )
1151
+ self.retrieve_usage_history = async_to_streamed_response_wrapper(
1152
+ subscriptions.retrieve_usage_history,
1153
+ )