Skip to main content

Process refund

If the payment was automatically captured or processed as a capture-separated payment after the payment confirmation, you cannot void the confirmed payment and can only process a refund. You can process a full refund by using the transaction ID of the completed payment as follows.

For information on obtaining the credentials needed to call the Online API, see Prepare API credentials. The code example described on this page uses the requestOnlineAPI() function defined in the Prepare API credentials code example.

try {
let refundResponse = await requestOnlineAPI({
method: "POST",
baseUrl: targetAPIServer,
apiPath: `/v3/payments/${transactionId}/refund`,
});

console.log("Refund response: ", refundResponse);
} catch (error) {
console.log(error);
}

Depending on the service implementation language, you may need to process the transaction ID as a string when handling transaction ID information. For more information, see the Transaction ID.

In case of a partial refund, enter the amount to be partially refunded (refundAmount) in the body parameter as follows.

const refund = async function (transactionId, amount = 0) {
if (!transactionId) throw new Error("Transaction ID is required!");
if (amount < 0) throw new Error("Amount cannot be negative number");

const refundBody = amount > 0 ? { refundAmount: amount } : null;

let refundResponse = await requestOnlineAPI({
method: "POST",
baseUrl: targetAPIServer,
apiPath: `/v3/payments/${transactionId}/refund`,
data: refundBody,
});

return refundResponse;
};

// ...

try {
let response = refund("2018082512345678910", 500);

console.log(response);
} catch (error) {
console.log(error);
}

Once the refund request is successfully processed, the following refund transaction information is returned in the response.

{
"returnCode": "0000",
"returnMessage": "success",
"info": {
"refundTransactionId": 2018082512345678911,
"refundTransactionDate": "2018-08-25T09:15:01Z"
}
}