# 订阅取消通知

> 接收订阅取消生效后的通知，按合约号关联订阅并应答。

```yaml
openapi: 3.1.0
x-onerway-docs-version: original
x-onerway-spec-key: payments/webhooks/subscription-canceled
info:
  title: 订阅取消通知
  version: original
  description: 接收订阅取消生效后的通知，按合约号关联订阅并应答。
webhooks:
  subscription.canceled:
    post:
      summary: 订阅取消通知
      description: 接收订阅取消生效后的通知，按合约号关联订阅并应答。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                notifyType:
                  type: string
                  description: 通知类型，固定为 `SUBSCRIPTION_CANCELED`。
                  x-onerway-signature-participation: included
                transactionId:
                  type: string
                  description: 本次取消通知中的 Onerway 标识。应答时在响应体中原样返回收到的该字段值。
                  x-onerway-signature-participation: included
                merchantNo:
                  type: string
                  description: Onerway 分配的商户号。
                  x-onerway-signature-participation: included
                responseTime:
                  type: string
                  description: 通知结果时间，格式为 `yyyy-MM-dd HH:mm:ss`。
                  x-onerway-signature-participation: included
                txnTime:
                  type: string
                  description: 通知中记录的操作时间，格式为 `yyyy-MM-dd HH:mm:ss`。
                  x-onerway-signature-participation: included
                txnTimeZone:
                  type: string
                  description: "`txnTime` 使用的时区偏移。"
                  x-onerway-signature-participation: included
                status:
                  type: string
                  description: 取消结果，取消成功时固定为 `S`。
                  x-onerway-signature-participation: included
                contractId:
                  type: string
                  description: 已取消的订阅合约号，用于关联商户侧的订阅记录。
                  x-onerway-signature-participation: included
                sign:
                  type: string
                  description: 请求体签名，不参与签名计算。请按[请求签名](/zh/payments/get-started/request-signing#webhook-验签)中的规则，使用
                    `X-Rh-Signature` 请求头验证通知。
                  x-onerway-signature-participation: signature-field
                subscriptionExpireDate:
                  type: string
                  description: 通知中携带的订阅到期日期，格式为 `yyyy-MM-dd`。不要仅据此日期判断取消是否生效，应查看
                    `subscriptionStatus`。
                  x-onerway-signature-participation: included
                subscriptionStatus:
                  type: string
                  description: 订阅生命周期状态，取消生效后固定为 `canceled`。
                  x-onerway-signature-participation: included
                dataStatus:
                  type: string
                  description: 已取消订阅的合约状态，固定为 `3`。
                  x-onerway-signature-participation: included
                products:
                  type: string
                  description: 以 JSON 字符串表示的订阅商品信息，商品条目包含 `name`、`price`、`num` 和
                    `currency`。计算签名时使用收到的原始字符串，不要解析后重新序列化。
                  x-onerway-signature-participation: included
                scenarios:
                  type: string
                  description: 订阅事件，固定为 `SUBSCRIPTION_CANCELED`。
                  x-onerway-signature-participation: included
            examples:
              subscription_canceled:
                summary: 订阅立即取消
                value:
                  notifyType: SUBSCRIPTION_CANCELED
                  transactionId: example_subscription_contract
                  merchantNo: replace_with_merchant_no
                  responseTime: 2026-09-29 00:00:03
                  txnTime: 2026-09-29 00:00:03
                  txnTimeZone: +08:00
                  status: S
                  contractId: example_subscription_contract
                  sign: replace_with_signature
                  subscriptionExpireDate: 2099-12-31
                  subscriptionStatus: canceled
                  dataStatus: "3"
                  products: '[{"name": "example_membership", "price": "0.99", "num": "1",
                    "currency": "USD"}]'
                  scenarios: SUBSCRIPTION_CANCELED
                x-onerway-headers:
                  X-Rh-Signature: v1=replace_with_signature
      responses:
        "200":
          description: "成功接收并受理通知后，返回 HTTP 200，使用 `Content-Type: text/plain`，并在响应体中原样返回收到的
            `transactionId`。"
          content:
            text/plain:
              schema:
                type: string
              examples:
                return_transaction_id:
                  summary: 返回 transactionId
                  value: example_subscription_contract
      x-onerway-verification:
        scheme: header-sign
        header: X-Rh-Signature
        version: v1
        algorithm: sha256
        rule: acquiring-sorted-concat-secret
        reference: /zh/payments/get-started/request-signing
      x-onerway-header-fields:
        - name: X-Rh-Signature
          schema:
            type: string
            description: 用于验证本通知的签名，包含逗号分隔的一项或多项 `v1=<签名>`。
        - name: x-signature
          schema:
            type: string
            description: 同时提供的签名请求头，格式和签名规则与 `X-Rh-Signature` 相同。
      x-onerway-destination:
        description: 通知发送至原交易请求中的 `notifyUrl`。
```
