---
url: https://simplepay.webmania.cc/en/guide/refunds-and-queries.md
description: >-
  Full and partial refunds, transaction status and queries with the
  simplepay-js-sdk refund, getTransactionStatus and queryTransactions functions.
---

# Refunds and transaction queries

## Refunds

`refund` refunds a `FINISHED` transaction fully or partially (`/refund` endpoint). Pass exactly one identifier: `transactionId` or `orderRef`.

```ts
import { refund } from 'simplepay-js-sdk'

const { refundTransactionId, refundTotal, remainingTotal } = await refund({
  orderRef: 'ORDER-1001',
  refundTotal: 2500,
})
```

* The refund is in the transaction's currency. `currency` must be that currency, and it also picks the merchant account (default: `HUF`). For a SZÉP card transaction: `currency: 'HUF_SZEP'`.
* Partial refunds can be repeated until the original amount is used up. `remainingTotal` shows how much can still be refunded.
* Each refund is a separate transaction; its id is `refundTransactionId`.
* For a full refund, pass the whole remaining amount (the `remainingTotal` from `queryTransactions`).
* A zero, negative or non-numeric `refundTotal` throws before any request is sent.

## Transaction status

`getTransactionStatus` looks up one transaction on SimplePay's lightweight `/status` endpoint. Pass exactly one identifier: the SimplePay `transactionId` or your own `orderRef`. Passing both or neither throws before any request is sent.

```ts
import { getTransactionStatus } from 'simplepay-js-sdk'

const { status, endState } = await getTransactionStatus({ orderRef: 'ORDER-1001' })
// or: await getTransactionStatus({ transactionId: 501234567 })

if (endState) {
  // final status: FINISHED, CANCELLED, NOTAUTHORIZED, TIMEOUT or REVERSED
}
```

* `currency` picks the merchant account (default: `HUF`). For a SZÉP card transaction pass `currency: 'HUF_SZEP'`.
* `transactionId` can be a number or a numeric string.
* Possible `status` values: `INIT`, `INPAYMENT`, `INFRAUD`, `AUTHORIZED`, `FINISHED`, `CANCELLED`, `NOTAUTHORIZED`, `TIMEOUT`, `REVERSED`.
* `endState` is `true` when the status will not change any more.

The [IPN](./ipn) also reports the final result. The status lookup helps when an IPN did not arrive, or when you want the status right away as the customer returns.

## Transaction query

`queryTransactions` looks up one or more transactions on the `/query` endpoint by `transactionIds` and/or `orderRefs`. At least one identifier is required.

```ts
import { queryTransactions } from 'simplepay-js-sdk'

const { transactions, totalCount } = await queryTransactions({
  orderRefs: ['ORDER-1001', 'ORDER-1002'],
  transactionIds: [501234567],
  detailed: true,   // order data: customer, invoice and delivery address, ...
  refunds: true,    // refund status and the list of refunds
})

for (const t of transactions) {
  console.log(t.orderRef, t.status, t.remainingTotal, t.customerEmail, t.refundStatus, t.refunds)
}
```

* Every transaction has: `orderRef`, `transactionId`, `status`, `total`, `remainingTotal`, `method`, `paymentDate`, `finishDate`.
* With `detailed: true`: `currency`, `customer`, `customerEmail`, `language`, `twoStep`, `shippingCost`, `discount`, `invoice`, `delivery`.
* With `refunds: true`: `refundStatus` and `refunds` (`transactionId`, `refundTotal`, `refundDate`, `status`).
* The response type follows the flags: with `detailed: true`, for example, `customerEmail` is not optional. This works only when you write the flag as literal `true`; with a `boolean` variable the fields stay optional.
* `currency` picks the merchant account here too (default: `HUF`).
