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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@naeimsafaee/ipg-node

v1.0.5

Published

Pluggable drivers for Iranian payment gateways

Readme

@naeimsafaee/ipg-node

A lightweight, pluggable driver framework for integrating Iranian payment gateways (e.g. Zibal, IdPay, …) into your Node.js or TypeScript projects.


Features

  • Modular drivers — isolate each gateway’s API in its own class
  • Uniform API — same .pay(...) and .verify(...) calls for every gateway
  • TypeScript support — full type definitions included
  • Easy to extend — drop in new drivers as they become available

Table of Contents

  1. Installation

  2. Usage

  3. API Reference

  4. Contributing

  5. License


Installation

From npm registry

npm install @naeimsafaee/ipg-node
# or
yarn add @naeimsafaee/ipg-node

Usage

TypeScript Example

const { PaymentGateway , ZibalDriver } = require('ipg-node');

const gateway = new PaymentGateway({
   drivers: [new ZibalDriver("")],
   config: {
      callbackUrlOverride: paymentCallbackUrl,
      sandbox: true
   }
});

async function checkout() {
  // 1. Create payment
  const { success, paymentUrl, raw } = await gateway.pay('zibal', {
    amount:      250000,
     // If no callbackUrl was provided in the PaymentRequest, fall back to callbackUrlOverride from the gateway config
     //callbackUrl: 'https://yourapp.com/callback',  
    orderId:     'order_1234'
  })

  if (success && paymentUrl) {
    // redirect user
    console.log('Go pay at:', paymentUrl)
  } else {
    console.error('Error requesting payment:', raw)
  }
}

// 2. In your callback handler
import express from 'express'
const app = express()

app.get('/callback', async (req, res) => {
  const result = await gateway.verify('zibal', req.query)
  if (result.success) {
    console.log('Paid! TraceNo:', result.traceNo)
    res.send('Payment successful!')
  } else {
    console.warn('Verification failed:', result.raw)
    res.status(400).send('Payment verification failed.')
  }
})

JavaScript (CommonJS) Example

const { PaymentGateway , ZibalDriver } = require('ipg-node');

const gateway = new PaymentGateway([
  new ZibalDriver(process.env.ZIBAL_API_KEY)
])

// Create payment
gateway.pay('zibal', {
  amount:      250000,
  callbackUrl: 'https://yourapp.com/callback',
  orderId:     'order_1234'
})
.then(({ success, paymentUrl, raw }) => {
  if (success) {
    console.log('Redirect to:', paymentUrl)
  } else {
    console.error('Payment error:', raw)
  }
})

// Verify callback (e.g. in Express)
app.get('/callback', (req, res) => {
  gateway.verify('zibal', req.query)
    .then(result => {
      if (result.success) {
        res.send('OK')
      } else {
        res.sendStatus(400)
      }
    })
})

API Reference

new PaymentGateway(drivers?: PaymentDriver[])

  • drivers — optional array of pre-registered PaymentDriver instances

gateway.register(driver: PaymentDriver): void

Register a new driver at runtime. Must have a unique driver.driverName.

gateway.pay(driverName: string, req: PaymentRequest): Promise<PaymentResponse>

  • driverName'zibal', 'idpay', etc.
  • req{ amount: number; callbackUrl: string; orderId?: string; [k: string]: any }
  • returns{ success: boolean; paymentUrl?: string; raw: any }

gateway.verify(driverName: string, data: any): Promise<VerificationResponse>

  • data — callback payload from the gateway
  • returns{ success: boolean; traceNo?: string; raw: any }

Contributing

Contributions, issues, and feature requests are welcome! Please open an issue or pull request on GitHub.


License

MIT © [Naeim Safaee] - https://github.com/naeimsafaee