邮递员:如何在邮递员中执行Paypal CURL请求?

时间:2017-03-03 03:43:24

标签: php curl paypal postman

我能够获得oAuth Request&响应

https://developer.paypal.com/docs/integration/direct/make-your-first-call/

enter code here

但是当我跑的时候总是给401 Unauthorized

如何在Postman中执行以下内容?

curl -v https://api.sandbox.paypal.com/v1/payments/payment \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer Access-Token" \
  -d '{
  "intent":"sale",
  "redirect_urls":{
    "return_url":"http://example.com/your_redirect_url.html",
    "cancel_url":"http://example.com/your_cancel_url.html"
  },
  "payer":{
    "payment_method":"paypal"
  },
  "transactions":[
    {
      "amount":{
        "total":"7.47",
        "currency":"USD"
      }
    }
  ]
}'

enter image description here

3 个答案:

答案 0 :(得分:3)

首先,您需要将数据部分粘贴到正文中:

{"intent": "sale",
 "redirect_urls": {
    "return_url": "http://example.com/your_redirect_url.html",
    "cancel_url": "http://example.com/your_cancel_url.html"

 },
 "payer": {
    "payment_method": "paypal"

 },
 "transactions": [{
    "amount": {
        "total": "7.47",
        "currency": "USD"

    }
    }]

}

然后,你必须选择raw并在Text下选择JSON(application / json)

对于授权部分,请转到标题:

[key:Content-Type, value:application/json]
[key:Authorization, value:Bearer YOUR_TOKEN]

然后点击发送,你应该获得201创建状态

答案 1 :(得分:1)

从上图中看来,您似乎没有以JSON格式发送数据。在paypal示例中,它显示了数据的JSON对象(-d)。你所要做的就是将它复制并粘贴到主体上,然后将主体更改为raw,然后在最后一列上它会显示文本和箭头,只需单击它并选择JSON(application / json)就可以了。< / p>

答案 2 :(得分:0)

好像你有两个问题:

1:您必须获取访问令牌

作为sais文档:enter image description here

这就是为什么你获得401 Unauthorized,你必须配置授权类型OAuth2,并使用你的访问令牌:enter image description here

2:我在邮递员上制作了这个卷曲示例的图形示例。

标题: enter image description here

正文: enter image description here

授权:不要像第一个问题那样忘记配置令牌。

这就是全部!