> ## 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 概览

> 说明 webhook 如何订阅事件，以及 Yuno 在投递事件时如何向您的 endpoint 进行身份验证

Webhook 告诉 Yuno 将事件通知发送到哪里（`url`）、发送哪些事件（触发器），以及 Yuno 在投递事件时应如何向您的 endpoint 进行身份验证。同样的配置也可以在 [Yuno Dashboard](https://docs.y.uno/zh-hans/docs/webhooks/configure-webhooks.md) 中完成。

每个请求都必须提供 `account_id`：`POST` 和 `PATCH` 请求放在请求体中，`GET` 和 `DELETE` 请求作为查询参数传入。您只能管理您自己组织中各账户的 webhook。

## 密钥

密钥是只写的。`api_key`、`secret`、`hmac_client_secret` 和 `oauth2_client_secret` 配置后以 `***` 返回，未配置时返回 `null`。

如需保持某个密钥不变，请在更新时省略它。回传掩码值会将 `***` 本身存储为密钥，发送空字符串则会移除该密钥。

## 触发器

Webhook 通过 5 个触发器字段订阅事件，每个领域一个字段，并且至少需要一个触发器。带有 `payment_triggers: ["AUTHORIZE"]` 的 webhook 会在支付获得授权时收到通知。请将每个触发器放在其所属领域的字段中，因为正是该字段让 webhook 订阅这一类事件。有关每个字段接受的所有值及其对应的事件，请参阅 [事件和触发器](https://docs.y.uno/zh-hans/docs/webhooks/events.md)；有关每个事件携带的 payload，请参阅 [Payload 与示例](https://docs.y.uno/zh-hans/docs/webhooks/object-and-examples.md)。

| 字段 | 订阅内容 |
| :- | :- |
| `enrollment_triggers` | 支付方式的注册和取消注册 |
| `payment_triggers` | 支付生命周期事件（授权、捕获、退款等） |
| `subscription_triggers` | 订阅生命周期事件 |
| `onboarding_triggers` | Onboarding 生命周期事件 |
| `report_triggers` | 报告生命周期事件 |

`renewal_days` 用于设置 Yuno 在续订前多少天发送 `CLOSE_TO_RENEWAL` 通知，仅当 `subscription_triggers` 包含 `CLOSE_TO_RENEWAL` 时有效。

## 投递认证

这是 Yuno 在发送事件时向您的 endpoint 进行身份验证的方式，以便您的接收端区分真实通知和伪造通知。所有方式均为可选，并且可以组合使用。

### API 密钥和 secret

配置 `api_key` 和 `secret`。Yuno 会在每次投递时将它们作为标头发送，您的 endpoint 需检查它们是否与您的配置一致。

```http theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
x-api-key: <api_key>
x-secret:  <secret>
```

### HMAC 签名

配置 `hmac_client_secret`。Yuno 使用它对 payload 进行签名，并将签名作为标头发送，以便您验证通知是否真实且未被篡改。

Webhook 的身份验证（包括 `hmac_client_secret`）作用于 webhook 对象本身，而不是某个特定的支付服务提供商连接。如果您的账户通过多个 PSP 连接路由支付，单个 webhook 仍会以相同方式为所有连接投递事件并签名，不会为每个连接单独设置密钥。只有在需要将事件分发到不同 endpoint 时才配置多个 webhook，而不是为了按服务提供商进行区分。

```http theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
x-hmac-signature: Base64(
  HMAC-SHA256(key = hmac_client_secret, msg = <raw request body>)
)
```

有关如何计算和检查此签名，请参阅 [验证 Webhook 签名（HMAC）](https://docs.y.uno/zh-hans/docs/webhooks/verify-webhook-signatures-hmac.md)。

### OAuth2

配置您的令牌 endpoint 和客户端凭证。在投递之前，Yuno 会向您的 endpoint 请求令牌，并以 `Authorization: Bearer <token>` 的形式发送。

您的令牌 endpoint 必须使用 HTTPS。Yuno 会在一个账户的多次投递之间复用同一令牌，直到其即将过期，因此有效期很短的令牌意味着几乎每次投递都会发起一次令牌请求。

| 字段 | 描述 |
| :- | :- |
| `oauth2_authentication_url` | 您的令牌 endpoint，通过 HTTPS 访问。 |
| `oauth2_client_id` | Yuno 进行身份验证时使用的客户端标识符。 |
| `oauth2_client_secret` | Yuno 进行身份验证时使用的客户端密钥。 |
| `oauth2_grant_type` | Yuno 请求令牌时使用的授权类型，通常为 `client_credentials`。 |
| `oauth2_scope` | Yuno 请求令牌时使用的范围。请通过 [更新 Webhook](https://docs.y.uno/zh-hans/reference/webhooks/update-webhook.md) 进行设置。 |
| `oauth2_authorization_name` | Yuno 发送令牌时使用的标头。默认为 `Authorization`。 |
| `oauth2_include_client_id` | 在令牌请求中也将客户端标识符作为标头发送。 |

请同时发送 `oauth2_authentication_url`、`oauth2_client_id`、`oauth2_client_secret` 和 `oauth2_grant_type`，因为它们作为一组进行配置。


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