> ## 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.

# 生成网络令牌加密凭证

> 为已存储的卡片生成新的一次性网络令牌加密凭证，以便在外部 PSP 上进行授权。

此 endpoint 为已存储的卡片按需返回一个**网络令牌加密凭证**，并默认返回该卡片当前的网络令牌（DPAN）。仅凭卡片的网络令牌无法授权支付。卡组织要求每笔交易使用一次性加密凭证，而只有 Yuno 能够请求该加密凭证，因为 Yuno 持有 Token Requestor ID。如果您想获取 Yuno 网络令牌并在您自己的 PSP 上授权交易，请使用此 endpoint。

您通过卡片的 `vaulted_token` 来标识卡片，这与您在[创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)中使用的标识符相同。Yuno 会在内部解析卡片当前的网络令牌并处理令牌轮换，因此您始终会收到一组一致且最新的 `(DPAN, cryptogram, ECI)`。

> [!WARNING]
>
> **DPAN 需要 PCI 认证：加密凭证则不需要**
>
> 完整的网络令牌（DPAN）属于等同于 PAN 的数据，因此包含该数据的默认响应仅向通过 PCI 认证的商户提供。加密凭证本身不等同于 PAN：它是一次性的、有效期短，并且绑定到特定的 DPAN，因此无法单独授权任何交易。
>
> 如果您的组织未通过 PCI 认证，请发送 `include_network_token: false`，仅接收加密凭证。请参阅下文的[仅加密凭证模式](#cryptogram-only-mode)。如需启用该产品，请联系您的大客户经理（KAM）。

> [!WARNING]
>
> **始终提交一致的配对。** 加密凭证绑定到特定的网络令牌。请将**同一响应**中返回的 `network_token.number`（DPAN）与其 `cryptogram` 和 `eci` 一起提交。切勿将返回的加密凭证与之前存储的 DPAN 配对。令牌轮换后，存储的 DPAN 将不再匹配。在[仅加密凭证模式](#cryptogram-only-mode)下，同样的规则通过代理适用：请求加密凭证后立即转发，以确保代理解析出的 DPAN 正是生成该加密凭证时对应的 DPAN。

## 工作原理

1. 在授权之前立即请求加密凭证。每次调用都会从卡组织生成一个**全新的一次性**加密凭证：不存在幂等性，重复调用会返回新的加密凭证（不会发生资金流动）。
2. 将 `network_token.number`（DPAN）、`cryptogram` 和 `eci` 作为网络令牌交易提交给您的 PSP。
3. 如果授权已拒绝并且您要重试，请先请求一个**新的**加密凭证。已使用或过期的加密凭证无法重放。

## 仅加密凭证模式

发送 `include_network_token: false` 后，响应将完全省略 `network_token.number`（DPAN）和 `network_token.token_data`。`network_token` 对象会保留其不等同于 PAN 的元数据（`network`、`status`、`par`、`network_token_id`），响应照常包含 `cryptogram` 和 `eci`。由于不会返回等同于 PAN 的数据，此模式不需要 PCI 认证。

将其与 [Forward Proxy](https://docs.y.uno/zh-hans/docs/security-and-compliance/pci-proxy/forward-proxy.md) 结合使用，即可端到端地执行网络令牌交易，而等同于 PAN 的数据永远不会进入您的系统：

1. 使用 `include_network_token: false` 请求加密凭证。
2. 在目标方需要 DPAN 的位置，使用 `{{vaulted_token.<TOKEN>.network_token_number}}` 表达式（以及 `network_token_expiration_*` 表达式）构建转发请求。直接在请求体中包含 `cryptogram` 值，因为加密凭证按交易生成，代理不会将其作为表达式解析。
3. **立即**通过代理发送：代理在转发时解析卡片当前的 DPAN，而加密凭证绑定到特定的 DPAN。在转发之前立即请求加密凭证可以保持配对一致。如果延迟期间发生令牌轮换，两者将不匹配。

完整的条件矩阵：

| 您的组织 | `include_network_token` | 结果 |
| - | - | - |
| 已通过 PCI 认证 | `true` / 省略 | 完整响应（网络令牌 + 加密凭证） |
| 已通过 PCI 认证 | `false` | 仅加密凭证响应 |
| 未通过 PCI 认证 | `false` | 仅加密凭证响应 |
| 未通过 PCI 认证 | `true` / 省略 | `403 NETWORK_TOKEN_RETURN_NOT_ALLOWED` |

最后一行是有意设计的明确错误：期望响应中包含 `network_token` 的集成方会收到清晰的拒绝，而不会收到被静默降级的响应结构。

## 要求

要使用此 endpoint，您的组织必须：

* 已为您的组织**启用该产品**。
* 已针对卡片品牌和所请求的 `country` **完成网络令牌接入**。
* 是**通过 PCI 认证的商户**，才能在响应中接收网络令牌（DPAN）。[仅加密凭证模式](#cryptogram-only-mode)（`include_network_token: false`）不需要 PCI 认证。

`vaulted_token` 所引用的卡片必须是您组织的**已注册卡片**，并且已拥有**有效的网络令牌**。

支持的卡组织：**Visa** 和 **Mastercard**。

> [!NOTE]
>
> **何时不需要此 endpoint。** 定期的商户发起交易（MIT）使用网络令牌和存储的 `network_transaction_id` 进行授权，**不**需要加密凭证。此 endpoint 适用于需要全新加密凭证的客户发起交易。

## 加密凭证有效期

加密凭证是一次性的。请在授权之前立即请求，并且不要缓存。

`expires_at` 是卡组织接受该加密凭证的最晚时间。它是**加密凭证**的有效期，而不是网络令牌或卡片的有效期。

* **时间戳**（目前为 Mastercard）：请将其视为硬性期限。在 `expires_at` 之后提交的加密凭证会被拒绝。
* **`null`**（目前为 Visa）：卡组织未公布此加密凭证的有效期。这并不表示它永不过期。请立即使用。

在这两种情况下，请为每次授权尝试（包括重试）请求新的加密凭证。

## 错误

错误会返回 `code` 和 `messages` 数组。每个 `code` 对应的确切 `messages` 值：

| HTTP | `code` | `messages` |
| - | - | - |
| 404 | `PAYMENT_METHOD_NOT_FOUND` | "Payment method not found." |
| 400 | `INSTRUMENT_NOT_TOKENIZABLE` | "Payment method is not a card." |
| 400 | `PAYMENT_METHOD_NOT_ENROLLED` | "Payment method is not enrolled." |
| 400 | `NETWORK_TOKEN_NOT_FOUND` | "Payment method has no network token." |
| 400 | `TOKEN_NOT_ACTIVE` | "Network token is not active." |
| 400 | `NETWORK_NOT_SUPPORTED` | "Network token brand is not supported." |
| 400 | `COUNTRY_NOT_SUPPORTED` | "Country is not supported for this organization." |
| 400 | `INVALID_REQUEST` | 具体的无效字段，例如 "The field 'vaulted\_token' must be a valid uuid v4." |
| 403 | `PCI_MERCHANT_REQUIRED` | "This endpoint is only available to PCI-certified merchants." |
| 403 | `NETWORK_TOKEN_RETURN_NOT_ALLOWED` | "Returning the network token requires PCI certification. Send include\_network\_token: false to receive the cryptogram only, or contact your Key Account Manager (KAM)." |
| 403 | `PRODUCT_NOT_ENABLED` | "The Network Token Cryptogram API is enabled per organization. Contact your Key Account Manager (KAM) to activate it." |
| 502 | `PROVIDER_ERROR` | "The network token cryptogram service is temporarily unavailable, please retry." |

不存在的 `vaulted_token` 与属于其他组织的令牌都会返回相同的 `PAYMENT_METHOD_NOT_FOUND`，因此不会泄露其是否存在。


## OpenAPI

````yaml openapi/zh-hans/network-tokens/generate-network-token-cryptogram.json POST /network-tokens/cryptograms
openapi: 3.1.0
info:
  title: network-token-cryptogram
  version: 1.0.0
servers:
  - url: https://api-sandbox.y.uno/v1
    description: Sandbox
  - url: https://api.y.uno/v1
    description: Production (US)
security:
  - sec0: []
    sec1: []
paths:
  /network-tokens/cryptograms:
    post:
      summary: 生成网络令牌加密凭证
      description: >-
        为已存入 vault 的卡生成全新的一次性网络令牌加密凭证，使其可在外部 PSP
        上授权。默认情况下，响应还会包含该卡当前的网络令牌（DPAN），这需要 PCI 认证；如果设置 `include_network_token:
        false`，响应仅包含加密凭证，则无需 PCI 认证。
      operationId: generate-network-token-cryptogram
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - vaulted_token
                - country
              properties:
                vaulted_token:
                  type: string
                  format: uuid
                  description: >-
                    该卡的存储令牌，与 [Create
                    Payment](https://docs.y.uno/zh-hans/reference/payments/create-payment)
                    中用作 `payment_method.vaulted_token`
                    的标识符相同。该卡必须是您组织已注册的卡，并具有有效的网络令牌。
                  examples:
                    - 9b2f4b1c-7f3a-4c2e-9b1a-2b3c4d5e6f70
                country:
                  type: string
                  description: >-
                    令牌将在其使用的国家的 ISO 3166-1 alpha-2 国家代码。用于确定网络令牌的入网配置（组织 + 品牌 +
                    国家），语义与 Create Payment 中的 `country` 相同。
                  examples:
                    - US
                amount:
                  type: object
                  description: 可选。转发给卡组织；建议提供，因为某些卡组织流程会绑定金额。
                  properties:
                    currency:
                      type: string
                      description: ISO 4217 货币代码。
                      examples:
                        - USD
                    value:
                      type: number
                      description: 给定货币下的金额值。
                      examples:
                        - 49.99
                include_network_token:
                  type: boolean
                  default: true
                  description: >-
                    可选。响应是否包含网络令牌中等同于 PAN 的部分：`network_token.number`（DPAN）和
                    `network_token.token_data`。默认为 `true`，这要求您的组织是通过 PCI
                    认证的商户。发送 `false` 则响应仅含加密凭证，不含等同于 PAN 的数据（`network_token`
                    对象保留 `network`、`status`、`par` 和 `network_token_id`）：无需 PCI
                    认证即可使用，设计上与 [Forward
                    Proxy](https://docs.y.uno/zh-hans/docs/security-and-compliance/pci-proxy/forward-proxy)
                    搭配使用，后者在转发时通过 `network_token_number` 表达式解析 DPAN。未通过 PCI
                    认证的组织如果发送 `true` 或省略该字段，将收到 `403
                    NETWORK_TOKEN_RETURN_NOT_ALLOWED`。
                  examples:
                    - false
            examples:
              cryptogram_only:
                summary: Cryptogram-only (no PCI certification required)
                value:
                  vaulted_token: 9b2f4b1c-7f3a-4c2e-9b1a-2b3c4d5e6f70
                  country: US
                  amount:
                    currency: USD
                    value: 49.99
                  include_network_token: false
              default:
                summary: With the network token (PCI certification required)
                value:
                  vaulted_token: 9b2f4b1c-7f3a-4c2e-9b1a-2b3c4d5e6f70
                  country: US
                  amount:
                    currency: USD
                    value: 49.99
                  include_network_token: true
      responses:
        '201':
          description: 加密凭证已生成。
          content:
            application/json:
              schema:
                type: object
                properties:
                  vaulted_token:
                    type: string
                    description: 回显请求中的存储令牌。
                  network_token:
                    type: object
                    description: >-
                      该卡当前的网络令牌。结构与 PCI 网络令牌检索返回的相同。**当请求设置
                      `include_network_token: false` 时，`number`（DPAN）和
                      `token_data` 字段会被完全省略**，对象保留 `network`、`status`、`par` 和
                      `network_token_id`。
                    properties:
                      network:
                        type: string
                        description: 卡组织。
                        examples:
                          - VISA
                      number:
                        type: string
                        description: >-
                          当前的 DPAN（设备/网络 PAN）。**请始终将该值与返回的 `cryptogram`
                          一起提交**，切勿使用之前存储的 DPAN。
                        examples:
                          - '4111111111111111'
                      status:
                        type:
                          - string
                          - 'null'
                        description: 网络令牌状态。
                        examples:
                          - ACTIVE
                      par:
                        type:
                          - string
                          - 'null'
                        description: 支付账户参考（Payment Account Reference）。
                      network_token_id:
                        type:
                          - string
                          - 'null'
                        description: 网络令牌标识符。
                      token_data:
                        type: object
                        properties:
                          iin:
                            type: string
                          lfd:
                            type: string
                            description: DPAN 的后四位数字。
                          expiration_month:
                            type: integer
                            examples:
                              - 7
                          expiration_year:
                            type: integer
                            examples:
                              - 2029
                  cryptogram:
                    type: string
                    description: >-
                      卡组织生成的全新一次性加密凭证，每次调用都会生成。请将其与
                      `network_token.number`（DPAN）和 `eci` 一起提交给您的 PSP。
                    examples:
                      - AgAAAAAABk4DWZ4C28yUQAAAAAA=
                  eci:
                    type:
                      - string
                      - 'null'
                    description: 电子商务指示符（ECI）。对于某些 Mastercard DSRP 格式，可能为 `null`。
                    examples:
                      - '05'
                  created_at:
                    type: string
                    format: date-time
                    description: 签发时间戳（UTC）。
                  expires_at:
                    type:
                      - string
                      - 'null'
                    format: date-time
                    description: >-
                      卡组织接受该加密凭证的最晚时间（UTC）。它是加密凭证的有效期，而非网络令牌或卡的有效期。当卡组织未公布加密凭证的有效期时为
                      `null`（目前为 Visa）。无论哪种情况，每次授权尝试都应请求新的加密凭证，且不要缓存。
                    examples:
                      - '2026-07-21T14:32:10Z'
              examples:
                default:
                  summary: Visa, with the network token (PCI certification required)
                  value:
                    vaulted_token: 9b2f4b1c-7f3a-4c2e-9b1a-2b3c4d5e6f70
                    network_token:
                      network: VISA
                      number: '4111111111111111'
                      status: ACTIVE
                      par: V0010013022280191
                      network_token_id: DNITHE302344816910968
                      token_data:
                        iin: '411111'
                        lfd: '1111'
                        expiration_month: 7
                        expiration_year: 2029
                    cryptogram: AgAAAAAABk4DWZ4C28yUQAAAAAA=
                    eci: '05'
                    created_at: '2026-07-16T14:32:10Z'
                    expires_at: null
                cryptogram_only:
                  summary: 'Visa, cryptogram-only (include_network_token: false)'
                  value:
                    vaulted_token: 9b2f4b1c-7f3a-4c2e-9b1a-2b3c4d5e6f70
                    network_token:
                      network: VISA
                      status: ACTIVE
                      par: V0010013022280191
                      network_token_id: DNITHE302344816910968
                    cryptogram: AgAAAAAABk4DWZ4C28yUQAAAAAA=
                    eci: '05'
                    created_at: '2026-07-16T14:32:10Z'
                    expires_at: null
                mastercard_cryptogram_only:
                  summary: 'Mastercard, cryptogram-only (include_network_token: false)'
                  value:
                    vaulted_token: 9b2f4b1c-7f3a-4c2e-9b1a-2b3c4d5e6f70
                    network_token:
                      network: MASTERCARD
                      status: ACTIVE
                      par: '50010013022280191'
                      network_token_id: MDNITHE302344816910968
                    cryptogram: AgAAAAAABk4DWZ4C28yUQAAAAAA=
                    eci: '02'
                    created_at: '2026-07-16T14:32:10Z'
                    expires_at: '2026-07-21T14:32:10Z'
        '400':
          description: >-
            请求错误：`INVALID_REQUEST`、`INSTRUMENT_NOT_TOKENIZABLE`、`PAYMENT_METHOD_NOT_ENROLLED`、`NETWORK_TOKEN_NOT_FOUND`、`TOKEN_NOT_ACTIVE`、`NETWORK_NOT_SUPPORTED`
            或 `COUNTRY_NOT_SUPPORTED`。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                  messages:
                    type: array
                    items:
                      type: string
              examples:
                network_token_not_found:
                  value:
                    code: NETWORK_TOKEN_NOT_FOUND
                    messages:
                      - Payment method has no network token.
        '403':
          description: >-
            禁止访问：`NETWORK_TOKEN_RETURN_NOT_ALLOWED`（组织未通过 PCI 认证，且请求未设置
            `include_network_token: false`）、`PCI_MERCHANT_REQUIRED`（组织不是通过 PCI
            认证的商户）或 `PRODUCT_NOT_ENABLED`（该组织的产品开关已关闭）。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                  messages:
                    type: array
                    items:
                      type: string
              examples:
                network_token_return_not_allowed:
                  value:
                    code: NETWORK_TOKEN_RETURN_NOT_ALLOWED
                    messages:
                      - >-
                        Returning the network token requires PCI certification.
                        Send include_network_token: false to receive the
                        cryptogram only, or contact your Key Account Manager
                        (KAM).
                pci_merchant_required:
                  value:
                    code: PCI_MERCHANT_REQUIRED
                    messages:
                      - >-
                        This endpoint is only available to PCI-certified
                        merchants.
        '404':
          description: >-
            未找到：`PAYMENT_METHOD_NOT_FOUND`。`vaulted_token`
            不存在或不属于您的组织（响应相同，不会泄露是否存在）。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                  messages:
                    type: array
                    items:
                      type: string
              examples:
                payment_method_not_found:
                  value:
                    code: PAYMENT_METHOD_NOT_FOUND
                    messages:
                      - Payment method not found.
        '502':
          description: >-
            服务提供商错误：`PROVIDER_ERROR`。无法连接卡组织（Visa VTS / Mastercard
            MDES），或其返回了错误。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                  messages:
                    type: array
                    items:
                      type: string
              examples:
                provider_error:
                  value:
                    code: PROVIDER_ERROR
                    messages:
                      - >-
                        The network token cryptogram service is temporarily
                        unavailable, please retry.
components:
  securitySchemes:
    sec0:
      type: apiKey
      in: header
      name: public-api-key
      x-default: <Your public-api-key>
    sec1:
      type: apiKey
      in: header
      name: private-secret-key
      x-default: <Your private-secret-key>

````

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