我正在为我的网站设置在线支付门户。 我使用以下代码:
ZARINPAL_WEBSERVICE ='https://www.zarinpal.com/pg/services/WebGate/wsdl' # Required
MERCHANT_ID = 'blah-blah-blah' # Required
amount = 0
@method_decorator(login_required, name='dispatch')
class Upgrade(View):
def get(self, request):
current_plan = UserPlan.objects.filter(user=request.user).first()
all_plans = Plans.objects.all()
old_plans = None
if current_plan:
new_plans = all_plans.filter(no__gt=current_plan.no)
old_plans = all_plans.filter(no__lte=current_plan.no)
else:
new_plans = all_plans
return render(request, 'business/upgrade.html', {'current_plan': current_plan,
'new_plans': new_plans,
'old_plans': old_plans})
def post(self, request):
current_plan = UserPlan.objects.filter(user=request.user).first()
form = UpgradeForm(request.POST)
if form.is_valid():
new_plan = form.cleaned_data.get('requested_plan')
requested_plan = Plans.objects.filter(no=new_plan).first()
global amount
if current_plan:
amount = requested_plan.price - current_plan.price
else:
amount = requested_plan.price
# redirect to ZarinPal page and send data to it
description = u'TEST DESCRIPTION' # Required
email = form.cleaned_data.get('email') # Optional
mobile = form.cleaned_data.get('phone') # Optional
CallbackURL = 'http://127.0.0.1:8000/business/verify/'
client = Client(ZARINPAL_WEBSERVICE)
result = client.service.PaymentRequest(MERCHANT_ID, amount, description, email, mobile, CallbackURL)
if result.Status == 100:
return redirect('https://www.zarinpal.com/pg/StartPay/' + result.Authority)
else:
return HttpResponse('Error')
else:
messages.error(request, form.errors)
print(form.errors)
return redirect('upgrade_plan')
@login_required
def verify(request):
client = Client(ZARINPAL_WEBSERVICE)
if request.GET.get('Status') == 'OK':
result = client.service.PaymentVerification(MMERCHANT_ID,
request.GET['Authority'],
amount)
if result.Status == 100:
# in this step, it must create or update UserPlan row in DB.
# also, it should be create a row in Sells table and save transaction defatils.
return HttpResponse('Transaction was successfull. RefID: ' + str(result.RefID))
elif result.Status == 101:
return HttpResponse('Transaction submitted : ' + str(result.Status))
else:
return HttpResponse('Transaction failed. Status: ' + str(result.Status))
else:
return HttpResponse('Transaction failed or canceled by user')
但在显示付款门之前,它会生成一个错误:
Exception at /business/upgrade/
(404, 'Not Found')
Request Method: POST
Request URL: http://localhost:8000/business/upgrade/ Django Version: 1.11.4 Exception Type: Exception Exception Value:
(404, 'Not Found')
错误是针对这行代码:
^{pr2}$怎么了?我该怎么解决呢? 谢谢
*更新*
下面的片段是我的网址.py文件:
from django.conf.urls import url
from . import views
urlpatterns = [
# for explicit urls
url(r'^upgrade/$', views.Upgrade.as_view(), name='upgrade_plan'),
url(r'^verify/$', views.verify, name='verify'),
]
这里有很多事情没有任何意义。在
首先,你不能让你的支付提供商用127.0.0.1地址回拨你的网站。这只是您的本地主机;但显然网关位于Internet的其他位置。它需要有一个你的网站的实际地址,它可以调用。在
第二,与你的问题无关但仍然是一个非常严重的问题,你绝对不能像这样使用全局变量。这些将被你的网站的所有用户共享,所以数量会全部混在一起。我不知道这个支付提供者的任何信息,但我绝对确定它会在回调参数中提供金额。在
相关问题 更多 >
编程相关推荐