【发布时间】:2021-09-30 13:56:10
【问题描述】:
我正在尝试将 Paypal 集成到我的应用程序中。该应用程序将允许人们在他们之间出售代币。所以钱不是给我,而是给收款人。
我第一次直接在我的前端使用智能按钮 (https://developer.paypal.com/docs/checkout/integrate/)。我只需要添加一个收款人字段,它工作得非常好。 0 个错误,没问题。
但现在,我想在 NodejS 后端进行集成,因为它对我来说更安全。
尽管我在做完全相同的事情(创建订单 -> 捕获订单),但我收到了这个错误:
{"name":"NOT_AUTHORIZED","details": [{
"issue":"PAYEE_NOT_CONSENTED","description":"Payee does not have appropriate consent to
allow the API caller to process this type of transaction on their behalf. Your current
setup requires the 'payee' to provide a consent before this transaction can be
processed successfully."
}],
"message": "Authorization failed due to insufficient permissions.",
"debug_id":"300756d694c77","links": [{
"href":"https://developer.paypal.com/docs/api/orders/v2/#error-PAYEE_NOT_CONSENTED",
"rel":"information_link","method":"GET"
}]
}
为什么?为什么用智能按钮做这种操作没有问题,但我用nodejs上的结账sdk就不行,需要收款人同意?
有什么区别?
需要收款人的同意或任何形式的操作对我来说真的很烦人,因为我需要收款人以最少的行动出售他们的代币。
而且我看不出使用智能按钮或使用后端有什么区别。
顺便说一句,这是我的代码:
const paypal = require('@paypal/checkout-server-sdk')
if (process.env.NODE_ENV === "prod") {
APP_SETTINGS = require('src/PRIVATE_APP_SETTINGS.json').prod;
var environment = new paypal.core.LiveEnvironment(APP_SETTINGS.paypal.paypal_client_id, APP_SETTINGS.paypal.paypal_secret);
} else {
APP_SETTINGS = require('src/PRIVATE_APP_SETTINGS.json').dev;
var environment = new paypal.core.SandboxEnvironment(APP_SETTINGS.paypal.paypal_client_id, APP_SETTINGS.paypal.paypal_secret);
}
var client = new paypal.core.PayPalHttpClient(environment);
function createPayment(info)
{
const body = {
intent: 'CAPTURE',
purchase_units: [{
amount:
{
value: info.usdAmount,
currency_code: 'USD'
},
payee: {
email_address: info.paypalEmail
}
}],
}
let request = new paypal.orders.OrdersCreateRequest()
request.requestBody(body)
return client.execute(request).then(res => {
return {res: true, id: res.result.id}
}).catch(err => {
if (err) {
console.error(err.message);
}
return {res: false}
})
}
function executePayment(info)
{
console.log(info)
const request = new paypal.orders.OrdersCaptureRequest(info.orderId)
request.requestBody({})
return client.execute(request).then((result) => {
console.log("Payment suceed")
return {res: true}
}).catch(err => {
if (err) {
console.error(err);
}
return {res: false}
})
}
【问题讨论】:
标签: node.js paypal paypal-sandbox paypal-rest-sdk