node.js - 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上的示例,但我似乎仍然无法弄清楚为什么它不能在沙盒模式下工作,感谢任何帮助。
解决方案
确保接收方沙盒帐户存在并且有确认的电子邮件,https://www.sandbox.paypal.com/businessprofile/settings/email(如果需要确认,请在此处阅读消息)
如果问题仍然存在,请记录您的请求正文
推荐阅读
- java - CAS过滤器在部署war时不拦截服务票证
- time-series - 选择最佳时间序列集合来预测给定的时间序列
- php - 使用 '?' 在旧 URL 的路由中
- multithreading - 线程状态和进程状态有什么区别?
- javascript - 有没有办法确保所有元素在再次操作之前都已重置到原始位置?
- python-3.x - 基维。用不同的数据刷新屏幕
- swift - 在 Swift 扩展中访问具有多个参数的方法
- java - 通过从 Java 8 到 Java 11 的 CDATA 的 XML 转换处理换行符的变化
- c# - EF Core:使用链式属性为复合 PK 的一部分定义外键
- delphi-10-seattle - 在 TMemo 后代中获取屏幕线与 TStrings 线的对应关系