Class: Dodopayments::Resources::Subscriptions
- Inherits:
-
Object
- Object
- Dodopayments::Resources::Subscriptions
- Defined in:
- lib/dodopayments/resources/subscriptions.rb,
sig/dodopayments/resources/subscriptions.rbs
Instance Method Summary collapse
- #cancel_change_plan(subscription_id, request_options: {}) ⇒ nil
-
#change_plan(subscription_id, product_id:, proration_billing_mode:, quantity:, adaptive_currency_fees_inclusive: nil, addons: nil, discount_code: nil, discount_codes: 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, customer_business_name: nil, discount_code: nil, discount_codes: nil, force_3ds: nil, mandate_min_amount_inr_paise: nil, metadata: nil, on_demand: nil, one_time_product_cart: nil, payment_link: nil, payment_method_id: nil, redirect_immediately: nil, require_phone_number: 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:, adaptive_currency_fees_inclusive: nil, addons: nil, discount_code: nil, discount_codes: 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, cancellation_comment: nil, cancellation_feedback: nil, credit_entitlement_cart: nil, customer_business_name: nil, customer_name: nil, disable_on_demand: nil, metadata: nil, next_billing_date: nil, status: nil, subscription_period_count: nil, subscription_period_interval: nil, tax_id: nil, request_options: {}) ⇒ Dodopayments::Models::Subscription
Some parameter documentations has been truncated, see Models::SubscriptionUpdateParams for more details.
- #update_payment_method(subscription_id, payment_method:, 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.
441 442 443 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 441 def initialize(client:) @client = client end |
Instance Method Details
#cancel_change_plan(subscription_id, request_options: {}) ⇒ nil
193 194 195 196 197 198 199 200 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 193 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:, adaptive_currency_fees_inclusive: nil, addons: nil, discount_code: nil, discount_codes: 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.
234 235 236 237 238 239 240 241 242 243 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 234 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.
269 270 271 272 273 274 275 276 277 278 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 269 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, customer_business_name: nil, discount_code: nil, discount_codes: nil, force_3ds: nil, mandate_min_amount_inr_paise: nil, metadata: nil, on_demand: nil, one_time_product_cart: nil, payment_link: nil, payment_method_id: nil, redirect_immediately: nil, require_phone_number: 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.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 66 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>
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 171 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:, adaptive_currency_fees_inclusive: nil, addons: nil, discount_code: nil, discount_codes: 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.
312 313 314 315 316 317 318 319 320 321 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 312 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
86 87 88 89 90 91 92 93 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 86 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
332 333 334 335 336 337 338 339 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 332 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)
403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 403 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, cancellation_comment: nil, cancellation_feedback: nil, credit_entitlement_cart: nil, customer_business_name: nil, customer_name: nil, disable_on_demand: nil, metadata: nil, next_billing_date: nil, status: nil, subscription_period_count: nil, subscription_period_interval: nil, tax_id: nil, request_options: {}) ⇒ Dodopayments::Models::Subscription
Some parameter documentations has been truncated, see Models::SubscriptionUpdateParams for more details.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 137 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, payment_method:, request_options: {}) ⇒ Dodopayments::Models::SubscriptionUpdatePaymentMethodResponse
427 428 429 430 431 432 433 434 435 436 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 427 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[:payment_method], model: Dodopayments::Models::SubscriptionUpdatePaymentMethodResponse, options: ) end |