# Refunds

import { Aside, Tabs, TabItem } from '@astrojs/starlight/components';
import Multicode from '@components/content/Multicode.astro';

## Overview

In this guide, you will learn how to refund a transaction. You will go through the following steps:

1. [Look up a transaction ID (Optional)](#1-look-up-a-transaction-id)
2. [Refund a transaction](#2-refund-a-transaction) by using one of the available options:
   - [Option A: Make a full refund](#make-a-full-refund)
   - [Option B: Make a partial refund](#make-a-partial-refund)

When you complete these steps, the payment you have previously processed through SumUp will be refunded either partially or in full.

## Before You Begin

Here are the things that you need in order to complete the steps in this guide:

- [SumUp merchant account](https://me.sumup.com/login) with completed [account details](https://me.sumup.com/account).
  - You can also use a [sandbox merchant account](/online-payments/#getting-a-sandbox-merchant-account).
- [Registered client application](/tools/authorization/oauth/#register-an-oauth-application) with SumUp.
- Valid access token obtained with the [Authorization code flow](/tools/authorization/oauth/#authorization-code-flow).
- You have processed a checkout and you have the checkout ID.

<Aside type="note">

Transactions are associated with active merchant user accounts. As a result, you _cannot_ use an access token obtained via the [Client credentials flow](/tools/authorization/oauth/#client-credentials-flow) to complete the steps in this guide.

</Aside>

## Steps

### 1. Look up a Transaction ID

<Aside type="note">
If you already have the ID of the transaction you want to refund, you can skip this step and continue with [Step 2](#2-refund-a-transaction).
</Aside>

1. Make a GET request to the `https://api.sumup.com/v0.1/checkouts/{id}` endpoint, where the value of the `{id}` path parameter is the identifier of the checkout resource.

Example request:

<Tabs syncKey="backend_lang">
  <TabItem label="cURL" icon="seti:powershell">
    ```bash
    curl -X GET \
      https://api.sumup.com/v0.1/checkouts/4ebc2ed7-bb8c-4d4d-a110-08fd31301bf2 \
      -H "Authorization: Bearer $SUMUP_API_KEY"
    ```
  </TabItem>
  <TabItem label="Node.js" icon="seti:javascript">
    ```ts
    const checkout = await client.checkouts.get("4ebc2ed7-bb8c-4d4d-a110-08fd31301bf2");
    ```
  </TabItem>
  <TabItem label=".NET" icon="seti:c-sharp">
    ```csharp
    var checkout = await client.Checkouts.GetAsync("4ebc2ed7-bb8c-4d4d-a110-08fd31301bf2");
    ```
  </TabItem>
  <TabItem label="Java" icon="seti:java">
    ```java
    var checkout = client.checkouts().getCheckout("4ebc2ed7-bb8c-4d4d-a110-08fd31301bf2");
    ```
  </TabItem>
  <TabItem label="Go" icon="seti:go">
    ```go
    ctx := context.Background()
    client := sumup.NewClient()

    checkout, err := client.Checkouts.Get(ctx, "4ebc2ed7-bb8c-4d4d-a110-08fd31301bf2")
    ```
  </TabItem>
  <TabItem label="Python" icon="seti:python">
    ```py
    checkout = client.checkouts.get("4ebc2ed7-bb8c-4d4d-a110-08fd31301bf2")
    ```
  </TabItem>
  <TabItem label="Rust" icon="seti:rust">
    ```rust
    let checkout = client
        .checkouts()
        .get("4ebc2ed7-bb8c-4d4d-a110-08fd31301bf2")
        .await?;
    ```
  </TabItem>
  <TabItem label="PHP" icon="seti:php">
    ```php
    $checkout = $sumup->checkouts->get('4ebc2ed7-bb8c-4d4d-a110-08fd31301bf2');
    $checkoutReference = $checkout->checkout_reference;
    $checkoutId = $checkout->id;
    ```
  </TabItem>
</Tabs>

The response contains a JSON body with the full details of the processed checkout resource. You can find the transaction ID in the `id` attribute of the respective transaction resource (`664200af-2b62-4142-9c73-a2a505310d78` in the sample response below).

```json
{
  "checkout_reference": "CO287866",
  ...
  "id": "4ebc2ed7-bb8c-4d4d-a110-08fd31301bf2",
  ...
  "transactions": [
    {
      "id": "664200af-2b62-4142-9c73-a2a505310d78",
      ...
    }
  ]
}
```

### 2. Refund a Transaction

- [Option A: Make a full refund](#make-a-full-refund)
- [Option B: Make a partial refund](#make-a-partial-refund)

#### Make a Full Refund

1. Make a POST request with an empty request body to the `https://api.sumup.com/v0.1/me/refund/{txn_id}` endpoint, where the value of the `{txn_id}` path parameter is the identifier of the transaction resource.

Example request for the transaction with identifier `664200af-2b62-4142-9c73-a2a505310d78`:

<Tabs syncKey="backend_lang">
  <TabItem label="cURL" icon="seti:powershell">
    ```bash
    curl -X POST \
      https://api.sumup.com/v0.1/me/refund/19aa3cca-89f6-42d2-b462-463b0b53e959 \
      -H "Authorization: Bearer $SUMUP_API_KEY"
    ```
  </TabItem>
  <TabItem label="Node.js" icon="seti:javascript">
    ```ts
    await client.transactions.refund("19aa3cca-89f6-42d2-b462-463b0b53e959");
    ```
  </TabItem>
  <TabItem label=".NET" icon="seti:c-sharp">
    ```csharp
    await client.Transactions.RefundAsync("19aa3cca-89f6-42d2-b462-463b0b53e959");
    ```
  </TabItem>
  <TabItem label="Java" icon="seti:java">
    ```java
    client.transactions().refundTransaction(
        "19aa3cca-89f6-42d2-b462-463b0b53e959",
        RefundTransactionRequest.builder().build()
    );
    ```
  </TabItem>
  <TabItem label="Go" icon="seti:go">
    ```go
    ctx := context.Background()
    client := sumup.NewClient()

    err := client.Transactions.Refund(ctx, "19aa3cca-89f6-42d2-b462-463b0b53e959", sumup.TransactionsRefundParams{})
    ```
  </TabItem>
  <TabItem label="Python" icon="seti:python">
    ```py
    from sumup.transactions.resource import RefundTransactionBody

    client.transactions.refund(
        "19aa3cca-89f6-42d2-b462-463b0b53e959",
        RefundTransactionBody(),
    )
    ```
  </TabItem>
  <TabItem label="Rust" icon="seti:rust">
    ```rust
    client
        .transactions()
        .refund("19aa3cca-89f6-42d2-b462-463b0b53e959", None)
        .await?;
    ```
  </TabItem>
  <TabItem label="PHP" icon="seti:php">
    ```php
    $sumup->transactions->refund('19aa3cca-89f6-42d2-b462-463b0b53e959');
    ```
  </TabItem>
</Tabs>

The response returns a 204 HTTP status code and contains no body.

#### Make a Partial Refund

1. Make a POST request to the `https://api.sumup.com/v0.1/me/refund/{txn_id}` endpoint, where the value of the `{txn_id}` path parameter is the identifier of the transaction resource.

Unlike the option for a full refund, the request body for partial refunds should be a JSON object with the amount you want to refund for the transaction.

Example request for a partial refund for the amount of 24.42 EUR:

<Tabs syncKey="backend_lang">
  <TabItem label="cURL" icon="seti:powershell">
    ```bash
    curl -X POST \
      https://api.sumup.com/v0.1/me/refund/19aa3cca-89f6-42d2-b462-463b0b53e959 \
      -H "Authorization: Bearer $SUMUP_API_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"amount": 24.42}'
    ```
  </TabItem>
  <TabItem label="Node.js" icon="seti:javascript">
    ```ts
    await client.transactions.refund("19aa3cca-89f6-42d2-b462-463b0b53e959", {
      amount: 24.42,
    });
    ```
  </TabItem>
  <TabItem label=".NET" icon="seti:c-sharp">
    ```csharp
    await client.Transactions.RefundAsync(
        "19aa3cca-89f6-42d2-b462-463b0b53e959",
        new TransactionsRefundRequest
        {
            Amount = 24.42f,
        });
    ```
  </TabItem>
  <TabItem label="Java" icon="seti:java">
    ```java
    client.transactions().refundTransaction(
        "19aa3cca-89f6-42d2-b462-463b0b53e959",
        RefundTransactionRequest.builder().amount(24.42f).build()
    );
    ```
  </TabItem>
  <TabItem label="Go" icon="seti:go">
    ```go
    ctx := context.Background()
    client := sumup.NewClient()

    amount := float32(24.42)
    client.Transactions.Refund(ctx, "19aa3cca-89f6-42d2-b462-463b0b53e959", sumup.TransactionsRefundParams{
    	Amount: &amount,
    })
    ```
  </TabItem>
  <TabItem label="Python" icon="seti:python">
    ```py
    from sumup.transactions.resource import RefundTransactionBody

    client.transactions.refund(
        "19aa3cca-89f6-42d2-b462-463b0b53e959",
        RefundTransactionBody(amount=24.42),
    )
    ```
  </TabItem>
  <TabItem label="Rust" icon="seti:rust">
    ```rust
    use sumup::resources::transactions::RefundTransactionBody;

    client
        .transactions()
        .refund(
            "19aa3cca-89f6-42d2-b462-463b0b53e959",
            Some(RefundTransactionBody { amount: Some(24.42) }),
        )
        .await?;
    ```
  </TabItem>
  <TabItem label="PHP" icon="seti:php">
    ```php
    $sumup->transactions->refund('19aa3cca-89f6-42d2-b462-463b0b53e959', [
        'amount' => 24.42,
    ]);
    ```
  </TabItem>
</Tabs>

The response returns a 204 HTTP status code and contains no body.

## Result

You have successfully refunded a transaction (either partially or in full) for a payment you previously processed. The refunded amount will be credited to the same payment method the customer had used to pay with in the original transaction.
The processing fees associated with the original transaction are not returned.