我尝试实施贝宝。我正在做官方教程,现在我停留在“创建付款资源”上
样品请求为:
import re
from lxml import etree as et
# Open original file
tree = et.parse('t.xml')
for article in tree.iter("Affiliation"):
if(article.text != "-"):
email = re.search(r'[\w\.-]+@[\w\.-]+', article.text)
child = et.SubElement(article.getparent(), 'Email')
child.text = email.group(0)
else:
child = et.SubElement(article.getparent(), 'Email')
child.text = ' - '
# Write back to file
tree.write('t.xml')
我用访问令牌更改了-{accessToken}:
curl -v https://api.sandbox.paypal.com/v1/payments/payment \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {accessToken}' \
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"total": "21.50",
"currency": "EUR",
"details": {
"subtotal": "15.00",
"tax": "2.00",
"shipping": "2.50",
"handling_fee": "1.00",
"shipping_discount": "-1.00",
"insurance": "2.00"
}
},
"description": "This is the payment transaction description.",
"custom": "This is a hidden value",
"invoice_number": "unique_invoice_number",
"soft_descriptor": "your order description",
"item_list": {
"items": [{
"name": "Item 1",
"description": "add description here",
"quantity": "2",
"price": "10.00",
"sku": "1",
"currency": "EUR"
},
{
"name": "Voucher",
"description": "discount on your order",
"quantity": "1",
"price": "-5.00",
"sku": "vouch1",
"currency": "EUR"
}
]
}
}],
"note_to_payer": "Contact us for any questions on your order.",
"redirect_urls": {
"return_url": "http://example.com/success",
"cancel_url": "http://example.com/cancel"
}
}
当我在控制台中运行它时,我得到
curl -v https://api.sandbox.paypal.com/v1/payments/payment \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {A21AAHxasde3pBCINcYK6_VkHF2Y2M6dZIGRrvWBHKn1-0A9njg73e3KzrHAL94rVtPOOacMZzyzh-AqSagXEvGT6oY3C4UIsg}' \
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"total": "21.50",
"currency": "EUR",
"details": {
"subtotal": "15.00",
"tax": "2.00",
"shipping": "2.50",
"handling_fee": "1.00",
"shipping_discount": "-1.00",
"insurance": "2.00"
}
},
"description": "This is the payment transaction description.",
"custom": "This is a hidden value",
"invoice_number": "unique_invoice_number",
"soft_descriptor": "your order description",
"item_list": {
"items": [{
"name": "Item 1",
"description": "add description here",
"quantity": "2",
"price": "10.00",
"sku": "1",
"currency": "EUR"
},
{
"name": "Voucher",
"description": "discount on your order",
"quantity": "1",
"price": "-5.00",
"sku": "vouch1",
"currency": "EUR"
}
]
}
}],
"note_to_payer": "Contact us for any questions on your order.",
"redirect_urls": {
"return_url": "http://example.com/success",
"cancel_url": "http://example.com/cancel"
}
}
那么,为什么它不授权我的令牌?语法有问题,还是我错过了一些完全相关的内容?
感谢您的帮助 干杯蒂姆
答案 0 :(得分:0)
尝试摆脱令牌值附近的{}。应该是:
Bearer A21AAHxasde3pBCINcYK6_VkHF2Y2M6dZIGRrvWBHKn1...