# 沙盒测试

> 使用沙盒测试卡验证卡支付、3DS 场景、失败响应、订阅、token 支付与钱包支付。

在沙盒环境中使用以下测试卡验证支付流程。测试卡仅适用于沙盒环境，不要在生产环境使用，也不要用真实持卡人信息替换这些测试值。

<note>

表格中的“响应”表示用于验证成功或失败分支的典型响应。实际接口返回仍以沙盒环境的当前配置为准。

</note>

## 卡支付测试卡

使用这些卡号验证一次性扣款、3DS 认证流程、豁免场景、失败响应、订阅支付和 token 支付。

<tip>

“3DS 测试场景”表示这些测试卡在沙盒中用于模拟的认证流程或豁免路径。`Challenge flow` 和 `Frictionless flow` 是 3DS 认证流程，`Exemption` 表示豁免场景；它们不是卡片本身的固定属性，也不代表同一国家/地区的所有交易都会触发相同结果。

</tip>

| 卡号 | 国家和地区 | 卡组织 | 3DS 测试场景 | 响应 | 订阅 | 保存支付方式 |
| --- | --- | --- | --- | --- | --- | --- |
| `4000020951595032` | 🇺🇸 `US` | Visa | Challenge flow | Success | Yes | Yes |
| `4761344136141390` | 🇸🇬 `SG` | Visa | Exemption | Success | Yes | Yes |
| `4000319872807223` | 🇺🇸 `US` | Visa | Frictionless flow | Success | No | Yes |
| `4000128449498204` | 🇺🇸 `US` | Visa | Frictionless flow | Do not honor | No | Yes |
| `4021937195658141` | 🇬🇧 `GB` | Visa | Frictionless flow | Insufficient funds | No | No |
| `4000164166749263` | 🇮🇳 `IN` | Visa | Frictionless flow | Suspected fraud | No | No |
| `2221008123677736` | 🇺🇸 `US` | Mastercard | Challenge flow | Success | Yes | No |
| `5333302221254276` | 🇹🇷 `TR` | Mastercard | Exemption | Success | No | No |
| `5333418445863914` | 🇲🇽 `MX` | Mastercard | Frictionless flow | Success | No | No |
| `5109486948867999` | 🇺🇸 `US` | Mastercard | Frictionless flow | Restricted Card | No | No |
| `4998170000000015` | 🇧🇷 `BR` | Visa | Challenge flow | Success | No | No |
| `4998170000000023` | 🇧🇷 `BR` | Visa | Challenge flow | Suspected fraud | No | No |

## Apple Pay 沙盒测试

在沙盒环境测试 Apple Pay 前，请先完成以下准备：

1. **域名验证**：通过 Web SDK 或 API 直连在自有页面展示 Apple Pay 按钮的，测试域名需先完成 Apple 域名验证（由商户自有 Apple Developer 账号或 Onerway 代为报备），见 [Apple Pay 接入准备](/zh/payments/online-payments/payment-methods/apple-pay#%E6%8E%A5%E5%85%A5%E5%87%86%E5%A4%87)；收银台为 Onerway 托管页面，无需此步骤。
2. **Sandbox 测试账户**：在 App Store Connect 中创建 sandbox 测试账户；测试设备退出 iCloud 账户后，使用该测试账户登录。
3. **设备国家与地区**：将测试设备的国家与地区设置为 Apple Pay 沙盒支持、且与所用测试卡卡组织匹配的地区；中国大陆地区的 Wallet 仅支持银联测试卡。

测试卡由 Apple 提供并会整批更换，请直接使用 [Apple Pay sandbox testing](https://developer.apple.com/apple-pay/sandbox-testing/)（[中文版](https://developer.apple.com/cn/apple-pay/sandbox-testing/)）页面上的最新测试卡，在测试设备的 Wallet 中手动添加。

## Google Pay 测试卡

测试 Google Pay 前，请使用 Google 账号加入 [Google Pay 测试卡套件群组](https://groups.google.com/g/googlepay-test-mode-stub-data)，加入后该账号的 Google Pay 会自动展示一组测试卡，无需手动添加。

## 建议验证场景

- 使用预期响应为 `Success` 的测试卡验证支付创建和支付确认。
- 验证服务端能正常接收支付 Webhook：使用通知 header `X-Rh-Signature` 完成[验签](/zh/payments/get-started/request-signing)，并在处理后返回确认响应，避免通知被重复投递。
- 使用预期响应为失败原因的测试卡验证错误展示、重试逻辑和订单状态回滚。
- 使用支持订阅的卡验证订阅支付。
- 使用支持保存支付方式的卡验证保存支付方式（绑卡）和后续 token 支付。
- 使用 Apple Pay / Google Pay 测试卡验证钱包支付流程。
