upiqrcode
v1.5.9
Published
Generate UPI compatible QR codes as SVG -- compiled into WebAssembly
Readme
✨ Features
- 🚀 WebAssembly Powered: Built in Rust and compiled via
wasm-packfor peak performance. - 🎨 Pure SVG Output: No canvas or DOM dependencies—renders crystal-clear at any resolution.
- 📱 Universal Compatibility: Works seamlessly across Node.js, browsers, Edge runtimes, and Cloudflare Workers.
- 🔗 Dual Output: Returns both the visual SVG QR code and the raw UPI deep-link intent (
upi://pay?...). - 🛡️ Spec Compliant: Adheres strictly to the NPCI Unified Payments Interface specifications.
📦 Installation
Install with your preferred package manager:
# npm
npm install upiqrcode
# pnpm
pnpm add upiqrcode
# yarn
yarn add upiqrcode
# bun
bun add upiqrcode🚀 Quick Start
1. Node.js / TypeScript / ESM
import { upiqrcode } from "upiqrcode";
async function generateInvoice() {
const result = await upiqrcode({
payeeVPA: "merchant@bank",
payeeName: "Acme Corporation",
amount: "499.00",
currency: "INR",
transactionNote: "Invoice #INV-2026-001",
transactionId: "TXN1234567890",
});
console.log("UPI Intent Link:", result.intent);
// Output: upi://pay?pa=merchant@bank&pn=Acme%20Corporation&am=499.00&cu=INR&tn=Invoice%20%23INV-2026-001&tr=TXN1234567890
console.log("Raw SVG Code:\n", result.qr);
}
generateInvoice();2. React / Next.js
"use client";
import { useEffect, useState } from "react";
import { upiqrcode } from "upiqrcode";
export default function PaymentQRCode() {
const [svg, setSvg] = useState<string>("");
const [intent, setIntent] = useState<string>("");
useEffect(() => {
async function fetchQR() {
const data = await upiqrcode({
payeeVPA: "business@upi",
payeeName: "My Online Store",
amount: "1500.00",
transactionNote: "Order #8821",
});
setSvg(data.qr);
setIntent(data.intent);
}
fetchQR();
}, []);
return (
<div style={{ textAlign: "center", padding: "1.5rem" }}>
<h3>Scan to Pay</h3>
{svg ? (
<div
style={{ width: 250, margin: "0 auto" }}
dangerouslySetInnerHTML={{ __html: svg }}
/>
) : (
<p>Loading QR Code...</p>
)}
{intent && (
<p>
<a href={intent}>Click here to pay directly on mobile</a>
</p>
)}
</div>
);
}3. Vanilla JavaScript (Browser / CDN)
Link the CDN script and use the upiqrcode function directly.
https://esm.sh/upiqrcode ..
https://cdn.jsdelivr.net/npm/upiqrcode/+esm
https://unpkg.com/[email protected]/upiqrcode.js
<div id="qrcode-container"></div>
<script type="module">
import { upiqrcode } from "https://cdn.jsdelivr.net/npm/upiqrcode/+esm";
const { qr } = await upiqrcode({
payeeVPA: "username@okhdfcbank",
payeeName: "Rahul Sharma",
amount: "250.00",
});
document.getElementById("qrcode-container").innerHTML = qr;
</script>📖 API Reference
upiqrcode(params)
function upiqrcode(params: UpiqrcodeParams): Promise<UpiqrcodeResult>Parameters (UpiqrcodeParams)
| Parameter | Type | Required | Default | Description |
| :--- | :--- | :---: | :---: | :--- |
| payeeVPA | string | Yes | — | Payee Virtual Payment Address (e.g., user@upi). |
| payeeName | string | Yes | — | Name of the recipient or merchant. |
| amount | string | No | — | Transaction amount (e.g., "100.00"). |
| minimumAmount | string | No | — | Minimum transaction amount allowed. |
| currency | string | No | "INR" | 3-letter currency code (Standard: INR). |
| transactionId | string | No | — | Unique bank transaction reference ID (tr). |
| transactionRef | string | No | — | Merchant reference / order ID. |
| transactionNote | string | No | — | Short description or remark (tn). |
| payeeMerchantCode| string | No | — | 4-digit Merchant Category Code (MCC). |
| transactionRefUrl| string | No | — | Order URL / digital invoice URL (url). |
Return Value (UpiqrcodeResult)
| Property | Type | Description |
| :--- | :--- | :--- |
| qr | string | Complete <svg>...</svg> string ready to insert into DOM or file. |
| intent | string | Fully-encoded UPI intent link (upi://pay?...). |
🛠️ Building from Source
This package compiles Rust code to WebAssembly using wasm-pack.
Prerequisites
- Rust & Cargo (latest stable)
- Node.js (v18+)
- wasm-pack
Steps
# 1. Clone the repository
git clone https://github.com/Pratyay360/upiqrcode.git
cd upiqrcode
# 2. Build WebAssembly target
wasm-pack build --target bundler
# 3. Install JS dependencies
npm install🤝 Contributing
Contributions, issues, and feature requests are welcome! Feel free to open an issue or pull request on GitHub.
📄 License
Distributed under the Apache-2.0 License. See LICENSE_APACHE for more information.
