---
title: Refund
slug: ezdh-refund
docTags: 
createdAt: 2025-03-14T13:15:25.424Z
---

:::hint{type="warning"}
It is important to note that refunds are still a work in progress, therefore minor changes to the SDK may be required in future releases.
:::

## Starting a refund

Refunds work very similarly to [purchases](docId\:xfTYvCsCNePqsmJfZ6o4a) , with a few key differences.

1. The `TransactionType` must be specified as `Refund` when calling `toro.startTransaction()`
2. There needs to be an existing purchase to refund.
3. Some details of the original purchase are required in order to initiate the refund.
4. The refund amount cannot be more than the original purchase amount.
5. Gratuities are not applicable.
6. The refund amount cannot be greater than the original purchase amount.

:::CodeblockTabs
```kotlin
toro.startTransaction(
    amount = 1000,
    type = TransactionType.Refund
    currencyCode = CurrencyCode.GBP,
    metadata = TransactionMetadata(
        originalTransactionDetails = originalTransactionDetails
    ),
    onCompleted = { receipt ->
        println("Transaction completed: ${receipt.transactionId}")
    },
    onCancelled = { cancellationType ->
        when (cancellationType) {
            CancellationType.ATTENDANT -> println("Transaction cancelled in app")
            CancellationType.CUSTOMER -> println("Transaction cancelled on Miura device")
        }
    },
    onError = { error ->
        when (error) {
            is DeviceNotSelected -> handleDeviceError(error)
            is DeviceConnectionFailed -> reconnectDevice()
            is DeviceDisconnected -> showReconnectionPrompt()
            else -> showErrorMessage(error.message)
        }
    }
)
```

```java
toro.startTransaction(
        1000, // £10.00
        TransactionType.Refund,
        CurrencyCode.GBP,
        new TransactionMetadata(
                null,
                0,
                originalTransactionDetails,
                Collections.emptyMap()
        ),
        result -> {
            // Handle successful transaction
            System.out.println("Transaction completed: " + result);
            return null;
        },
        cancellationType -> {
            if (cancellationType == CancellationType.ATTENDANT) {
                System.out.println("Transaction cancelled in app");
            } else if (cancellationType == CancellationType.CUSTOMER) {
                System.out.println("Transaction cancelled on Miura device");
            }
            return null;
        },
        error -> {
            if (error instanceof ToroException.DeviceNotSelected) {
                handleDeviceError((ToroException.DeviceNotSelected) error);
            } else if (error instanceof ToroException.DeviceConnectionFailed) {
                reconnectDevice();
            } else if (error instanceof ToroException.DeviceDisconnected) {
                showReconnectionPrompt();
            } else {
                showErrorMessage(error.getMessage());
            }
            return null;
        },
        (gratuityAmount, gratuityPercentage) -> {
            // Handle gratuity confirmation
            System.out.println("Gratuity added: £" + (gratuityAmount / 100.0) +
                    " (" + gratuityPercentage + "%)");
            return null;
        }
);
```
:::

Below is an example `OriginalTransactionDetails` object which needs to be passed through the `TransactionMetadata`.

```kotlin
OriginalTransactionDetails(
    saleReferenceId = "sale-12345",
    amount = 1000,
    currency = CurrencyCode.GBP,
    dateTime = "2025-01-01T00:00:00.000Z",
    transactionReference = "purchase_12345123",
    responseCode = ResponseCode.APPROVED,
    authCode = "123456",
    paymentInterface = PaymentInterface.CONTACT,
    terminalSerialNumber = "2110022",
    additionalResponseInformation = "01:XZZ022a3a0a9a99f1B5MXJYICT525HCF"
)
```



