跳轉至主體

退款處理

執行付款請求後自動處理為買入,或執行分開買入則無法取消已授權的付款,只能採取退款處理。可以如下使用付款請求時輸入的訂單號碼,以獲得全額退款。

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);
}

若只需退還部分金額,請在主體參數部分輸入要部分退款的金額(refundAmount),如下所示。

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);
}

如果退款處理要求正常進行,則會回傳以下退款交易訊息回應。

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