DEV Community

Azqora Tech
Azqora Tech

Posted on

What's inside a UPI QR code? The upi://pay link, explained

In India you scan a UPI QR code at almost every shop. It feels like something special, but a basic UPI QR is just a text link encoded as a QR code. Any QR library can make one.

If you're building a checkout page, an invoice, or a small tool for a shop, here's what goes inside it and the mistakes to avoid.

The format

A UPI payment QR holds a URI like this:

upi://pay?pa=shopname@okbank&pn=Sharma%20General%20Store&am=150.00&cu=INR&tn=Order%2042
Enter fullscreen mode Exit fullscreen mode

The common parameters:

Param Meaning Required?
pa Payee address (the UPI ID / VPA) Yes
pn Payee name shown to the payer Strongly recommended
am Amount Optional
cu Currency, INR Usually included
tn Note shown in the payment Optional

There are more parameters for registered merchants (like a transaction reference), but for a simple shop or personal QR these five cover it.

When a payer scans it, their UPI app reads the link and opens a payment screen with these fields filled in.

Building the link

function upiLink({ vpa, name, amount, note }) {
  const params = [
    ['pa', vpa],
    ['pn', name],
    ['cu', 'INR'],
  ];
  if (amount) params.push(['am', Number(amount).toFixed(2)]);
  if (note) params.push(['tn', note]);

  const query = params
    // keep @ readable in the UPI ID; some apps may not decode %40
    .map(([k, v]) => `${k}=${encodeURIComponent(v).replace(/%40/g, '@')}`)
    .join('&');
  return `upi://pay?${query}`;
}

upiLink({ vpa: 'shopname@okbank', name: 'Sharma General Store', amount: 150 });
// upi://pay?pa=shopname@okbank&pn=Sharma%20General%20Store&cu=INR&am=150.00
Enter fullscreen mode Exit fullscreen mode

Then pass that string to any QR generator library.

Mistakes to avoid

Using URLSearchParams for the query. It encodes spaces as +. Browsers understand that, but a UPI app isn't a browser, and you can't test every app. encodeURIComponent gives %20, which is the safer choice.

Putting an amount on a shop's counter QR. If you include am, every customer gets the same fixed amount. For a QR printed at the counter, leave am out so the payer types the amount. Use a fixed amount only for a specific bill or invoice.

A typo in the UPI ID. The QR will still scan, and the money will try to go to whatever ID you typed. Always scan your own QR once and check the name your UPI app shows before printing it.

Thinking the QR confirms payment. A static UPI QR only opens the payment screen. It doesn't tell your website or your shop that the payment happened. Confirm it in the bank app, the SMS, or a payment gateway's callback, not from the customer's screen. Fake "payment successful" screenshots are a known trick.

Making it too small or low contrast. UPI QRs get scanned in bad light by old phones. Keep a quiet zone (white border) around the code and print it at a decent size, dark on light.

For payers: check before you pay

Because the payee name comes from the UPI system, your app shows the real account holder's name after you scan. If it doesn't match the shop or person you expect, stop. Scam QR stickers pasted over a real one are common.

Try it

QRizeo's UPI QR code generator builds the upi://pay link from your UPI ID, name and optional amount and turns it into a QR code you can download and print.

Have you added UPI payments to a project? I'd like to know how you handled confirming the payment.

Top comments (0)