为什么发布到PayPal沙箱API对我不起作用?

时间:2018-10-07 14:08:10

标签: rest api paypal paypal-sandbox

我将POST(带有合适的ans标头)发布到Authorization:

https://api.sandbox.paypal.com/v1/payments/payment

并收到回报

{"intent": "sale", "payer": {"payment_method": "paypal"}, "transactions": [{"amount": 10.0, "currency": "USD", "details": {"subtotal": 10.0, "shipping": 0.0, "tax": 0.0}, "description": "Item 1"}], "redirect_urls": {"return_url": "https://example.com", "cancel_url": "https://example.com"}}

为什么会出错?我怎么了?

2 个答案:

答案 0 :(得分:1)

请签出Paypal documentation

请参见右侧的示例。 amount应该是一个对象-currencydetails必须是amount的属性,同样您也缺少必需的total属性

返工JSON

{
   "intent":"sale",
   "payer":{
      "payment_method":"paypal"
   },
   "transactions":[
      {
         "amount":{
            "total":"10.00",
            "currency":"USD",
            "details":{
               "subtotal":"10.00",
               "shipping":"0.00",
               "tax":"0.00"
            }
         },
         "description":"Item 1"
      }
   ],
   "redirect_urls":{
      "return_url":"https://example.com",
      "cancel_url":"https://example.com"
   }
}

指定“ price-numbers”(总数,小计……)时,请务必小心,它们必须是字符串,并遵守有关十进制数字的规则

答案 1 :(得分:0)

问题已编辑,该答案不再相关。