dodopayments 1.51.1 → 1.52.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +1 -1
- data/lib/dodopayments/client.rb +8 -0
- data/lib/dodopayments/models/add_meter_to_price.rb +58 -0
- data/lib/dodopayments/models/event.rb +71 -0
- data/lib/dodopayments/models/event_input.rb +70 -0
- data/lib/dodopayments/models/invoices/payment_retrieve_refund_params.rb +16 -0
- data/lib/dodopayments/models/meter.rb +88 -0
- data/lib/dodopayments/models/meter_aggregation.rb +39 -0
- data/lib/dodopayments/models/meter_archive_params.rb +14 -0
- data/lib/dodopayments/models/meter_create_params.rb +62 -0
- data/lib/dodopayments/models/meter_filter.rb +482 -0
- data/lib/dodopayments/models/meter_list_params.rb +38 -0
- data/lib/dodopayments/models/{product_delete_params.rb → meter_retrieve_params.rb} +2 -2
- data/lib/dodopayments/models/meter_unarchive_params.rb +14 -0
- data/lib/dodopayments/models/payment.rb +10 -1
- data/lib/dodopayments/models/price.rb +122 -7
- data/lib/dodopayments/models/product.rb +2 -2
- data/lib/dodopayments/models/product_archive_params.rb +14 -0
- data/lib/dodopayments/models/product_create_params.rb +2 -2
- data/lib/dodopayments/models/product_list_response.rb +2 -2
- data/lib/dodopayments/models/product_update_params.rb +2 -2
- data/lib/dodopayments/models/subscription.rb +57 -1
- data/lib/dodopayments/models/subscription_retrieve_usage_history_params.rb +54 -0
- data/lib/dodopayments/models/subscription_retrieve_usage_history_response.rb +101 -0
- data/lib/dodopayments/models/usage_event_ingest_params.rb +22 -0
- data/lib/dodopayments/models/usage_event_ingest_response.rb +16 -0
- data/lib/dodopayments/models/usage_event_list_params.rb +75 -0
- data/lib/dodopayments/models/usage_event_retrieve_params.rb +14 -0
- data/lib/dodopayments/models.rb +32 -2
- data/lib/dodopayments/resources/invoices/payments.rb +18 -0
- data/lib/dodopayments/resources/meters.rb +123 -0
- data/lib/dodopayments/resources/products.rb +5 -5
- data/lib/dodopayments/resources/subscriptions.rb +74 -0
- data/lib/dodopayments/resources/usage_events.rb +193 -0
- data/lib/dodopayments/version.rb +1 -1
- data/lib/dodopayments.rb +21 -1
- data/rbi/dodopayments/client.rbi +6 -0
- data/rbi/dodopayments/models/add_meter_to_price.rbi +75 -0
- data/rbi/dodopayments/models/event.rbi +88 -0
- data/rbi/dodopayments/models/event_input.rbi +102 -0
- data/rbi/dodopayments/models/invoices/payment_retrieve_refund_params.rbi +34 -0
- data/rbi/dodopayments/models/meter.rbi +107 -0
- data/rbi/dodopayments/models/meter_aggregation.rbi +68 -0
- data/rbi/dodopayments/models/meter_archive_params.rbi +32 -0
- data/rbi/dodopayments/models/meter_create_params.rbi +92 -0
- data/rbi/dodopayments/models/meter_filter.rbi +1042 -0
- data/rbi/dodopayments/models/meter_list_params.rbi +68 -0
- data/rbi/dodopayments/models/{product_delete_params.rbi → meter_retrieve_params.rbi} +2 -2
- data/rbi/dodopayments/models/meter_unarchive_params.rbi +32 -0
- data/rbi/dodopayments/models/payment.rbi +10 -0
- data/rbi/dodopayments/models/price.rbi +153 -7
- data/rbi/dodopayments/models/product.rbi +2 -1
- data/rbi/dodopayments/models/product_archive_params.rbi +32 -0
- data/rbi/dodopayments/models/product_create_params.rbi +6 -3
- data/rbi/dodopayments/models/product_list_response.rbi +2 -1
- data/rbi/dodopayments/models/product_update_params.rbi +6 -3
- data/rbi/dodopayments/models/subscription.rbi +78 -0
- data/rbi/dodopayments/models/subscription_retrieve_usage_history_params.rbi +78 -0
- data/rbi/dodopayments/models/subscription_retrieve_usage_history_response.rbi +159 -0
- data/rbi/dodopayments/models/usage_event_ingest_params.rbi +46 -0
- data/rbi/dodopayments/models/usage_event_ingest_response.rbi +26 -0
- data/rbi/dodopayments/models/usage_event_list_params.rbi +119 -0
- data/rbi/dodopayments/models/usage_event_retrieve_params.rbi +32 -0
- data/rbi/dodopayments/models.rbi +33 -2
- data/rbi/dodopayments/resources/invoices/payments.rbi +9 -0
- data/rbi/dodopayments/resources/meters.rbi +102 -0
- data/rbi/dodopayments/resources/products.rbi +5 -3
- data/rbi/dodopayments/resources/subscriptions.rbi +74 -0
- data/rbi/dodopayments/resources/usage_events.rbi +175 -0
- data/sig/dodopayments/client.rbs +4 -0
- data/sig/dodopayments/models/add_meter_to_price.rbs +45 -0
- data/sig/dodopayments/models/event.rbs +53 -0
- data/sig/dodopayments/models/event_input.rbs +48 -0
- data/sig/dodopayments/models/invoices/payment_retrieve_refund_params.rbs +17 -0
- data/sig/dodopayments/models/meter.rbs +65 -0
- data/sig/dodopayments/models/meter_aggregation.rbs +35 -0
- data/sig/dodopayments/models/meter_archive_params.rbs +15 -0
- data/sig/dodopayments/models/meter_create_params.rbs +51 -0
- data/sig/dodopayments/models/meter_filter.rbs +417 -0
- data/sig/dodopayments/models/meter_list_params.rbs +38 -0
- data/sig/dodopayments/models/{product_delete_params.rbs → meter_retrieve_params.rbs} +2 -2
- data/sig/dodopayments/models/meter_unarchive_params.rbs +15 -0
- data/sig/dodopayments/models/payment.rbs +5 -0
- data/sig/dodopayments/models/price.rbs +88 -9
- data/sig/dodopayments/models/product_archive_params.rbs +15 -0
- data/sig/dodopayments/models/subscription.rbs +52 -0
- data/sig/dodopayments/models/subscription_retrieve_usage_history_params.rbs +46 -0
- data/sig/dodopayments/models/subscription_retrieve_usage_history_response.rbs +82 -0
- data/sig/dodopayments/models/usage_event_ingest_params.rbs +24 -0
- data/sig/dodopayments/models/usage_event_ingest_response.rbs +13 -0
- data/sig/dodopayments/models/usage_event_list_params.rbs +70 -0
- data/sig/dodopayments/models/usage_event_retrieve_params.rbs +15 -0
- data/sig/dodopayments/models.rbs +32 -2
- data/sig/dodopayments/resources/invoices/payments.rbs +5 -0
- data/sig/dodopayments/resources/meters.rbs +39 -0
- data/sig/dodopayments/resources/products.rbs +1 -1
- data/sig/dodopayments/resources/subscriptions.rbs +10 -0
- data/sig/dodopayments/resources/usage_events.rbs +28 -0
- metadata +65 -5
data/lib/dodopayments/models.rb
CHANGED
@@ -39,6 +39,8 @@ module Dodopayments
|
|
39
39
|
mod.define_sorbet_constant!(const) { T.type_alias { mod.to_sorbet_type } }
|
40
40
|
end
|
41
41
|
|
42
|
+
AddMeterToPrice = Dodopayments::Models::AddMeterToPrice
|
43
|
+
|
42
44
|
AddonCartResponseItem = Dodopayments::Models::AddonCartResponseItem
|
43
45
|
|
44
46
|
AddonCreateParams = Dodopayments::Models::AddonCreateParams
|
@@ -125,6 +127,10 @@ module Dodopayments
|
|
125
127
|
|
126
128
|
DisputeStatus = Dodopayments::Models::DisputeStatus
|
127
129
|
|
130
|
+
Event = Dodopayments::Models::Event
|
131
|
+
|
132
|
+
EventInput = Dodopayments::Models::EventInput
|
133
|
+
|
128
134
|
GetDispute = Dodopayments::Models::GetDispute
|
129
135
|
|
130
136
|
IntentStatus = Dodopayments::Models::IntentStatus
|
@@ -157,6 +163,22 @@ module Dodopayments
|
|
157
163
|
|
158
164
|
LicenseValidateParams = Dodopayments::Models::LicenseValidateParams
|
159
165
|
|
166
|
+
Meter = Dodopayments::Models::Meter
|
167
|
+
|
168
|
+
MeterAggregation = Dodopayments::Models::MeterAggregation
|
169
|
+
|
170
|
+
MeterArchiveParams = Dodopayments::Models::MeterArchiveParams
|
171
|
+
|
172
|
+
MeterCreateParams = Dodopayments::Models::MeterCreateParams
|
173
|
+
|
174
|
+
MeterFilter = Dodopayments::Models::MeterFilter
|
175
|
+
|
176
|
+
MeterListParams = Dodopayments::Models::MeterListParams
|
177
|
+
|
178
|
+
MeterRetrieveParams = Dodopayments::Models::MeterRetrieveParams
|
179
|
+
|
180
|
+
MeterUnarchiveParams = Dodopayments::Models::MeterUnarchiveParams
|
181
|
+
|
160
182
|
MiscListSupportedCountriesParams = Dodopayments::Models::MiscListSupportedCountriesParams
|
161
183
|
|
162
184
|
NewCustomer = Dodopayments::Models::NewCustomer
|
@@ -183,9 +205,9 @@ module Dodopayments
|
|
183
205
|
|
184
206
|
Product = Dodopayments::Models::Product
|
185
207
|
|
186
|
-
|
208
|
+
ProductArchiveParams = Dodopayments::Models::ProductArchiveParams
|
187
209
|
|
188
|
-
|
210
|
+
ProductCreateParams = Dodopayments::Models::ProductCreateParams
|
189
211
|
|
190
212
|
ProductListParams = Dodopayments::Models::ProductListParams
|
191
213
|
|
@@ -221,6 +243,8 @@ module Dodopayments
|
|
221
243
|
|
222
244
|
SubscriptionRetrieveParams = Dodopayments::Models::SubscriptionRetrieveParams
|
223
245
|
|
246
|
+
SubscriptionRetrieveUsageHistoryParams = Dodopayments::Models::SubscriptionRetrieveUsageHistoryParams
|
247
|
+
|
224
248
|
SubscriptionStatus = Dodopayments::Models::SubscriptionStatus
|
225
249
|
|
226
250
|
SubscriptionUpdateParams = Dodopayments::Models::SubscriptionUpdateParams
|
@@ -229,6 +253,12 @@ module Dodopayments
|
|
229
253
|
|
230
254
|
TimeInterval = Dodopayments::Models::TimeInterval
|
231
255
|
|
256
|
+
UsageEventIngestParams = Dodopayments::Models::UsageEventIngestParams
|
257
|
+
|
258
|
+
UsageEventListParams = Dodopayments::Models::UsageEventListParams
|
259
|
+
|
260
|
+
UsageEventRetrieveParams = Dodopayments::Models::UsageEventRetrieveParams
|
261
|
+
|
232
262
|
WebhookCreateParams = Dodopayments::Models::WebhookCreateParams
|
233
263
|
|
234
264
|
WebhookDeleteParams = Dodopayments::Models::WebhookDeleteParams
|
@@ -22,6 +22,24 @@ module Dodopayments
|
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
25
|
+
# @overload retrieve_refund(refund_id, request_options: {})
|
26
|
+
#
|
27
|
+
# @param refund_id [String]
|
28
|
+
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
29
|
+
#
|
30
|
+
# @return [StringIO]
|
31
|
+
#
|
32
|
+
# @see Dodopayments::Models::Invoices::PaymentRetrieveRefundParams
|
33
|
+
def retrieve_refund(refund_id, params = {})
|
34
|
+
@client.request(
|
35
|
+
method: :get,
|
36
|
+
path: ["invoices/refunds/%1$s", refund_id],
|
37
|
+
headers: {"accept" => "application/pdf"},
|
38
|
+
model: StringIO,
|
39
|
+
options: params[:request_options]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
25
43
|
# @api private
|
26
44
|
#
|
27
45
|
# @param client [Dodopayments::Client]
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dodopayments
|
4
|
+
module Resources
|
5
|
+
class Meters
|
6
|
+
# @overload create(aggregation:, event_name:, measurement_unit:, name:, description: nil, filter: nil, request_options: {})
|
7
|
+
#
|
8
|
+
# @param aggregation [Dodopayments::Models::MeterAggregation] Aggregation configuration for the meter
|
9
|
+
#
|
10
|
+
# @param event_name [String] Event name to track
|
11
|
+
#
|
12
|
+
# @param measurement_unit [String] measurement unit
|
13
|
+
#
|
14
|
+
# @param name [String] Name of the meter
|
15
|
+
#
|
16
|
+
# @param description [String, nil] Optional description of the meter
|
17
|
+
#
|
18
|
+
# @param filter [Dodopayments::Models::MeterFilter, nil] Optional filter to apply to the meter
|
19
|
+
#
|
20
|
+
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
21
|
+
#
|
22
|
+
# @return [Dodopayments::Models::Meter]
|
23
|
+
#
|
24
|
+
# @see Dodopayments::Models::MeterCreateParams
|
25
|
+
def create(params)
|
26
|
+
parsed, options = Dodopayments::MeterCreateParams.dump_request(params)
|
27
|
+
@client.request(
|
28
|
+
method: :post,
|
29
|
+
path: "meters",
|
30
|
+
body: parsed,
|
31
|
+
model: Dodopayments::Meter,
|
32
|
+
options: options
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
# @overload retrieve(id, request_options: {})
|
37
|
+
#
|
38
|
+
# @param id [String] Meter ID
|
39
|
+
#
|
40
|
+
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
41
|
+
#
|
42
|
+
# @return [Dodopayments::Models::Meter]
|
43
|
+
#
|
44
|
+
# @see Dodopayments::Models::MeterRetrieveParams
|
45
|
+
def retrieve(id, params = {})
|
46
|
+
@client.request(
|
47
|
+
method: :get,
|
48
|
+
path: ["meters/%1$s", id],
|
49
|
+
model: Dodopayments::Meter,
|
50
|
+
options: params[:request_options]
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @overload list(archived: nil, page_number: nil, page_size: nil, request_options: {})
|
55
|
+
#
|
56
|
+
# @param archived [Boolean] List archived meters
|
57
|
+
#
|
58
|
+
# @param page_number [Integer] Page number default is 0
|
59
|
+
#
|
60
|
+
# @param page_size [Integer] Page size default is 10 max is 100
|
61
|
+
#
|
62
|
+
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
63
|
+
#
|
64
|
+
# @return [Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::Meter>]
|
65
|
+
#
|
66
|
+
# @see Dodopayments::Models::MeterListParams
|
67
|
+
def list(params = {})
|
68
|
+
parsed, options = Dodopayments::MeterListParams.dump_request(params)
|
69
|
+
@client.request(
|
70
|
+
method: :get,
|
71
|
+
path: "meters",
|
72
|
+
query: parsed,
|
73
|
+
page: Dodopayments::Internal::DefaultPageNumberPagination,
|
74
|
+
model: Dodopayments::Meter,
|
75
|
+
options: options
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
# @overload archive(id, request_options: {})
|
80
|
+
#
|
81
|
+
# @param id [String] Meter ID
|
82
|
+
#
|
83
|
+
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
84
|
+
#
|
85
|
+
# @return [nil]
|
86
|
+
#
|
87
|
+
# @see Dodopayments::Models::MeterArchiveParams
|
88
|
+
def archive(id, params = {})
|
89
|
+
@client.request(
|
90
|
+
method: :delete,
|
91
|
+
path: ["meters/%1$s", id],
|
92
|
+
model: NilClass,
|
93
|
+
options: params[:request_options]
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
# @overload unarchive(id, request_options: {})
|
98
|
+
#
|
99
|
+
# @param id [String] Meter ID
|
100
|
+
#
|
101
|
+
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
102
|
+
#
|
103
|
+
# @return [nil]
|
104
|
+
#
|
105
|
+
# @see Dodopayments::Models::MeterUnarchiveParams
|
106
|
+
def unarchive(id, params = {})
|
107
|
+
@client.request(
|
108
|
+
method: :post,
|
109
|
+
path: ["meters/%1$s/unarchive", id],
|
110
|
+
model: NilClass,
|
111
|
+
options: params[:request_options]
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
# @api private
|
116
|
+
#
|
117
|
+
# @param client [Dodopayments::Client]
|
118
|
+
def initialize(client:)
|
119
|
+
@client = client
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -11,7 +11,7 @@ module Dodopayments
|
|
11
11
|
#
|
12
12
|
# @overload create(price:, tax_category:, addons: nil, brand_id: nil, description: nil, digital_product_delivery: nil, license_key_activation_message: nil, license_key_activations_limit: nil, license_key_duration: nil, license_key_enabled: nil, metadata: nil, name: nil, request_options: {})
|
13
13
|
#
|
14
|
-
# @param price [Dodopayments::Models::Price::OneTimePrice, Dodopayments::Models::Price::RecurringPrice] Price configuration for the product
|
14
|
+
# @param price [Dodopayments::Models::Price::OneTimePrice, Dodopayments::Models::Price::RecurringPrice, Dodopayments::Models::Price::UsageBasedPrice] Price configuration for the product
|
15
15
|
#
|
16
16
|
# @param tax_category [Symbol, Dodopayments::Models::TaxCategory] Tax category applied to this product
|
17
17
|
#
|
@@ -98,7 +98,7 @@ module Dodopayments
|
|
98
98
|
#
|
99
99
|
# @param name [String, nil] Name of the product, optional and must be at most 100 characters.
|
100
100
|
#
|
101
|
-
# @param price [Dodopayments::Models::Price::OneTimePrice, Dodopayments::Models::Price::RecurringPrice, nil] Price details of the product.
|
101
|
+
# @param price [Dodopayments::Models::Price::OneTimePrice, Dodopayments::Models::Price::RecurringPrice, Dodopayments::Models::Price::UsageBasedPrice, nil] Price details of the product.
|
102
102
|
#
|
103
103
|
# @param tax_category [Symbol, Dodopayments::Models::TaxCategory, nil] Tax category of the product.
|
104
104
|
#
|
@@ -150,15 +150,15 @@ module Dodopayments
|
|
150
150
|
)
|
151
151
|
end
|
152
152
|
|
153
|
-
# @overload
|
153
|
+
# @overload archive(id, request_options: {})
|
154
154
|
#
|
155
155
|
# @param id [String]
|
156
156
|
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
157
157
|
#
|
158
158
|
# @return [nil]
|
159
159
|
#
|
160
|
-
# @see Dodopayments::Models::
|
161
|
-
def
|
160
|
+
# @see Dodopayments::Models::ProductArchiveParams
|
161
|
+
def archive(id, params = {})
|
162
162
|
@client.request(
|
163
163
|
method: :delete,
|
164
164
|
path: ["products/%1$s", id],
|
@@ -203,6 +203,80 @@ module Dodopayments
|
|
203
203
|
)
|
204
204
|
end
|
205
205
|
|
206
|
+
# Get detailed usage history for a subscription that includes usage-based billing
|
207
|
+
# (metered components). This endpoint provides insights into customer usage
|
208
|
+
# patterns and billing calculations over time.
|
209
|
+
#
|
210
|
+
# ## What You'll Get:
|
211
|
+
#
|
212
|
+
# - **Billing periods**: Each item represents a billing cycle with start and end
|
213
|
+
# dates
|
214
|
+
# - **Meter usage**: Detailed breakdown of usage for each meter configured on the
|
215
|
+
# subscription
|
216
|
+
# - **Usage calculations**: Total units consumed, free threshold units, and
|
217
|
+
# chargeable units
|
218
|
+
# - **Historical tracking**: Complete audit trail of usage-based charges
|
219
|
+
#
|
220
|
+
# ## Use Cases:
|
221
|
+
#
|
222
|
+
# - **Customer support**: Investigate billing questions and usage discrepancies
|
223
|
+
# - **Usage analytics**: Analyze customer consumption patterns over time
|
224
|
+
# - **Billing transparency**: Provide customers with detailed usage breakdowns
|
225
|
+
# - **Revenue optimization**: Identify usage trends to optimize pricing strategies
|
226
|
+
#
|
227
|
+
# ## Filtering Options:
|
228
|
+
#
|
229
|
+
# - **Date range filtering**: Get usage history for specific time periods
|
230
|
+
# - **Meter-specific filtering**: Focus on usage for a particular meter
|
231
|
+
# - **Pagination**: Navigate through large usage histories efficiently
|
232
|
+
#
|
233
|
+
# ## Important Notes:
|
234
|
+
#
|
235
|
+
# - Only returns data for subscriptions with usage-based (metered) components
|
236
|
+
# - Usage history is organized by billing periods (subscription cycles)
|
237
|
+
# - Free threshold units are calculated and displayed separately from chargeable
|
238
|
+
# units
|
239
|
+
# - Historical data is preserved even if meter configurations change
|
240
|
+
#
|
241
|
+
# ## Example Query Patterns:
|
242
|
+
#
|
243
|
+
# - Get last 3 months:
|
244
|
+
# `?start_date=2024-01-01T00:00:00Z&end_date=2024-03-31T23:59:59Z`
|
245
|
+
# - Filter by meter: `?meter_id=mtr_api_requests`
|
246
|
+
# - Paginate results: `?page_size=20&page_number=1`
|
247
|
+
# - Recent usage: `?start_date=2024-03-01T00:00:00Z` (from March 1st to now)
|
248
|
+
#
|
249
|
+
# @overload retrieve_usage_history(subscription_id, end_date: nil, meter_id: nil, page_number: nil, page_size: nil, start_date: nil, request_options: {})
|
250
|
+
#
|
251
|
+
# @param subscription_id [String] Unique subscription identifier
|
252
|
+
#
|
253
|
+
# @param end_date [Time, nil] Filter by end date (inclusive)
|
254
|
+
#
|
255
|
+
# @param meter_id [String, nil] Filter by specific meter ID
|
256
|
+
#
|
257
|
+
# @param page_number [Integer, nil] Page number (default: 0)
|
258
|
+
#
|
259
|
+
# @param page_size [Integer, nil] Page size (default: 10, max: 100)
|
260
|
+
#
|
261
|
+
# @param start_date [Time, nil] Filter by start date (inclusive)
|
262
|
+
#
|
263
|
+
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
264
|
+
#
|
265
|
+
# @return [Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::SubscriptionRetrieveUsageHistoryResponse>]
|
266
|
+
#
|
267
|
+
# @see Dodopayments::Models::SubscriptionRetrieveUsageHistoryParams
|
268
|
+
def retrieve_usage_history(subscription_id, params = {})
|
269
|
+
parsed, options = Dodopayments::SubscriptionRetrieveUsageHistoryParams.dump_request(params)
|
270
|
+
@client.request(
|
271
|
+
method: :get,
|
272
|
+
path: ["subscriptions/%1$s/usage-history", subscription_id],
|
273
|
+
query: parsed,
|
274
|
+
page: Dodopayments::Internal::DefaultPageNumberPagination,
|
275
|
+
model: Dodopayments::Models::SubscriptionRetrieveUsageHistoryResponse,
|
276
|
+
options: options
|
277
|
+
)
|
278
|
+
end
|
279
|
+
|
206
280
|
# @api private
|
207
281
|
#
|
208
282
|
# @param client [Dodopayments::Client]
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dodopayments
|
4
|
+
module Resources
|
5
|
+
class UsageEvents
|
6
|
+
# Some parameter documentations has been truncated, see
|
7
|
+
# {Dodopayments::Models::UsageEventRetrieveParams} for more details.
|
8
|
+
#
|
9
|
+
# Fetch detailed information about a single event using its unique event ID. This
|
10
|
+
# endpoint is useful for:
|
11
|
+
#
|
12
|
+
# - Debugging specific event ingestion issues
|
13
|
+
# - Retrieving event details for customer support
|
14
|
+
# - Validating that events were processed correctly
|
15
|
+
# - Getting the complete metadata for an event
|
16
|
+
#
|
17
|
+
# ## Event ID Format:
|
18
|
+
#
|
19
|
+
# The event ID should be the same value that was provided during event ingestion
|
20
|
+
# via the `/events/ingest` endpoint. Event IDs are case-sensitive and must match
|
21
|
+
# exactly.
|
22
|
+
#
|
23
|
+
# ## Response Details:
|
24
|
+
#
|
25
|
+
# The response includes all event data including:
|
26
|
+
#
|
27
|
+
# - Complete metadata key-value pairs
|
28
|
+
# - Original timestamp (preserved from ingestion)
|
29
|
+
# - Customer and business association
|
30
|
+
# - Event name and processing information
|
31
|
+
#
|
32
|
+
# ## Example Usage:
|
33
|
+
#
|
34
|
+
# ```text
|
35
|
+
# GET /events/api_call_12345
|
36
|
+
# ```
|
37
|
+
#
|
38
|
+
# @overload retrieve(event_id, request_options: {})
|
39
|
+
#
|
40
|
+
# @param event_id [String] Unique event identifier (case-sensitive, must match the ID used during ingestion
|
41
|
+
#
|
42
|
+
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
43
|
+
#
|
44
|
+
# @return [Dodopayments::Models::Event]
|
45
|
+
#
|
46
|
+
# @see Dodopayments::Models::UsageEventRetrieveParams
|
47
|
+
def retrieve(event_id, params = {})
|
48
|
+
@client.request(
|
49
|
+
method: :get,
|
50
|
+
path: ["events/%1$s", event_id],
|
51
|
+
model: Dodopayments::Event,
|
52
|
+
options: params[:request_options]
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Some parameter documentations has been truncated, see
|
57
|
+
# {Dodopayments::Models::UsageEventListParams} for more details.
|
58
|
+
#
|
59
|
+
# Fetch events from your account with powerful filtering capabilities. This
|
60
|
+
# endpoint is ideal for:
|
61
|
+
#
|
62
|
+
# - Debugging event ingestion issues
|
63
|
+
# - Analyzing customer usage patterns
|
64
|
+
# - Building custom analytics dashboards
|
65
|
+
# - Auditing billing-related events
|
66
|
+
#
|
67
|
+
# ## Filtering Options:
|
68
|
+
#
|
69
|
+
# - **Customer filtering**: Filter by specific customer ID
|
70
|
+
# - **Event name filtering**: Filter by event type/name
|
71
|
+
# - **Meter-based filtering**: Use a meter ID to apply the meter's event name and
|
72
|
+
# filter criteria automatically
|
73
|
+
# - **Time range filtering**: Filter events within a specific date range
|
74
|
+
# - **Pagination**: Navigate through large result sets
|
75
|
+
#
|
76
|
+
# ## Meter Integration:
|
77
|
+
#
|
78
|
+
# When using `meter_id`, the endpoint automatically applies:
|
79
|
+
#
|
80
|
+
# - The meter's configured `event_name` filter
|
81
|
+
# - The meter's custom filter criteria (if any)
|
82
|
+
# - If you also provide `event_name`, it must match the meter's event name
|
83
|
+
#
|
84
|
+
# ## Example Queries:
|
85
|
+
#
|
86
|
+
# - Get all events for a customer: `?customer_id=cus_abc123`
|
87
|
+
# - Get API request events: `?event_name=api_request`
|
88
|
+
# - Get events from last 24 hours:
|
89
|
+
# `?start=2024-01-14T10:30:00Z&end=2024-01-15T10:30:00Z`
|
90
|
+
# - Get events with meter filtering: `?meter_id=mtr_xyz789`
|
91
|
+
# - Paginate results: `?page_size=50&page_number=2`
|
92
|
+
#
|
93
|
+
# @overload list(customer_id: nil, end_: nil, event_name: nil, meter_id: nil, page_number: nil, page_size: nil, start: nil, request_options: {})
|
94
|
+
#
|
95
|
+
# @param customer_id [String] Filter events by customer ID
|
96
|
+
#
|
97
|
+
# @param end_ [Time] Filter events created before this timestamp
|
98
|
+
#
|
99
|
+
# @param event_name [String] Filter events by event name. If both event_name and meter_id are provided, they
|
100
|
+
#
|
101
|
+
# @param meter_id [String] Filter events by meter ID. When provided, only events that match the meter's eve
|
102
|
+
#
|
103
|
+
# @param page_number [Integer] Page number (0-based, default: 0)
|
104
|
+
#
|
105
|
+
# @param page_size [Integer] Number of events to return per page (default: 10)
|
106
|
+
#
|
107
|
+
# @param start [Time] Filter events created after this timestamp
|
108
|
+
#
|
109
|
+
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
110
|
+
#
|
111
|
+
# @return [Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::Event>]
|
112
|
+
#
|
113
|
+
# @see Dodopayments::Models::UsageEventListParams
|
114
|
+
def list(params = {})
|
115
|
+
parsed, options = Dodopayments::UsageEventListParams.dump_request(params)
|
116
|
+
@client.request(
|
117
|
+
method: :get,
|
118
|
+
path: "events",
|
119
|
+
query: parsed.transform_keys(end_: "end"),
|
120
|
+
page: Dodopayments::Internal::DefaultPageNumberPagination,
|
121
|
+
model: Dodopayments::Event,
|
122
|
+
options: options
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
126
|
+
# This endpoint allows you to ingest custom events that can be used for:
|
127
|
+
#
|
128
|
+
# - Usage-based billing and metering
|
129
|
+
# - Analytics and reporting
|
130
|
+
# - Customer behavior tracking
|
131
|
+
#
|
132
|
+
# ## Important Notes:
|
133
|
+
#
|
134
|
+
# - **Duplicate Prevention**:
|
135
|
+
# - Duplicate `event_id` values within the same request are rejected (entire
|
136
|
+
# request fails)
|
137
|
+
# - Subsequent requests with existing `event_id` values are ignored (idempotent
|
138
|
+
# behavior)
|
139
|
+
# - **Rate Limiting**: Maximum 1000 events per request
|
140
|
+
# - **Time Validation**: Events with timestamps older than 1 hour or more than 5
|
141
|
+
# minutes in the future will be rejected
|
142
|
+
# - **Metadata Limits**: Maximum 50 key-value pairs per event, keys max 100 chars,
|
143
|
+
# values max 500 chars
|
144
|
+
#
|
145
|
+
# ## Example Usage:
|
146
|
+
#
|
147
|
+
# ```json
|
148
|
+
# {
|
149
|
+
# "events": [
|
150
|
+
# {
|
151
|
+
# "event_id": "api_call_12345",
|
152
|
+
# "customer_id": "cus_abc123",
|
153
|
+
# "event_name": "api_request",
|
154
|
+
# "timestamp": "2024-01-15T10:30:00Z",
|
155
|
+
# "metadata": {
|
156
|
+
# "endpoint": "/api/v1/users",
|
157
|
+
# "method": "GET",
|
158
|
+
# "tokens_used": "150"
|
159
|
+
# }
|
160
|
+
# }
|
161
|
+
# ]
|
162
|
+
# }
|
163
|
+
# ```
|
164
|
+
#
|
165
|
+
# @overload ingest(events:, request_options: {})
|
166
|
+
#
|
167
|
+
# @param events [Array<Dodopayments::Models::EventInput>] List of events to be pushed
|
168
|
+
#
|
169
|
+
# @param request_options [Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil]
|
170
|
+
#
|
171
|
+
# @return [Dodopayments::Models::UsageEventIngestResponse]
|
172
|
+
#
|
173
|
+
# @see Dodopayments::Models::UsageEventIngestParams
|
174
|
+
def ingest(params)
|
175
|
+
parsed, options = Dodopayments::UsageEventIngestParams.dump_request(params)
|
176
|
+
@client.request(
|
177
|
+
method: :post,
|
178
|
+
path: "events/ingest",
|
179
|
+
body: parsed,
|
180
|
+
model: Dodopayments::Models::UsageEventIngestResponse,
|
181
|
+
options: options
|
182
|
+
)
|
183
|
+
end
|
184
|
+
|
185
|
+
# @api private
|
186
|
+
#
|
187
|
+
# @param client [Dodopayments::Client]
|
188
|
+
def initialize(client:)
|
189
|
+
@client = client
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
data/lib/dodopayments/version.rb
CHANGED
data/lib/dodopayments.rb
CHANGED
@@ -58,6 +58,7 @@ require_relative "dodopayments/models/get_dispute"
|
|
58
58
|
require_relative "dodopayments/models/refund"
|
59
59
|
require_relative "dodopayments/models/subscription"
|
60
60
|
require_relative "dodopayments/models/payment"
|
61
|
+
require_relative "dodopayments/models/add_meter_to_price"
|
61
62
|
require_relative "dodopayments/models/addon_cart_response_item"
|
62
63
|
require_relative "dodopayments/models/addon_create_params"
|
63
64
|
require_relative "dodopayments/models/addon_list_params"
|
@@ -104,8 +105,11 @@ require_relative "dodopayments/models/dispute_list_response"
|
|
104
105
|
require_relative "dodopayments/models/dispute_retrieve_params"
|
105
106
|
require_relative "dodopayments/models/dispute_stage"
|
106
107
|
require_relative "dodopayments/models/dispute_status"
|
108
|
+
require_relative "dodopayments/models/event"
|
109
|
+
require_relative "dodopayments/models/event_input"
|
107
110
|
require_relative "dodopayments/models/intent_status"
|
108
111
|
require_relative "dodopayments/models/invoices/payment_retrieve_params"
|
112
|
+
require_relative "dodopayments/models/invoices/payment_retrieve_refund_params"
|
109
113
|
require_relative "dodopayments/models/license_activate_params"
|
110
114
|
require_relative "dodopayments/models/license_deactivate_params"
|
111
115
|
require_relative "dodopayments/models/license_key_duration"
|
@@ -119,6 +123,14 @@ require_relative "dodopayments/models/license_key_status"
|
|
119
123
|
require_relative "dodopayments/models/license_key_update_params"
|
120
124
|
require_relative "dodopayments/models/license_validate_params"
|
121
125
|
require_relative "dodopayments/models/license_validate_response"
|
126
|
+
require_relative "dodopayments/models/meter"
|
127
|
+
require_relative "dodopayments/models/meter_aggregation"
|
128
|
+
require_relative "dodopayments/models/meter_archive_params"
|
129
|
+
require_relative "dodopayments/models/meter_create_params"
|
130
|
+
require_relative "dodopayments/models/meter_filter"
|
131
|
+
require_relative "dodopayments/models/meter_list_params"
|
132
|
+
require_relative "dodopayments/models/meter_retrieve_params"
|
133
|
+
require_relative "dodopayments/models/meter_unarchive_params"
|
122
134
|
require_relative "dodopayments/models/misc_list_supported_countries_params"
|
123
135
|
require_relative "dodopayments/models/misc_list_supported_countries_response"
|
124
136
|
require_relative "dodopayments/models/new_customer"
|
@@ -136,8 +148,8 @@ require_relative "dodopayments/models/payout_list_params"
|
|
136
148
|
require_relative "dodopayments/models/payout_list_response"
|
137
149
|
require_relative "dodopayments/models/price"
|
138
150
|
require_relative "dodopayments/models/product"
|
151
|
+
require_relative "dodopayments/models/product_archive_params"
|
139
152
|
require_relative "dodopayments/models/product_create_params"
|
140
|
-
require_relative "dodopayments/models/product_delete_params"
|
141
153
|
require_relative "dodopayments/models/product_list_params"
|
142
154
|
require_relative "dodopayments/models/product_list_response"
|
143
155
|
require_relative "dodopayments/models/product_retrieve_params"
|
@@ -159,10 +171,16 @@ require_relative "dodopayments/models/subscription_create_response"
|
|
159
171
|
require_relative "dodopayments/models/subscription_list_params"
|
160
172
|
require_relative "dodopayments/models/subscription_list_response"
|
161
173
|
require_relative "dodopayments/models/subscription_retrieve_params"
|
174
|
+
require_relative "dodopayments/models/subscription_retrieve_usage_history_params"
|
175
|
+
require_relative "dodopayments/models/subscription_retrieve_usage_history_response"
|
162
176
|
require_relative "dodopayments/models/subscription_status"
|
163
177
|
require_relative "dodopayments/models/subscription_update_params"
|
164
178
|
require_relative "dodopayments/models/tax_category"
|
165
179
|
require_relative "dodopayments/models/time_interval"
|
180
|
+
require_relative "dodopayments/models/usage_event_ingest_params"
|
181
|
+
require_relative "dodopayments/models/usage_event_ingest_response"
|
182
|
+
require_relative "dodopayments/models/usage_event_list_params"
|
183
|
+
require_relative "dodopayments/models/usage_event_retrieve_params"
|
166
184
|
require_relative "dodopayments/models/webhook_create_params"
|
167
185
|
require_relative "dodopayments/models/webhook_delete_params"
|
168
186
|
require_relative "dodopayments/models/webhook_details"
|
@@ -189,6 +207,7 @@ require_relative "dodopayments/resources/invoices/payments"
|
|
189
207
|
require_relative "dodopayments/resources/license_key_instances"
|
190
208
|
require_relative "dodopayments/resources/license_keys"
|
191
209
|
require_relative "dodopayments/resources/licenses"
|
210
|
+
require_relative "dodopayments/resources/meters"
|
192
211
|
require_relative "dodopayments/resources/misc"
|
193
212
|
require_relative "dodopayments/resources/payments"
|
194
213
|
require_relative "dodopayments/resources/payouts"
|
@@ -196,6 +215,7 @@ require_relative "dodopayments/resources/products"
|
|
196
215
|
require_relative "dodopayments/resources/products/images"
|
197
216
|
require_relative "dodopayments/resources/refunds"
|
198
217
|
require_relative "dodopayments/resources/subscriptions"
|
218
|
+
require_relative "dodopayments/resources/usage_events"
|
199
219
|
require_relative "dodopayments/resources/webhook_events"
|
200
220
|
require_relative "dodopayments/resources/webhooks"
|
201
221
|
require_relative "dodopayments/resources/webhooks/headers"
|
data/rbi/dodopayments/client.rbi
CHANGED
@@ -77,6 +77,12 @@ module Dodopayments
|
|
77
77
|
sig { returns(Dodopayments::Resources::Webhooks) }
|
78
78
|
attr_reader :webhooks
|
79
79
|
|
80
|
+
sig { returns(Dodopayments::Resources::UsageEvents) }
|
81
|
+
attr_reader :usage_events
|
82
|
+
|
83
|
+
sig { returns(Dodopayments::Resources::Meters) }
|
84
|
+
attr_reader :meters
|
85
|
+
|
80
86
|
# @api private
|
81
87
|
sig { override.returns(T::Hash[String, String]) }
|
82
88
|
private def auth_headers
|