gpt4 book ai didi

python - 为什么代码在收到响应后不执行

转载 作者:行者123 更新时间:2023-11-28 16:36:39 25 4
gpt4 key购买 nike

我正在运行下面的代码,它将用户带到 PayPal 进行付款,然后按预期将它们返回到 return_url。但是,代码不会进一步执行,也不会执行付款。

我的代码基于 https://github.com/paypal/rest-api-sdk-python :

class PayPalHandler(tornado.web.RequestHandler):

def get(self):

logging.basicConfig(level=logging.INFO)

paypal.configure({
"mode": PAYPAL_MODE,
"client_id": PAYPAL_CLIENT_ID,
"client_secret": PAYPAL_CLIENT_SECRET})



payment = paypal.Payment({
"intent": "sale",


"payer": {
"payment_method": "paypal" },


"redirect_urls": {
"return_url": "http://127.0.0.1:8000/ty",
"cancel_url": "http://127.0.0.1:8000/" },


"transactions": [ {

"item_list": {
"items": [{
"name": "membership",
"price": "2.00",
"currency": "GBP",
"quantity": 1 }]},


"amount": {
"total": "2.00",
"currency": "GBP" },
"description": "One of membership fee." } ] } )

redirect_url = ""

if payment.create():
print("Payment[%s] created successfully"%(payment.id))

for link in payment.links:
if link.method == "REDIRECT":
redirect_url = link.href
print("Redirect for approval: %s"%(redirect_url))
return self.redirect(redirect_url)

else:
print("Error while creating payment.")
print(payment.error)


response = payment.to_dict()
print response
payment = paypal.Payment.find(payment.id)

if payment.execute({"payer_id": response['payer_id']}):
print ("Payment executed successfully")
else:
print(payment.error) # Error Hash

print payment.to_dict()

print userData

所以在 https://devtools-paypal.com/guide/pay_paypal/python?success=true&token=EC-8JL96732FP068791F&PayerID=QQGSRNHDACTLJ 的例子中.第 5 步没有发生,PayPal 没有发送响应?

最佳答案

这是来自 PayPal 的 Avi。我对 Tornado 不是很熟悉,但是在 return self.redirect(redirect_url) 这行之后发生在您的代码中,并将用户返回到 payment.execute({"payer_id": response['payer_id']}) 中的 return_url您是否正确获取了 payer_id? Payer_id 作为参数之一返回附加到 return_url,格式为 http://<return_url>?token=EC-60U79048BN7719609&PayerID=7E7MGXCWTTKK2 .另外,你执行payment = paypal.Payment.find(payment.id)后付款状态如何? .我的另一个建议是查看是否 print payment.error打印一条有用的调试消息和一个 debug_id,paypal 商家技术服务可以使用它来查看问题。

关于python - 为什么代码在收到响应后不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25314836/

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