gpt4 book ai didi

python - 如何将变量发送到 paypal api 并使用 python SDK 取回它们?

转载 作者:太空宇宙 更新时间:2023-11-03 15:57:38 30 4
gpt4 key购买 nike

我正在制作一个包含卖家和买家的市场类型的应用程序,并尝试将 PayPal API 集成为用户之间的支付方式。

我需要能够将卖家的用户名(在我的网站上)作为参数发送到 PayPal 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')

我的payment.html支付模板

<html>
<head>

</head>


<body>
<h3>Seller username:foo1 Buyer username:foo2</h3>

<form action='{% url "app:payment_page" %}' method='post'>
{% csrf_token %}
<input type='submit' value='pay'>

</form>
</body>




</html>

最佳答案

我假设您使用的是 PayPal REST API。下transaction object有一个名为 note_to_payee 的字段,它会在付款查询的响应中返回。

你可以使用它,或者在 description 上想出一些字符串格式并寻找它。

关于python - 如何将变量发送到 paypal api 并使用 python SDK 取回它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54277358/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com