Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
101 lines (77 loc) · 3.46 KB
/
Copy pathapp.py
File metadata and controls
101 lines (77 loc) · 3.46 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import qrcode
from flask import Flask, render_template, request, redirect
import io
import base64
from PIL import Image
import re
app = Flask(__name__)
validEndings = ["@abcdicici", "@apl", "@yapl", "@rapl", "@abfspay", "@abfspay", "@bpunity", "@axisb", "@yescred", "@yescurie", "@yesfam", "@fifederal", "@fkaxis", "@freoicici", "@gwaxis", "@okaxis", "@okhdfcbank", "@okicici", "@oksbi", "@yesg", "@inhdfc", "@jupiteraxis", "@goaxb", "@kphdfc", "@ikwik", "@mvhdfc", "@naviaxis", "@niyoicici", "@oneyes", "@axb", "@paytm", "@ptyes", "@ptaxis", "@pthdfc", "@ptsbi", "@ybl", "@ibl", "@axl", "@yespop", "@rmrbl", "@pingpay", "@seyes", "@shriramhdfcbank", "@sliceaxis", "@superyes", "@tapicici", "@timecosmos", "@axisbank", "@yestp", "@idfcbank", "@waicici", "@icici", "@waaxis", "@wahdfcbank", "@wasbi"]
@app.errorhandler(404)
def not_found(error):
return {
"error": "Not Found",
"message": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."
}
@app.route('/qr')
def qr():
return render_template('qr.html')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/generate_upi', methods=['POST'])
def generate_upi():
vpa = request.form['vpa']
amount = request.form['amount']
amount = round(float(amount), 2)
# Construct the UPI link
upi_link = f"/qr/{vpa}&{amount}"
return redirect(upi_link)
@app.route('/qr/<vpa_and_amount>')
def upi_redirect(vpa_and_amount):
try:
vpa, amount = vpa_and_amount.split('&')
amount = round(float(amount), 2)
if not re.fullmatch(r'[a-zA-Z0-9]+@[a-zA-Z0-9]+', vpa):
return {"error": "Invalid VPA. Only letters, numbers, and '@' is allowed."}, 400
if vpa_and_amount.count('@') != 1:
return {"error": "Invalid VPA"}, 400
upi_link = f"upi://pay?pa={vpa}&am={amount}&cu=INR"
qr = qrcode.make(upi_link)
img = io.BytesIO()
qr.save(img, format='PNG')
img.seek(0)
qr_code_base64 = base64.b64encode(img.getvalue()).decode('utf-8')
return render_template('upiQR.html', vpa=vpa, amount=amount, qr_code=qr_code_base64)
except Exception as e:
return {"error": str(e)}, 400
@app.route('/upi/api/<vpa_and_amount>')
def upi_api(vpa_and_amount):
try:
vpa, amount = vpa_and_amount.split('&')
amount = round(float(amount), 2)
if not re.fullmatch(r'[a-zA-Z0-9]+@[a-zA-Z0-9]+', vpa):
return {"error": "Invalid VPA. Only letters, numbers, and '@' is allowed."}, 400
if vpa_and_amount.count('@') != 1:
return {"error": "Invalid VPA"}, 400
upi_link = f"upi://pay?pa={vpa}&am={amount}&cu=INR"
return {
"vpa": vpa,
"amount": amount,
"upi_link": upi_link,
"gpay_link": f'tez://upi/pay?pa={vpa}&am={amount}&cu=INR',
"phonepe_link": f"phonepe://upi/pay?pa={vpa}&am={amount}&cu=INR"
}
except Exception as e:
return {"error": str(e)}, 400
@app.route('/upi/api/validEndings')
def valid_endings():
try:
return {
"validEndings": validEndings,
"lastUpdated": "2025-02-10 17:11:21 UTC+5;30",
"source": "https://www.npci.org.in/what-we-do/upi/3rd-party-apps"
}
except Exception as e:
return {"error": str(e)}, 400
if __name__ == '__main__':
app.run(debug=True)