gpt4 book ai didi

python - 我无法在 python 中使用 zeep - 缺少元素 CallbackURL 错误

转载 作者:太空宇宙 更新时间:2023-11-03 20:29:23 25 4
gpt4 key购买 nike

我想用 zeep 模块在 django 中创建一个支付网关。我想使用本地托管测试这个支付网关。我从一个生产支付网关的网站获得了帮助并编写了以下代码:

views.py

from django.shortcuts import render, redirect
from django.http import HttpResponse
from zeep import Client

MERCHANT = '00'
client = Client('https://www.zarinpal.com/pg/services/WebGate/wsdl')
amount = 1000
description = 'تست درگاه پرداخت'
CallbackURL = 'http://localhost:8000/' #whatever! i am just testing

def send_request(request):
result = client.service.PaymentRequest(MERCHANT, amount, description, CallbackURL)
if result.Status == 100:
return redirect('https://www.sandbox.zarinpal.com/pg/StartPay/' + str(result.Authority))
else:
return HttpResponse('Error code: ' + str(result.Status))

def verify(request):
if request.GET.get('Status') == 'OK':
result = client.service.PaymentVerification(MERCHANT, request.GET['Authority'], amount)
if result.Status == 100:
return HttpResponse('Transaction success.\nRefID: ' + str(result.RefID))
elif result.Status == 101:
return HttpResponse('Transaction submitted : ' + str(result.Status))
else:
return HttpResponse('Transaction failed.\nStatus: ' + str(result.Status))
else:
return HttpResponse('Transaction failed or canceled by user')

运行服务器时出现以下错误:

Exception Value: Missing element CallbackURL (PaymentRequest.CallbackURL)

Exception Location:C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\zeep\xsd\elements\element.py in validate, line 280

最佳答案

看起来您的 PaymentRequest 端点需要的参数比您提供的要多 - 它需要电子邮件和手机,然后才是 CallbackURL。由于这些是可以为空的,所以您不必提供它们是对的,但是您需要告诉 zeep 最终值适用于 CallbackURL 参数 - 您可以通过关键字参数来执行此操作。

client.service.PaymentRequest(MERCHANT, amount, description, CallbackURL=CallbackURL)

关于python - 我无法在 python 中使用 zeep - 缺少元素 CallbackURL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57603983/

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