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-auto-capture

v0.2.0

Published

Minimal BharatPe UPI payment auto-capture — no database, in-memory only

Readme

upi-auto-capture

Minimal BharatPe UPI payment auto-capture — no database, no magic, just works.

Install

npm install upi-auto-capture

Quick start

const express = require('express');
const { UpiPayment, buildRouter } = require('upi-auto-capture');

const upi = new UpiPayment({
    upiId:      'BHARATPE.xxxx@fbpe',
    merchantId: '49354135',
    token:      '<BharatPe API token>',
    cookie:     '<BharatPe API cookie>',
});

const app = express();
app.use(express.json());

// Mount the payment routes
app.use('/pay', buildRouter(upi));

app.listen;

API

POST /pay/create

Create a payment session.

curl -X POST http://localhost:3000/pay/create \
  -H "Content-Type: application/json" \
  -d '{"orderId":"ORD-001","amount":10.00}'

Response:

{
  "status": "OK",
  "orderId": "ORD-001",
  "payToken": "a1b2c3d4",
  "qrCodeUrl": "data:image/png;base64,...",
  "upiDeepLink": "upi://pay?pa=...&am=10.00&pn=Pay&tn=ORD-001",
  "expiresAt": 1700000000000,
  "sessionAmount": 10.00
}

GET /pay/status/:orderId or POST /pay/status

Check payment status.

curl http://localhost:3000/pay/status/ORD-001

Response (pending):

{ "status": "PENDING" }

Response (captured):

{
  "status": "SUCCESS",
  "utr": "123456789012",
  "payerVpa": "customer@okaxis",
  "payerName": "John Doe",
  "payerHandle": "Google Pay",
  "amount": 10.00
}

Response (expired):

{ "status": "FAILURE" }

upi.checkPayment(orderId) (programmatic)

const result = await upi.checkPayment('ORD-001');
if (result.status === 'SUCCESS') {
    console.log('UTR:', result.utr);
    console.log('Payer VPA:', result.payerVpa);   // e.g. "customer@okaxis"
    console.log('Payer Name:', result.payerName);
    console.log('App Used:', result.payerHandle); // "Google Pay", "PhonePe", etc.
}

upi.findPayment(amount, windowMinutes) (manual reconciliation)

Look up a payment by amount — useful for enriching old sessions or finding payments after a server restart.

const result = await upi.findPayment(10.03, 15);
// { found: true, utr: '...', payerVpa: 'customer@okaxis', payerName: 'John Doe', payerHandle: 'Google Pay', amount: 10.03 }

How payerVpa works

The BharatPe PAYMENT_QR transaction list endpoint does not include the payer's UPI VPA. This package fetches it automatically using a two-step process:

  1. ListGET /api/v1/merchant/transactions?module=PAYMENT_QR&merchantId=... — finds the matching transaction by amount
  2. DetailGET /api/v1/merchant/transactions/{id}?module=PAYMENT_QR&merchantId=... — returns full details including payerVpa

The payerVpa enrichment happens automatically in checkPayment() and findPayment() — no extra code needed.

How it works

  1. Unique amount algorithm — each payment gets a slightly different amount (base + 0.01 to base + 0.99) so QR codes don't collide.
  2. In-memory sessions — 5-minute TTL, auto-expire. No database needed.
  3. BharatPe polling — the status endpoint queries BharatPe's transaction API and matches by amount (no stale date filters).
  4. payerVpa enrichment — after matching a transaction, a second API call fetches the payer's UPI ID from the transaction detail endpoint.

Options

const upi = new UpiPayment({
    upiId:      'BHARATPE.xxx@fbpe',
    merchantId: '49354135',
    token:      '...',
    cookie:     '...',
    ttl: 300,              // session TTL in seconds (default: 300)
});

// Customize route prefix
app.use('/payment', buildRouter(upi));

Response fields

| Field | Description | |-------|-------------| | status | PENDING, SUCCESS, or FAILURE | | utr | UPI transaction reference number | | payerVpa | Payer's UPI ID (e.g. user@okaxis) | | payerName | Payer's registered name on UPI | | payerHandle | UPI app used (Google Pay, PhonePe, BHIM, etc.) | | amount | Amount paid in INR |

Requirements

  • Node.js >= 18
  • BharatPe merchant account with API access

License

MIT