跳转到主要内容

GitHub Repository

完整的 Expo + React Native + Dodo Payments 样板

概述

一个适用于将 Dodo Payments 集成到 Expo/React Native 应用程序的生产就绪模板。该模板包括结账会话创建、支付处理和适当的 TypeScript 配置,帮助您快速开始在移动应用中接受支付。
该样板使用 Expo SDK 和 TypeScript,并包含用于结账会话和支付处理的示例实现。

先决条件

  • Node.js 18+
  • Expo CLI 或 EAS CLI
  • Dodo Payments 账户(来自仪表板的 API 密钥)
  • iOS 模拟器或 Android 模拟器(或物理设备)

快速开始

1

Clone the Repository

克隆样板仓库并进入项目目录:
git clone https://github.com/dodopayments/expo-boilerplate.git
cd expo-boilerplate
2

Get Your API Credentials

在测试模式下从 Dodo Payments 仪表板获取凭证:
  • API 密钥:在您的 仪表板 中导航到 开发者 → API 密钥
从测试模式开始,安全地测试集成而无需处理真实支付。
3

Configure Environment Variables

在根目录下创建 .env 文件:
touch .env
添加您的 Dodo Payments 凭据:
.env
EXPO_PUBLIC_DODO_API_KEY=your_test_api_key_here
切勿将 .env 文件提交到版本控制。它已包含在 .gitignore 中。
4

Install Dependencies

安装所需的 npm 包:
npm install
5

Start the Development Server

启动 Expo 开发服务器:
npx expo start
使用 Expo Go 应用扫描二维码,或按 i 以在 iOS 模拟器上运行,或 a 以在 Android 模拟器上运行。
你已经可以开始构建了!该样板包含示例屏幕和组件,帮助你理解集成过程。

包含内容

该模板附带预配置的基本内容:

Checkout Integration

创建和处理结账会话的示例实现

Payment Handling

完整的支付流程,包含成功与错误处理

TypeScript Support

完整的 TypeScript 配置,附带正确的类型定义

Expo Router

使用 Expo Router 的导航设置,实现无缝路由

项目结构

expo-boilerplate/
├── app/
│   ├── (tabs)/
│   │   └── index.tsx          # Home screen with examples
│   └── checkout.tsx           # Checkout screen
├── components/
│   └── PaymentButton.tsx      # Payment button component
├── lib/
│   └── dodo.ts                # Dodo Payments client setup
├── .env.example               # Environment variables template
└── package.json

下一步

一旦您运行了模板:
1

Create Your Products

在你的 Dodo Payments 仪表板 中添加产品以启用结账功能。
2

Customize the Integration

根据你的应用需求和设计调整示例代码。
3

Test on Real Devices

在实体设备上测试支付流程,以确保一切正常。
4

Go Live

准备就绪后,将 API 密钥切换到实时模式并构建你的生产应用。

为生产构建

1

Install EAS CLI

npm install -g eas-cli
2

Configure EAS

eas build:configure
3

Build Your App

对于 iOS:
eas build --platform ios
对于 Android:
eas build --platform android

其他资源

Mobile Integration Guide

移动应用中实现支付的详细指南

React Native Integration

React Native 专用集成文档

Integration Guide

一次性支付实现的详细指南

API Reference

探索完整的 Dodo Payments API 文档

支持

需要有关模板的帮助吗?
Last modified on February 27, 2026