-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
84 lines (66 loc) · 2.88 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import datetime
import logging
import requests
from flask import Flask, render_template, request
from paytm_checksum import generate_checksum, verify_checksum
logging.basicConfig(level=logging.DEBUG)
app = Flask(__name__)
# Staging configs:
# Keys from https://dashboard.paytm.com/next/apikeys
MERCHANT_ID = "cqxpFk55774655560618"
MERCHANT_KEY = "4a%G!gRDQrao6eC1"
WEBSITE_NAME = "WEBSTAGING"
INDUSTRY_TYPE_ID = "Retail"
BASE_URL = "https://securegw-stage.paytm.in"
# Production configs:
# Keys from https://dashboard.paytm.com/next/apikeys
# MERCHANT_ID = "VVWXUz15467369219240"
# MERCHANT_KEY = "GGmMYgzRcb7_FX&M"
# WEBSITE_NAME = "WEBSTAGING"
# INDUSTRY_TYPE_ID = "Retail"
# BASE_URL = "https://securegw.paytm.in"
@app.route("/")
def index():
amount = 11.07
transaction_data = {
"MID": MERCHANT_ID,
"WEBSITE": WEBSITE_NAME,
"INDUSTRY_TYPE_ID": INDUSTRY_TYPE_ID,
"ORDER_ID": str(datetime.datetime.now().timestamp()),
"CUST_ID": "007",
"TXN_AMOUNT": 100,
"CHANNEL_ID": "WEB",
"MOBILE_NO": "9553168964",
"EMAIL": "[email protected]",
"CALLBACK_URL": "http://127.0.0.1:5000/callback"
}
# Generate checksum hash
transaction_data["CHECKSUMHASH"] = generate_checksum(transaction_data, MERCHANT_KEY)
logging.info("Request params: {transaction_data}".format(transaction_data=transaction_data))
url = BASE_URL + '/theia/processTransaction'
return render_template("index.html", data=transaction_data, url=url)
@app.route('/callback', methods=["GET", "POST"])
def callback():
# log the callback response payload returned:
callback_response = request.form.to_dict()
logging.info("Transaction response: {callback_response}".format(callback_response=callback_response))
# verify callback response checksum:
checksum_verification_status = verify_checksum(callback_response, MERCHANT_KEY,
callback_response.get("CHECKSUMHASH"))
logging.info("checksum_verification_status: {check_status}".format(check_status=checksum_verification_status))
# verify transaction status:
transaction_verify_payload = {
"MID": callback_response.get("MID"),
"ORDERID": callback_response.get("ORDERID"),
"CHECKSUMHASH": callback_response.get("CHECKSUMHASH")
}
url = BASE_URL + '/order/status'
verification_response = requests.post(url=url, json=transaction_verify_payload)
logging.info("Verification response: {verification_response}".format(
verification_response=verification_response.json()))
return render_template("callback.html",
callback_response=callback_response,
checksum_verification_status=checksum_verification_status,
verification_response=verification_response.json())
if __name__ == "__main__":
app.run(DEBUG=True)