Class: Dodopayments::Resources::Subscriptions
- Inherits:
-
Object
- Object
- Dodopayments::Resources::Subscriptions
- Defined in:
- lib/dodopayments/resources/subscriptions.rb
Instance Method Summary collapse
- #cancel_change_plan(subscription_id, request_options: {}) ⇒ nil
-
#change_plan(subscription_id, product_id:, proration_billing_mode:, quantity:, addons: nil, discount_code: nil, effective_at: nil, metadata: nil, on_payment_failure: nil, request_options: {}) ⇒ nil
Some parameter documentations has been truncated, see Models::SubscriptionChangePlanParams for more details.
-
#charge(subscription_id, product_price:, adaptive_currency_fees_inclusive: nil, customer_balance_config: nil, metadata: nil, product_currency: nil, product_description: nil, request_options: {}) ⇒ Dodopayments::Models::SubscriptionChargeResponse
Some parameter documentations has been truncated, see Models::SubscriptionChargeParams for more details.
- #create(billing:, customer:, product_id:, quantity:, addons: nil, allowed_payment_method_types: nil, billing_currency: nil, discount_code: nil, force_3ds: nil, metadata: nil, on_demand: nil, one_time_product_cart: nil, payment_link: nil, payment_method_id: nil, redirect_immediately: nil, return_url: nil, short_link: nil, show_saved_payment_methods: nil, tax_id: nil, trial_period_days: nil, request_options: {}) ⇒ Dodopayments::Models::SubscriptionCreateResponse deprecated Deprecated.
-
#initialize(client:) ⇒ Subscriptions
constructor
private
A new instance of Subscriptions.
- #list(brand_id: nil, created_at_gte: nil, created_at_lte: nil, customer_id: nil, page_number: nil, page_size: nil, product_id: nil, status: nil, request_options: {}) ⇒ Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::SubscriptionListResponse>
-
#preview_change_plan(subscription_id, product_id:, proration_billing_mode:, quantity:, addons: nil, discount_code: nil, effective_at: nil, metadata: nil, on_payment_failure: nil, request_options: {}) ⇒ Dodopayments::Models::SubscriptionPreviewChangePlanResponse
Some parameter documentations has been truncated, see Models::SubscriptionPreviewChangePlanParams for more details.
- #retrieve(subscription_id, request_options: {}) ⇒ Dodopayments::Models::Subscription
- #retrieve_credit_usage(subscription_id, request_options: {}) ⇒ Dodopayments::Models::SubscriptionRetrieveCreditUsageResponse
-
#retrieve_usage_history(subscription_id, end_date: nil, meter_id: nil, page_number: nil, page_size: nil, start_date: nil, request_options: {}) ⇒ Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::SubscriptionRetrieveUsageHistoryResponse>
Get detailed usage history for a subscription that includes usage-based billing (metered components).
- #update(subscription_id, billing: nil, cancel_at_next_billing_date: nil, cancel_reason: nil, credit_entitlement_cart: nil, customer_name: nil, disable_on_demand: nil, metadata: nil, next_billing_date: nil, status: nil, tax_id: nil, request_options: {}) ⇒ Dodopayments::Models::Subscription
- #update_payment_method(subscription_id, body:, request_options: {}) ⇒ Dodopayments::Models::SubscriptionUpdatePaymentMethodResponse
Constructor Details
#initialize(client:) ⇒ Subscriptions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Subscriptions.
412 413 414 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 412 def initialize(client:) @client = client end |
Instance Method Details
#cancel_change_plan(subscription_id, request_options: {}) ⇒ nil
172 173 174 175 176 177 178 179 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 172 def cancel_change_plan(subscription_id, params = {}) @client.request( method: :delete, path: ["subscriptions/%1$s/change-plan/scheduled", subscription_id], model: NilClass, options: params[:request_options] ) end |
#change_plan(subscription_id, product_id:, proration_billing_mode:, quantity:, addons: nil, discount_code: nil, effective_at: nil, metadata: nil, on_payment_failure: nil, request_options: {}) ⇒ nil
Some parameter documentations has been truncated, see Models::SubscriptionChangePlanParams for more details.
209 210 211 212 213 214 215 216 217 218 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 209 def change_plan(subscription_id, params) parsed, = Dodopayments::SubscriptionChangePlanParams.dump_request(params) @client.request( method: :post, path: ["subscriptions/%1$s/change-plan", subscription_id], body: parsed, model: NilClass, options: ) end |
#charge(subscription_id, product_price:, adaptive_currency_fees_inclusive: nil, customer_balance_config: nil, metadata: nil, product_currency: nil, product_description: nil, request_options: {}) ⇒ Dodopayments::Models::SubscriptionChargeResponse
Some parameter documentations has been truncated, see Models::SubscriptionChargeParams for more details.
244 245 246 247 248 249 250 251 252 253 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 244 def charge(subscription_id, params) parsed, = Dodopayments::SubscriptionChargeParams.dump_request(params) @client.request( method: :post, path: ["subscriptions/%1$s/charge", subscription_id], body: parsed, model: Dodopayments::Models::SubscriptionChargeResponse, options: ) end |
#create(billing:, customer:, product_id:, quantity:, addons: nil, allowed_payment_method_types: nil, billing_currency: nil, discount_code: nil, force_3ds: nil, metadata: nil, on_demand: nil, one_time_product_cart: nil, payment_link: nil, payment_method_id: nil, redirect_immediately: nil, return_url: nil, short_link: nil, show_saved_payment_methods: nil, tax_id: nil, trial_period_days: nil, request_options: {}) ⇒ Dodopayments::Models::SubscriptionCreateResponse
Some parameter documentations has been truncated, see Models::SubscriptionCreateParams for more details.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 58 def create(params) parsed, = Dodopayments::SubscriptionCreateParams.dump_request(params) @client.request( method: :post, path: "subscriptions", body: parsed, model: Dodopayments::Models::SubscriptionCreateResponse, options: ) end |
#list(brand_id: nil, created_at_gte: nil, created_at_lte: nil, customer_id: nil, page_number: nil, page_size: nil, product_id: nil, status: nil, request_options: {}) ⇒ Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::SubscriptionListResponse>
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 150 def list(params = {}) parsed, = Dodopayments::SubscriptionListParams.dump_request(params) query = Dodopayments::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: "subscriptions", query: query, page: Dodopayments::Internal::DefaultPageNumberPagination, model: Dodopayments::Models::SubscriptionListResponse, options: ) end |
#preview_change_plan(subscription_id, product_id:, proration_billing_mode:, quantity:, addons: nil, discount_code: nil, effective_at: nil, metadata: nil, on_payment_failure: nil, request_options: {}) ⇒ Dodopayments::Models::SubscriptionPreviewChangePlanResponse
Some parameter documentations has been truncated, see Models::SubscriptionPreviewChangePlanParams for more details.
283 284 285 286 287 288 289 290 291 292 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 283 def preview_change_plan(subscription_id, params) parsed, = Dodopayments::SubscriptionPreviewChangePlanParams.dump_request(params) @client.request( method: :post, path: ["subscriptions/%1$s/change-plan/preview", subscription_id], body: parsed, model: Dodopayments::Models::SubscriptionPreviewChangePlanResponse, options: ) end |
#retrieve(subscription_id, request_options: {}) ⇒ Dodopayments::Models::Subscription
78 79 80 81 82 83 84 85 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 78 def retrieve(subscription_id, params = {}) @client.request( method: :get, path: ["subscriptions/%1$s", subscription_id], model: Dodopayments::Subscription, options: params[:request_options] ) end |
#retrieve_credit_usage(subscription_id, request_options: {}) ⇒ Dodopayments::Models::SubscriptionRetrieveCreditUsageResponse
303 304 305 306 307 308 309 310 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 303 def retrieve_credit_usage(subscription_id, params = {}) @client.request( method: :get, path: ["subscriptions/%1$s/credit-usage", subscription_id], model: Dodopayments::Models::SubscriptionRetrieveCreditUsageResponse, options: params[:request_options] ) end |
#retrieve_usage_history(subscription_id, end_date: nil, meter_id: nil, page_number: nil, page_size: nil, start_date: nil, request_options: {}) ⇒ Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::SubscriptionRetrieveUsageHistoryResponse>
Get detailed usage history for a subscription that includes usage-based billing (metered components). This endpoint provides insights into customer usage patterns and billing calculations over time.
## What You’ll Get:
-
**Billing periods**: Each item represents a billing cycle with start and end dates
-
**Meter usage**: Detailed breakdown of usage for each meter configured on the subscription
-
**Usage calculations**: Total units consumed, free threshold units, and chargeable units
-
**Historical tracking**: Complete audit trail of usage-based charges
## Use Cases:
-
**Customer support**: Investigate billing questions and usage discrepancies
-
**Usage analytics**: Analyze customer consumption patterns over time
-
**Billing transparency**: Provide customers with detailed usage breakdowns
-
**Revenue optimization**: Identify usage trends to optimize pricing strategies
## Filtering Options:
-
**Date range filtering**: Get usage history for specific time periods
-
**Meter-specific filtering**: Focus on usage for a particular meter
-
Pagination: Navigate through large usage histories efficiently
## Important Notes:
-
Only returns data for subscriptions with usage-based (metered) components
-
Usage history is organized by billing periods (subscription cycles)
-
Free threshold units are calculated and displayed separately from chargeable units
-
Historical data is preserved even if meter configurations change
## Example Query Patterns:
-
Get last 3 months: ‘?start_date=2024-01-01T00:00:00Z&end_date=2024-03-31T23:59:59Z`
-
Filter by meter: ‘?meter_id=mtr_api_requests`
-
Paginate results: ‘?page_size=20&page_number=1`
-
Recent usage: ‘?start_date=2024-03-01T00:00:00Z` (from March 1st to now)
374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 374 def retrieve_usage_history(subscription_id, params = {}) parsed, = Dodopayments::SubscriptionRetrieveUsageHistoryParams.dump_request(params) query = Dodopayments::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: ["subscriptions/%1$s/usage-history", subscription_id], query: query, page: Dodopayments::Internal::DefaultPageNumberPagination, model: Dodopayments::Models::SubscriptionRetrieveUsageHistoryResponse, options: ) end |
#update(subscription_id, billing: nil, cancel_at_next_billing_date: nil, cancel_reason: nil, credit_entitlement_cart: nil, customer_name: nil, disable_on_demand: nil, metadata: nil, next_billing_date: nil, status: nil, tax_id: nil, request_options: {}) ⇒ Dodopayments::Models::Subscription
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 116 def update(subscription_id, params = {}) parsed, = Dodopayments::SubscriptionUpdateParams.dump_request(params) @client.request( method: :patch, path: ["subscriptions/%1$s", subscription_id], body: parsed, model: Dodopayments::Subscription, options: ) end |
#update_payment_method(subscription_id, body:, request_options: {}) ⇒ Dodopayments::Models::SubscriptionUpdatePaymentMethodResponse
398 399 400 401 402 403 404 405 406 407 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 398 def update_payment_method(subscription_id, params) parsed, = Dodopayments::SubscriptionUpdatePaymentMethodParams.dump_request(params) @client.request( method: :post, path: ["subscriptions/%1$s/update-payment-method", subscription_id], body: parsed[:body], model: Dodopayments::Models::SubscriptionUpdatePaymentMethodResponse, options: ) end |