# Unreferenced Refund

An **unreferenced refund** is a card-present credit that is **not tied to any original sale**. Instead of pointing at a previous payment, you start a brand new transaction and the customer presents their card at the terminal to receive the money back.

Use this when you need to return funds but don't have, or don't want to use, the original payment's transaction reference. If you do have the original payment, prefer a [Referenced Refund](./refund-a-payment.md), which links the credit back to the initial sale for cleaner reconciliation.

```admonition
icon: fas fa-exclamation-triangle
content: |
  Unreferenced refunds is currently not open to new applications. You may implement and test but not board any live customers.
```

```admonition
icon: fas fa-exclamation-triangle
content: |
  Referenced refunds are strongly recommended wherever possible.
  An unreferenced refund sends a credit to a card without any link to a prior payment. Because there is no original transaction to validate against, these refunds are subject to additional fraud screening. As a result:
    - Some merchants may not be eligible to process unreferenced refunds at all.
    - An individual unreferenced refund may be declined even where the same refund would succeed as a referenced refund.
    - Eligibility cannot be reliably predicted, so building exclusively on unreferenced refunds risks unexplained refusals for merchants.
To use referenced refunds, the ePOS stores the `gateway_payment_id` returned when the original payment succeeds - the identifier of the original payment on a successful payment request. This single stored field unlocks automatic validation, lower decline rates, prevention of over-refunds and duplicate refunds, and cleaner reconciliation, since each refund maps directly to its original payment.
  Use unreferenced refunds only where the original `gateway_payment_id` is genuinely unavailable.
```  

## Make an unreferenced refund

Call `makeUnreferencedRefund` on your `transactionsApi` instance. It reuses the same state machine as [`makePayment`](./make-payment.md), so it returns a payment subscription rather than the `TeyaRefundResultListener` flow used by referenced refunds.

```swift
let transactionId = UUID().uuidString  // Or pass an identifier you already use; must be unique within the linked store
let amountToRefund: Int32 = 100        // Amount in the smallest currency unit (e.g., cents)
let currency = "GBP"                   // ISO 4217 currency code (e.g., "GBP", "EUR")

let refundSubscription = teyaPosLinkSDK.transactionsApi.makeUnreferencedRefund(
    transactionId: transactionId,
    amount: amountToRefund,
    currency: currency
)
```

```admonition
icon: fas fa-info-circle
content: |
    Unreferenced refunds are **not available for tab, or Pay at Table, payments**.
```

## Subscribe to the refund status

Since `makeUnreferencedRefund` returns a payment subscription, you track its progress exactly like a payment. Subscribe a `TeyaPaymentStateChangeListener` and read the same `TeyaPaymentStateDetails` states described in [Make Payment](./make-payment.md), for example `In_Progress`, `Successful` and `Processing_Failed`.

```swift
private class RefundStateListener: TeyaPaymentStateChangeListener {
    func onPaymentStateChanged(state: TeyaPaymentStateDetails) {
        print("Refund state changed: \(state)")
        // Update your UI based on state.state and state.isFinal
    }
}

refundSubscription.subscribe(listener: RefundStateListener())
```

## Transaction type

The payment subscription exposes a `transactionType` property so you can tell, at runtime, whether it tracks a payment or a refund.

| Value | Description |
|-------|-------------|
| `payment` | Money charged to the customer. |
| `refund` | Money returned to the customer. |

For an unreferenced refund, `refundSubscription.transactionType` is `TeyaTransactionType.refund`. The id of the created refund is available on `TeyaPaymentStateDetails.gatewayRefundId` once it reaches the `Successful` state.

## Re-attach to a refund in progress

If your app loses track of a refund it started, you can re-attach to it with `subscribeToPayment` and the ePOS `transactionId` you started it with - see [Subscribe to an existing payment](./make-payment.md#subscribe-to-an-existing-payment).

```admonition
icon: fas fa-warning-triangle
title: Availability
content: |
    Contact us at partnersupport@teya.com to have unreferenced refunds enabled for your account. Until the feature is activated, the refund reaches a failed state whose `reason` is `TeyaPaymentStateReason.featureNotActivatedUnreferencedRefunds`. You can read `state.reason` on the latest `TeyaPaymentStateDetails`.
```
