2

我在我的 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))();
        })
    });   
});
 
4

0 回答 0