【发布时间】:2018-12-10 20:04:02
【问题描述】:
我在我的 django 项目中使用 paypal sdk 制作 paypal 发票时遇到了一点问题。当我尝试执行此代码时
invoice_id = ''
invoice = Invoice({
"merchant_info": {
"email": '', # You must change this to your sandbox email account
"first_name": str(merchant.first_name),
"last_name": str(merchant.last_name),
"business_name": str(merchant_full_name),
"phone": {
"country_code": "001",
"national_number": str(merchant.phone)
},
"address": {
"line1": str(merchant_address.address),
"city": str(merchant_address.city),
"state": str(merchant_address.state),
"postal_code": str(merchant_address.zip_code),
"country_code": "US"
}
},
"billing_info": [{"email": buyer.paypal_address}],
"items": [
{
"name": "Slab",
"quantity": 1,
"unit_price": {
"currency": "USD",
"value": float(slab.price)
}
}
],
"note": "Invoice for slab",
"payment_term": {
"term_type": "NET_45"
},
"shipping_info": {
"first_name": buyer.first_name,
"last_name": buyer.last_name,
"business_name": str(buyer_full_name),
"phone": {
"country_code": "001",
"national_number": str(buyer.phone)
},
"address": {
"line1": str(buyer_address.address),
"city": str(buyer_address.city),
"state": str(buyer_address.state),
"postal_code": str(buyer_address.zip_code),
"country_code": "US"
}
},
"shipping_cost": {
"amount": {
"currency": "USD",
"value": 0
}
}
})
if invoice.create():
print(json.dumps(invoice.to_dict(), sort_keys=False, indent=4))
invoice_id = invoice['id']
return invoice_id
else:
print(invoice.error)
我的服务器将这些错误返回给我
信息:paypalrestsdk.api:请求[POST]: https://api.sandbox.paypal.com/v1/oauth2/token 信息:paypalrestsdk.api:Response[200]:好的,持续时间:1.156739s。 信息:paypalrestsdk.api:贝宝请求 ID: 660f7807-961f-4460-bafd-18412b489a91 信息:paypalrestsdk.api:请求[POST]: https://api.sandbox.paypal.com/v1/invoicing/invoices 信息:paypalrestsdk.api:Response[401]:未经授权,持续时间: 1.213655 秒。信息:paypalrestsdk.api:Request[POST]:https://api.sandbox.paypal.com/v1/oauth2/token INFO:paypalrestsdk.api:Response[200]:好的,持续时间:1.53491s。
据我了解,这是贝宝令牌的问题,对吧?
【问题讨论】:
-
在提出这个问题之前,您进行了哪些研究、尝试、迭代等工作?如果您怀疑这是一个令牌问题,您做了什么来确认或否认该断言?
-
@dfundako 如果我在消息中看到 Unauthorized 这个词,那么我明白是令牌的问题,但我不知道如何解决它
标签: python django rest paypal paypal-sandbox