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

@paybridgejs/khalti

v0.1.0

Published

Type-safe Khalti payment gateway integration for Node.js and browsers. Simplify Khalti payments with automatic error handling, payment verification, and built-in retry logic.

Readme

@paybridgejs/khalti

Type-safe Khalti payment gateway integration for Node.js and browsers. Simplify Khalti payments with automatic error handling, payment verification, and built-in retry logic.

Features

Type-safe API - Full TypeScript support with auto-generated types
Payment Initiation - Create payment sessions with a single method call
Payment Verification - Verify transaction status securely
Error Handling - Comprehensive error handling with custom error classes
Easy Integration - Simple API designed for rapid integration

Installation

npm install paybridgejs/khalti
# or
pnpm add paybridgejs/khalti
# or
yarn add paybridgejs/khalti

Quick Start

1. Initialize the Client

import { khalti } from "paybridgejs/khalti";

const client = new khalti({
  secretKey: process.env.KHALTI_SECRET_KEY!,
});

2. Initiate a Payment

const payment = await client.initiate({
  amount: 10000, // NPR 100 (in paisa, 1 NPR = 100 paisa)
  purchase_order_id: "ORDER-123",
  purchase_order_name: "iPhone 15",
  return_url: "https://yoursite.com/success",
  website_url: "https://yoursite.com",
});

console.log(payment.payment_url); // Redirect user to this URL
console.log(payment.pidx); // Store for later verification

3. Verify Payment

const result = await client.verify({
  pidx: "storedPidxFromInitiation",
});

if (result.status === "Completed") {
  console.log("✅ Payment successful!");
  console.log("Transaction ID:", result.transaction_id);
  console.log("Amount:", result.total_amount);
}

API Reference

KhaltiClient

Constructor

new khalti({
  secretKey: string; // Khalti API secret key (required)
})

Methods

initiate(payload)

Initiates a new payment transaction.

Parameters:

  • amount (number) - Amount in paisa (1 NPR = 100 paisa)
  • purchase_order_id (string) - Unique order identifier
  • purchase_order_name (string) - Display name for the order
  • return_url (string) - URL to redirect after payment completion
  • website_url (string) - Your website URL

Returns:

{
  pidx: string; // Payment index for tracking
  payment_url: string; // URL to redirect user for payment
  expires_at: string; // Expiration timestamp
  expires_in: number; // Expiration time in seconds
}
verify(payload)

Verifies the status of a payment transaction.

Parameters:

  • pidx (string) - Payment index from initiation

Returns:

{
  pidx: string;
  total_amount: number;
  status: "Completed" |
    "Pending" |
    "Initiated" |
    "Refunded" |
    "Expired" |
    "User canceled" |
    "Partially Refunded";
  transaction_id: string | null;
  fee: number;
  refunded: boolean;
}

Common Patterns

Store Payment References

Always store the pidx for later verification:

// When initiating payment
const payment = await client.initiate({...});
await db.payments.create({
  pidx: payment.pidx,
  orderId: "ORDER-123",
  amount: 10000,
  status: "pending",
  expiresAt: payment.expires_at,
});

// Later, when verifying
const result = await client.verify({ pidx });
await db.payments.update(pidx, {
  status: result.status,
  transactionId: result.transaction_id
});

Handle Different Payment States

const result = await client.verify({ pidx });

switch (result.status) {
  case "Completed":
    console.log("Payment successful");
    break;
  case "Pending":
  case "Initiated":
    console.log("Payment awaiting completion");
    break;
  case "Expired":
    console.log("Payment link expired");
    break;
  case "User canceled":
    console.log("User cancelled the payment");
    break;
  case "Refunded":
  case "Partially Refunded":
    console.log("Payment refunded");
    break;
}

Khalti Payment Gateway Features

Khalti is Nepal's leading payment gateway with support for:

  • 🏦 Bank Transfers - Direct bank payments
  • 📱 Mobile Banking - Internet banking via mobile
  • 💰 Mobile Wallet - KhaltiPay digital wallet
  • 🎫 QR Codes - QR-based payments
  • Instant Settlement - Fast fund transfers
  • 💳 Low Fees - Competitive transaction fees

Documentation

For more detailed documentation, visit:

Error Handling

The package includes custom error classes for different scenarios:

import { khalti } from "paybridgejs/khalti";

try {
  const payment = await client.initiate({...});
} catch (error) {
  console.error("Payment initiation failed:", error.message);
}

License

MIT © 2024 PayBridge Contributors

Support

For issues, questions, or contributions, please visit: