The upi:// link format: build a UPI payment QR without a gateway
If you build anything for Indian users, sooner or later someone asks for "a UPI QR with the amount already in it". You don't need a payment gateway or an SDK for that. UPI apps all read the same small URI, and a QR code
If you build anything for Indian users, sooner or later someone asks for "a UPI QR with the amount already in it". You don't need a payment gateway or an SDK for that. UPI apps all read the same small URI, and a QR code is just that URI drawn as squares.
The format
upi://pay?pa=yourname@okaxis&pn=Your%20Shop&am=499.00&cu=INR&tn=Order%201042
| Param | What it is |
|---|---|
pa |
Payee UPI ID (required), e.g. yourname@okaxis
|
pn |
Payee name |
am |
Amount in rupees, two decimals |
cu |
Currency, INR
|
tn |
Note shown to the payer |
tr |
Transaction reference (mostly for merchant IDs) |
Building it safely in JavaScript
function upiLink({ pa, pn, am, tn }) {
if (!/^[\w.-]{2,256}@[a-zA-Z][a-zA-Z0-9]{1,64}$/.test(pa)) {
throw new Error('Not a UPI ID');
}
const p = new URLSearchParams({ pa, cu: 'INR' });
if (pn) p.set('pn', pn);
if (am) p.set('am', Number(am).toFixed(2));
if (tn) p.set('tn', tn.slice(0, 80));
// spaces as %20, and keep the @ readable for older apps
return 'upi://pay?' + p.toString().replace(/\+/g, '%20').replace(/%40/g, '@');
}
Feed the string to any QR library and you have a scannable payment QR. Use error-correction level M or higher if it's going to be printed and handled.
Three gotchas that bite in production
- Link/button payments to personal UPI IDs. Since 1 April 2024, NPCI has asked UPI apps to block payments started from a link or button when the payee is a personal UPI ID. Users may see "This transaction may be risky". It works for verified merchant IDs. If your users collect on personal IDs, always show the QR and the UPI ID as text next to the button.
- Gallery QR limit. A QR picked from the phone's gallery can pay a personal UPI ID at most ₹2,000. Camera scans aren't affected.
-
The name on screen isn't from your QR. Since 30 June 2025, UPI apps show the payer the bank-registered name, not the
pnyou put in the code. Don't promise users their shop name will appear unless they use a business account.
Copy-paste version
I put a dependency-free version (button + UPI ID fallback, MIT) on GitHub: ezyupi/upi-pay-button.
If you just need the QR without writing code, the free generator at ezyupi.com does the amount, note, PNG/SVG download and printable standees. Disclosure: I work on it.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.