def update_packet(self, msg_type=None, seqno=None, data=None, full_packet=None, update_checksum=True): """ This function handles safely changing the contents of a packet. By default, we re-compute the checksum every time the packet is updated. However, you can disable this if you intend to create a corrupted packet. Note that the checksum is calculated over the NON-0-indexed sequence number. """ if not self.bogon: if msg_type == None: msg_type = self.msg_type if seqno == None: seqno = self.seqno if data == None: data = self.data if msg_type == "ack": # doesn't have a data field, so handle separately body = "%s|%d|" % (msg_type, seqno) checksum_body = "%s|%d|" % (msg_type, seqno + self.start_seqno_base) else: body = "%s|%d|%s|" % (msg_type,seqno,data) checksum_body = "%s|%d|%s|" % (msg_type, seqno + self.start_seqno_base, data) if update_checksum: checksum = Checksum.generate_checksum(checksum_body) else: checksum = self.checksum self.msg_type = msg_type self.seqno = seqno self.data = data self.checksum = checksum if full_packet: self.full_packet = full_packet else: self.full_packet = "%s%s" % (body,checksum)
def shop(): name = request.form['name'] email = request.form['email'] blog_id = request.form['blog_id'] amount = request.form['amount'] orderid = str(random.randint(1, 2000)) paymentemail[orderid] = email paymentblog[orderid] = blog_id # password1=request.form['password1'] # password2=request.form['password2'] # print(name,email,paytmno,amount) deepak_dict = { 'MID': MERCHANT_ID, 'ORDER_ID': orderid, 'TXN_AMOUNT': str(amount), 'CUST_ID': email, 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'WEBSTAGING', 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': 'http://localhost:5000/shop/handlerequest/', } deepak_dict['CHECKSUMHASH'] = Checksum.generate_checksum( deepak_dict, MERCHANT_KEY) print(deepak_dict) return render_template('payment/paytm.html', deepak_dict=deepak_dict)
def payment(request): MERCHANT_KEY = settings.PAYTM_MERCHANT_KEY MERCHANT_ID = settings.PAYTM_MERCHANT_ID get_lang = "/" + get_language() if get_language() else '' CALLBACK_URL = settings.HOST_URL + get_lang + settings.PAYTM_CALLBACK_URL # Generating unique temporary ids order_id = Checksum.__id_generator__() bill_amount = request.GET.get("bill_amount") if bill_amount: data_dict = { 'MID': MERCHANT_ID, 'ORDER_ID': order_id, 'TXN_AMOUNT': bill_amount, 'CUST_ID': '*****@*****.**', 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'WEB_STAGING', 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': CALLBACK_URL, } param_dict = data_dict param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( data_dict, MERCHANT_KEY) return render(request, "paytm/payment.html", {'paytmdict': param_dict}) return HttpResponse("Bill Amount Could not find. ?bill_amount=10")
def paytm_request(request, token): teamcaptain = TeamCaptain.objects.get(payment_token=token) MERCHANT_KEY = settings.PAYTM_MERCHANT_KEY MERCHANT_ID = settings.PAYTM_MERCHANT_ID CALLBACK_URL = settings.HOST_URL + settings.PAYTM_CALLBACK_URL # Generating unique temporary ids order_id = Checksum.__id_generator__() teamcaptain.order_id = order_id teamcaptain.save() bill_amount = teamcaptain.event.price name = str(teamcaptain.name) + ' ' + str(teamcaptain.event.name) if bill_amount: data_dict = { 'MID': MERCHANT_ID, 'ORDER_ID': order_id, 'TXN_AMOUNT': bill_amount, 'CUST_ID': 'Cust002', 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'DIYtestingweb', #testing phase 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': CALLBACK_URL, } param_dict = data_dict param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( data_dict, MERCHANT_KEY) print param_dict return render(request, "registrations/payment.html", {'paytmdict': param_dict}) return HttpResponse("Bill Amount Error.")
def update_packet(self, msg_type=None, seqno=None, data=None, full_packet=None, update_checksum=True): """ This function handles safely changing the contents of a packet. By default, we re-compute the checksum every time the packet is updated. However, you can disable this if you intend to create a corrupted packet. Note that the checksum is calculated over the NON-0-indexed sequence number. """ if not self.bogon: if msg_type == None: msg_type = self.msg_type if seqno == None: seqno = self.seqno if data == None: data = self.data if msg_type == "ack": # doesn't have a data field, so handle separately body = "%s|%d|" % (msg_type, seqno) checksum_body = "%s|%d|" % (msg_type, seqno + self.start_seqno_base) else: body = "%s|%d|%s|" % (msg_type, seqno, data) checksum_body = "%s|%d|%s|" % (msg_type, seqno + self.start_seqno_base, data) if update_checksum: checksum = Checksum.generate_checksum(checksum_body) else: checksum = self.checksum self.msg_type = msg_type self.seqno = seqno self.data = data self.checksum = checksum if full_packet: self.full_packet = full_packet else: self.full_packet = "%s%s" % (body, checksum)
def make_packet(self,msg_type,seqno,msg): # msg_type can be either 'start', 'end', 'data', or 'ack' # seqno is simply the sequence number of the packet # msg is simply the packet's data body = "%s|%d|%s|" % (msg_type,seqno,msg) checksum = Checksum.generate_checksum(body) packet = "%s%s" % (body,checksum) return packet
def make_packet(self, msg_type=None, seqno=None, msg=None, packet=None): if msg_type is not None: body = b"".join([ msg_type.encode(), b'|', bytes(str(seqno).encode()), b'|', msg, b'|' ]) checksum = Checksum.generate_checksum(body) return_packet = body + checksum return return_packet else: body = b"".join([ packet[0].encode(), b'|', bytes(str(packet[1]).encode()), b'|', packet[2], b'|' ]) checksum = Checksum.generate_checksum(body) return_packet = body + checksum return return_packet
def make_packet(self, msg_type, seqno, msg): # msg_type can be either 'start', 'end', 'data', or 'ack' # seqno is simply the sequence number of the packet # msg is simply the packet's data body = "%s|%d|%s|" % (msg_type, seqno, msg) checksum = Checksum.generate_checksum(body) packet = "%s%s" % (body, checksum) return packet
def PaytmPaymentPage(param_dict): param_dict['MID'] = MERCHANT_ID param_dict['INDUSTRY_TYPE_ID'] = PAYTM_INDUSTRY_TYPE_ID param_dict['WEBSITE'] = PAYTM_WEBSITE param_dict['CHANNEL_ID'] = PAYTM_CHANNEL_ID param_dict['CALLBACK_URL'] = CALLBACK_URL param_dict['MOBILE_NO'] = PAYTM_MOBILE param_dict['EMAIL'] = PAYTM_EMAIL param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( param_dict, MERCHANT_KEY) return (GeneratePaymentPage(param_dict))
def payment_portal(request, *args, **kwargs): # if 'access_token' in request.session.keys(): error = {} success = {} if "transaction_type" not in request.POST or "amount" not in request.POST or "event_id" not in request.POST: return HttpResponse("transaction_type not found") else: request.session["ACCESS_TOKEN"] = kwargs["access_token"] amount = request.POST["amount"] if request.POST["transaction_type"] == "EVENT": request.session["transaction_type"] = "EVENT" request.session["event_id"] = request.POST["event_id"] elif request.POST["transaction_type"] == "USER": request.session["transaction_type"] = "USER" else: error["details"] = "Unknown transaction type" return HttpResponse(status=500, content_type="application/json", content=json.dumps(error)) data_dict = { 'MID': 'Rustic14665252659839', 'ORDER_ID': 'RUSTIC' + str(random.randint(1, 100000)), 'TXN_AMOUNT': amount, 'CUST_ID': '*****@*****.**', 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'WEB_STAGING', 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': 'http://35.162.117.56:9090/process_payment/', } param_dict = data_dict param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( data_dict, MERCHANT_KEY) # for key in param_dict: # print key.strip()+param_dict[key].strip() response = """ <h1>Merchant Check Out Page</h1></br> <form method="post" action="https://pguat.paytm.com/oltp-web/processTransaction" name="f1"> <table border="1"> <tbody>""" for key in param_dict: response += '<input type="hidden" name="' + key.strip( ) + '"value="' + param_dict[key].strip() + '">' response += """"</tbody> </table> <script type="text/javascript"> document.f1.submit(); </script> </form> """ return HttpResponse(response)
def index(request): if request.method == 'POST': data = {} mob = request.POST['mob_no'] amts = request.POST['amt'] data['mob'] = mob data['amt'] = amts inv_len = 20 special_char = '@-_.' order_id = ''.join(random.choice(ascii_uppercase + digits + ascii_lowercase + special_char) for _ in range(inv_len)) print order_id MERCHANT_KEY = '%xnpkZ!oREvq_Id9' data_dict = {'REQUEST_TYPE':'DEFAULT','MID': 'rechar67895469891518', 'ORDER_ID': '%s' % order_id, 'TXN_AMOUNT': '%s' % amts, 'CUST_ID': '*****@*****.**', 'CHANNEL_ID': 'WEB', 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'WEB_STAGING', 'MOBILE_NO': '%s' % mob, 'EMAIL':'*****@*****.**'} param_dict = data_dict link = 'https://pguat.paytm.com/oltp/HANDLER_INTERNAL/getTxnStatus?JsonData=' param_dict['CHECKSUMHASH'] = Checksum.generate_checksum(data_dict, MERCHANT_KEY) print param_dict result = connectionutils.get_response(link, param_dict) return HttpResponse(result) return render(request, "recharge/index.html")
def getpaid(invoice): # Request paytm to transfer the amount to your account after payment by user with open("invoice.json", "r") as meandyou: youandme = json.load(meandyou) if youandme[str(invoice)]["status"].lower() != "paid": param_dict = { 'MID': 'TirnwY02884048811102', 'ORDER_ID': str(invoice), 'TXN_AMOUNT': str(youandme[str(invoice)]["amount"]), 'CUST_ID': str(youandme[str(invoice)]["cno"]), 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'WEBSTAGING', 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': 'http://192.168.43.181:8080/handlerequest/', } param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( param_dict, MERCHANT_KEY) return render_template("paytm.html", param_dict=param_dict) else: return "your bill is paid"
def payment(request): MERCHANT_KEY = settings.PAYTM_MERCHANT_KEY MERCHANT_ID = settings.PAYTM_MERCHANT_ID CALLBACK_URL = settings.PAYTM_CALLBACK_URL # Generating unique temporary ids order_id = Checksum.__id_generator__() bill_amount = "100" data_dict = { 'MID': MERCHANT_ID, 'ORDER_ID': order_id, 'TXN_AMOUNT': bill_amount, 'CUST_ID': '*****@*****.**', 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'WEB_STAGING', 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': CALLBACK_URL, } param_dict = data_dict param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( data_dict, MERCHANT_KEY) return render(request, "payment.html", {'paytmdict': param_dict})
def make_packet(self,msg_type,seqno,msg): body = "%s|%d|%s|" % (msg_type,seqno,msg) checksum = Checksum.generate_checksum(body) packet = "%s%s" % (body,checksum) return packet
def __sign__(param_dict): param_dict['CHECKSUMHASH'] = Checksum.generate_checksum(param_dict=param_dict, merchant_key={YOUR_MERCHANT_KEY})
"MOBILE_NO" : "#Consumer_mob_no", # customer's email "EMAIL" : "#Consumer_email", # Amount in INR that is payble by customer # this should be numeric with optionally having two decimal points "TXN_AMOUNT" : "200", # on completion of transaction, we will send you the response on this URL "CALLBACK_URL" : "http://127.0.0.1:5000/pay_status", } # Generate checksum for parameters we have # Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys checksum = Checksum.generate_checksum(paytmParams, "#your_Merchant_Key") # for Staging url = "https://securegw-stage.paytm.in/order/process" @app.route('/') def index(): return render_template('payment.html',paytmParams=paytmParams,checksum=checksum) @app.route('/pay_status', methods=['GET','POST']) def paystatus(): paytmChecksum = {} data = {} if request.method == 'POST' :
'ORDER_ID': 'genz_order_5', 'TXN_AMOUNT': '1', 'CUST_ID': '*****@*****.**', 'INDUSTRY_TYPE_ID': 'Retail', # 'WEBSITE':'worldpressplg', 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': 'https://studentingera.com/paytm-status.php', } # headers = { # 'Content-Type': 'application/json', # 'mid': 'Studen81446331199922', # 'checksumhash': checksum # } param_dict = data_dict param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( data_dict, MERCHANT_KEY) # def exe(): # r2 = requests.post('https://securegw.paytm.in/order/process', data=param_dict, headers=headers) # return r2 for key in param_dict: print(key.strip() + param_dict[key].strip()) print('<h1>Merchant Check Out Page</h1></br>') print( '<form method="post" action="https://securegw.paytm.in/order/process" name="f1">' ) for key in param_dict: print('<input type="hidden" name="' + key.strip() + '"value="' + param_dict[key].strip() + '">') print('<script type="text/javascript">')
def make_packet(self, msg_type, seqno, message): body = "%s|%d|%s|" % (msg_type, seqno, message) #%将前面的变量和后面的字符关联起来 checksum = Checksum.generate_checksum(body) #嵌入方便绑定 packet = "%s%s" % (body, checksum) return packet
def _send_ack(self, seqno, address): m = "ack|%d|" % seqno checksum = Checksum.generate_checksum(m) message = "%s%s" % (m, checksum) self.send(message, address)
def _send_ack(self, seqno, address): m = b"".join([b'ack|', bytes(str(seqno).encode()), b'|']) checksum = Checksum.generate_checksum(m) #message = "%s%s" % (m, checksum) message = m + checksum self.send(message, address)
def __sign__(param_dict): param_dict['CHECKSUMHASH'] = Checksum.generate_checksum( param_dict=param_dict, merchant_key={YOUR_MERCHANT_KEY})
"MOBILE_NO" : "9768890726", # customer's email "EMAIL" : "*****@*****.**", # Amount in INR that is payble by customer # this should be numeric with optionally having two decimal points "TXN_AMOUNT" : "5000", # on completion of transaction, we will send you the response on this URL "CALLBACK_URL" : "YOUR_CALLBACK_URL", } # Generate checksum for parameters we have # Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys checksum = Checksum.generate_checksum(paytmParams, "SG4UY9spY6dyf!l6") # for Staging url = "https://securegw-stage.paytm.in/order/process" # for Production # url = "https://securegw.paytm.in/order/process" # Prepare HTML Form and Submit to Paytm print('<html>') print('<head>') print('<title>Merchant Checkout Page</title>') print('</head>') print('<body>') print('<center><h1>Please do not refresh this page...</h1></center>') print('<form method="post" action="' + url + '" name="paytm_form">')
def make_packet(self, msg_type, seqno, msg): body = "%s|%d|%s|" % (msg_type, seqno, msg) checksum = Checksum.generate_checksum(body) packet = "%s%s" % (body, checksum) return packet
def design_confirm_c(): global details connection = mysql.connect(host='localhost', database='user_information', user='******', password='******') cursor = connection.cursor() product_id = request.form['product_id'] slot_id = request.form['slot_id'] sql = ("SELECT price FROM design where product_id = '%s';" % product_id) cursor.execute(sql) result_1 = cursor.fetchall() print(result_1) details = { flask_login.current_user.id: { "name": request.form.get('name'), "number": request.form.get('number'), "email": request.form.get('email'), "price": str(result_1[0][0]), "product_id": request.form['product_id'], "slot_id": request.form['slot_id'], "sadan": request.form.get('sadan'), "room_number": request.form.get('room_number') } } print(details) paytmParams = { # Find your MID in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys "MID": "wZoPLo18357123923799", # Find your WEBSITE in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys "WEBSITE": "WEBSTAGING", # Find your INDUSTRY_TYPE_ID in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys "INDUSTRY_TYPE_ID": "Retail", # WEB for website and WAP for Mobile-websites or App "CHANNEL_ID": "WEB", # Enter your unique order id "ORDER_ID": str(uuid.uuid1()), # unique id that belongs to your customer "CUST_ID": details[flask_login.current_user.id]['product_id'], # customer's mobile number "MOBILE_NO": details[flask_login.current_user.id]['number'], # customer's email "EMAIL": details[flask_login.current_user.id]['email'], # Amount in INR that is payble by customer # this should be numeric with optionally having two decimal points "TXN_AMOUNT": details[flask_login.current_user.id]['price'], # on completion of transaction, we will send you the response on this URL "CALLBACK_URL": "http://ecommerce-env.u6cbbx6p7d.ap-south-1.elasticbeanstalk.com/confirm", } print(paytmParams) checksum = Checksum.generate_checksum(paytmParams, "vwBZlOSxr0&k_Am7") paytmParams["CHECKSUMHASH"] = checksum r = requests.post(url="https://securegw-stage.paytm.in/order/process", data=paytmParams) return r.text return 'done'