Introduction In today’s cash‑less economy, UPI (Unified Payments Interface) has become the backbone of digital transactions in India. Businesses of all sizes— from street vendors to e‑commerce platforms—are leveraging QR codes to simplify payment collection. Unlike static QR codes that embed a fixed payment address, dynamic QR codes embed transaction‑specific data such as amount, order ID, and merchant reference, enabling real‑time reconciliation and a smoother customer experience. This tutorial walks you through the end‑to‑end process of creating dynamic QR codes and merchant badges that work seamlessly with popular UPI apps like Google Pay, PhonePe, PayTM, Amazon Pay, and any BHIM‑compatible wallet. By the end, you’ll be equipped to generate, customize, and deploy QR codes that automatically capture payments and feed data directly into your backend systems.
Understanding Dynamic vs. Static QR Codes
Static QR codes contain a fixed UPI ID (e.g., merchant@upi) and are suitable only for “any‑amount” payments. They lack the ability to pre‑fill the transaction amount or order details, which means the payer must manually enter the amount each time. Dynamic QR codes, on the other hand, embed a UPI deep‑link URL that includes parameters such as pa (payee address), pn (payee name), am (amount), tid (transaction ID), and tr (reference). This structure not only auto‑populates the payment screen on the user’s UPI app but also provides merchants with instant, verifiable data for each transaction, reducing errors and improving cash flow visibility.
Setting Up Your UPI Merchant Account and API Access
- Register a UPI merchant ID with a participating bank or a payment aggregator that supports dynamic QR generation.
- Obtain API credentials (API key, secret, and endpoint URL) from the aggregator’s developer portal.
- Configure webhook URLs to receive real‑time payment notifications (success, failure, refunds).
- Secure your credentials by storing them in environment variables or a secret manager; never hard‑code them in client‑side code.
These steps lay the foundation for programmatic QR creation and ensure that every payment can be traced back to a unique merchant reference.
Generating Dynamic QR Codes Programmatically
Once you have API access, the typical workflow is:
- Collect order details (amount, order ID, customer ID) in your backend.
- Build a UPI deep‑link string using the required parameters, for example:
upi://pay?pa=merchant@upi&pn=Merchant%20Name&am=250.00&tid=ORD12345&tr=INV67890 - Send this string to the aggregator’s QR‑generation endpoint (usually a POST request with JSON payload).
- The API returns a base64‑encoded PNG or a short URL; embed the PNG in your web page or mobile app.
- Optionally, store the QR image or URL in your database for future reference.
Using server‑side languages like Node.js, Python, or PHP, you can automate this process for every checkout, ensuring each QR code is unique to the transaction.
Designing Merchant Badges and Integrating Across Channels
Beyond the QR image, a merchant badge combines branding (logo, colors) with the QR code, creating a professional look that builds trust. Follow these steps:
- Design a badge template in a graphics editor (e.g., 300 × 300 px) with placeholders for the QR image and merchant name.
- Use server‑side image libraries (ImageMagick, GD, Pillow) to overlay the generated QR onto the template dynamically.
- Serve the final badge as a responsive
<img>tag on your website, in email invoices, or within POS apps. - For physical stores, print the badge on durable material (PVC or laminated paper) and place it near the checkout counter.
This unified visual identity ensures customers recognize your brand across all UPI apps, encouraging repeat payments.
Testing, Monitoring, and Optimizing the Payment Flow
Before going live, perform comprehensive testing:
- Use sandbox credentials provided by the aggregator to simulate successful and failed payments.
- Verify that the amount, order ID, and reference fields appear correctly in the payer’s UPI app.
- Check webhook payloads for accurate status updates and reconcile them with your order database.
- Monitor QR scan rates and payment conversion using analytics tools; adjust badge placement or QR size if needed.
Regularly audit API logs for anomalies and rotate API keys periodically to maintain security. Continuous optimization will keep the checkout experience frictionless and trustworthy.
Conclusion Dynamic QR codes empower merchants to collect UPI payments with precision, speed, and brand consistency. By understanding the technical distinction between static and dynamic codes, securing a merchant UPI account, and leveraging API‑driven QR generation, you can automate payment collection for any transaction size. Adding custom merchant badges enhances visual trust, while rigorous testing and real‑time monitoring ensure the system remains reliable and secure. Implementing these steps will not only streamline your cash flow but also provide customers with a seamless, app‑agnostic checkout experience across Google Pay, PhonePe, PayTM, Amazon Pay, and other BHIM‑compatible wallets. Embrace dynamic QR technology today to stay ahead in India’s fast‑moving digital payments landscape.









