我已使用PayPal-Python-SDK以下列方式整合了PayPal付款流程。
paypalrestsdk
参数作为mode
(不是live
),sandbox
设置的客户端ID和客户端密码传递来配置live
模块。paypalrestsdk.Payment
创建付款,我传递了大量参数,包括return_url
,cancel_url
,price
,currency
,quantity
和其他一些人。redirect_url
。redirect_url
的链接,这是PayPal页面,他填写了PayPal详细信息或信用卡详细信息。paid
现在,问题是整个过程工作正常并且符合预期,但是钱不会从用于付款的PayPal帐户中流出。钱也不会从信用卡中流出。当然,用于接收的帐户不会收到钱。
以下是生成付款的代码:
# Configure SDK.
paypalrestsdk.configure({
'mode': settings.PAYPAL_MODE, # This one is set to 'live'.
'client_id': settings.PAYPAL_CLIENT_ID,
'client_secret': settings.PAYPAL_SECRET,
})
# Create a payment.
payment = paypalrestsdk.Payment({
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": '...', # Here's the return URL.
"cancel_url": '...', # Here's the cancel URL.
},
"transactions": [{
"item_list": {
"items": [{
"name": "Invoice Payment #1",
"sku": "item",
"price": "1.00", # This is set to 1 for testing only.
"currency": "AUD",
"quantity": 1
}]
},
"amount": {
"total": "1.00", # Same as above.
"currency": "AUD"
},
"description": "Invoice Payment #1"
}]
})
# Get the payment URL if successful.
if payment.create():
for link in payment.links:
if link.method == "REDIRECT":
redirect_url = str(link.href)
"..."
# Pass this variable to the HTML template context.
else:
"..."
# Handle the error.
因此,我将redirect_url
传递给用户。用户启动付款。付款处理正确,但不会转移或收到款项。
我做错了吗?
PS:这是我刚刚找到的类似问题 - “Paypal App does not receive money via REST”。
答案 0 :(得分:0)
回答我自己的问题。
在PayPal将您重定向回您的重定向网址后,您的GET或POST参数中会显示“paymentId”和“PayerID”。
之后,您可以使用它们来获得成功的付款。
payment_id = request.GET.get('paymentId', None) or request.POST.get('paymentId', None)
payer_id = request.GET.get('PayerID', None) or request.POST.get('PayerID', None)
payment = paypalrestsdk.Payment.find(payment_id)
然后您需要执行付款。
payment_response = payment.execute({'payer_id': payer_id})
然后,如果付款成功执行,请完成您需要的其他内容:
if payment_response:
# Payment successful.
...
else:
# Something went wrong.
...