如何解决贝宝“PAYEE_NOT_CONSENTED”仅用于 REST API?
我正在尝试将 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上用checkout 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}
})
}
解决方法
奇怪的是,你似乎没有做错任何事。除了使用简单的 curl 集成而不是 node 之外,我测试了完全相同的东西,一切都按预期工作。这是 curl 请求,因此您可以验证它是否适合您...
#!/bin/bash
access_token=$(curl -s https://api-m.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "clientid:secret" \
-d "grant_type=client_credentials" | python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")
echo $access_token
#!/bin/bash
access_token=$(./curl_rest_gettoken);
curl $@ -s https://api-m.sandbox.paypal.com/v2/checkout/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $access_token" \
-d '{
"intent": "CAPTURE","purchase_units": [
{
"amount": {
"currency_code": "USD","value": "5"
},"payee": {
"email_address": "......@business.example.com"
}
}
],"application_context": {
"return_url": "https://www.yahoo.com"
}
}' | python -mjson.tool
#!/bin/bash
access_token=$(./curl_rest_gettoken);
curl -v -s -X POST https://api-m.sandbox.paypal.com/v2/checkout/orders/$1/capture \
-H "Content-Type:application/json" \
-H "Authorization: Bearer $access_token" | python -mjson.tool
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。