Quick Start
API Reference
Preview Endpoint
Session Validity: Checkout sessions expire after 24 hours by default, or 15 minutes when
confirm: true.Prerequisites
You need:- An active Dodo Payments merchant account
- API credentials from Developer → API Keys in the dashboard
- At least one product created in Products
Creating Your First Checkout Session
- Node.js SDK
- Python SDK
- REST API
API Response
All methods return:session_id is guaranteed to be present. When payment_method_id is provided, the charge processes immediately and checkout_url is null. Use the returned payment_id instead.
When confirm: true, the payment is created at session-creation time, and the response also includes payment_id, client_secret, and publishable_key for use with the Dodo Payments checkout SDK.
Redirect Your Customer
1
Extract the checkout URL
Get
checkout_url from the API response.2
Redirect to checkout
Send your customer to the URL:Alternatively, open in a new window:
3
Handle the return
After payment, customers are redirected to your
return_url with query parameters:Example redirect:
Check Session Status
To check a session’s status, call Get Checkout Session (GET /checkouts/{id}). The response has the session id, created_at, customer_email, and customer_name, plus payment_id and payment_status. Both payment fields are null while the customer is still entering details. After the customer submits payment, payment_status holds the payment’s status, such as succeeded, failed, or processing. Use webhooks as the source of truth for fulfillment.
Request Body
Required Fields
array
必填
Array of products to include in the checkout session. Each product must have a valid
product_id from your dashboard.您可以在同一会话中将一次性付款产品与一个订阅产品组合使用。购物车也可以包含两个或更多订阅产品,但此时不能包含一次性付款产品。请参阅 多订阅购物车。购物车最多可包含 20 个产品。Optional Fields
Customer Information
Customer Information
object
Customer information. You can either attach an existing customer using their ID or create a new customer record during checkout.
- Attach Existing Customer
- Create New Customer
object
Billing address information for accurate tax calculation, fraud prevention, and regulatory compliance.当
confirm: true 时,所有账单地址字段都变为必填,除非 minimal_address 为 true。Payment Configuration
Payment Configuration
array
Control which payment methods are available to customers during checkout. This helps optimize for specific markets or business requirements.Common options:
credit, debit, upi_collect, apple_pay, google_pay, amazon_pay, klarna, affirm, afterpay_clearpay, cashapp, ach, multibanco, bancontact_card, eps, ideal, blik, gcash, ali_pay_hk, fps, touch_n_go, paypalSee the Create Checkout Session API reference for the complete list.Example:string
Override the default currency selection with a fixed billing currency. Uses ISO 4217 currency codes.Supported Currencies:
USD, EUR, GBP, CAD, AUD, INR, and moreExample: "USD" for US Dollars, "EUR" for Euros此字段仅在启用自适应定价时生效。如果禁用自适应定价,API 会丢弃此字段,货币将取自产品价格或账单国家/地区。boolean
默认值:"false"
Display previously saved payment methods for returning customers, improving checkout speed and user experience.
Session Management
Session Management
string
URL to redirect customers after payment completion. Dodo Payments appends query parameters to your URL on redirect (see the redirect table above).Example redirect URLs:Use the
license_key and email query parameters to display license keys or send a confirmation immediately on your return page, without needing an extra API call.string
URL to redirect customers when they click the back button or cancel the checkout session. If not provided, the back button will not be displayed.Set a
cancel_url to give customers a clear way to return to your site without completing the purchase.boolean
默认值:"false"
If true, finalizes all session details immediately. The API throws an error if required data is missing.当
confirm: true 时:- 所有账单地址字段都变为必填(当
minimal_address为true时,仅country和zipcode为必填) - 可以提供
payment_method_id以立即处理扣款 - 会话将在 15 分钟后过期,而不是 24 小时
- 如果提供了
payment_method_id,则必须已有customer_id
array
Apply one or more stacked discount codes to the checkout session. Codes are applied in array order (the first code reduces the starting price, the second reduces the already-discounted price, and so on), up to a maximum of 20 codes per session.When Purchasing Power Parity is enabled, the starting price is the PPP-adjusted amount, not the base price.The singular
discount_code field below is deprecated but still fully supported. It cannot be combined with discount_codes in the same request.string
已弃用
Deprecated — prefer
discount_codes for new integrations. This field still works for backward compatibility, but cannot be combined with discount_codes in the same request.object
Custom key-value pairs to store additional information about the session.
boolean
Override merchant default 3DS behaviour for this session.
boolean
默认值:"false"
Enable minimal address collection mode. When enabled, the checkout only collects:
- Country: Always required for tax determination
- ZIP/Postal code: Only in regions where it’s necessary for sales tax, VAT, or GST calculation
confirm: true 时,只需填写 zipcode(以及 country);其他账单地址字段仍为可选。string
属于所附客户的已保存支付方式。需要
confirm: true 和现有的 customer.customer_id。系统会根据付款货币验证该支付方式是否符合条件。设置后会立即处理扣款,并将 checkout_url 作为 null 返回。请改用返回的 payment_id。boolean
默认值:"false"
如果为 true,则返回缩短的结账 URL,而不是完整的会话 URL。
string
客户的税号(例如 VAT 号码)。需要将
billing_address 与 country 一起使用。string
与税号关联的可选企业或法定名称,最多 250 个字符。若与有效的
tax_id 一起提供,该名称会显示在发票上,而不是客户的个人姓名。integer
为印度银行卡的 INR 电子委托设置商户级委托下限的覆盖值(以 INR 派士为单位)。发送给处理方的委托金额为
max(this_floor, actual_billing_amount),因此当账单金额较低时,这实际上就是面向客户的授权上限。未设置时使用商户设置;商户设置也未设置时,使用系统默认值 ₹15,000。UI Customization
UI Customization
object
自定义结账界面的外观和行为。
Feature Flags
Feature Flags
object
配置结账会话的特定功能和行为。
Custom Fields
Custom Fields
array
通过自定义表单字段在结账时收集客户的其他信息。每个结账会话最多可定义 5 个自定义字段。客户响应会包含在 webhook payload 中,并可通过 API 获取。
- Webhooks:
payment.succeeded、subscription.active及其他相关事件 payload 包含custom_field_responses数组 - API 响应:付款和订阅对象包含
custom_field_responses
Subscription Configuration
Subscription Configuration
object
包含订阅产品的结账会话的其他配置。
使用示例
简单的单产品结账
多产品购物车
多订阅购物车
要在一次结账中销售多个订阅产品,请将两个或更多订阅产品添加到product_cart。客户只需付款一次,Dodo Payments 会为每个产品创建一笔付款、一张发票和一个订阅。每个订阅都有自己的计费周期并独立续订,因此月付产品和年付产品可以共用一个购物车。
- 不能包含一次性付款产品。API 会使用
422拒绝请求。 - 最多可包含 20 个订阅产品。
- 不能两次列出同一产品。要销售一个产品的多个单位,请改为设置
quantity。 - 不能使用按需计费(
subscription_data.on_demand)。 - 应用于购物车的折扣码计为一次兑换。
subscription_data.trial_period_days 会应用于购物车中的每个订阅。没有此项时,每个订阅会使用其自身产品上设置的试用期。如果未设置此项且已启用防止试用滥用,客户已经试用过的产品将不再提供试用期。
生成的付款具有 is_multi_subscription: true,并在 subscription_ids 中列出其启动的每个订阅。其 subscription_id 为 null,因为没有任何单个订阅拥有该付款。payment.succeeded webhook 携带相同字段。请读取 is_multi_subscription 来查找付款类型,而不要根据 subscription_ids 的长度判断。
付款成功后,您会收到一个购物车的 payment.succeeded 事件,以及每个订阅各一个 subscription.active 事件。此后,每个订阅都会独立续订、变更计划和取消,并且每次续订都有自己的发票。
同一购物车中的所有订阅共享客户在结账时使用的支付方式。当您更新其中一个订阅的支付方式时,Dodo Payments 会将新支付方式移至同一购物车中、具有相同结算货币和账单货币且处于 active、on_hold、past_due 或 paused 状态的所有订阅。购物车中的每个订阅都以相同的结算货币和账单货币开始,即使其产品使用不同的价格货币也是如此。之后的变更(例如计划变更)可能会使订阅转为其他结算货币或账单货币。该订阅会保留旧的支付方式,因此需要单独更新。对于 on_hold 订阅,此更新只会重试该订阅未支付的发票。
带试用期的订阅
预确认结账
覆盖货币的结账
回头客使用已保存的支付方式
收集税号的 B2B 结账
深色主题结账与堆叠折扣码
区域支付方式(印度 UPI)
有关 UPI 配置和测试的详细信息,请参阅印度支付方式页面。BNPL(先买后付)结账
有关 BNPL 配置和测试的详细信息,请参阅先买后付 (BNPL)页面。使用现有支付方式的即时结账
更简洁的付款 URL 的短链接
跳过付款成功页面并立即重定向
强制指定语言
收集自定义字段
预览结账会话
使用 Preview Checkout Session endpoint,在创建会话前计算价格、税费和总额。这有助于在您的网站上显示准确的价格信息。当购物车包含订阅产品时,预览响应还会返回
next_billing_date,即即将到来的账单日期的预览,因此您可以在创建订阅前显示该日期。它是相对于当前时间计算的:适用试用期时为 now + trial period,否则为 now + one payment frequency。仅包含一次性产品的购物车不会返回此字段。这是以预览时间为基准的估算值;权威的 next_billing_date 会在订阅激活时设置。预览还会返回
trial_period_days(有效试用期长度,可免费或付费)和 trial_amount(折扣后的每单位试用费用,以价格货币的最小单位表示)。trial_amount 仅在付费试用时存在;免费试用或无试用时为 null。请使用 current_breakup 获取今天实际应支付的含税总额。对于多订阅购物车,响应还会返回
subscriptions 数组,其中每个订阅对应一个条目:product_id、amount_due_now、tax_due_now、recurring_amount、recurring_tax、trial_period_days 和 next_billing_date。顶层 next_billing_date 是购物车中的最早日期,顶层 trial_period_days 和 trial_amount 为 null。请从 subscriptions 和 current_breakup 读取金额。即使每个订阅的续订日期不同,recurring_breakup 也会汇总所有订阅的续订金额,因此请从 subscriptions 读取每次续订金额。- Node.js SDK
- Python SDK
- REST API
从 Dynamic Links 迁移
如果您正在使用 Dynamic Links,Checkout Sessions 可提供更大的灵活性。使用 Dynamic Links 时,您必须提供客户完整的账单地址。使用 Checkout Sessions 时,您可以传入已有的任意信息,结账流程会收集其余信息。 例如:- 仅提供客户的账单国家/地区,结账流程会收集其余详细信息。
- 或提供所有信息,并将
confirm: true设置为直接跳转到付款页面。