我在我的React应用程序中使用PayPal付款,在这里我试图为选择退出比赛的用户退款。我曾经在后端节点js上执行退款。
好,开始讨论这个问题。当我要进行多次退款时,我将无法执行退款。 以下是我用于对多笔交易进行退款的代码。这是我使用的SDK https://github.com/paypal/Checkout-NodeJS-SDK。
对于异步,我已经推荐了此博客https://zellwk.com/blog/async-await-in-loops/
我在日志中没有错误。
app.post('/tournament/users/withdraw',VerifyRoute,(request, response)=>{
const {withDrawUsers,tournament_id,registration_fee,payer_info}=request.body;
....
....
to_withdraw.map(async(withDrawUsers)=>{
function client() {
let clientId = "xyz";
let clientSecret = "abc";
let environment = new checkoutNodeJssdk.core.SandboxEnvironment(clientId, clientSecret);
return new checkoutNodeJssdk.core.PayPalHttpClient(environment);
}
async function refundOrder(captureId,amount ,debug=false) {
try {
const request = new checkoutNodeJssdk.payments.CapturesRefundRequest(captureId);
request.requestBody({
"amount": {
"value": amount,
"currency_code": "USD"
}
});
const response = await client().execute(request);
}
catch (error) {
errorLogger.error("Error refunding the order "+error);
}
}
(async() => await refundOrder(withDrawUsers.transaction_id,(registration_fee*(withDrawUsers.noOfUsers)).toString(),false))();
})
});
});