┌─────────────────────────────────────────────────────────────┐
│ 1. 页面加载 - 初始化 UseePay SDK │
│ UseePay(publicKey) → elements(options) │
└────────────────────────┬────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 2. 创建并挂载 Payment Element │
│ elements.create('payment', options) │
│ paymentElement.mount(domId) │
└────────────────────────┬────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 3. ready 事件触发 │
│ → Payment Element 已准备就绪 │
└────────────────────────┬────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 4. 客户填写支付信息 │
│ → 选择支付方式(卡、Apple Pay、Google Pay 等) │
│ → 填写必要信息 │
└────────────────────────┬────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 5. 客户点击支付按钮 │
│ → 调用 elements.submit() 验证表单 │
└────────────────────────┬────────────────────────────────────┘
↓
┌───────────────┴───────────────┐
│ 验证是否通过? │
└───────┬───────────────┬───────┘
│ 否 │ 是
↓ ↓
┌──────────────────┐ ┌──────────────────────┐
│ 显示验证错误 │ │ 6. 调用后端 API │
│ 让客户修正 │ │ 创建支付意图 │
└──────────────────┘ │ 返回 paymentIntentId│
│ 和 clientSecret │
└──────────┬───────────┘
↓
┌──────────────────────┐
│ 7. 确认支付 │
│ useepay.confirmPayment│
└──────────┬───────────┘
↓
┌──────────────────┴──────────────────┐
│ 支付结果 │
└──────┬───────────────────┬──────────┘
│ 成功 │ 失败
↓ ↓
┌──────────────────┐ ┌──────────────────┐
│ 8a. 重定向到 │ │ 8b. 显示错误信息 │
│ 成功页面 │ │ 让客户重试 │
└──────────────────┘ └──────────────────┘window.onload 或 DOMContentLoaded 事件中检查 SDK 是否加载UseePay_PK_ 开头(例如:UseePay_PK_1234567890abcdef...)UseePay_PK_TEST_ 开头(例如:UseePay_PK_TEST_1234567890abcdef...)⚠️ 重要提示:请从 MC 管理后台获取正确的公钥,切勿在生产环境使用测试公钥。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
mode | String | 是 | 支付模式,可选值:'payment'(一次性支付)或 'subscription'(订阅支付) |
amount | Number | 是 | 支付金额(实际金额) |
currency | String | 是 | 货币代码(例如:'USD'、'EUR'、'CNY') |
paymentMethodTypes | Array | 否 | 可用支付方式的字符串数组。可选值包括:'credit_card'(信用卡/借记卡)、'apple_pay'(Apple Pay)、'google_pay'(Google Pay)等。如果不提供,将显示所有支持的支付方式 |
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
applePay | Object | 否 | Apple Pay 特定配置选项。当 mode 为 'subscription' 时必须提供 |
📖 详细参数说明
关于 Apple Pay 循环支付的详细参数和配置,请参考 Apple 官方文档:
Apple Pay on the Web - Recurring Payments
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
recurringPaymentRequest | Object | 否 | 循环支付请求配置,用于订阅类型的支付 |
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
paymentDescription | String | 是 | 支付描述,向客户说明此循环支付的用途 |
managementURL | String | 是 | 管理 URL,客户可以在此 URL 管理其订阅 |
regularBilling | Object | 是 | 常规账单配置 |
billingAgreement | String | 否 | 账单协议文本 |
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
amount | Number | 是 | 循环支付金额(实际金额) |
label | String | 是 | 账单标签,向客户显示的账单项名称 |
recurringPaymentStartDate | Date | 是 | 循环支付开始日期 |
recurringPaymentEndDate | Date | 是 | 循环支付结束日期 |
recurringPaymentIntervalUnit | String | 是 | 循环支付间隔单位,可选值:'year'、'month'、'day'、'hour'、'minute' |
recurringPaymentIntervalCount | Number | 是 | 循环支付间隔数量,例如:每 2 个月则为 2 |
mode: 'subscription' 时,必须配置 Apple Pay 的循环支付功能:domId (String):组件应挂载到的 DOM 元素的 IDoptions (Object):更新选项applePay (Object,可选):Apple Pay 特定配置更新event (Object):事件对象options (Object):更新选项mode (String,可选):支付模式('payment' 或 'subscription')amount (Number,可选):支付金额currency (String,可选):货币代码paymentMethodTypes (Array,可选):可用支付方式的字符串数组,例如:['credit_card', 'googlepay']| 参数 | 类型 | 描述 |
|---|---|---|
selectedPaymentMethod | String | 客户选择的支付方式(例如:'credit_card'、'apple_pay'、'google_pay') |
error | Object | 错误信息对象,如果验证成功则为 null |
| 参数 | 类型 | 描述 |
|---|---|---|
type | String | 错误类型 |
message | String | 错误消息 |
| 值 | 描述 |
|---|---|
no_select_payment_method | 未选择支付方式 |
validation_error | 表单验证错误(例如:卡号无效、必填字段缺失) |
google_pay_cancel | Google Pay 支付被取消 |
apple_pay_cancel | Apple Pay 支付被取消 |
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
elements | Elements | 是 | Elements 实例 |
paymentIntentId | String | 是 | 从后端 API 返回的支付意图 ID |
clientSecret | String | 是 | 从后端 API 返回的客户端密钥 |
| 参数 | 类型 | 描述 |
|---|---|---|
paymentIntent | Object | 支付意图对象(支付成功时) |
error | Object | 错误信息对象(支付失败时) |
confirmPayment 时,您需要关注支付的结果,根据 ResultCode 来进行相应的操作。mode 为 'subscription' 时,必须在创建 Payment Element 时提供 applePay 配置。elements.submit() 进行表单验证。submit() 和 confirmPayment() 的返回值中的 error 对象。