def pay(request): merchantMid = settings.PAYTM_MERCHANT_ID merchantKey = settings.PAYTM_MERCHANT_KEY order_id = Checksum.__id_generator__() #order_id = pk channelId = 'WEB' custId = "dfsvfdc" txnAmount = '10.00' website = 'WEBSTAGING' industryTypeId = 'Retail' callbackUrl = settings.HOST_URL + settings.PAYTM_CALLBACK_URL paytmParams = { 'MID': merchantMid, 'ORDER_ID': order_id, 'CUST_ID': custId, 'INDUSTRY_TYPE_ID': industryTypeId, 'CHANNEL_ID': channelId, 'TXN_AMOUNT': txnAmount, 'WEBSITE': website, 'CALLBACK_URL': callbackUrl, } paytmChecksum = generate_checksum(paytmParams, merchantKey) paytmParams['CHECKSUMHASH'] = paytmChecksum context = {'paytmDict': paytmParams} return render(request, 'payment/form1.html', context)
def createOrder(request, pk): OrderFormSet = inlineformset_factory(register, Booking, fields=('name', 'email', 'service', 'status', 'date', 'time'), extra=1) customer = register.objects.get(id=pk) formset = OrderFormSet(queryset=Booking.objects.none(), instance=customer) # form = OrderForm(initial={'customer':customer}) if request.method == 'POST': # print('Printing POST:', request.POST) # form = OrderForm(request.POST) formset = OrderFormSet(request.POST, instance=customer) if formset.is_valid(): formset.save() param_dict = { 'MID': 'Your Merchant Id', 'ORDER_ID': '65', 'TXN_AMOUNT': '100', 'CUST_ID': '*****@*****.**', 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'WEBSTAGING', 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': 'http://127.0.0.1:8000/dashboard/handlerequest/', } param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( param_dict, MERCHANT_KEY) return render(request, 'paytm.html', {'param_dict': param_dict}) context = {'form': formset} return render(request, 'order_form.html', context)
def pay(request): merchantMid = settings.PAYTM_MERCHANT_ID merchantKey = settings.PAYTM_MERCHANT_KEY order_id = Checksum.__id_generator__() channelId = 'WEB' #custId = request.POST['cnumber'] custId = "abcdef" #txnAmount = request.POST['fine'] txnAmount = 5.0 #custId = "fds" #txnAmount = '43' website = 'WEBSTAGING' industryTypeId = 'Retail' callbackUrl = reverse('check') paytmParams = { 'MID': merchantMid, 'ORDER_ID': order_id, 'CUST_ID': custId, 'INDUSTRY_TYPE_ID': industryTypeId, 'CHANNEL_ID': channelId, 'TXN_AMOUNT': txnAmount, 'WEBSITE': website, 'CALLBACK_URL': callbackUrl, } paytmChecksum = generate_checksum(paytmParams, merchantKey) paytmParams['CHECKSUMHASH'] = paytmChecksum context = {'paytmDict': paytmParams} return render(request, 'payment/form1.html', context)
def post(self, request): # print('post request.data:',request.data) print('checking paytm response:', request.data['RESPCODE'], request.data.keys()) MERCHANT_KEY = '2uE5Gn#pU5hcXdJ8' orderStatusMessage = None verify = False form = request.data respons_dict = {} for i in form.keys(): respons_dict[i] = form[i] if i == 'CHECKSUMHASH': checksum = form[i] verify = Checksum.verify_checksum(respons_dict, MERCHANT_KEY.encode(), checksum) print(verify) if 'GATEWAYNAME' in respons_dict: if respons_dict['GATEWAYNAME'] == 'WALLET': respons_dict['BANKNAME'] = 'null' if verify: if respons_dict['RESPCODE'] == '01': orderStatusMessage = "order successful" print('orderID :', respons_dict['ORDERID'], type(respons_dict['ORDERID'])) orderObj = Order.objects.get( orderNo=(int(respons_dict['ORDERID']) - 224)) tz = pytz.timezone('GMT') currentDT = datetime.datetime.now(tz) currentDT = currentDT + datetime.timedelta(hours=5, minutes=30) orderObj.paymentCompleted = True orderObj.orderPaidTime = currentDT orderObj.save() else: orderStatusMessage = "order unsuccessful because " + respons_dict[ 'RESPMSG'] else: orderStatusMessage = "order unsuccessful because " + respons_dict[ 'RESPMSG'] orderStatus = {'order status': orderStatusMessage} return Response(orderStatus)
def handlerequest(request): # paytm will send you post request here form = request.POST response_dict = {} for i in form.keys(): response_dict[i] = form[i] if i == 'CHECKSUMHASH': checksum = form[i] verify = Checksum.verify_checksum(response_dict, MERCHANT_KEY, checksum) if verify: if response_dict['RESPCODE'] == '01': print('order successful') else: print('order was not successful because' + response_dict['RESPMSG']) return render(request, 'paymentstatus.html', {'response': response_dict})
def payment(request): service1 = request.session.get('service') bill = service.objects.get(Service=service1) print(bill) param_dict = { 'MID': 'your merchant id', 'ORDER_ID': '205', 'TXN_AMOUNT': str(bill.price), 'CUST_ID': '*****@*****.**', 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'WEBSTAGING', 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': 'http://127.0.0.1:8000/appoinment/handlerequest/', } param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( param_dict, MERCHANT_KEY) return render(request, 'paytm.html', {'param_dict': param_dict})
def post(self, request): bills = {} MERCHANT_KEY = '2uE5Gn#pU5hcXdJ8'.encode() orderObj = Order.objects.get(orderNo=request.data['orderNo']) # for i in obj1.orderRestaurants.all(): order_id = str(224 + orderObj.orderNo.id) # obj2 = BillModel.objects.get(orderNo = request.data['orderNo'],billResId = i.id) # print('hello:',i.res_user) # MerchObj = Merchant.objects.get(merchant= i.res_user) # print(MerchObj) # print (obj1.orderNo.Totalcost) data_dict = { 'MID': 'HYqgIk22213857160559', 'ORDER_ID': order_id, 'TXN_AMOUNT': str(orderObj.totalcost) + '.00', 'CUST_ID': request.user.username, 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'WEBSTAGING', 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': 'http://127.0.0.1:8000/orders/response/', } param_dict = data_dict param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( data_dict, MERCHANT_KEY) bills['bill'] = param_dict if 'bill' in bills.keys(): return Response(bills) else: return Response({'status': 'failure'})