# Create or cancel refund

> Create a refund request or cancel a submitted refund request for a paid transaction.

```yaml
openapi: 3.1.0
info:
  title: Create or cancel refund
  version: 1.0.0
  description: Create a refund request or cancel a submitted refund request for a
    paid transaction.
paths:
  /v1/txn/onlineRefund:
    post:
      summary: Create or cancel refund
      description: Create a refund request or cancel a submitted refund request for a
        paid transaction.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                merchantNo:
                  type: string
                  description: Merchant number assigned by Onerway. See
                    [Setup](/payments/get-started/setup#retrieve-your-credentials)
                    for how to obtain it.
                refundType:
                  type: string
                  description: "Refund operation type: create a refund request or cancel a
                    submitted request."
                  enum:
                    - "0"
                    - "1"
                  x-enum-descriptions:
                    "0": Create a refund request.
                    "1": Cancel a submitted refund request.
                  x-onerway-constraints:
                    - kind: rule
                      text: Refund availability, support for partial or multiple refunds, and the
                        refund request time limit depend on the payment method.
                        Most payment methods support partial and multiple
                        refunds.
                    - kind: rule
                      text: Submit a cancellation before Onerway approves the refund request. After
                        approval, Onerway submits the request to the payment
                        channel or card issuer. A processing status alone does
                        not mean that the refund request can still be cancelled.
                merchantTxnId:
                  type: string
                  description: Merchant transaction number for this refund, used for tracking and
                    reconciliation.
                  x-onerway-constraints:
                    - kind: rule
                      text: Onerway generates this identifier if it is omitted. Duplicate submissions
                        are rejected.
                originTransactionId:
                  type: string
                  description: Original Onerway transaction number associated with this refund
                    operation.
                  x-onerway-constraints:
                    - kind: rule
                      text: For `refundType=0`, provide the transaction ID of the original payment.
                        For `refundType=1`, provide the transaction ID of the
                        refund request to cancel.
                refundAmount:
                  type: string
                  description: Amount to refund.
                  x-onerway-constraints:
                    - kind: consistency
                      text: The refund amount is expressed in the original payment currency.
                    - kind: consistency
                      text: The total amount refunded across all refunds must not exceed the payment
                        amount.
                sign:
                  type: string
                  description: Request signature string. See [Request
                    signing](/payments/get-started/request-signing) for how to
                    generate it.
              required:
                - merchantNo
                - refundType
                - originTransactionId
                - refundAmount
                - sign
            examples:
              create-refund:
                summary: Create a refund request
                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: Cancel a refund request
                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: Refund request accepted
          content:
            application/json:
              schema:
                type: object
                properties:
                  respCode:
                    type: string
                    description: For `refundType=0`, `20000` means the refund request was accepted,
                      not that the refund succeeded. Handle the [Refund result
                      webhook](/payments/api-reference/webhooks/refund-result)
                      or [Refund request rejection
                      webhook](/payments/api-reference/webhooks/refund-audit-rejected);
                      use [Query
                      refunds](/payments/api-reference/endpoints/query-refunds)
                      if no notification arrives. A successful cancellation
                      (`refundType=1`) does not trigger a notification. Other
                      response codes are listed in [Response
                      codes](/payments/api-reference/response-codes).
                    x-onerway-constraints:
                      - kind: rule
                        text: Most refunds are credited immediately. Other refunds can take up to 25
                          days.
                  respMsg:
                    type: string
                    description: Human-readable message for the response code.
                  data:
                    type: string
                    description: Refund transaction number.
                    x-onerway-constraints:
                      - kind: rule
                        text: For `refundType=0`, this is the newly created Onerway refund transaction
                          number. For a successful cancellation
                          (`refundType=1`), this equals `originTransactionId` in
                          the request.
              examples:
                refund-accepted:
                  summary: Refund request accepted
                  value:
                    respCode: "20000"
                    respMsg: Success
                    data: demo_refund_transaction_id
                refund-cancelled:
                  summary: Refund request cancelled
                  value:
                    respCode: "20000"
                    respMsg: Success
                    data: demo_refund_transaction_id
```
