django - 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'
不记名令牌很好。
任何想法?我错过了什么?
解决方案
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()
作品。
推荐阅读
- java - 如何在 Visual Studio Code 中使用 java .class 文件?
- python - 使用 df2 中的值,其中行值与 df1 列名匹配
- vb.net - 如何将“System.Drawing.Image”带到 DIB
- terraform - Terraform user_data 输出在换行符上拆分
- delphi - 将 CopyRecord 从柏林翻译成 XE2
- angular - 将 mat Calender 转换为 dd/mm/yyyy 时出错
- java - Jsch:获取会话的打开通道数
- r - 使用 for 循环和存储系数估计对数据帧 2 的每一列 i 回归数据帧 1 的每一列 i
- mysql - 错误:行大小太大(> 8126)。序列化
- javascript - 当有人单击“垃圾箱”图标时,如何删除特定的 localStorage,这会在前端而不是本地删除它