🚀. Socket Launch Week Day 3:Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions.Learn more
Sign In

@adityavijay21/upiqr

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adityavijay21/upiqr

Generate NPCI's UPI QR code along with UPI intent link. Supports Node.js, browsers, and React Native.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

@adityavijay21/upiqr: UPI QR Code Generator

npm version build status npm downloads license

A lightweight, modern, and customizable UPI QR code generator for Node.js, browsers, and React Native. Generate static and dynamic UPI QR codes with a simple, fluent API.

🌐 Live Demo

Test out the package in a live environment! The React demo app we built is a perfect showcase.

➡️ Launch the Live Demo (You can deploy the React demo to a service like Vercel or Netlify to get this link)

✨ Features

  • Fluent API: Easy-to-use, chainable methods for a clean development experience.
  • Framework Agnostic: Works in Node.js, browsers, React, Vue, Svelte, and more.
  • React Native Support: First-class support for React Native via SVG output.
  • Flexible Output: Generate QR codes as Base64 PNGs (dataURL), SVG strings, or UTF8 strings.
  • Fully Typed: Written in TypeScript for a great developer experience with autocompletion.
  • Easy Installation: No peer dependencies to manage. It just works.

⚙️ How It Works

The library simplifies the process of creating a valid UPI intent URL and encoding it into a QR code.

Your Data ➡️ UPIQR Class ➡️ UPI Intent String ➡️ QR Code

📦 Installation

npm install @adityavijay21/upiqr

🚀 Usage Examples

1. Basic Usage (Node.js or Browser)

Create a QR code with a fixed amount and a transaction note.

import { UPIQR } from '@adityavijay21/upiqr';

async function generate() {
  const { qr, intent } = await new UPIQR()
    .set({
      upiId: 'adityavijay21@okicici',
      name: 'Aditya Vijay',
      amount: 150.75,
      transactionNote: 'For the awesome project!',
    })
    .generate();
    
  // qr is a base64 PNG dataURL string that can be used in an <img> tag.
  console.log(qr);
}

generate();

2. Variable Amount (Static QR)

Omit the amount field to let the person paying enter the amount themselves.

import { UPIQR } from '@adityavijay21/upiqr';

const { qr } = await new UPIQR()
  .set({
    upiId: 'adityavijay21@okicici',
    name: 'Aditya Vijay',
    // No amount is specified
  })
  .generate();

3. React Example

A simple React component to display a generated QR code.

import React, { useState, useEffect } from 'react';
import { UPIQR } from '@adityavijay21/upiqr';

function PaymentQRCode() {
  const [qrCode, setQrCode] = useState('');
  
  useEffect(() => {
    async function getQRCode() {
      const { qr } = await new UPIQR()
        .set({
          upiId: 'shop@ybl',
          name: 'My Awesome Shop',
          amount: 250,
        })
        .generate();
      setQrCode(qr);
    };

    getQRCode();
  }, []);

  if (!qrCode) return <div>Loading...</div>;

  return <img src={qrCode} alt="UPI QR Code" />;
};

4. React Native Example (using SVG)

For React Native, generating an SVG is the best approach. You'll need react-native-svg.

import React, { useState, useEffect } from 'react';
import { View, Text } from 'react-native';
import { SvgXml } from 'react-native-svg';
import { UPIQR } from '@adityavijay21/upiqr';

function PaymentQRCodeNative() {
  const [qrSvg, setQrSvg] = useState(null);

  useEffect(() => {
    async function getQRCode() {
      const { qr } = await new UPIQR()
        .set({ upiId: 'shop@ybl', name: 'React Native Shop' })
        .setOptions({ outputType: 'svg' }) // Generate an SVG string
        .generate();
      setQrSvg(qr);
    };

    getQRCode();
  }, []);

  if (!qrSvg) return <Text>Loading QR Code...</Text>;

  return <SvgXml xml={qrSvg} width="250" height="250" />;
};

🛠️ API Reference

.set(params)

Sets the UPI payment parameters.

FieldTypeDescriptionRequired
upiIdStringThe UPI ID of the payee (e.g., user@bank).Yes
nameStringThe registered name of the payee.Yes
amountNumberAmount to be paid. Omit for variable amount.No
payeeMerchantCodeStringYour Merchant Category Code.No
transactionIdStringA unique transaction ID for your reference.No
transactionRefStringA reference ID for the transaction (e.g., Invoice #).No
transactionNoteStringA note for the payment (e.g., "Coffee Payment").No
minimumAmountNumberThe minimum amount allowed for payment.No
currencyStringCurrency code (defaults to INR).No

.setOptions(options)

Customizes the visual appearance of the generated QR code.

FieldTypeDescriptionDefault
outputType'dataURL', 'svg', 'utf8'The desired output format of the QR code.'dataURL'
widthNumberThe width of the QR code image in pixels.undefined
marginNumberThe width of the quiet zone border.4
color.darkString (Hex)The color of the dark modules (e.g., #000000).#000000FF
color.lightString (Hex)The color of the light modules (e.g., #FFFFFF).#FFFFFFFF
errorCorrectionLevel'L', 'M', 'Q', 'H'The level of error correction.'M'

.generate()

Generates the QR code.

  • Returns: Promise<UPIQRResult>
  • UPIQRResult is an object: { qr: string, intent: string }

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

📄 License

This project is MIT licensed.

Keywords

upi

FAQs

Package last updated on 26 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts