from flask import Flask, request, redirect import urllib.parse app = Flask(__name__) @app.route('/upi') def upi_redirect(): try: # 1. Get the UPI Address from the Query Parameter encoded_address = request.args.get('address') upi_address = urllib.parse.unquote(encoded_address) # 2. Validate UPI Address (Optional) # You can add validation logic here to ensure the address is in the correct format # 3. Construct UPI Payment Link payment_link = f"upi://pay?pa={upi_address}&pn=TIGER%20CODEZ&am=5&tn=THIS%20IS%20TEST%20NOTE&cu=INR" # 4. Redirect the User to UPI App return redirect(payment_link, code=302) # 302 Found except Exception as e: # Handle any potential errors (e.g., invalid address) return "Error: Invalid UPI address or payment request." if __name__ == '__main__': app.run(debug=True)