首页 > 解决方案 > Django Paypal 集成 createOrder curl

问题描述

我正在尝试在没有任何 SDK 或包的情况下在 Django 中实现 PayPal。

https://developer.paypal.com/docs/business/checkout/server-side-api-calls/create-order/

想将此 cURL 重写为 Python

 curl -v -X POST https://api-m.sandbox.paypal.com/v2/checkout/orders \ 
-H "Content-Type: application/json" \
-H "Authorization: Bearer Access-Token" \
-d '{
  "intent": "CAPTURE",
  "purchase_units": [
    {
      "amount": {
        "currency_code": "USD",
        "value": "100.00"
      }
    }
  ]
}'

我当前的代码:

t = gettoken()
d = {"intent": "CAPTURE","purchase_units": [{"amount": {"currency_code": "USD","value": "100.00"}}]}
h = {"Content-Type: application/json", "Authorization: Bearer "+t}
r = requests.post('https://api-m.sandbox.paypal.com/v2/checkout/orders', headers=h, data=d).json()

我的错误:

Internal Server Error: /createOrder
.....
AttributeError: 'set' object has no attribute 'items'

不记名令牌很好。

任何想法?我错过了什么?

标签: djangocurlpaypal

解决方案


 d = {"intent": "CAPTURE","purchase_units": [{"amount": {"currency_code": "USD","value": "100.00"}}]}
 h = {"Content-Type": "application/json", "Authorization": "Bearer "+t}
 r = requests.post('https://api-m.sandbox.paypal.com/v2/checkout/orders', headers=h, json=d).json()

作品。


推荐阅读