dodopayments 1.51.1__py3-none-any.whl → 1.52.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.

Potentially problematic release.


This version of dodopayments might be problematic. Click here for more details.

Files changed (47) hide show
  1. dodopayments/_base_client.py +3 -3
  2. dodopayments/_client.py +18 -0
  3. dodopayments/_compat.py +48 -48
  4. dodopayments/_models.py +40 -40
  5. dodopayments/_utils/__init__.py +8 -2
  6. dodopayments/_utils/_compat.py +45 -0
  7. dodopayments/_utils/_datetime_parse.py +136 -0
  8. dodopayments/_utils/_transform.py +11 -1
  9. dodopayments/_utils/_typing.py +1 -1
  10. dodopayments/_utils/_utils.py +0 -1
  11. dodopayments/_version.py +1 -1
  12. dodopayments/resources/__init__.py +28 -0
  13. dodopayments/resources/discounts.py +6 -6
  14. dodopayments/resources/invoices/payments.py +80 -0
  15. dodopayments/resources/meters.py +554 -0
  16. dodopayments/resources/products/products.py +16 -16
  17. dodopayments/resources/subscriptions.py +223 -0
  18. dodopayments/resources/usage_events.py +597 -0
  19. dodopayments/types/__init__.py +20 -0
  20. dodopayments/types/add_meter_to_price.py +29 -0
  21. dodopayments/types/add_meter_to_price_param.py +30 -0
  22. dodopayments/types/discount_create_params.py +3 -2
  23. dodopayments/types/discount_update_params.py +3 -2
  24. dodopayments/types/event.py +26 -0
  25. dodopayments/types/event_input_param.py +38 -0
  26. dodopayments/types/meter.py +40 -0
  27. dodopayments/types/meter_aggregation.py +16 -0
  28. dodopayments/types/meter_aggregation_param.py +16 -0
  29. dodopayments/types/meter_create_params.py +31 -0
  30. dodopayments/types/meter_filter.py +131 -0
  31. dodopayments/types/meter_filter_param.py +143 -0
  32. dodopayments/types/meter_list_params.py +18 -0
  33. dodopayments/types/payment.py +6 -0
  34. dodopayments/types/price.py +52 -5
  35. dodopayments/types/price_param.py +52 -5
  36. dodopayments/types/product_create_params.py +3 -2
  37. dodopayments/types/product_update_params.py +4 -3
  38. dodopayments/types/subscription.py +20 -1
  39. dodopayments/types/subscription_retrieve_usage_history_params.py +28 -0
  40. dodopayments/types/subscription_retrieve_usage_history_response.py +46 -0
  41. dodopayments/types/usage_event_ingest_params.py +15 -0
  42. dodopayments/types/usage_event_ingest_response.py +9 -0
  43. dodopayments/types/usage_event_list_params.py +42 -0
  44. {dodopayments-1.51.1.dist-info → dodopayments-1.52.5.dist-info}/METADATA +1 -1
  45. {dodopayments-1.51.1.dist-info → dodopayments-1.52.5.dist-info}/RECORD +47 -27
  46. {dodopayments-1.51.1.dist-info → dodopayments-1.52.5.dist-info}/WHEEL +0 -0
  47. {dodopayments-1.51.1.dist-info → dodopayments-1.52.5.dist-info}/licenses/LICENSE +0 -0
@@ -16,6 +16,7 @@ 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
21
  from .._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
21
22
  from .._utils import maybe_transform, async_maybe_transform
@@ -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
 
@@ -428,6 +430,109 @@ class SubscriptionsResource(SyncAPIResource):
428
430
  cast_to=SubscriptionChargeResponse,
429
431
  )
430
432
 
433
+ def retrieve_usage_history(
434
+ self,
435
+ subscription_id: str,
436
+ *,
437
+ end_date: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
438
+ meter_id: Optional[str] | NotGiven = NOT_GIVEN,
439
+ page_number: Optional[int] | NotGiven = NOT_GIVEN,
440
+ page_size: Optional[int] | NotGiven = NOT_GIVEN,
441
+ start_date: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
442
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
443
+ # The extra values given here take precedence over values defined on the client or passed to this method.
444
+ extra_headers: Headers | None = None,
445
+ extra_query: Query | None = None,
446
+ extra_body: Body | None = None,
447
+ timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
448
+ ) -> SyncDefaultPageNumberPagination[SubscriptionRetrieveUsageHistoryResponse]:
449
+ """
450
+ Get detailed usage history for a subscription that includes usage-based billing
451
+ (metered components). This endpoint provides insights into customer usage
452
+ patterns and billing calculations over time.
453
+
454
+ ## What You'll Get:
455
+
456
+ - **Billing periods**: Each item represents a billing cycle with start and end
457
+ dates
458
+ - **Meter usage**: Detailed breakdown of usage for each meter configured on the
459
+ subscription
460
+ - **Usage calculations**: Total units consumed, free threshold units, and
461
+ chargeable units
462
+ - **Historical tracking**: Complete audit trail of usage-based charges
463
+
464
+ ## Use Cases:
465
+
466
+ - **Customer support**: Investigate billing questions and usage discrepancies
467
+ - **Usage analytics**: Analyze customer consumption patterns over time
468
+ - **Billing transparency**: Provide customers with detailed usage breakdowns
469
+ - **Revenue optimization**: Identify usage trends to optimize pricing strategies
470
+
471
+ ## Filtering Options:
472
+
473
+ - **Date range filtering**: Get usage history for specific time periods
474
+ - **Meter-specific filtering**: Focus on usage for a particular meter
475
+ - **Pagination**: Navigate through large usage histories efficiently
476
+
477
+ ## Important Notes:
478
+
479
+ - Only returns data for subscriptions with usage-based (metered) components
480
+ - Usage history is organized by billing periods (subscription cycles)
481
+ - Free threshold units are calculated and displayed separately from chargeable
482
+ units
483
+ - Historical data is preserved even if meter configurations change
484
+
485
+ ## Example Query Patterns:
486
+
487
+ - Get last 3 months:
488
+ `?start_date=2024-01-01T00:00:00Z&end_date=2024-03-31T23:59:59Z`
489
+ - Filter by meter: `?meter_id=mtr_api_requests`
490
+ - Paginate results: `?page_size=20&page_number=1`
491
+ - Recent usage: `?start_date=2024-03-01T00:00:00Z` (from March 1st to now)
492
+
493
+ Args:
494
+ end_date: Filter by end date (inclusive)
495
+
496
+ meter_id: Filter by specific meter ID
497
+
498
+ page_number: Page number (default: 0)
499
+
500
+ page_size: Page size (default: 10, max: 100)
501
+
502
+ start_date: Filter by start date (inclusive)
503
+
504
+ extra_headers: Send extra headers
505
+
506
+ extra_query: Add additional query parameters to the request
507
+
508
+ extra_body: Add additional JSON properties to the request
509
+
510
+ timeout: Override the client-level default timeout for this request, in seconds
511
+ """
512
+ if not subscription_id:
513
+ raise ValueError(f"Expected a non-empty value for `subscription_id` but received {subscription_id!r}")
514
+ return self._get_api_list(
515
+ f"/subscriptions/{subscription_id}/usage-history",
516
+ page=SyncDefaultPageNumberPagination[SubscriptionRetrieveUsageHistoryResponse],
517
+ options=make_request_options(
518
+ extra_headers=extra_headers,
519
+ extra_query=extra_query,
520
+ extra_body=extra_body,
521
+ timeout=timeout,
522
+ query=maybe_transform(
523
+ {
524
+ "end_date": end_date,
525
+ "meter_id": meter_id,
526
+ "page_number": page_number,
527
+ "page_size": page_size,
528
+ "start_date": start_date,
529
+ },
530
+ subscription_retrieve_usage_history_params.SubscriptionRetrieveUsageHistoryParams,
531
+ ),
532
+ ),
533
+ model=SubscriptionRetrieveUsageHistoryResponse,
534
+ )
535
+
431
536
 
432
537
  class AsyncSubscriptionsResource(AsyncAPIResource):
433
538
  @cached_property
@@ -813,6 +918,112 @@ class AsyncSubscriptionsResource(AsyncAPIResource):
813
918
  cast_to=SubscriptionChargeResponse,
814
919
  )
815
920
 
921
+ def retrieve_usage_history(
922
+ self,
923
+ subscription_id: str,
924
+ *,
925
+ end_date: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
926
+ meter_id: Optional[str] | NotGiven = NOT_GIVEN,
927
+ page_number: Optional[int] | NotGiven = NOT_GIVEN,
928
+ page_size: Optional[int] | NotGiven = NOT_GIVEN,
929
+ start_date: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
930
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
931
+ # The extra values given here take precedence over values defined on the client or passed to this method.
932
+ extra_headers: Headers | None = None,
933
+ extra_query: Query | None = None,
934
+ extra_body: Body | None = None,
935
+ timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
936
+ ) -> AsyncPaginator[
937
+ SubscriptionRetrieveUsageHistoryResponse,
938
+ AsyncDefaultPageNumberPagination[SubscriptionRetrieveUsageHistoryResponse],
939
+ ]:
940
+ """
941
+ Get detailed usage history for a subscription that includes usage-based billing
942
+ (metered components). This endpoint provides insights into customer usage
943
+ patterns and billing calculations over time.
944
+
945
+ ## What You'll Get:
946
+
947
+ - **Billing periods**: Each item represents a billing cycle with start and end
948
+ dates
949
+ - **Meter usage**: Detailed breakdown of usage for each meter configured on the
950
+ subscription
951
+ - **Usage calculations**: Total units consumed, free threshold units, and
952
+ chargeable units
953
+ - **Historical tracking**: Complete audit trail of usage-based charges
954
+
955
+ ## Use Cases:
956
+
957
+ - **Customer support**: Investigate billing questions and usage discrepancies
958
+ - **Usage analytics**: Analyze customer consumption patterns over time
959
+ - **Billing transparency**: Provide customers with detailed usage breakdowns
960
+ - **Revenue optimization**: Identify usage trends to optimize pricing strategies
961
+
962
+ ## Filtering Options:
963
+
964
+ - **Date range filtering**: Get usage history for specific time periods
965
+ - **Meter-specific filtering**: Focus on usage for a particular meter
966
+ - **Pagination**: Navigate through large usage histories efficiently
967
+
968
+ ## Important Notes:
969
+
970
+ - Only returns data for subscriptions with usage-based (metered) components
971
+ - Usage history is organized by billing periods (subscription cycles)
972
+ - Free threshold units are calculated and displayed separately from chargeable
973
+ units
974
+ - Historical data is preserved even if meter configurations change
975
+
976
+ ## Example Query Patterns:
977
+
978
+ - Get last 3 months:
979
+ `?start_date=2024-01-01T00:00:00Z&end_date=2024-03-31T23:59:59Z`
980
+ - Filter by meter: `?meter_id=mtr_api_requests`
981
+ - Paginate results: `?page_size=20&page_number=1`
982
+ - Recent usage: `?start_date=2024-03-01T00:00:00Z` (from March 1st to now)
983
+
984
+ Args:
985
+ end_date: Filter by end date (inclusive)
986
+
987
+ meter_id: Filter by specific meter ID
988
+
989
+ page_number: Page number (default: 0)
990
+
991
+ page_size: Page size (default: 10, max: 100)
992
+
993
+ start_date: Filter by start date (inclusive)
994
+
995
+ extra_headers: Send extra headers
996
+
997
+ extra_query: Add additional query parameters to the request
998
+
999
+ extra_body: Add additional JSON properties to the request
1000
+
1001
+ timeout: Override the client-level default timeout for this request, in seconds
1002
+ """
1003
+ if not subscription_id:
1004
+ raise ValueError(f"Expected a non-empty value for `subscription_id` but received {subscription_id!r}")
1005
+ return self._get_api_list(
1006
+ f"/subscriptions/{subscription_id}/usage-history",
1007
+ page=AsyncDefaultPageNumberPagination[SubscriptionRetrieveUsageHistoryResponse],
1008
+ options=make_request_options(
1009
+ extra_headers=extra_headers,
1010
+ extra_query=extra_query,
1011
+ extra_body=extra_body,
1012
+ timeout=timeout,
1013
+ query=maybe_transform(
1014
+ {
1015
+ "end_date": end_date,
1016
+ "meter_id": meter_id,
1017
+ "page_number": page_number,
1018
+ "page_size": page_size,
1019
+ "start_date": start_date,
1020
+ },
1021
+ subscription_retrieve_usage_history_params.SubscriptionRetrieveUsageHistoryParams,
1022
+ ),
1023
+ ),
1024
+ model=SubscriptionRetrieveUsageHistoryResponse,
1025
+ )
1026
+
816
1027
 
817
1028
  class SubscriptionsResourceWithRawResponse:
818
1029
  def __init__(self, subscriptions: SubscriptionsResource) -> None:
@@ -836,6 +1047,9 @@ class SubscriptionsResourceWithRawResponse:
836
1047
  self.charge = to_raw_response_wrapper(
837
1048
  subscriptions.charge,
838
1049
  )
1050
+ self.retrieve_usage_history = to_raw_response_wrapper(
1051
+ subscriptions.retrieve_usage_history,
1052
+ )
839
1053
 
840
1054
 
841
1055
  class AsyncSubscriptionsResourceWithRawResponse:
@@ -860,6 +1074,9 @@ class AsyncSubscriptionsResourceWithRawResponse:
860
1074
  self.charge = async_to_raw_response_wrapper(
861
1075
  subscriptions.charge,
862
1076
  )
1077
+ self.retrieve_usage_history = async_to_raw_response_wrapper(
1078
+ subscriptions.retrieve_usage_history,
1079
+ )
863
1080
 
864
1081
 
865
1082
  class SubscriptionsResourceWithStreamingResponse:
@@ -884,6 +1101,9 @@ class SubscriptionsResourceWithStreamingResponse:
884
1101
  self.charge = to_streamed_response_wrapper(
885
1102
  subscriptions.charge,
886
1103
  )
1104
+ self.retrieve_usage_history = to_streamed_response_wrapper(
1105
+ subscriptions.retrieve_usage_history,
1106
+ )
887
1107
 
888
1108
 
889
1109
  class AsyncSubscriptionsResourceWithStreamingResponse:
@@ -908,3 +1128,6 @@ class AsyncSubscriptionsResourceWithStreamingResponse:
908
1128
  self.charge = async_to_streamed_response_wrapper(
909
1129
  subscriptions.charge,
910
1130
  )
1131
+ self.retrieve_usage_history = async_to_streamed_response_wrapper(
1132
+ subscriptions.retrieve_usage_history,
1133
+ )