贝宝 "PAYEE_NOT_CONSENTED" 仅适用于 REST API?

Paypal "PAYEE_NOT_CONSENTED" Only for 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"
  }]
}

为什么?为什么用smart button做这种操作没有问题,但是我用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 集成而不是节点之外,我测试了完全相同的东西,并且一切都按预期工作。以下是 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//capture   \
  -H "Content-Type:application/json" \
  -H "Authorization: Bearer $access_token" | python -mjson.tool