更新记录
1.0.4(2026-06-03)
支持可选启用 Apple Pay / Google Pay
1.0.3(2026-06-03)
修复已知问题
1.0.2(2026-05-26)
修复 uni-app项目 安卓平台无法收到支付回调的问题
查看更多平台兼容性
uni-app(4.87)
| Vue2 | Vue2插件版本 | Vue3 | Vue3插件版本 | Chrome | Safari | app-vue | app-vue插件版本 | app-nvue | app-nvue插件版本 | Android | Android插件版本 | iOS | iOS插件版本 | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | 1.0.0 | √ | 1.0.0 | × | × | √ | 1.0.0 | √ | 1.0.0 | 5.0 | 1.0.0 | 13 | 1.0.0 | × |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | × | × | × | × |
uni-app x(4.87)
| Chrome | Safari | Android | Android插件版本 | iOS | iOS插件版本 | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|---|---|
| × | × | 5.0 | 1.0.0 | 13 | 1.0.0 | × | × |
tt-stripe-pay
uni-app / uni-app x 的 Stripe PaymentSheet 插件:在 iOS、Android App 内调起原生收银台。需服务端创建 PaymentIntent 并下发 client_secret。
1. 接入前必读
- 服务端必须用 Secret Key 创建 PaymentIntent,再把
client_secret和 Publishable Key 下发给 App。 client_secret和 Publishable Key 必须属于同一 Stripe 账号和同一环境(test / live)。- 含 Stripe 原生依赖时,请使用自定义基座或正式包测试;不要用未集成本插件的标准基座。
success只表示客户端 PaymentSheet 流程完成;最终支付状态以服务端查询 PaymentIntent 或 Webhook 为准。- Apple Pay / Google Pay 默认关闭;不传
applePay/googlePay就是普通 PaymentSheet。
2. iOS:外跳回 App(returnURL)
启用会跳出 App 的支付方式时,建议配置自定义 URL Scheme,并传入同 scheme 的 returnURL:
- 在
utssdk/app-ios/Info.plist配置CFBundleURLSchemes。 - 调用时传入完整
returnURL,如myapp://stripe-redirect。 - 挂载
TTStripePayHookProxy,把 iOS open URL 回调交给 Stripe。
只测不外跳的卡支付时,returnURL 可不传。
3. Apple Pay / Google Pay(可选)
iOS:启用 Apple Pay
启用前需要:
- 在 Apple Developer 创建 Merchant ID,如
merchant.com.example.app。 - 为 App ID 启用 Apple Pay,并关联该 Merchant ID。
- 在 Stripe Dashboard 配置 Apple Pay iOS certificate。
- 复制
utssdk/app-ios/UTS.entitlements.example为utssdk/app-ios/UTS.entitlements,把merchant.com.example.app改为你的 Merchant ID。 - 调用
presentPaymentSheet时传入同一个merchantId。
applePay.merchantCountryCode 是商户业务国家/地区代码,不是用户所在地。
UTS.entitlements 示例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.in-app-payments</key>
<array>
<string>merchant.com.example.app</string>
</array>
</dict>
</plist>
不需要 Apple Pay 时,不要创建 UTS.entitlements,或不要包含 com.apple.developer.in-app-payments。可以保留有效的空 plist,但不要保留零字节空文件。
Android:启用 Google Pay
插件已声明 Google Pay API:
<meta-data
android:name="com.google.android.gms.wallet.api.enabled"
android:value="true" />
调用时传入 googlePay 即可启用。测试环境设置 testEnv: true。不使用 Google Pay 时不需要删除上面的 meta-data;只要不传 googlePay,插件不会启用 Google Pay。
googlePay.merchantCountryCode 是商户业务国家/地区代码。currencyCode 对 PaymentIntent 可选但建议传,对 SetupIntent 必填。Google Pay 需在支持地区用 Android 真机测试,并登录已配置 Google Wallet 的账号。
4. 代码示例
// #ifdef APP-ANDROID || APP-IOS
import { getTTStripePay } from '@/uni_modules/tt-stripe-pay';
// #endif
const stripePay = getTTStripePay();
stripePay.presentPaymentSheet({
publishableKey: 'pk_test_xxx',
paymentIntentClientSecret: 'pi_xxx_secret_xxx',
merchantDisplayName: '我的商户',
returnURL: 'myapp://stripe-redirect',
customerId: 'cus_xxx',
customerEphemeralKeySecret: 'ek_test_xxx',
// #ifdef APP-IOS
applePay: {
merchantId: 'merchant.com.example.app',
merchantCountryCode: 'US',
},
// #endif
// #ifdef APP-ANDROID
googlePay: {
merchantCountryCode: 'US',
currencyCode: 'USD',
testEnv: true,
},
// #endif
success: () => {
/* 建议服务端再查 PaymentIntent */
},
fail: (err) => {
console.error(err.errCode, err.errMsg);
},
complete: null,
});
类型见 utssdk/interface.uts。
5. API:presentPaymentSheet
| 参数 | 必填 | 说明 |
|---|---|---|
publishableKey |
是 | Stripe Publishable Key,pk_test_ / pk_live_ |
paymentIntentClientSecret |
是 | PaymentIntent 的 client_secret |
merchantDisplayName |
否 | 收银台标题,默认 App |
returnURL |
否 | iOS 外跳回 App 的 URL |
customerId |
否 | 与 customerEphemeralKeySecret 成对传入 |
customerEphemeralKeySecret |
否 | Customer 的 Ephemeral Key secret |
applePay |
否 | iOS Apple Pay 配置;不传则不启用 |
googlePay |
否 | Android Google Pay 配置;不传则不启用 |
success / fail / complete |
否 | 回调;取消走 fail,errCode 为 102 |
applePay
| 参数 | 必填 | 说明 |
|---|---|---|
merchantId |
是 | Apple Merchant ID;须与 UTS.entitlements 一致 |
merchantCountryCode |
是 | 商户业务国家/地区代码,如 US、SG |
googlePay
| 参数 | 必填 | 说明 |
|---|---|---|
merchantCountryCode |
是 | 商户业务国家/地区代码,如 US、SG |
currencyCode |
否 | 币种代码,如 USD、SGD;PaymentIntent 可选,SetupIntent 必填 |
testEnv |
否 | true 使用 Test 环境;默认 false 使用 Production |
6. 演示联调(可选)
Stripe 官方示例后端:
POSThttps://stripe-mobile-payment-sheet.stripedemos.com/checkout- 响应含
publishableKey、paymentIntent、customer、ephemeralKey。 - 演示
returnURL为payments-example://stripe-redirect,iOS 需保留或追加payments-examplescheme。 - 该接口不下发 Apple Pay / Google Pay 配置;钱包测试需手动填写参数。
tt-stripe-demo 内「拉取官方演示数据」可一键填入。
7. 错误码(errSubject: TTStripePay)
| errCode | 说明 |
|---|---|
| 100 | 参数无效 |
| 102 | 用户取消 / 关闭收银台 |
| 103 | iOS 无法取得 UIViewController |
| 104 | Android 无法取得 Activity |
| 105 | Android 无法取得 Application Context |
| 106 | Android PaymentSheet 未就绪 |
| 999 | Stripe 或其它错误(见 errMsg) |
| 1000 | 平台不支持 |
8. 常见问题
| 问题 | 处理 |
|---|---|
| iOS 一点支付就崩 | 检查 PI 是否关联 Customer 但未传 customerId + customerEphemeralKeySecret;再检查是否用了未集成插件的标准基座。 |
| Apple Pay 不显示 | 检查 applePay、UTS.entitlements、Merchant ID、provisioning profile、设备和银行卡。 |
| Google Pay 不显示 | 检查 googlePay、国家/币种、Android 真机、Google Wallet;生产环境还需完成 Google Pay 发布配置。 |
| 能否只在客户端收款 | 不能,PaymentIntent 必须由服务端创建。 |
| 客户端 success 是否等于到账 | 不一定,以服务端状态与 Webhook 为准。 |

收藏人数:
购买源码授权版(
试用
使用 HBuilderX 导入示例项目
赞赏(1)
下载 796
赞赏 4
下载 12197179
赞赏 1918
赞赏
京公网安备:11010802035340号