Class: Dodopayments::Resources::Subscriptions
- Inherits:
-
Object
- Object
- Dodopayments::Resources::Subscriptions
- Defined in:
- lib/dodopayments/resources/subscriptions.rb
Instance Method Summary collapse
-
#change_plan(subscription_id, product_id: , proration_billing_mode: , quantity: , addons: 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, payment_link: nil, return_url: 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.
-
#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, status: nil, request_options: {}) ⇒ Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::SubscriptionListResponse>
- #retrieve(subscription_id, request_options: {}) ⇒ Dodopayments::Models::Subscription
-
#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, 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, type: , payment_method_id: , return_url: nil, 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.
315 316 317 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 315 def initialize(client:) @client = client end |
Instance Method Details
#change_plan(subscription_id, product_id: , proration_billing_mode: , quantity: , addons: nil, request_options: {}) ⇒ nil
Some parameter documentations has been truncated, see Models::SubscriptionChangePlanParams for more details.
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 166 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.
201 202 203 204 205 206 207 208 209 210 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 201 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, payment_link: nil, return_url: 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.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 48 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, status: nil, request_options: {}) ⇒ Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::SubscriptionListResponse>
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 134 def list(params = {}) parsed, = Dodopayments::SubscriptionListParams.dump_request(params) @client.request( method: :get, path: "subscriptions", query: parsed, page: Dodopayments::Internal::DefaultPageNumberPagination, model: Dodopayments::Models::SubscriptionListResponse, options: ) end |
#retrieve(subscription_id, request_options: {}) ⇒ Dodopayments::Models::Subscription
68 69 70 71 72 73 74 75 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 68 def retrieve(subscription_id, params = {}) @client.request( method: :get, path: ["subscriptions/%1$s", subscription_id], model: Dodopayments::Subscription, 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)
274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 274 def retrieve_usage_history(subscription_id, params = {}) parsed, = Dodopayments::SubscriptionRetrieveUsageHistoryParams.dump_request(params) @client.request( method: :get, path: ["subscriptions/%1$s/usage-history", subscription_id], query: parsed, page: Dodopayments::Internal::DefaultPageNumberPagination, model: Dodopayments::Models::SubscriptionRetrieveUsageHistoryResponse, options: ) end |
#update(subscription_id, billing: nil, cancel_at_next_billing_date: nil, customer_name: nil, disable_on_demand: nil, metadata: nil, next_billing_date: nil, status: nil, tax_id: nil, request_options: {}) ⇒ Dodopayments::Models::Subscription
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 102 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, type: , payment_method_id: , return_url: nil, request_options: {}) ⇒ Dodopayments::Models::SubscriptionUpdatePaymentMethodResponse
301 302 303 304 305 306 307 308 309 310 |
# File 'lib/dodopayments/resources/subscriptions.rb', line 301 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, model: Dodopayments::Models::SubscriptionUpdatePaymentMethodResponse, options: ) end |