> ## Documentation Index
> Fetch the complete documentation index at: https://docs.y.uno/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Test in the sandbox first: base URL https://api-sandbox.y.uno (Test Mode in the Dashboard). Production is https://api.y.uno (Live Mode).
> Every API request needs the public-api-key and private-secret-key headers. Get them in the Dashboard at https://dashboard.y.uno/developers (Developers > Credentials); sandbox and production keys are different.
> Send an X-Idempotency-Key (a UUID) when creating payments, refunds and cancels, so retries do not create duplicates.
> Start with the Quickstart (https://docs.y.uno/docs/quickstart.md) and the agent guide (https://docs.y.uno/agents.md). To search these docs from a coding agent, connect the docs MCP server at https://docs.y.uno/mcp.

# 使用两张卡支付

> 通过 Direct API 或 headless Web SDK，使用恰好两张卡为一笔支付出资：请求、响应、状态、冲正和操作。

双卡支付是由恰好两张卡共同出资的一笔支付。每张卡支付金额中属于自己的部分，两部分相加等于支付金额。您的客户为一个订单付款，您只需对账一笔支付。

当客户希望将一个订单拆分到两张卡上时使用此功能，例如因为一张卡的额度不足以支付整个订单。

## 限制

* 恰好两张卡，均为 `type: CARD`。
* 单一币种：两张卡的金额均使用支付的币种。
* 不允许使用 `split_marketplace`、`external_subscription` 和 `amount.currency_conversion`，也不接受促销报价（请参阅[促销](https://docs.y.uno/zh-hans/docs/payment-features/promotions)）。
* 全有或全无：两张卡都成功，否则支付失败。请参阅[全有或全无](#all-or-nothing)。
* `payment_method.capture` 由两张卡共享。

## 启用

在生产环境中，双卡支付按组织启用。在 Yuno 启用之前，`POST /v2/payments` 会返回：

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "code": "PRODUCT_NOT_ENABLED",
  "messages": [
    "Payments with more than one payment method are enabled per account. Contact your Key Account Manager (KAM) to activate it."
  ]
}
```

HTTP 状态码为 `403`。请联系您的大客户经理启用此功能。在 sandbox 中，所有组织均已启用双卡支付。

## 创建支付

发送 `POST /v2/payments`（sandbox 中为 `https://api-sandbox.y.uno/v2/payments`，生产环境中为 `https://api.y.uno/v2/payments`），并使用与 v1 endpoint 相同的 `public-api-key` 和 `private-secret-key` 标头。此请求以及每个 v2 操作都必须包含 `X-Idempotency-Key` 标头；缺少该标头时，请求将被拒绝，并返回 `400` 和消息 `The header 'x-idempotency-key' is required.`

| 字段 | 描述 |
| - | - |
| `workflow` | `DIRECT`、`REDIRECT` 或 `SDK_CHECKOUT`。 |
| `amount` | 支付总额。必须等于两张卡金额之和。 |
| `payment_method.payment_methods` | 仅限 `DIRECT` 和 `REDIRECT`。恰好两项，均为 `type: CARD`。 |
| `payment_method.payment_methods[].amount` | 此卡所付部分的 `currency` 和 `value`。`value` 大于 0，`currency` 与 `amount.currency` 相同。 |
| `payment_method.payment_methods[].detail.card` | 卡数据。发送此字段或 `vaulted_token`。不要在此处发送 `capture`。 |
| `payment_method.payment_methods[].vaulted_token` | 已注册卡的已存储令牌（vaulted token）。 |
| `payment_method.payment_methods[].payment_method_owner` | 可选。此卡的持卡人（当其不是付款人时）。 |
| `payment_method.payment_methods[].account_updater` | 可选。 |
| `payment_method.token` | 仅限 `SDK_CHECKOUT`。复合令牌。不要同时发送 `payment_methods`。 |
| `checkout.session` | 仅限 `SDK_CHECKOUT`。创建该复合令牌时所对应的结账会话。 |
| `payment_method.capture` | 由两张卡共享。默认为 `true`（两张卡均被扣款）。发送 `false` 可授权两张卡，之后再分别捕获每张卡。 |
| `customer_payer` | 必填。付款人，由两张卡共享。 |
| `callback_url` | 可选。3DS 挑战或重定向结束后将客户返回到的地址。 |

```bash DIRECT: two new cards theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
curl --request POST \
  --url https://api-sandbox.y.uno/v2/payments \
  --header 'X-Idempotency-Key: 6f1c2a3b-4d5e-4f60-8a7b-9c0d1e2f3a4b' \
  --header 'public-api-key: <PUBLIC_API_KEY>' \
  --header 'private-secret-key: <PRIVATE_SECRET_KEY>' \
  --header 'content-type: application/json' \
  --data '{
    "account_id": "<ACCOUNT_ID>",
    "merchant_order_id": "order-10045",
    "description": "Order paid with two cards",
    "country": "BR",
    "amount": { "currency": "BRL", "value": 300 },
    "workflow": "DIRECT",
    "customer_payer": { "id": "<CUSTOMER_ID>" },
    "payment_method": {
      "capture": true,
      "payment_methods": [
        {
          "type": "CARD",
          "amount": { "currency": "BRL", "value": 200 },
          "detail": { "card": { "number": "4111111111111111", "expiration_month": 11, "expiration_year": 2029, "security_code": "123", "holder_name": "ANA SOUZA" } }
        },
        {
          "type": "CARD",
          "amount": { "currency": "BRL", "value": 100 },
          "detail": { "card": { "number": "5555555555554444", "expiration_month": 3, "expiration_year": 2030, "security_code": "456", "holder_name": "ANA SOUZA" } }
        }
      ]
    }
  }'
```

```bash DIRECT: one vaulted card and one new card theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
curl --request POST \
  --url https://api-sandbox.y.uno/v2/payments \
  --header 'X-Idempotency-Key: 7a2d3b4c-5e6f-4a71-9b8c-0d1e2f3a4b5c' \
  --header 'public-api-key: <PUBLIC_API_KEY>' \
  --header 'private-secret-key: <PRIVATE_SECRET_KEY>' \
  --header 'content-type: application/json' \
  --data '{
    "account_id": "<ACCOUNT_ID>",
    "merchant_order_id": "order-10046",
    "description": "Order paid with two cards",
    "country": "BR",
    "amount": { "currency": "BRL", "value": 300 },
    "workflow": "DIRECT",
    "customer_payer": { "id": "<CUSTOMER_ID>" },
    "payment_method": {
      "capture": false,
      "payment_methods": [
        {
          "type": "CARD",
          "amount": { "currency": "BRL", "value": 120 },
          "vaulted_token": "aad8578e-ac2f-40a0-8065-25b5957f6555"
        },
        {
          "type": "CARD",
          "amount": { "currency": "BRL", "value": 180 },
          "detail": { "card": { "number": "4111111111111111", "expiration_month": 11, "expiration_year": 2029, "security_code": "123", "holder_name": "JOAO SOUZA" } },
          "payment_method_owner": { "first_name": "Joao", "last_name": "Souza", "email": "joao.souza@example.com" }
        }
      ]
    }
  }'
```

```bash SDK_CHECKOUT: composite token theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
curl --request POST \
  --url https://api-sandbox.y.uno/v2/payments \
  --header 'X-Idempotency-Key: 8b3e4c5d-6f7a-4b82-8c9d-1e2f3a4b5c6d' \
  --header 'public-api-key: <PUBLIC_API_KEY>' \
  --header 'private-secret-key: <PRIVATE_SECRET_KEY>' \
  --header 'content-type: application/json' \
  --data '{
    "account_id": "<ACCOUNT_ID>",
    "merchant_order_id": "order-10047",
    "description": "Order paid with two cards",
    "country": "BR",
    "amount": { "currency": "BRL", "value": 300 },
    "workflow": "SDK_CHECKOUT",
    "checkout": { "session": "<CHECKOUT_SESSION>" },
    "customer_payer": { "id": "<CUSTOMER_ID>" },
    "payment_method": { "token": "<COMPOSITE_TOKEN>", "capture": true },
    "callback_url": "https://merchant.example.com/checkout/return"
  }'
```

在 SDK 路径上，使用 [headless Web SDK](https://docs.y.uno/docs/sdks/headless-web/payment.md#split-one-payment-across-two-cards) 中的 `generateToken` 创建复合令牌。该令牌包含两张卡及其金额。在 Yuno SDK 中，向 `start()` 传入一个数组：请参阅[将一笔支付拆分到两张卡](https://docs.y.uno/docs/yuno-sdk/features/split-payment.md)。

完整参考请参阅 [Create Payment (two cards)](https://docs.y.uno/reference/payments/create-payment-v2.md)。

## 读取响应

创建请求与 [Retrieve Payment (two cards)](https://docs.y.uno/reference/payments/retrieve-payment-two-cards.md) 返回相同的结构：

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "id": "7c1b6e2a-5f3d-4a8e-9b21-3e4f5a6b7c8d",
  "status": "SUCCEEDED",
  "sub_status": "APPROVED",
  "split_payment_methods": true,
  "payment_methods_count": 2,
  "sdk_action_required": false,
  "amount": { "currency": "BRL", "value": 300 },
  "payment_method": {
    "capture": true,
    "payment_methods": [
      {
        "sequence": 1,
        "type": "CARD",
        "amount": { "currency": "BRL", "value": 200 },
        "transactions": [
          { "id": "d2a4f6b8-1c3e-4a5b-8d7f-9e0a1b2c3d4e", "type": "PURCHASE", "status": "SUCCEEDED", "amount": 200, "response_code": "SUCCEEDED" }
        ]
      },
      {
        "sequence": 2,
        "type": "CARD",
        "amount": { "currency": "BRL", "value": 100 },
        "transactions": [
          { "id": "e3b5a7c9-2d4f-4b6c-9e8a-0f1b2c3d4e5f", "type": "PURCHASE", "status": "SUCCEEDED", "amount": 100, "response_code": "SUCCEEDED" }
        ]
      }
    ]
  }
}
```

* `split_payment_methods` 为 `true`，`payment_methods_count` 为 `2`。
* `payment_method.payment_methods` 中每张卡对应一个条目，包含其 `sequence`（`1` 或 `2`）、`type`、`amount`（`currency` 和 `value`）以及 `transactions`。
* 卡本身没有状态。请从每张卡的 `transactions` 中读取其结果：该卡的最后一笔交易及其 `status` 会告诉您该卡发生了什么。经过 3DS 的卡会显示 `THREE_D_SECURE`，随后是 `PURCHASE`（当 `capture` 为 `false` 时为 `AUTHORIZE`）。
* 从支付级别的 `status` 和 `sub_status` 读取支付结果。当 `sdk_action_required` 为 `true` 时，SDK 需要继续该支付，例如运行 3DS 挑战。

## 状态

Yuno 会在支付的 `status` 和 `sub_status` 中汇总两张卡的情况。第一条匹配的规则生效：

| 卡 | `status` | `sub_status` |
| - | - | - |
| 任一卡被欺诈筛查拒绝 | `DECLINED` | `FRAUD_DECLINED` |
| 两张卡均被驳回 | `REJECTED` | `REJECTED` |
| 任一卡被拒绝 | `DECLINED` | `DECLINED` |
| 任一卡出错 | `ERROR` | `ERROR` |
| 任一卡已过期 | `EXPIRED` | `EXPIRED` |
| 一张卡处于欺诈审核中 | `PENDING` | `PENDING_FRAUD_REVIEW` |
| 一张卡正在等待 3DS | `PENDING` | `WAITING_ADDITIONAL_STEP` |
| 两张卡均已授权（`capture: false`） | `PENDING` | `AUTHORIZED` |
| 两张卡均已扣款 | `SUCCEEDED` | `APPROVED` |
| 两张卡均已由您捕获 | `SUCCEEDED` | `CAPTURED` |
| 一张卡已捕获，另一张尚未捕获 | `SUCCEEDED` | `PARTIALLY_CAPTURED` |
| 一张卡已退款 | `SUCCEEDED` | `PARTIALLY_REFUNDED` |
| 两张卡均已退款 | `REFUNDED` | `REFUNDED` |
| 一张卡存在未结拒付 | `IN_DISPUTE` | |

有关所有状态和子状态，请参阅[支付状态](https://docs.y.uno/reference/payments/status-and-response-codes/payment.md)。

## 全有或全无

两张卡都成功，否则支付失败。如果一张卡失败（被拒绝、出错或欺诈），Yuno 会**在响应创建请求之前**冲正另一张卡，因此响应中已显示最终结果：

* 已扣款的卡（`PURCHASE` 或已捕获）将被**退款**。
* 仅已授权的卡将被**取消**。
* 正在等待 3DS 的卡由 Yuno 关闭，不会调用服务提供商。

如果冲正失败，支付将保持 `DECLINED`，子状态为 `REFUND_RETRY_IN_PROCESS` 或 `CANCEL_RETRY_IN_PROCESS`，Yuno 会自动重试冲正。当支付处于上述子状态之一时，捕获和取消请求将被拒绝。

> [!WARNING]
>
> 失败后，请不要要求客户继续使用剩余的卡，而应发起新的支付。

## 欺诈筛查

* 在授权前拒绝一张卡会导致支付被拒绝（`DECLINED / FRAUD_DECLINED`），Yuno 会关闭另一张卡。
* 授权后的拒绝会冲正**两张**卡。

## 操作

捕获、取消和退款均按卡进行：发送该卡交易的 `id`，取自 `payment_method.payment_methods[].transactions`。每个操作都返回 `201` 以及相同 v2 结构的支付，并且需要 `X-Idempotency-Key`。

| 操作 | 请求 |
| - | - |
| 捕获一张卡 | [`POST /v2/payments/{payment_id}/transactions/{transaction_id}/capture`](https://docs.y.uno/reference/payments/capture-authorization-v2) |
| 取消一张卡 | [`POST /v2/payments/{payment_id}/transactions/{transaction_id}/cancel`](https://docs.y.uno/reference/payments/cancel-payment-v2) |
| 为一张卡退款 | [`POST /v2/payments/{payment_id}/transactions/{transaction_id}/refund`](https://docs.y.uno/reference/payments/refund-payment-v2) |
| 取消一张卡或为其退款 | [`POST /v2/payments/{payment_id}/transactions/{transaction_id}/cancel-or-refund`](https://docs.y.uno/reference/payments/cancel-or-refund-payment-with-transaction-v2) |
| 取消整笔支付或为其退款 | [`POST /v2/payments/{payment_id}/cancel-or-refund`](https://docs.y.uno/reference/payments/cancel-or-refund-a-payment-v2) |

* 一张卡的退款上限为该卡金额减去该卡已退款的金额。
* 支付级别的 `cancel-or-refund` 接受可选的 `amount`。Yuno 会将其分摊到各张卡上，从可退款金额最多的卡开始。超过可退款总额的 `amount` 将被拒绝。
* 当一张卡存在未结拒付时，退款请求将被拒绝并返回 `INVALID_STATUS`。

## Webhook

支付 webhook 的 payload 与 v1 支付相同，另外还包含：

* `split_payment_methods` 和 `payment_methods_count`。
* `payment_method.capture`。
* `payment_method.payment_methods[]`，每张卡包含 `sequence`、`type`、`amount` 和 `transactions`。

webhook 中同样没有每张卡的状态：请从每张卡的交易中读取其结果。请参阅[配置 webhook](https://docs.y.uno/zh-hans/docs/webhooks/configure-webhooks.md)。

## 错误

除非另有说明，错误均为 `400 INVALID_PARAMETERS`。`messages` 数组列出请求中发现的所有问题。

| 情况 | 消息 |
| - | - |
| 缺少幂等性键 | `The header 'x-idempotency-key' is required.` |
| 不允许的 workflow | `The field 'workflow' has an invalid value for /v2/payments, the allowed values are: 'DIRECT', 'REDIRECT', 'SDK_CHECKOUT'.` |
| `SDK_CHECKOUT` 未包含 `checkout.session` | `The field 'checkout.session' is required for the SDK_CHECKOUT workflow.` |
| `SDK_CHECKOUT` 未包含 `payment_method.token` | `The field 'payment_method.token' is required for the SDK_CHECKOUT workflow.` |
| `payment_method.token` 不是 UUID | `The field 'payment_method.token' must be a valid UUID.` |
| `payment_methods` 与 `SDK_CHECKOUT` 同时使用 | `The field 'payment_method.payment_methods' is not allowed for the SDK_CHECKOUT workflow, the one-time token carries the payment methods.` |
| `token` 与 `DIRECT` 或 `REDIRECT` 同时使用 | `The field 'payment_method.token' is only allowed for the SDK_CHECKOUT workflow, not for DIRECT.`（使用 `REDIRECT` 时为 `not for REDIRECT.`） |
| 双卡支付中使用 `split_marketplace` | `The field 'split_marketplace' is not allowed with more than one payment method.` |
| 双卡支付中使用 `external_subscription` | `The field 'external_subscription' is not allowed with more than one payment method.` |
| 双卡支付中使用 `amount.currency_conversion` | `The field 'amount.currency_conversion' is not allowed with more than one payment method.` |
| 在 `detail.card` 中包含 `capture` | `The field 'payment_method.payment_methods[0].detail.card.capture' is not allowed, use 'payment_method.capture' for every payment method.` |
| 一张卡的类型不是 `CARD` | `The field 'payment_method.payment_methods[1].type' must be 'CARD'.` |
| 卡金额小于或等于 0 | `The field 'payment_method.payment_methods[0].amount.value' must be greater than 0.` |
| 卡币种与支付币种不同 | `The field 'payment_method.payment_methods[1].amount.currency' must match 'amount.currency'.` |
| 卡金额之和不相符 | `The sum of 'payment_method.payment_methods[].amount.value' must equal 'amount.value'.` |
| 复合令牌已被使用 | 代码 `INVALID_TOKEN_USED` |
| 结账会话对该令牌无效 | 代码 `INVALID_CHECKOUT_SESSION` |
| 复合令牌无效 | 代码 `INVALID_TOKEN` |
| 令牌总额与 `amount` 不同 | `Token total does not match the payment amount` |
| 该组织未启用此功能 | `403 PRODUCT_NOT_ENABLED` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.