【问题标题】:Error: Response Status: 400 at PayPal Rest SDK错误:响应状态:PayPal Rest SDK 上的 400
【发布时间】:2020-01-16 08:03:30
【问题描述】:

我在 NodeJS 的帮助下使用一些 PayPal 付款创建了一个平台,到目前为止一切正常,我不知道为什么它会抛出这个错误。 1 小时前我付款了,现在它不会让我付款。我没有修改任何代码或类似的东西。]

这是错误

/Users/calinonaca/Desktop/PEDIGREE-NOTES copy/controllers/feed.js:863 抛出错误; ^

错误:响应状态:400 在传入消息。 (/用户/calinonaca/桌面/PEDIGREE-NOTES 复制/node_modules/paypal-rest-sdk/lib/client.js:130:23) 在 IncomingMessage.emit (events.js:203:15) 在 endReadableNT (_stream_readable.js:1145:12) 在 process._tickCallback (internal/process/next_tick.js:63:19)

这是我的功能

exports.postPayment = (req,res,next) => {
    const uploadedBy = req.body.noteOwner;
    const finalprice = req.body.finalprice;
    const notename = req.body.notename;
    const loggedInUser = req.session.user._id;
    const noteprice = req.body.noteprice;




    const create_payment_json = {
        "intent": "sale",
        "payer": {
            "payment_method": "paypal"
        },
        "redirect_urls": {
            "return_url": "http://localhost/successPayment/"+finalprice+"/"+notename+"/"+uploadedBy+"/"+noteprice+"/"+loggedInUser,
            "cancel_url": "http://localhost/cancel"
        },
        "transactions": [{
            "item_list": {
                "items": [{
                    "name": "Note",
                    "sku": "001",
                    "price": finalprice,
                    "currency": "USD",
                    "quantity": 1
                }]
            },
            "amount": {
                "currency": "USD",
                "total": finalprice
            },
            "description": "Note you ordered"
        }]
    };



    paypal.payment.create(create_payment_json, function (error, payment) {
        if (error) {
            throw error;
        } else {
        for(let i = 0; i < payment.links.length; i++)
        {
            if(payment.links[i].rel === 'approval_url')
            {
                res.redirect(payment.links[i].href);
            }
        }
        }
    });

}

到目前为止一切正常,我不知道出了什么问题,你能帮帮我吗?谢谢!

【问题讨论】:

    标签: node.js paypal


    【解决方案1】:

    我希望这会有所帮助,我遇到了同样的问题,我不得不挖掘几乎所有可能的链接和资源,我发现你必须将完全相同的对象映射为 HERE

      "intent": "sale",
      "payer": {
        "payment_method": "paypal"
      },
      "transactions": [
        {
          "amount": {
            "total": "30.11",
            "currency": "USD",
            "details": {
              "subtotal": "30.00",
              "tax": "0.07",
              "shipping": "0.03",
              "handling_fee": "1.00",
              "shipping_discount": "-1.00",
              "insurance": "0.01"
            }
          },
          "description": "The payment transaction description.",
          "custom": "EBAY_EMS_90048630024435",
          "invoice_number": "48787589673",
          "payment_options": {
            "allowed_payment_method": "INSTANT_FUNDING_SOURCE"
          },
          "soft_descriptor": "ECHI5786786",
          "item_list": {
            "items": [
              {
                "name": "hat",
                "description": "Brown hat.",
                "quantity": "5",
                "price": "3",
                "tax": "0.01",
                "sku": "1",
                "currency": "USD"
              },
              {
                "name": "handbag",
                "description": "Black handbag.",
                "quantity": "1",
                "price": "15",
                "tax": "0.02",
                "sku": "product34",
                "currency": "USD"
              }
            ],
            "shipping_address": {
              "recipient_name": "Brian Robinson",
              "line1": "4th Floor",
              "line2": "Unit #34",
              "city": "San Jose",
              "country_code": "US",
              "postal_code": "95131",
              "phone": "011862212345678",
              "state": "CA"
            }
          }
        }
      ],
      "note_to_payer": "Contact us for any questions on your order.",
      "redirect_urls": {
        "return_url": "https://example.com/return",
        "cancel_url": "https://example.com/cancel"
      }
    

    只有在我复制并粘贴此对象后,我才获得带有重定向 URL 的成功响应。我希望这能帮到您。我会玩弄物体,看看有什么可以忽略的。

    【讨论】:

    • 谢谢,我发现我在逗号或点之后解析了超过 2 位小数的价格格式,这是问题所在
    • 谢谢你,我必须添加运输和小计的详细信息,因为它已经验证了他们的后端。我的答案不是完全解决方案,所有问题都与 create_payment_json 相关,必须正确构造。
    猜你喜欢
    • 2013-03-12
    • 1970-01-01
    • 2016-11-28
    • 2013-11-12
    • 2013-10-17
    • 2017-04-06
    • 1970-01-01
    • 2017-04-09
    • 2013-06-05
    相关资源
    最近更新 更多