npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

upi-qr-code-generator

v1.0.0

Published

Generate UPI payment URIs and QR codes with a pre-filled amount in Node.js and browsers.

Readme

UPI QR Code Generator

Generate UPI payment URIs and QR codes with a pre-filled INR amount. The library works in Node.js and browser applications using a bundler, and ships with ESM, CommonJS, and TypeScript declarations.

This package generates payment requests. It does not initiate, verify, or reconcile payments and never handles a payer's UPI PIN.

Features

  • Creates standards-shaped upi://pay URIs
  • Includes and validates a fixed payment amount
  • Generates PNG data URLs or SVG strings
  • Escapes payee names, notes, and references safely
  • Supports merchant transaction references and merchant category codes
  • Provides TypeScript types and works from JavaScript

Install

Once published to npm:

npm install upi-qr-code-generator

To install the current GitHub version:

npm install github:techpool/upi-qr-code-generator

Node.js 20 or newer is supported.

Quick start

import {
  createUpiPaymentUri,
  generateUpiQrDataUrl,
} from "upi-qr-code-generator";

const payment = {
  payeeVpa: "merchant@bank",
  payeeName: "Example Store",
  amount: "149.00",
  transactionRef: "ORDER-123",
  transactionNote: "Order 123",
};

const uri = createUpiPaymentUri(payment);
console.log(uri);

const qrDataUrl = await generateUpiQrDataUrl(payment);

// Browser example
document.querySelector("img").src = qrDataUrl;

The generated URI looks like this:

upi://pay?pa=merchant%40bank&pn=Example%20Store&am=149.00&cu=INR&tr=ORDER-123&tn=Order%20123

Generate SVG

import { generateUpiQrSvg } from "upi-qr-code-generator";

const svg = await generateUpiQrSvg({
  payeeVpa: "merchant@bank",
  payeeName: "Example Store",
  amount: "499.50",
  transactionRef: "ORDER-456",
});

In Node.js, save the returned SVG with node:fs/promises. A complete example is available in examples/generate-svg.mjs.

CommonJS

const { generateUpiQrDataUrl } = require("upi-qr-code-generator");

const qrDataUrl = await generateUpiQrDataUrl({
  payeeVpa: "merchant@bank",
  payeeName: "Example Store",
  amount: "99.00",
});

API

createUpiPaymentUri(payment)

Returns the encoded upi://pay URI.

generateUpiQrDataUrl(payment, qrOptions?)

Returns a promise containing a PNG data:image/png;base64,... URL.

generateUpiQrSvg(payment, qrOptions?)

Returns a promise containing an SVG string.

normalizeUpiAmount(amount)

Validates a positive amount with at most two decimal places and returns an exact two-decimal string. It does not silently round.

Payment options

| Option | Type | Required | UPI field | Description | | --- | --- | --- | --- | --- | | payeeVpa | string | Yes | pa | Payee UPI virtual payment address | | payeeName | string | Yes | pn | Name shown in the payer's app | | amount | string \| number | Yes | am | Positive INR amount, maximum two decimal places | | transactionRef | string | No | tr | Unique merchant reference, maximum 35 characters | | transactionNote | string | No | tn | Payment note | | merchantCode | string | No | mc | Merchant category code supplied by an acquirer |

Use decimal strings such as "149.00" for money. JavaScript numbers are accepted for convenience, but values with more than two decimal places are rejected rather than rounded.

For dynamic merchant QR codes, supply a unique transactionRef for each payment. Your acquiring bank or PSP may require additional fields or impose stricter rules.

QR options

{
  errorCorrectionLevel?: "low" | "medium" | "quartile" | "high" | "L" | "M" | "Q" | "H";
  width?: number;
  margin?: number;
  scale?: number;
  color?: {
    dark?: string;
    light?: string;
  };
}

Defaults are a width of 512 pixels, margin of 2 modules, and error correction level M.

Payment confirmation

A successful QR scan is not proof of payment. To confirm payments, use the status, reconciliation, or webhook APIs provided by your bank, PSP, or payment gateway. Match their confirmed transaction to your unique transactionRef.

Always show the expected payee and amount in your checkout UI. The payer should verify those details in their UPI app before authorizing the transaction.

UPI compatibility

UPI app behavior can vary. Test production QR codes with the UPI apps your customers use and follow the requirements supplied by your acquiring bank or PSP. NPCI's merchant QR interoperability circular identifies pa and pn as critical fields and requires am and tr for dynamic merchant QRs.

Development

npm install
npm test
npm run typecheck
npm run build

Run the complete verification suite with:

npm run check

License

MIT