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

# 登记试运行服务提供商事件

> 登记服务提供商的请求、响应或 webhook payload，用于上线前验证。

试运行是一个上线前验证接口。它接收您的集成发送给支付服务提供商的 API 调用（请求、响应和 webhook payload），并将其与您在设置 `X-Dry-Run: true` 标头后**并行**发起的对应 Yuno 公共 API 调用相关联。

随后，Yuno 会执行自动化验证流水线，对照服务提供商 payload 评估公共 API 请求的质量：缺失字段、结构不匹配、错误的枚举值、未映射的元数据，以及任何会在您正式上线后导致真实支付失败或行为不同的其他不一致之处。

### 配对的工作方式

1. 您的集成照常调用服务提供商（例如 Stripe、Adyen、dlocal）。
2. 您的集成同时调用相应的 Yuno 公共 API endpoint（例如 `POST /v1/payments`），并带上标头 **`X-Dry-Run: true`**。Yuno 接受该请求，不会将其路由到任何服务提供商，而是存储下来用于比对。
3. 您的集成调用 `POST /v1/dry-run/provider-events`，传入刚刚完成的原始服务提供商交互（请求、响应、webhook），并关联到同一个 `merchant_reference`。
4. Yuno 通过 `merchant_reference` + `account_id` 将两条记录配对，并运行验证流水线。结果可通过 Dashboard 以及 `GET /v1/dry-run/provider-events/{id}`（读取 API，另有参考文档）获取。

结果会告诉您：在 Yuno 开始路由该请求后，您当前构建的公共 API 请求是否会产生相同的服务提供商行为，整个过程不会动用生产环境资金，也不会通过 Yuno 向服务提供商发送真实交易。

### 使用场景

* **上线前**：对照您已正常运行的服务提供商行为，认证您的公共 API 集成。
* **服务提供商迁移**：在切换流量之前，验证新的服务提供商是否接受 Yuno 转发的字段。
* **回归检查**：在 CI 中重新运行试运行，以便在您的集成或服务提供商的契约发生变化时发现偏差。

> [!NOTE]
>
> 一次调用最多可携带 **10** 个事件条目（REQUEST、RESPONSE 和/或 WEBHOOK），它们都通过 `merchant_reference` 关联到同一笔支付。请参阅[关联规则](#correlation)。

> [!NOTE]
>
> 此 endpoint 有一个配套接口：`POST /v1/payments` 接受 `X-Dry-Run: true` 请求标头，告知 Yuno 执行验证而不是路由。两端必须使用相同的 `merchant_reference`，验证才能将它们配对。

> [!NOTE]
>
> 使用 `X-Idempotency-Key` 安全地重试。相同的键 + 相同的 payload 会返回原始响应；相同的键 + 不同的 payload 会返回 `409`。

> [!WARNING]
>
> **PCI 边界**
>
> `headers` 和 `body` 以 **base64 编码**形式发送。Yuno 在接收时进行 base64 解码，执行确定性的 PAN/CVV/授权令牌脱敏，并且只持久化脱敏后的数据。请参阅 [PCI 合规](https://docs.y.uno/zh-hans/docs/security-and-compliance/pci-compliance.md)。

***

## 关联

* `merchant_reference` 始终必填，用于在您这一侧唯一标识订单。未提供 `payment_id` 时，Yuno 会使用它将事件异步解析到对应的支付。
* 如果提供了 `payment_id`，则会立即解析。如果该 id 在您的账户中不存在，请求会返回 `404 PAYMENT_NOT_FOUND`。
* `provider_id` + `payment_method_type` 可选，用于标识试运行所测试的集成接口（例如 `stripe` + `CREDIT_CARD`）。如果省略，Yuno 会使用关联支付中的信息。


## OpenAPI

````yaml openapi/zh-hans/dry-run/register-dry-run-provider-event.json POST /dry-run/provider-events
openapi: 3.1.0
info:
  title: Yuno Dry-Run API
  version: '1.0'
servers:
  - url: https://api-sandbox.y.uno/v1
    description: Sandbox
  - url: https://api.y.uno/v1
    description: Production (US)
security: []
paths:
  /dry-run/provider-events:
    post:
      summary: 注册服务提供商的请求 / 响应 / webhook payload
      description: |
        存储商户与支付服务提供商之间直接交换的
        HTTP 流量（请求、响应和 webhook），以便与 Yuno 支付进行关联。
      operationId: registerDryRunProviderEvent
      parameters:
        - in: header
          name: PUBLIC-API-KEY
          schema:
            type: string
          description: 公钥 API 密钥。PUBLIC-API-KEY / PRIVATE-SECRET-KEY 中必须提供其一。
        - in: header
          name: PRIVATE-SECRET-KEY
          schema:
            type: string
          description: 用于服务器到服务器调用的私有密钥。PUBLIC-API-KEY / PRIVATE-SECRET-KEY 中必须提供其一。
        - in: header
          name: X-Idempotency-Key
          schema:
            type: string
            maxLength: 64
          description: 自由格式字符串（最大 64）。24 小时重放窗口。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DryRunRequest'
      responses:
        '201':
          description: 试运行已注册
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DryRunResponse'
        '400':
          description: 验证失败
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: 缺少凭证或凭证无效
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: 未找到支付
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: 幂等性重放，但 payload 不同
        '413':
          description: Payload 或批次超出大小限制
        '415':
          description: 不支持的 Content-Type（必须为 application/json）
        '429':
          description: 超出速率限制
components:
  schemas:
    DryRunRequest:
      type: object
      required:
        - merchant_reference
        - events
      properties:
        merchant_reference:
          type: string
          minLength: 3
          maxLength: 255
          description: 商户分配的标识符（最大 255；最小 3）。在每个账户内唯一。
          example: ORD-12345
        payment_id:
          type: string
          format: uuid
          description: Yuno 支付 UUID。如果提供，会立即解析。
          example: fb9e5fa4-684c-4747-9755-9d332617f16f
        account_id:
          type: string
          format: uuid
          description: Yuno 账户 UUID，与 POST /v1/payments 中的 account_id 结构相同。
          example: a389f417-ecd1-4355-89f5-7489564f264d
        provider_id:
          type: string
          description: 服务提供商标识符。允许的值与 Yuno 目录保持一致。
          example: STRIPE
          enum:
            - STRIPE
            - ADYEN
            - CYBERSOURCE
            - BRAINTREE
            - NMI
            - CHECKOUT
            - WORLDPAY
            - PAYPAL
            - EBANX
            - GLOBALPAYMENTS
            - NUVEI
            - CIELO
            - MPGS
            - PRISMA
            - FISERV
            - WORLDLINE
            - ANTOM
            - ORBITAL
            - GOCARDLESS
            - AUTHORIZE_NET
            - SONY
            - CITI
            - EPX
            - HPAY
            - PAYSTACK
            - PLAID
            - SAFERPAY
            - SIKA_HEALTH
            - VALIDIFI
            - WEPAY
            - CARD_CONNECT
            - GMO_PG
            - MONERIS
            - BLUESNAP
            - QUICK_GATEWAY
            - TWENTYFOUR_HOUR_FITNESS
            - MERCHANT_ESOLUTIONS
            - NETS
            - FAT_ZEBRA
            - WINDCAVE
            - CHASE_MOBILITY
            - HELIX
            - ANB
            - AMAZON_PAY
            - OPAYO
            - IP_PAYMENTS
            - KLARNA
            - BILLDESK
            - WELLS_FARGO
            - SAGEPAY
            - PLANET
        payment_method_type:
          type: string
          description: 此次试运行所使用的支付方式。词汇表与 POST /v1/payments 中的 payment_method.type 相同。
          example: CREDIT_CARD
          enum:
            - ''
            - CARD
            - CREDIT_CARD
            - CREDIT_CARD_REFERENCE_TRANSACTION
            - DEBIT_CARD
            - EPX_TOKEN
            - TEST_CREDIT_CARD
            - UPC_TOKEN_TRANSACTION
            - APPLE_PAY
            - GOOGLE_PAY
            - PIX
            - PSE
            - OXXO
            - BOLETO
            - ALI_PAY
            - AMAZON_PAY
            - GCASH
            - IDEAL
            - KAKAO_PAY
            - KLARNA
            - MOMO_PAY
            - NAVER_PAY
            - OVO
            - PAYPAL
            - PAYPAL_CREDIT
            - PAYPAY
            - PAZE
            - TOSS_PAY
            - UPI
            - VENMO
            - ACH
            - BANK_TRANSFER
            - CRYPTO
            - CASH
        events:
          type: array
          minItems: 1
          maxItems: 10
          description: 此次试运行的 1 到 10 个 HTTP 交换条目（最大 10；最小 1）。
          items:
            $ref: '#/components/schemas/Event'
          example:
            - type: REQUEST
              http_method: POST
              operation_type: PURCHASE
              base_url: https://api.stripe.com
              endpoint: /v1/charges
              headers: eyBDb250ZW50LVR5cGU6IGFwcGxpY2F0aW9uL2pzb24gfQ==
              body: eyBhbW91bnQ6IDIwMDAsIGN1cnJlbmN5OiAidXNkIiB9
    DryRunResponse:
      type: object
      required:
        - id
        - status
        - merchant_reference
      properties:
        id:
          type: string
          description: 试运行注册的公开标识符（nano_id，21 个字符）。
          example: drun_1209fnkw428ufwd
        status:
          type: string
          enum:
            - REGISTERED
          description: 生命周期状态。
          example: REGISTERED
        merchant_reference:
          type: string
          example: ORD-12345
        payment_id:
          type: string
          format: uuid
          nullable: true
          example: fb9e5fa4-684c-4747-9755-9d332617f16f
        account_id:
          type: string
          format: uuid
          nullable: true
          example: a389f417-ecd1-4355-89f5-7489564f264d
        provider_id:
          type: string
          example: STRIPE
        payment_method_type:
          type: string
          example: CARD
          enum:
            - ''
            - CARD
            - CREDIT_CARD
            - CREDIT_CARD_REFERENCE_TRANSACTION
            - DEBIT_CARD
            - EPX_TOKEN
            - TEST_CREDIT_CARD
            - UPC_TOKEN_TRANSACTION
            - APPLE_PAY
            - GOOGLE_PAY
            - PIX
            - PSE
            - OXXO
            - BOLETO
            - ALI_PAY
            - AMAZON_PAY
            - GCASH
            - IDEAL
            - KAKAO_PAY
            - KLARNA
            - MOMO_PAY
            - NAVER_PAY
            - OVO
            - PAYPAL
            - PAYPAL_CREDIT
            - PAYPAY
            - PAZE
            - TOSS_PAY
            - UPI
            - VENMO
            - ACH
            - BANK_TRANSFER
            - CRYPTO
            - CASH
        operation_type:
          type: string
          example: PURCHASE
    Error:
      type: object
      required:
        - code
        - messages
        - httpCode
      properties:
        code:
          type: string
          description: 稳定的错误代码。
          enum:
            - NOT_AUTHENTICATED
            - AuthenticationFail
            - INVALID_PARAMETERS
            - TRAFFIC_LOG_VALIDATION_FAILED
            - TRAFFIC_LOG_MERCHANT_REFERENCE_REQUIRED
            - TRAFFIC_LOG_BODY_ENCODING_MISMATCH
            - TRAFFIC_LOG_IDEMPOTENCY_REPLAY
            - TRAFFIC_LOG_PAYLOAD_TOO_LARGE
            - TRAFFIC_LOG_UNSUPPORTED_CONTENT_TYPE
            - TRAFFIC_LOG_SEMANTIC_INVALID
            - PAYMENT_NOT_FOUND
            - RATE_LIMITED
        messages:
          type: array
          items:
            type: string
          description: 可读的错误详情。
        httpCode:
          type: integer
          format: int32
    Event:
      type: object
      required:
        - type
        - http_method
        - operation_type
        - headers
      properties:
        type:
          type: string
          enum:
            - REQUEST
            - RESPONSE
            - WEBHOOK
          description: 此条目所捕获的交换环节。
          example: REQUEST
        http_method:
          type: string
          enum:
            - GET
            - POST
            - PUT
            - PATCH
            - DELETE
          example: POST
        operation_type:
          type: string
          enum:
            - PURCHASE
            - AUTHORIZE
            - CAPTURE
            - CANCEL
            - REFUND
            - CHARGEBACK
            - THREE_D_SECURE
          description: 标识所模拟的支付操作类型。
          example: PURCHASE
        base_url:
          type: string
          format: uri
          description: >-
            REQUEST 和 WEBHOOK 必填。服务提供商 endpoint 的来源：协议 + 主机 + 端口（例如
            https://api.stripe.com）。
          example: https://api.stripe.com
        endpoint:
          type: string
          description: REQUEST 和 WEBHOOK 必填。路径和查询部分（例如 /v1/charges?expand=customer）。
          example: /v1/charges
        http_status_code:
          type: integer
          format: int32
          minimum: 100
          maximum: 599
          description: RESPONSE 和 WEBHOOK 必填。REQUEST 时省略。
        headers:
          type: string
          format: byte
          maxLength: 87400
          description: |
            经 Base64 编码的标头 payload。解码后的内容可以是 JSON 序列化的
            `{header-name: header-value}` 映射，也可以是原始 HTTP 标头块。硬性
            上限：每个事件解码后 64 KB。
          example: eyBDb250ZW50LVR5cGU6IGFwcGxpY2F0aW9uL2pzb24gfQ==
        body:
          type: string
          format: byte
          maxLength: 1398000
          description: |
            经 Base64 编码的正文 payload。正文为空时省略。硬性上限：每个事件
            解码后 1 MB。对于非 UTF-8 正文（protobuf、gzip），
            请直接对原始字节进行 base64 编码。
          example: eyBhbW91bnQ6IDIwMDAsIGN1cnJlbmN5OiAidXNkIiB9

````

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