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.
currencymust 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.
remainingTotalshows 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
remainingTotalfromqueryTransactions). - A zero, negative or non-numeric
refundTotalthrows 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
}currencypicks the merchant account (default:HUF). For a SZÉP card transaction passcurrency: 'HUF_SZEP'.transactionIdcan be a number or a numeric string.- Possible
statusvalues:INIT,INPAYMENT,INFRAUD,AUTHORIZED,FINISHED,CANCELLED,NOTAUTHORIZED,TIMEOUT,REVERSED. endStateistruewhen the status will not change any more.
The 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:refundStatusandrefunds(transactionId,refundTotal,refundDate,status). - The response type follows the flags: with
detailed: true, for example,customerEmailis not optional. This works only when you write the flag as literaltrue; with abooleanvariable the fields stay optional. currencypicks the merchant account here too (default:HUF).
