Process refund
If the payment was automatically captured or processed as a capture-separated payment after the payment request, you cannot void the confirmed payment and can only process a refund. You can process a full refund by using the order ID entered in the payment request as follows.
try {
let refundResponse = await requestOfflineAPI({
method: "POST",
baseUrl: targetAPIServer,
apiPath: `/v2/payments/orders/${orderId}/refund`,
});
console.log("Refund response: ", refundResponse);
} catch (error) {
console.log(error);
}
If you want to refund only a partial amount, enter the amount to be partially refunded (refundAmount
) in the body parameter as follows.
const refund = async function (orderId, amount = 0) {
if (amount < 0) throw new Error("Amount cannot be negative number");
const refundBody = amount > 0 ? { refundAmount: amount } : null;
let refundResponse = await requestOfflineAPI({
method: "POST",
baseUrl: targetAPIServer,
apiPath: `/v2/payments/orders/${orderId}/refund`,
data: refundBody,
});
return refundResponse;
};
// ...
try {
let response = refund("test_order_1", 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"
}
}