我正在与卖家和买家制作一个市场类型的应用程序,并试图整合PayPal API作为用户之间的支付手段。在
我需要能够发送卖家的用户名(在我的网站上)作为一个参数到贝宝API,并在成功付款后取回它,以便我可以通知卖家他已经付款。如何做到这一点?在
from paypalrestsdk import Payment
from django.http import HttpResponseRedirect
def payment_page(request):
if request.method == 'POST':
approval_url = 'http://127.0.0.1:8000/'
paypalrestsdk.configure({
"mode": "sandbox", # sandbox or live
"client_id": "client_id",
"client_secret": "client_secret"})
payment = paypalrestsdk.Payment({
"intent": "sale",
"payer": {
"payment_method": "paypal"},
"redirect_urls": {
"return_url": "http://localhost:8000/success",
"cancel_url": "http://localhost:8000/fail"},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": "5.00",
"currency": "USD",
"quantity": 1}]},
"amount": {
"total": "5.00",
"currency": "USD"},
"description": "This is the payment transaction description."}]})
if payment.create():
print("Payment created successfully")
for link in payment.links:
if link.rel == "approval_url":
# Convert to str to avoid Google App Engine Unicode issue
# https://github.com/paypal/rest-api-sdk-python/pull/58
approval_url = str(link.href)
print("Redirect for approval: %s" % (approval_url))
return HttpResponseRedirect(approval_url)
else:
print(payment.error)
else:
print('loading page')
return render(request, 'app/payment.html')
def success(request):
//Here I also want to capture seller username and buyer username
payment_id = request.GET.get('paymentId')
payer_id = request.GET.get('PayerID')
# Payment ID obtained when creating the payment (following redirect)
payment = Payment.find(payment_id)
# Execute payment with the payer ID from the create payment call (following redirect)
if payment.execute({"payer_id": payer_id}):
print("Payment[%s] execute successfully" % (payment.id))
else:
print(payment.error)
return render(request, 'app/success.html')
我的付款.html付款模板
^{pr2}$
我假设你使用的是贝宝restapi。在transaction object下面有一个名为
note_to_payee
的字段,它在付款查找的响应中返回。在您可以使用它,或者在
description
上想出一些字符串格式并查找它。在相关问题 更多 >
编程相关推荐