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

fibpay

v1.0.7

Published

Official Node.js SDK for the First Iraqi Bank (FIB) Online Payment Gateway

Readme

FibPay

Official Node.js SDK for the First Iraqi Bank (FIB) Online Payment Gateway


Table of Contents


Features

  • ✅ Full coverage of the FIB payment API (create, status, cancel, refund)
  • 🔐 Automatic OAuth2 token management with expiry refresh
  • ⏳ Built-in polling helper (waitForStatus)
  • 🌍 Stage & Production environment support
  • 📦 Zero runtime dependencies
  • 📝 Full JSDoc type annotations
  • 🔷 ESM-native ("type": "module")

Installation

npm install fibpay

Requires Node.js v14 or higher. This package is ESM-only — use import, not require().


Quick Start

import { FibPay } from 'fibpay';

const fib = new FibPay({
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET',
  environment: 'stage', // or 'production'
});

// Create a payment
const payment = await fib.createPayment({
  amount: 5000,
  currency: 'IQD',
  description: 'Order #001',
});

console.log('QR Code:', payment.qrCode);
console.log('App Link:', payment.personalAppLink);

// Wait until the customer pays (or times out)
const result = await fib.waitForStatus(payment.paymentId);
console.log('Status:', result.status); // 'PAID' | 'DECLINED' | 'REFUNDED'

Configuration

import { FibPay } from 'fibpay';

const fib = new FibPay({
  clientId: 'YOUR_CLIENT_ID',        // required
  clientSecret: 'YOUR_CLIENT_SECRET', // required
  environment: 'stage',              // 'stage' (default) | 'production'
});

| Option | Type | Required | Default | Description | |-----------------|----------|----------|-----------|----------------------------------------------------| | clientId | string | ✅ | — | FIB-issued client ID | | clientSecret | string | ✅ | — | FIB-issued client secret | | environment | string | ❌ | 'stage' | 'stage' for testing, 'production' for live |

Environment base URLs

| Environment | Base URL | |---------------------|-------------------------------| | Stage (Test Mode) | https://fib-stage.fib.iq | | Production (Live) | https://fib.prod.fib.iq |

💡 Store credentials in environment variables — never hard-code them.

export FIB_CLIENT_ID=your_client_id
export FIB_CLIENT_SECRET=your_client_secret
import { FibPay } from 'fibpay';

const fib = new FibPay({
  clientId: process.env.FIB_CLIENT_ID,
  clientSecret: process.env.FIB_CLIENT_SECRET,
});

API Reference

Create Payment

const payment = await fib.createPayment(options);

Options

| Parameter | Type | Required | Default | Description | |----------------|----------|----------|----------|--------------------------------------------| | amount | number | ✅ | — | Amount to charge (positive number) | | currency | string | ❌ | 'IQD' | Currency code | | description | string | ❌ | — | Payment description shown to customer | | callbackUrl | string | ❌ | — | Webhook URL called on status change | | redirectUrl | string | ❌ | — | URL to redirect customer after payment |

Response

{
  "paymentId": "4d6f7625-60f7-48e3-82e3-b4592a4eb993",
  "readableCode": "FIB-XXXX",
  "qrCode": "<base64 PNG>",
  "validUntil": "2024-01-31T12:26:12.544Z",
  "personalAppLink": "https://...",
  "businessAppLink": "https://...",
  "corporateAppLink": "https://..."
}

Get Payment Status

const status = await fib.getStatus(paymentId);

Response

{
  "paymentId": "4d6f7625-...",
  "status": "PAID",
  "validUntil": "2024-01-31T12:26:12.544Z",
  "paidAt": "2024-01-31T12:10:05.000Z",
  "amount": { "amount": 5000, "currency": "IQD" },
  "decliningReason": null,
  "declinedAt": null,
  "paidBy": { "name": "Ahmed Ali", "iban": "IQ98..." }
}

Status values

| Status | Description | |----------------------|------------------------------------------------| | UNPAID | Payment created, awaiting customer action | | PAID | Successfully paid | | DECLINED | Payment was declined (see decliningReason) | | REFUND_REQUESTED | Refund initiated, processing | | REFUNDED | Refund completed |

Declining reasons

| Reason | Description | |--------------------------|------------------------------------| | SERVER_FAILURE | Internal error from FIB | | PAYMENT_EXPIRATION | Payment link expired | | PAYMENT_CANCELLATION | Cancelled by user or merchant |


Cancel Payment

Cancels an UNPAID payment. Returns null on success (HTTP 204).

await fib.cancelPayment(paymentId);

Refund Payment

Initiates a refund for a PAID payment made within the last 24 hours.

await fib.refundPayment(paymentId);

// Then poll until status === 'REFUNDED'
const final = await fib.waitForStatus(paymentId);

⚠️ Only payments with PAID status paid within the last 24 hours can be refunded.


Wait for Status

Polls getStatus() at regular intervals until a terminal state is reached or the timeout is exceeded.

const result = await fib.waitForStatus(paymentId, options);

Options

| Parameter | Type | Default | Description | |--------------|----------|-----------|-------------------------------------------| | intervalMs | number | 3000 | Polling interval in milliseconds | | timeoutMs | number | 300000 | Max wait time in ms (default: 5 min) |

Terminal states: PAID, DECLINED, REFUNDED


Error Handling

All SDK methods throw a FibPayError on API errors.

import { FibPay, FibPayError } from 'fibpay';

try {
  await fib.createPayment({ amount: 1000 });
} catch (err) {
  if (err instanceof FibPayError) {
    console.error('API Error:', err.message);
    console.error('Status Code:', err.statusCode);
    console.error('Body:', err.body);
  } else {
    throw err; // re-throw unexpected errors
  }
}

Webhook Integration

Pass a callbackUrl when creating a payment. FIB will POST to this URL whenever the payment status changes.

const payment = await fib.createPayment({
  amount: 1000,
  currency: 'IQD',
  callbackUrl: 'https://yoursite.com/fib/webhook',
});

Express.js webhook handler example:

app.post('/fib/webhook', (req, res) => {
  const { paymentId, status } = req.body;

  // Acknowledge quickly
  res.sendStatus(200);

  // Then handle async
  if (status === 'PAID') {
    fulfillOrder(paymentId);
  }
});

Examples

| File | Description | |------|-------------| | examples/basic.js | Full create → poll → refund flow | | examples/express-webhook.js | Express server with webhook handler |


ESM Compatibility Note

This package is ESM-only. If your project uses CommonJS (require()), you have two options:

Option 1 — Add "type": "module" to your package.json and use import.

Option 2 — Use a dynamic import inside a CommonJS file:

const { FibPay } = await import('fibpay');

License

MIT © Rageofkurd