PayPal 在有效的 METHOD 参数上出现 'Unspecified Method' 错误(错误代码 81002)

PayPal errors with 'Unspecified Method' on a valid METHOD argument (error code 81002)

我正在尝试集成 PayPal 的上下文快速结账体验,但我遇到了这个错误。 这是我正在测试的代码:

axios
  .post(
    "https://api-3t.sandbox.paypal.com/nvp",
    {
      USER: process.env.PAYPAL_USER,
      PWD: process.env.PAYPAL_PASSWORD,
      SIGNATURE: process.env.PAYPAL_SIGNATURE,
      METHOD: "SetExpressCheckout",
      VERSION: "124.0",
      PAYMENTREQUEST_0_CURRENCYCODE: "USD",
      PAYMENTREQUEST_0_AMT: "4.5",
      RETURNURL: "http://localhost:3000/pay",
      PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID:
        "sb-47jx7i2598580@business.example.com",
    },
    {
      headers: {
        "Content-Type": "application/url-form-encoded",
      },
    }
  )
    .then((res) => {
      console.log("Got res", res.data);
    })
    .catch((err) => {
      console.error("Caught err", err);
    });

有人可以帮我找出问题所在吗?

API 至少已经过时了几代,为什么不使用命令 V2 'Set Up Transaction' 和 'Capture Transaction',在此处记录:https://developer.paypal.com/docs/checkout/reference/server-integration/

我想通了:内容类型完全错误,post 数据需要不同的编码,我使用 qs 包实现了这种编码。

axios.post(
  "https://api-3t.sandbox.paypal.com/nvp",
  qs.stringify({
    USER: process.env.PAYPAL_USER,
    PWD: process.env.PAYPAL_PASSWORD,
    SIGNATURE: process.env.PAYPAL_SIGNATURE,
    METHOD: "SetExpressCheckout",
    VERSION: "124.0",
    PAYMENTREQUEST_0_CURRENCYCODE: "USD",
    PAYMENTREQUEST_0_AMT: "4.5",
    RETURNURL: "http://localhost:3000/pay",
    PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID:
      "sb-47jx7i2598580@business.example.com",
  }),
  {
    headers: {
      "Content-Type": "application/x-www-form-url-encoded", // right one!
    },
  }
)
.then((res) => {
  console.log("Got res", res.data);
})
.catch((err) => {
  console.error("Caught err", err);
});