
工作原理
Inline checkout 会将安全的 Dodo Payments frame 渲染到页面上的容器中。该 frame 负责收集客户信息和支付详细信息。您的页面负责显示商品、金额及其他信息。SDK 允许您的页面与 checkout frame 相互通信。 checkout 完成后,Dodo Payments 会创建 payment;如果是订阅商品,则会创建 subscription,并发送 webhook,以便您配置访问权限。优质 Inline Checkout 的要素
客户需要知道他们向谁购买、购买了什么以及需要支付多少。您的实现必须包含:
Example inline checkout layout showing required elements
- Recurring information:如果是 recurring,请显示 recurring 的频率以及续费时需要支付的总额。如果提供 trial,请显示 trial 时长。
- Item descriptions:所购买商品的描述。
- Transaction totals:小计、总税额和总计,包括 currency。
- Dodo Payments footer:完整的 inline checkout frame,包括包含 Dodo Payments 信息、销售条款和隐私政策的 footer。
- Refund policy:如果您的 refund policy 与 Dodo Payments 标准 refund policy 不同,请提供其链接。
客户旅程
checkout 流程取决于 checkout session 配置。根据您的 session 配置方式,客户可能会在单个页面上看到所有信息,也可能需要经过多个步骤。Customer opens checkout
checkout.breakdown)显示和更新页面上的信息。
Customer enters their details
Customer selects payment method

Checkout completed

Dodo Payments creates the payment or subscription

快速开始
安装 SDK,将其初始化为 inline 模式,然后在容器元素中打开 checkout:分步集成
Install the SDK
Initialize the SDK for Inline Display
displayType: 'inline'。监听 checkout.breakdown event,以使用实时税额和总额计算结果更新 UI:Create a Container Element
Open the Checkout
checkoutUrl 和 elementId 调用 DodoPayments.Checkout.open():Test Your Integration
- 启动开发服务器:
- 测试 checkout 流程:
- 在 inline frame 中输入 email 和地址详细信息
- 验证自定义订单摘要是否实时更新
- 使用 test credentials 测试支付流程
- 确认 redirects 正常工作
onEvent callback 中添加了 console log,那么应在浏览器控制台中看到记录的 checkout.breakdown events。Go Live
- 将 mode 更改为
'live':
- 更新 checkout URLs,使其使用 backend 中的 live checkout sessions
- 在 production 中测试完整流程
完整 React 示例
此示例演示如何在 inline checkout 旁实现自定义订单摘要,并使用checkout.breakdown event 使两者保持同步:
API 参考
Initialize
调用Initialize 一次以设置 SDK:
Open Checkout
在容器中打开 checkout frame:Close Checkout
以编程方式移除 checkout frame 并清理 event listeners:Check Status
检查 checkout frame 当前是否已注入:Events
SDK 通过onEvent callback 提供实时 events。对于 inline checkout,checkout.breakdown 尤其适合用于同步 UI:
Checkout Breakdown Data
checkout.breakdown event 会提供 pricing 和 tax 信息:
- Currency Formatting:Prices 使用最小 currency unit 的整数表示,例如 USD 的 cents。对于两位小数的 currencies,在使用
Intl.NumberFormat格式化前除以 100。JPY 等零小数 currencies 没有更小的 unit,因此不要除以 100。 - Handling Initial States:checkout 首次加载时,在用户提供 billing information 或应用 code 之前,
tax和discount可能为0或null。请妥善处理这些状态(例如显示短横线—或隐藏该行)。 - “Final Total” 与 “Total”:
total提供标准 price calculation,而finalTotal才是 transaction 的真实数据来源。如果存在finalTotal,它准确反映将从客户 card 中收取的金额。 - Real-time Feedback:使用
taxfield 向用户显示 taxes 正在实时计算。这会让 checkout page 更具“live”体验,并减少地址输入步骤中的阻力。
CDN 实现
如需在不使用 build step 的情况下快速集成,请从 CDN 加载 SDK:更新 Payment Method
Inline checkout 支持为 subscriptions 更新 payment method。当客户需要为 active subscription 更新 payment method,或重新激活 on-hold subscription 时,您可以直接在页面布局中渲染更新流程。工作原理
- 调用 Update Payment Method API 获取
payment_link:
- 将返回的
payment_link作为checkoutUrl传入,以打开 inline checkout:
对于 On-Hold Subscriptions
当更新处于on_hold status 的 subscription 的 payment method 时,Dodo Payments 会自动为任何剩余欠款创建 charge。监控 payment.succeeded 和 subscription.active webhooks,以确认重新激活。
错误处理
始终在onEvent callback 中实现 error handling:
最佳实践
- Responsive Design:确保容器元素具有足够的宽度和高度。iframe 通常会扩展以填满其容器。
- Synchronization:使用
checkout.breakdownevent,使自定义订单摘要或 pricing tables 与用户在 checkout frame 中看到的内容保持同步。 - Skeleton States:在
checkout.openedevent 触发前,在容器中显示 loading indicator。 - Cleanup:组件 unmount 时调用
DodoPayments.Checkout.close(),以清理 iframe 和 event listeners。
#0d0d0d 作为 background color,以便与 inline checkout frame 实现最佳视觉融合。Payment Status Validation
为什么 Server-Side Validation 至关重要
虽然 inline checkout events 可提供实时反馈,但不应将其作为 payment status 的唯一真实来源。网络问题、browser crashes 或用户关闭页面都可能导致 events 丢失。为确保可靠的 payment validation:- 监听 webhook events - Dodo Payments 会针对 payment status changes 发送 webhooks
- 实现 polling mechanism - 您的 frontend 应向 server 轮询 status updates
- 结合两种方式 - 使用 webhooks 作为 primary source,并以 polling 作为 fallback
推荐架构
实现步骤
1. 监听 checkout events - 用户点击 pay 后,开始准备验证 status:payment.succeeded 或 payment.failed webhooks 时更新 database。详情请参阅我们的 Webhooks documentation。
故障排除
Checkout frame is not appearing
Checkout frame is not appearing
- 验证
elementId是否匹配 DOM 中实际存在的div的id - 确保已将
displayType: 'inline'传入Initialize - 检查
checkoutUrl是否有效
Taxes are not updating in my UI
Taxes are not updating in my UI
- 确保正在监听
checkout.breakdownevent - 只有当用户在 checkout frame 中输入有效 country 和 postal code 后,才会计算 taxes
Digital Wallets
有关设置 Apple Pay、Google Pay 和其他 digital wallets 的详细信息,请参阅 Digital Wallets 页面。Apple Pay 快速设置
Open Wallet domains

Open Wallet domains from the Apple Pay row
Download the domain association file

Download the Apple Pay domain association file
Register your domain
shop.example.com),然后点击 Continue。
Register the domain where you embed inline checkout
Host the file on your domain
Content-Type: application/octet-stream 或 text/plain 提供。Verify the domain

Verify the hosted association file
Confirm it's active

Verified domains show an Active status
Test the integration
- 在 Apple device 上打开 checkout
- 确认 Apple Pay button 已显示
- 完成一次 test transaction
Browser Support
Dodo Payments Checkout SDK 支持:- Chrome(latest)
- Firefox(latest)
- Safari(latest)
- Edge(latest)
- IE11+