# 申请或取消退款

> 对已支付成功的交易发起退款，或取消已提交的退款申请。

```yaml
openapi: 3.1.0
info:
  title: 申请或取消退款
  version: 1.0.0
  description: 对已支付成功的交易发起退款，或取消已提交的退款申请。
paths:
  /v1/txn/onlineRefund:
    post:
      summary: 申请或取消退款
      description: 对已支付成功的交易发起退款，或取消已提交的退款申请。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                merchantNo:
                  type: string
                  description: Onerway 分配的商户号；获取方式参见[接入准备](/zh/payments/get-started/setup#获取凭证)。
                refundType:
                  type: string
                  description: 退款操作类型：申请退款或取消已提交的退款申请。
                  enum:
                    - "0"
                    - "1"
                  x-enum-descriptions:
                    "0": 申请退款。
                    "1": 取消退款申请。
                  x-onerway-constraints:
                    - kind: rule
                      text: 是否支持退款、部分退款及多次退款，以及申请退款的时限，均取决于支付方式。大多数支付方式支持部分退款及多次退款。
                    - kind: rule
                      text: 取消退款申请须在 Onerway 审核通过前发起。审核通过后，Onerway 将退款请求提交给支付渠道或发卡行；退款仍在处理中不代表仍可取消。
                merchantTxnId:
                  type: string
                  description: 本次退款的商户交易号，用于跟踪和对账。
                  x-onerway-constraints:
                    - kind: rule
                      text: 不传时由 Onerway 自动生成。重复提交会被拒绝。
                originTransactionId:
                  type: string
                  description: 本次退款操作对应的 Onerway 交易号。
                  x-onerway-constraints:
                    - kind: rule
                      text: "`refundType=0`（申请退款）时，传入原支付交易号；`refundType=1`（取消退款申请）时，传入要取消的退款交易号。"
                refundAmount:
                  type: string
                  description: 退款金额。
                  x-onerway-constraints:
                    - kind: consistency
                      text: 退款金额使用原支付交易的币种。
                    - kind: consistency
                      text: 累计退款金额不得超过支付金额。
                sign:
                  type: string
                  description: 请求签名字符串；生成方式详见[请求签名](/zh/payments/get-started/request-signing)。
              required:
                - merchantNo
                - refundType
                - originTransactionId
                - refundAmount
                - sign
            examples:
              create-refund:
                summary: 申请退款
                value:
                  merchantNo: demo_merchantNo
                  refundType: "0"
                  merchantTxnId: demo_refund_merchant_txn_id
                  originTransactionId: demo_payment_transaction_id
                  refundAmount: "20"
                  sign: replace_with_signature
              cancel-refund:
                summary: 取消退款申请
                value:
                  merchantNo: demo_merchantNo
                  refundType: "1"
                  merchantTxnId: demo_cancel_merchant_txn_id
                  originTransactionId: demo_refund_transaction_id
                  refundAmount: "20"
                  sign: replace_with_signature
      responses:
        "200":
          description: 退款申请已受理
          content:
            application/json:
              schema:
                type: object
                properties:
                  respCode:
                    type: string
                    description: "`refundType=0` 时，`20000`
                      表示退款申请已受理，不代表退款成功。请处理[退款结果通知](/zh/payments/api-reference/\
                      webhooks/refund-result)或[退款审核拒绝通知](/zh/payments/api-refer\
                      ence/webhooks/refund-audit-rejected)；未收到通知时可[查询退款记录](/zh/\
                      payments/api-reference/endpoints/query-refunds)。取消退款申请（`r\
                      efundType=1`）成功不发送通知。其他响应码见[响应码](/zh/payments/api-referen\
                      ce/response-codes)。"
                    x-onerway-constraints:
                      - kind: rule
                        text: 大部分退款即时到账；非即时到账的退款最长需要 25 天。
                  respMsg:
                    type: string
                    description: 响应码对应的可读消息。
                  data:
                    type: string
                    description: 退款交易号。
                    x-onerway-constraints:
                      - kind: rule
                        text: "`refundType=0`（申请退款）返回 Onerway 新创建的退款交易号；`refundType=1` 取消成功时，该值等于请求中的
                          `originTransactionId`。"
              examples:
                refund-accepted:
                  summary: 退款申请已受理
                  value:
                    respCode: "20000"
                    respMsg: Success
                    data: demo_refund_transaction_id
                refund-cancelled:
                  summary: 退款申请已取消
                  value:
                    respCode: "20000"
                    respMsg: Success
                    data: demo_refund_transaction_id
```
