Skip to main content
The Ruby SDK gives Ruby applications access to the Dodo Payments REST API. It sends requests with the standard library’s net/http and a connection pool, retries failed requests, iterates through paginated lists for you, and ships RBI and RBS type definitions.

Installation

Add the gem to your Gemfile:
Gemfile
SDK releases add support for API changes. Run bundle update dodopayments regularly to stay up to date.
Then install it:
The SDK requires Ruby 3.2.0 or later.

Quick Start

Create a client, then create a checkout session:
If you omit bearer_token, the client reads the DODO_PAYMENTS_API_KEY environment variable. If you omit environment, the client connects to live mode. A test mode API key works only with environment: "test_mode".
Keep API keys in environment variables or a secrets manager. Never commit them to version control or expose them in your code.

Core Features

Ruby Conventions

Snake_case methods and keyword arguments, with plain hashes accepted for nested parameters.

Elegant Syntax

Responses are objects with attribute readers, and obj[:prop] also reads fields the SDK doesn’t define.

Auto-Pagination

auto_paging_each iterates over every item and fetches the next page when needed.

Type Safety

RBI definitions for Sorbet, with no dependency on sorbet-runtime.

Configuration

Dodopayments::Client.new takes bearer_token, webhook_key, environment, base_url, max_retries, timeout, initial_retry_delay, and max_retry_delay. When you omit them, it reads DODO_PAYMENTS_API_KEY, DODO_PAYMENTS_WEBHOOK_KEY (your webhook signing secret), and DODO_PAYMENTS_BASE_URL from the environment. The client is thread-safe and keeps its own connection pool, so create one client for your application and reuse it. To verify a webhook, pass the raw request body and headers to dodo_payments.webhooks.unwrap(payload, headers: headers). It checks the signature with your webhook key and returns the parsed event. dodo_payments.webhooks.unsafe_unwrap(payload) parses the body without verifying it, so use it only for testing. See Webhooks.

Timeout Configuration

Requests time out after 60 seconds by default. Set timeout, in seconds, on the client or on a single request:
When a request times out, the SDK raises Dodopayments::Errors::APITimeoutError. Timed-out requests are retried by default.

Retry Configuration

The SDK retries connection errors, timeouts, and responses with status 408, 409, 429, or 500 and above. It retries twice by default, with a short exponential backoff. Set max_retries on the client or on a single request:

Common Operations

The examples in this section use the dodo_payments client from Quick Start.

Create a Checkout Session

Create a checkout session, then redirect the customer to the returned checkout_url:
Each checkout URL works once and expires after 24 hours. For every session option, see Checkout Sessions.

Manage Customers

Create a customer with an email address and name, then retrieve it by ID:

Handle Subscriptions

Create a subscription, charge an on-demand subscription, and update a subscription’s metadata.
POST /subscriptions (the SDK’s subscriptions.create method) is deprecated. It still works for existing integrations, but new integrations should create subscriptions through a Checkout Session.
billing requires only country, a two-letter ISO country code. customer takes { customer_id: "..." } to attach an existing customer or { email: "...", name: "..." } to create one. charge is for on-demand subscriptions, and product_price is in the smallest currency unit.

Pagination

Auto-Pagination

List methods return a page. Read items for the current page, or call auto_paging_each to iterate over every item. It fetches the next page when it needs it:

Manual Pagination

To move one page at a time, call next_page? and next_page:

Error Handling

When the SDK can’t connect to the API, or the API returns a 4xx or 5xx status, the SDK raises a subclass of Dodopayments::Errors::APIError:
The error class depends on the cause. Each error has status, headers, and body attributes:
The SDK already retries 429 responses with exponential backoff. A RateLimitError means those retries also failed, so wait longer before you send the request again.

Type Safety with Sorbet

The SDK ships RBI definitions and doesn’t depend on sorbet-runtime. To get type-checked request parameters, pass model classes instead of hashes:

Advanced Usage

Undocumented Endpoints

To call an endpoint that has no SDK method, use request. It applies the same authentication and retries as the SDK methods:

Undocumented Parameters

To send parameters that the SDK doesn’t define, pass them in request_options. An extra_* parameter that has the same name as a documented parameter overrides it:

Rails Integration

Create an Initializer

Create one client when Rails starts, in config/initializers/dodo_payments.rb:

Service Object Pattern

Wrap the client in a service object:

Controller Integration

Call the service from a controller and redirect to the checkout page:

Sinatra Integration

Create the client once in a configure block and use it in your routes:

Resources

GitHub Repository

Source code, releases, and the full method list.

API Reference

Every endpoint, parameter, and response.

Discord Community

Ask questions and talk with other developers.

Report Issues

Report bugs or request features.

Support

For help with the Ruby SDK:

Contributing

To contribute, read the contributing guidelines.
Senast ändrad 25 september 2026