在处理paytm付款并返回到我的Django应用程序时,我遇到了以下问题。下面是我在views.py
中的代码from django.http import HttpResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.conf import settings
from paytm import checksum
from paytm.models import PaymentHistory
@login_required
def payment(request):
CALLBACK_URL = settings.HOST_URL + settings.PAYTM_CALLBACK_URL
order_id = checksum.__id_generator__()
bill_amount = request.POST['amount']
if bill_amount:
data_dict = {
'MID':settings.PAYTM_MERCHANT_ID,
'ORDER_ID':order_id,
'TXN_AMOUNT': bill_amount,
'CUST_ID':request.user.email,
'INDUSTRY_TYPE_ID':settings.PAYTM_INDUSTRY_TYPE,
'WEBSITE': settings.PAYTM_WEBSITE,
'CHANNEL_ID':'WEB',
'CALLBACK_URL':CALLBACK_URL,
}
param_dict = data_dict
param_dict['CHECKSUMHASH'] = checksum.generate_checksum(data_dict, settings.PAYTM_MERCHANT_KEY)
return render(request,"paytm/payment.html",{'paytmdict':param_dict})
return HttpResponse("Bill Amount Could not find. ?bill_amount=10")
@login_required
@csrf_exempt
def response(request):
if request.method == 'GET':
return render(request, 'paytm/home.html')
elif request.method == "POST":
data_dict = {}
for key in request.POST:
data_dict[key] = request.POST[key]
verify = checksum.verify_checksum(data_dict, settings.PAYTM_MERCHANT_KEY, data_dict['CHECKSUMHASH'])
if verify:
for key in request.POST:
if key == "BANKTXNID" or key == "RESPCODE":
if request.POST[key]:
data_dict[key] = int(request.POST[key])
else:
data_dict[key] = 0
elif key == "TXNAMOUNT":
data_dict[key] = float(request.POST[key])
PaymentHistory.objects.create(user=request.user, **data_dict)
return render(request,"paytm/response.html",{"paytm":data_dict})
else:
return HttpResponse("checksum verify failed")
return HttpResponse(status=200)
urls.py中的代码
from django.urls import path
from paytm import views
urlpatterns = [
path('', views.response, name='home'),
path('payment/', views.payment, name='payment'),
path('response/', views.response, name='response'),
]
这是我的追溯异常详细信息。
[12/May/2019 08:38:35] "POST /paytm/payment/ HTTP/1.1" 200 4005
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 54543)
Traceback (most recent call last):
File "C:\Python\Python37\lib\socketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:\Python\Python37\lib\socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python\Python37\lib\socketserver.py", line 717, in __init__
self.handle()
File "C:\Python\Python37\lib\site-packages\django\core\servers\basehttp.py", line
171, in handle
self.handle_one_request()
File "C:\Python\Python37\lib\site-packages\django\core\servers\basehttp.py", line
179, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "C:\Python\Python37\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by
the remote host
----------------------------------------
[12/May/2019 08:39:25] "POST /paytm/response/ HTTP/1.1" 200 3154
交易应毫无例外地完成。在本地,即使出现错误,我也从Paytm获得响应。但是在实时网站中,交易发生而没有Paytm的任何回应。希望由于上述例外情况,网站上没有任何回应,它会自动返回首页。