Skip to main content

Refund

Use the Refund API to process a refund transaction securely. This API can be used to refund the full or partial amount of the original transaction.

Endpoint

Method: POST
URL: baseUrl/api/v1/transactions/refund

Headers

  • Authorization: Bearer {{accessToken}} (Include the token obtained from the Authentication API)
  • Content-Type: application/json

Request Body

Send a JSON object with the following fields:

FieldTypeRequiredDescription
amountstringYesThe amount to be processed. Must be a whole number, no decimals are allowed.
transactionIdstringYesThe unique identifier of the original transaction to be refunded.
refNumberstringYesA unique reference number for tracking (ECR reference number)

Note: The transactionId field value can be found on the original transaction purchase api response. The refNumber field should be a new, unique value generated by the user to track the refund transaction.

Example:

{
"amount": "12000",
"transactionId": "1004"
"refNumber": "refNumber"
}

Response

A successful transaction returns a JSON object with the following fields:

Key Attributes

FieldTypeDescription
statusstringOverall transaction status. Usually "APPROVED" or "DECLINED".
messagestringHuman-readable message related to the status.
receipt.idintegerUnique identifier for the transaction receipt.
merchantNameEnstringMerchant name in English.
merchantNameArstringMerchant name in Arabic.
addressEnstringMerchant location address in English.
terminalIdstringUnique ID of the payment terminal.
merchantIdstringUnique merchant ID from acquirer (host/bank).
stanstringSystem Trace Audit Number (STAN) for the transaction.
rrnstringRetrieval Reference Number used for tracking transactions.
amountAuthorizedstringAuthorized transaction amount in smallest currency unit (e.g., halalas).
cardSchemeEnstringCard scheme used (e.g., "Mada", "Visa", "MasterCard").
panstringMasked Primary Account Number (PAN) of the card.
cardExpirationstringCard expiration date (MM/YY).
transactionTypeEnstringType of transaction (e.g., "PURCHASE", "REFUND").
entryModestringHow the card was read (e.g., "CONTACTLESS", "CHIP", "MAGSTRIPE").
approvalCodestringApproval code returned from the issuer/bank.
switchResponseCodestringResponse code from the card switch. "000" usually indicates success.
startDatestringDate when the transaction started (dd/mm/yyyy).
startTimestringTime when the transaction started (hh:mm:ss).
endDatestringDate when the transaction ended.
endTimestringTime when the transaction ended.
statusMessageEnstringStatus description in English (e.g., "Approved", "Declined").
verificationMethodEnstringCardholder verification method (e.g., PIN, Contactless Auth).
thanksMessageEnstringThank you message shown on the receipt.
saveReceiptMessageEnstringInstruction to retain receipt.
applicationIdentifierstringAID – Identifies the card application used for the transaction.
applicationCryptogramstringCryptographic code generated by the card for security/authentication.
kernelIdstringIdentifier of the EMV kernel used for the transaction.
paymentAccountReferencestringUnique reference for linking payments to digital wallets or services.

Example:

{
"status": "APPROVED",
"message": "Approved",
"receipt": {
"id": 496,
"merchantNameAr": "Bab Merchant Ar",
"merchantNameEn": "Bab Merchant",
"addressAr": "الرياض",
"addressEn": "Riyadh",
"startDate": "27/05/2025",
"startTime": "13:21:51",
"startDateTime": null,
"endDateTime": null,
"acquirerCode": "INMA",
"merchantId": "100000000000001",
"terminalId": "0210046200100462",
"merchantCategoryCode": "0763",
"stan": "000059",
"appVersion": "1.0.0",
"rrn": "514713000747",
"cardSchemeId": "P1",
"cardSchemeAr":"‌مدى‌",
"cardSchemeEn": "Mada",
"applicationLabelAr": null,
"applicationLabelEn": null,
"pan": "5069 68** **** 9140",
"cardExpiration": "29/02",
"transactionTypeAr":"‌شراء‌",
"transactionTypeEn": "PURCHASE",
"amountAuthorized": "1000",
"amountAuthorizedAr":"‌مبلغ الشراء‌",
"amountAuthorizedEn": "PURCHASE AMOUNT",
"statusMessageAr":"‌مقبولة‌",
"statusMessageEn": "Approved",
"verificationMethodAr":"‌تم التحقق من هوية حامل الجهاز‌ ",
"verificationMethodEn": "DEVICE OWNER IDENTITY VERIFIED",
"approvalCodeAr":"‌رمز الموافقة‌",
"approvalCodeEn": "Approval Code",
"approvalCode": "519030",
"endTime": "13:21:53",
"endDate": "27/05/2025",
"entryMode": "CONTACTLESS",
"switchResponseCode": "000",
"applicationIdentifier": "A0000002281010",
"terminalVerificationResult": "0080008000",
"transactionStateInformation": "0000",
"cardholderVerificationResult": "640300",
"cryptogramInformationData": "80",
"applicationCryptogram": "AB621EA892D7072B",
"kernelId": "2d",
"paymentAccountReference": "23R0380GI98ZLTVEDGWQSUTKYVMDD",
"thanksMessageAr": "شكرا لاستخدامكم مدى",
"thanksMessageEn": "Thank you for using mada",
"saveReceiptMessageAr": "يرجى الاحتفاظ بالفاتورة",
"saveReceiptMessageEn": "please retain receipt",
"providerResponseCode": null
}
}

Error Handling

If the transaction fails, you may receive an error response.

Example:

{
"status": "failed",
"msg": "Insufficient Funds"
}
Error ScenarioPossible MessageAction Required
Invalid TokenUnauthorizedRe-authenticate to obtain a valid token.
Insufficient BalanceInsufficient FundsVerify the user’s account balance.
Missing FieldsBad RequestEnsure all required fields are included.

Usage Tips

  1. Match Original Transaction: Ensure the transactionId provided maps to an existing transaction eligible for refund.
  2. Reference Number: Use unique refNumber values for each transaction to prevent duplicate processing.
  3. Transaction Id: Use the integer value with the same name retrieved from the purchase api response of the original transaction.