首页 > 解决方案 > Nodejs Paypal 支付 SDK 格式错误的 JSON 错误

问题描述

嗨,我目前正在尝试在执行贝宝快递付款后使用 Nodejs 中的付款 sdk 以沙盒模式发送付款。贝宝快递付款正常,但由于某种原因,我在尝试执行付款时出现错误:

HttpError: {"name":"VALIDATION_ERROR","message":"Invalid 
request - see details","debug_id":"219a050508b90","details": 
[{"field":"/","location":"body","issue":"MALFORMED_REQUEST_JSON"}],"links":[]}

这是我初始化支付的代码:

try{
let environment = state.paypalMode === 'live' && process.env.VERSION !== 'testing' ? new payouts.core.LiveEnvironment(state.paypalClientId,state.paypalClientSecret)
        : new payouts.core.SandboxEnvironment(state.paypalClientId,state.paypalClientSecret);
    
    let client = new payouts.core.PayPalHttpClient(environment);
    let batchId = v4();

    let payoutObj = {
        sender_batch_header: {
            recipient_type: 'EMAIL',
            email_message: `${state.clientId} transaction occurred`,
            note: 'processing fee',
            sender_batch_id: batchId,
            email_subject: 'Processing Fee'
        },
        items: [{
            note: 'processing fee',
            amount: {
                currency: 'USD',
                value: processingFee
            },
            receiver: 'myemail@xyz.com',
            sender_item_id: (batchId + '_1')
        }]
    };

    let payoutsRequest = new payouts.payouts.PayoutsPostRequest();
    payoutsRequest.requestBody(JSON.stringify(payoutObj));

    let createPayouts = async() => {
        let payoutResponse = await client.execute(payoutsRequest);
        console.log(`payout response: ${JSON.stringify(payoutResponse)}`);
        console.log(`payouts create response: ${JSON.stringify(payoutResponse.result)}`);
        return payoutResponse.result;
    }

    let userPayoutResponse = await createPayouts();
}catch(e){
    console.log('handleProcessingFee error: ',e);
}

我已经检查了https://github.com/paypal/Payouts-NodeJS-SDK上的示例,但我似乎仍然无法弄清楚为什么它不能在沙盒模式下工作,感谢任何帮助。

标签: node.jspaypal

解决方案


确保接收方沙盒帐户存在并且有确认的电子邮件,https://www.sandbox.paypal.com/businessprofile/settings/email(如果需要确认,请在此处阅读消息

如果问题仍然存在,请记录您的请求正文


推荐阅读