Imports and Initialization python from dotenv import load_dotenv from flask import Flask, make_response, render_template, request, redirect, session, url_for, flash, send_file import mysql.connector import razorpay import os from reportlab.pdfgen import canvas import io from reportlab.lib.pagesizes import letter dotenv: Loads environment variables from a .env file. Flask: The main framework for building the web application. mysql.connector: Library to connect and interact with a MySQL database. razorpay: Library for integrating Razorpay payment gateway. os: Provides a way to use operating system functionalities like accessing environment variables. reportlab.pdfgen.canvas: Used for generating PDF files. io: Provides tools for handling streams (in this case, for PDF generation). reportlab.lib.pagesizes: Contains predefined page sizes (like letter) for PDF documents. Load Environment Variables python load_dotenv() Loads environment variables from a .env file to access sensitive information like API keys. Flask Application Setup python app = Flask(__name__) app.secret_key = 'arbab' Creates an instance of the Flask application and sets a secret key for session management. Database Connection python db = mysql.connector.connect( host="localhost", user="root", password="root", database="arbab_db" ) cursor = db.cursor() Establishes a connection to a MySQL database named arbab_db using specified credentials. A cursor is created for executing SQL queries. Razorpay Client Setup python razorpay_key_id = os.getenv("RAZORPAY_KEY_ID", "rzp_live_bEqiJu4kqFqRm5") razorpay_secret = os.getenv("RAZORPAY_KEY_SECRET", "FdxGjgjQ6tmyxZa6a1wJ81xD") client = razorpay.Client(auth=(razorpay_key_id, razorpay_secret)) Retrieves Razorpay API credentials from environment variables and initializes the Razorpay client for processing payments. Routes Definition Home Route python @app.route('/') def index(): return render_template('index.html') Defines the home route (/) which renders the index.html template. Registration Route python @app.route('/registration', methods=['GET', 'POST']) def registration(): if request.method == 'POST': ... return redirect(url_for('pay', id=user_id)) return render_template('registration.html') Handles user registration. On POST, it collects form data, generates a unique ID, inserts the data into the database, and redirects to the payment page. On GET, it renders the registration form. Payment Route python @app.route('/pay/<id>', methods=['GET', 'POST']) def pay(id): ... return render_template('pay.html', payment=payment, dummy_id=dummy_id, ticket=ticket, amount=amount) Handles payment processing. It retrieves registration details based on user ID, calculates the amount based on ticket type, and creates a payment order with Razorpay. It then renders the payment page. Information Route python @app.route('/info') def info(): return render_template('info.html') Renders an information page (info.html). ID Card Route python @app.route('/id_card') def id_card(): ... return render_template('id_card.html', **registration_data) Displays the ID card based on session data. If no data is found in the session, it redirects to the registration page. Confirmation Route python @app.route('/confirmation/<payment_id>') def confirmation(payment_id): return render_template('confirmation.html', payment_id=payment_id) Renders a confirmation page showing the payment ID after successful payment. Success Route python @app.route('/success', methods=['POST']) def success(): ... return redirect(url_for('registration')) Handles payment success by verifying the payment signature with Razorpay. If successful, it redirects to the ID card page; otherwise, it shows an error message. Download ID Card Route python @app.route('/download_id_card', methods=['GET']) def download_id_card(): ... return send_file(buffer, as_attachment=True, download_name="{name}.pdf", mimetype='application/pdf') Generates a PDF ID card using ReportLab and allows users to download it. If no registration data is found in the session, it redirects to the registration page. Main Block python if __name__ == '__main__': app.run(debug=True) Runs the Flask application in debug mode if this script is executed directly.