> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tesouro.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Refund a transaction

> Issue a full or partial refund to return funds to a customer after a transaction has been captured, such as for returns or billing errors.

The process of sending money back to a customer who has returned a purchase or no longer wants to receive services.

<Tip type="when to use">
  **When to Use**

  <ul>
    <li>
      A customer returns a product or cancels a service after you've already
      captured payment.
    </li>

    <li>
      You need to issue a full or partial refund for a completed transaction.
    </li>

    <li>
      You've made a billing error and need to return funds to the customer.
    </li>
  </ul>
</Tip>

<Callout icon="clapperboard-play" color="#6938EF" type="scenario">
  **Scenario**

  Ben returns two items he purchased with his card ending in 4242 from a Maple Street Coffee, one of Clearpath Payment's acceptors. Upon receiving the merchandise, Clearpath Payments verifies the original order number and issues a \$300 refund back to Ben's card on behalf of Maple Street Coffee.
</Callout>

### Steps

1. Retrieve the `paymentId` from the original transaction. This is how we link the refund to the previous payment.

2. Call the [refundPreviousPayment](/acquiring/reference/graphql/operations/refundpreviouspayment) mutation, passing in the required input fields:

   | Required input             | Description                                                                                                                                                                                             |
   | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
   | `paymentId`                | The unique "payment ID" returned on the original, approved transaction, used to tie that transactions together.                                                                                         |
   | `acceptorId`               | The unique, 36 character identifier assigned to the entity providing the goods or services to the customer. Other processors may refer to this as the Merchant ID (MID), Outlet ID, or Customer number. |
   | `transactionReference`     | The unique transaction identifier created by YOU to distinguish this transaction from another.                                                                                                          |
   | `transactionAmountDetails` | The transaction currency and amount to be refunded. You can refund the full amount or only a portion of it. If you do not specify an amount, Tesouro will by default refund the full amount.            |

<RequestExample>
  ```graphql Operation lines expandable theme={null}
  mutation refundPreviousPayment($input: RefundPreviousPaymentInput!) {
    refundPreviousPayment(refundPreviousPaymentInput: $input) {
      refundPreviousPaymentResponse {
        status: __typename
        activityDate
        transactionId
        paymentId
        activityDate
      }
      errors {
        errorType: __typename
        ... on RuleInViolationError {
          advice
          explanationOfRule
          ruleName
        }
        ... on ValidationFailureError {
          fieldName
          fieldPath
          valueInError
        }
        ... on IGraphQlError {
          message
          transactionId
          processorResponseCode
        }
      }
    }
  }
  ```

  ```json Variables lines theme={null}
  {
    "input": {
      "acceptorId": "05a39b14-f29f-443b-a107-da3e3e8969fb",
      "transactionReference": "8675309",
      "paymentId": "b2a92262-4c17-11ee-900c-7944c7cf2a3c",
      "transactionAmountDetails": {
        "totalAmount": 50,
        "currency": "USD"
      }
    }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Response lines theme={null}
  {
    "data": {
      "refundWithReference": {
        "transactionInformation": {
          "paymentId": "64495c8b-4c0f-11ee-bf97-0e7d489d8cb0"
        }
      }
    }
  }
  ```
</ResponseExample>
