如何修复Node JS中的PayPal的“验证错误”?

时间:2019-04-28 19:34:29

标签: javascript node.js json paypal paypal-sandbox

我正在尝试通过订单向PayPal api发送请求。但是,每次我发送请求时,都会出现此错误:

  

货币金额必须为非负数,可以选择包含正好2个小数位,中间用'。'分隔,可选的千位分隔符',',限于小数点前7位数字和有效ISO货币代码< / p>

我已经查看了我的请求对象,但是所有值都符合PayPal要求的信息。 amount.total是两位数,并且ISO货币代码正确,但是我仍然遇到相同的错误。

这是我要发送的JSON:

{  
   "amount":{  
      "total":24.51,
      "currency":"USD",
      "details":{  
         "subtotal":22.99,
         "tax":0.06625
      }
   },
   "description":"Nature Prints produced by Jonah's Photos.",
   "invoice_number":"deb03d30-69e5-11e9-bc27-855d4a6ff0e2",
   "payment_options":{  
      "allowed_payment_method":"INSTANT_FUNDING_SOURCE"
   },
   "item_list":{  
      "items":[  
         {  
            "name":"IMG_9454 | Nature Photo @ 8.5\" x 11\" |",
            "quantity":1,
            "price":14.99,
            "tax":0.06625,
            "sku":"40751898403_90408c24a3",
            "currency":"USD"
         }
      ]
   }
}

这是我的代码:

var payReq = {
      intent:'order',
      payer: {
        payment_method: 'paypal'
      },
      redirect_urls:{
        return_url:'http://localhost:3000/success',
        cancel_url:'http://localhost:3000/cancel'
      },
      transactions: [{
        amount: {
          total: Number((((req.session.cart.totalPrice + req.session.cart.shippingPrice) / 100) + ((req.session.cart.totalPrice + req.session.cart.shippingPrice) / 100) * determineSalesTax(req.session.orderInformation.userData.state.toLowerCase())).toFixed(2)),
          currency: 'USD',
          details: {
            subtotal: parseFloat((req.session.cart.totalPrice + req.session.cart.shippingPrice) / 100),
            tax: determineSalesTax(req.session.orderInformation.userData.state.toLowerCase())
          }
        },
        description: 'Nature Prints produced by Jonah\'s Photos.',
        invoice_number: req.session.orderInformation.orderID,
        payment_options: {
          allowed_payment_method: 'INSTANT_FUNDING_SOURCE'
        },
        item_list:{
          items: []
        }
      }]
    };

我希望请求能够成功完成,但是每次都会遇到相同的错误。

版本

PayPal-Rest-SDK:1.8.1

0 个答案:

没有答案