更新记录

1.0.0(2026-04-24)

支持 stripe支付


平台兼容性

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

💳 Stripe PaymentSheet 插件,为 uni-app / uni-app x 提供原生收银台能力(银行卡等),在 iOS、Android App 上调起 Stripe 预置 UI,配合服务端 PaymentIntent 完成收款。

📖 目录

SDK 版本信息

  • iOS23.28.3deploymentTarget 13
  • Android20.48.0minSdkVersion 21

重要提示

⚠️ 建议使用自定义基座或正式包,在 真机 上调试支付;模拟器部分能力受限。

⚠️ 客户端 success 仅表示 PaymentSheet 流程结束;是否到账请以 服务端查询 PaymentIntentWebhook(如 payment_intent.succeeded)为准。

⚠️ iOS 若用户会跳到 Safari / 银行 App 鉴权,必须配置 自定义 URL SchemereturnURL,并挂载 TTStripePayHookProxy(见 环境配置 - iOS 回跳)。

环境配置

前置条件

  1. Stripe Dashboard 开通账号,配置 支付方式
  2. 服务端:使用 Secret Key 创建 PaymentIntent,将 client_secretPublishable Key(可下发给客户端)返回给 App。
  3. App 内使用服务端下发的 Publishable Key,在 presentPaymentSheet 中与 client_secret 一并传入(须同属一套账号与环境)。

iOS 回跳(return URL + URL Scheme)

与 Web 版 Checkout 的 success_url / return_url 不是同一套。原生 PaymentSheet 要求:

  1. 在插件内配置 URL Scheme
    编辑 uni_modules/tt-stripe-pay/utssdk/app-ios/Info.plist 中的 CFBundleURLSchemes:须与调用 presentPaymentSheet 时传入的 returnURLscheme 一致(例如 returnURLmyapp://stripe-redirect,则此处需包含 myapp)。 插件默认带有 payments-example,与 官方演示payments-example://stripe-redirect 一致;正式环境请改为或追加你的自有 scheme
  2. 调起支付时传入 returnURL(完整 URL,含 scheme / host / path),与 PaymentSheet.Configuration.returnURL 一致。

📚 官方说明Set up a return URL(Stripe 文档写明 不支持 用 Universal Links 替代该自定义 Scheme 回跳。)

仅银行卡、无需跳出 App

若仅测试 无需外跳 的卡支付,可暂不设置 returnURL;一旦启用可能外跳的支付方式,请按上文补齐。

快速开始

1. 导入插件

uni-app x(script setup + lang="uts"

import { getTTStripePay } from '@/uni_modules/tt-stripe-pay';

const stripePay = getTTStripePay();

uni-app(Vue3)

import { getTTStripePay } from '@/uni_modules/tt-stripe-pay';

const stripePay = getTTStripePay();

类型定义可从 utssdk/interface.uts 对照;业务侧可按需 import type { ... } from '@/uni_modules/tt-stripe-pay/utssdk/interface'(路径以工程为准)。

2. 条件编译(推荐)

App-Android / App-iOS 引用,避免编译到小程序与 H5:

// #ifdef APP-ANDROID || APP-IOS
import { getTTStripePay } from '@/uni_modules/tt-stripe-pay';
// #endif

基础使用

流程:服务端拿到 publishableKey + client_secret → 一次调用 presentPaymentSheet({ publishableKey, paymentIntentClientSecret, ... })(内部会先写入 Key 再调起收银台)。

示例(uni-app x)

const stripePay = getTTStripePay();

stripePay.presentPaymentSheet({
    publishableKey: 'pk_test_xxx',
    paymentIntentClientSecret: 'pi_xxx_secret_xxx',
    merchantDisplayName: '我的商户',
    returnURL: 'myapp://stripe-redirect', // iOS 外跳支付时建议填写,并与 URL Scheme 一致
    customerId: 'cus_xxx', // PI 若关联 Customer,须与 customerEphemeralKeySecret 成对传入(官方演示后端会返回)
    customerEphemeralKeySecret: 'ek_test_xxx',
    success: (_res) => {
        console.log('流程完成,仍建议服务端查 PaymentIntent');
    },
    fail: (err) => {
        console.error(err.errCode, err.errMsg);
    },
    complete: null,
});

API 文档

getTTStripePay

type GetTTStripePay = () => TTStripePay;

返回单例式 TTStripePay 接口实现。

TTStripePay.presentPaymentSheet

调起 PaymentSheet。会先写入 publishableKey(iOS:STPAPIClient;Android:PaymentConfiguration.init),再展示 UI。须保证当前页面可取得 UIViewController(iOS)或 Activity(Android)。

参数 TTStripePresentPaymentSheetOptions

参数 类型 必填 说明
publishableKey string pk_test_ / pk_live_,与 client_secret 同属一套账号与环境
paymentIntentClientSecret string 服务端创建 PaymentIntent 返回的 client_secret
merchantDisplayName string | null 收银台展示名称,默认 App
returnURL string | null iOS 外跳回 App 的自定义 URL,见 iOS 回跳
customerId string | null 若 PI 关联 Customer,须与 customerEphemeralKeySecret 同时传入,否则易崩溃或无法拉齐支付方式(官方演示接口会返回 customer
customerEphemeralKeySecret string | null 服务端为该 Customer 创建的 Ephemeral Key secret(演示 JSON 常为 ephemeralKey
success function 成功:空对象 {}
fail function 失败:IUniError
complete function 完成回调

官方演示数据(联调)

stripe-iosPaymentSheet Example 使用演示后端(与 ExampleCheckoutViewController.swiftbackendCheckoutUrl 一致):

  • URLhttps://stripe-mobile-payment-sheet.stripedemos.com/checkout
  • 方法POST
  • 响应字段publishableKeypaymentIntent(即 client secret)等

tt-stripe-demo 示例页提供「拉取官方演示数据」按钮,可快速填入上述字段;演示用 returnURLpayments-example://stripe-redirect,需在 iOS 配置 Scheme payments-example。正式环境请使用自有服务端,勿依赖演示站。

错误码

errSubjectTTStripePay 时常见 errCode

errCode 说明
100 参数无效(如空 publishableKey、空 client_secret
102 用户取消/关闭收银台,按失败处理(仅触发 fail / complete(IUniError),不触发 success
103 无法获取当前 UIViewController(iOS)
104 无法获取当前 Activity(Android)
105 无法获取 Application Context(Android)
106 PaymentSheet 未就绪(Android 内部初始化异常,可重试)
999 Stripe 支付失败或其它错误(见 errMsg
1000 当前平台不支持(预留)

常见问题

Q:iOS 点击调起收银台立刻崩溃?
A:多为 PaymentIntent 在服务端关联了 Customer,但客户端未传入 customerId + customerEphemeralKeySecret,Stripe SDK 会断言失败。tt-stripe-demo 里点「拉取官方演示数据」会把这两项一并填入;自有服务端若创建带 Customer 的 PI,也需同样下发并在 presentPaymentSheet 里成对传入。

Q:为什么文档里写了 return_url,插件里没有 Web 那种页面地址?
A:那是 网页 / Stripe.jsCheckout Session 的跳转地址。本插件走的是 原生 PaymentSheet,iOS 使用 returnURL + URL Scheme + StripeAPI.handleURLCallback,见 官方 Set up a return URL

Q:能否只在客户端完成收款?
A:不能。PaymentIntent 必须由服务端创建;客户端只用 client secret + publishable key 完成 SDK 展示与确认,否则密钥泄露且不符合 Stripe 安全模型。

Q:支付成功就一定到账吗?
A:不一定。请以服务端 PaymentIntent 状态Webhook 为准;部分支付方式为延迟通知(若开启 allowsDelayedPaymentMethods 相关能力,更需依赖服务端事件)。

Q:Android 云打包报 Could not find stripe-android-… / Failed to transform … stripe-android
A:多为 镜像未同步 Stripe 子模块(尤其 23.xpaymentsheet)。请使用当前插件默认的 stripe-android:20.48.0;若自行升级到 23.x,需云打包能访问 Maven Central 或镜像已补全对应 paymentsheet 版本。

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率: