Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation


iraq-pay

One SDK. Every Iraqi payment gateway. Zero pain. ZainCash ยท FIB ยท AsiaCell Cash ยท FastPay ยท Qi Card ยท Switch โ€” unified API.


npm i iraq-pay
# or
pip install iraq-pay
# or  
flutter pub add iraq_pay


๐Ÿ‡ฎ๐Ÿ‡ถ The Iraqi Payment Problem

ูƒู„ ุจูˆุงุจุฉ ุฏูุน ุนุฑุงู‚ูŠุฉ ู„ู‡ุง:

  • API ู…ุฎุชู„ู (REST vs SOAP vs custom)
  • ุชูˆุซูŠู‚ ู…ุชูุฑู‚
  • ุตูŠุงุบุฉ ู…ุฎุชู„ูุฉ ู„ู„ุฃุฑู‚ุงู… ูˆุงู„ุนู…ู„ุงุช
  • webhooks ู…ุชุจุงูŠู†ุฉ
  • ุจูŠุฆุฉ sandbox ุบูŠุฑ ู…ูˆุญุฏุฉ

ุงู„ู†ุชูŠุฌุฉ: ุฃูŠ ู…ุทูˆุฑ ูŠู‚ุฑุฑ ูŠุฏุนู… ู…ุชุฌุฑู‡ ุฃูƒุซุฑ ู…ู† ุจูˆุงุจุฉ โ†’ 3 ุฃุณุงุจูŠุน ุดุบู„ + bugs ู„ุง ู†ู‡ุงูŠุฉ ู„ู‡ุง.

iraq-pay ูŠุญู„ ู‡ุฐุง. SDK ูˆุงุญุฏ. API ู…ูˆุญุฏ. ูƒู„ ุงู„ุจูˆุงุจุงุช.


โšก One API, every gateway

import { IraqPay } from "iraq-pay";

const pay = new IraqPay({
  zaincash: { merchant_id: "...", secret: "..." },
  fib: { client_id: "...", client_secret: "..." },
  asiacell: { api_key: "..." },
  fastpay: { merchant_code: "..." },
  qi: { terminal_id: "..." },
});

// Same API for every gateway
const session = await pay.createPayment({
  gateway: "zaincash",     // or "fib", "asiacell", "fastpay", "qi"
  amount: 50000,            // in IQD (Iraqi Dinar)
  currency: "IQD",
  reference: "ORDER-12345",
  customer: {
    name: "ู‚ุงุณู… ู…ุญู…ุฏ",
    phone: "+9647763695936",
    email: "customer@example.com",
  },
  redirect_url: "https://yoursite.com/thanks",
  webhook_url: "https://yoursite.com/api/webhook",
});

console.log(session.payment_url);   // Redirect customer here

๐Ÿ“ฆ Supported gateways

Gateway Type Status Sandbox
ZainCash Mobile wallet โœ… Production โœ…
FIB (First Iraqi Bank) Card + wallet โœ… Production โœ…
AsiaCell Cash Mobile wallet โœ… Production โœ…
FastPay Card + wallet โœ… Production โœ…
Qi Card Government salaries + e-commerce โœ… Production โš ๏ธ Limited
Switch Visa/Mastercard via Iraqi switch ๐Ÿšง Beta โœ…
Nass Wallet New mobile wallet ๐Ÿšง Beta โœ…

We add new gateways quarterly. Request one.


๐Ÿ—๏ธ Architecture โ€” why this works

            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚           Your App                       โ”‚
            โ”‚  (one SDK call โ€” gateway-agnostic)       โ”‚
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
                โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                โ”‚     iraq-pay SDK        โ”‚
                โ”‚  - Normalizes inputs    โ”‚
                โ”‚  - Routes to gateway    โ”‚
                โ”‚  - Validates response   โ”‚
                โ”‚  - Handles webhooks     โ”‚
                โ”‚  - Idempotency keys     โ”‚
                โ”‚  - Retry policy         โ”‚
                โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ–ผ          โ–ผ               โ–ผ          โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚ZainCash โ”‚ โ”‚ FIB  โ”‚... โ”‚FastPay   โ”‚  โ”‚  Qi    โ”‚
   โ”‚  API    โ”‚ โ”‚ API  โ”‚    โ”‚  API     โ”‚  โ”‚  API   โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Each gateway has its own adapter under the hood. Your code never sees the gateway-specific quirks.


๐Ÿ›ก๏ธ Webhook handling

Every gateway sends webhooks differently. We unify them:

import { IraqPay } from "iraq-pay";

const pay = new IraqPay({ /* ... */ });

app.post("/api/webhook", async (req, res) => {
  const event = pay.parseWebhook({
    headers: req.headers,
    body: req.body,
    signature: req.headers["x-iraq-pay-signature"],
  });

  // Same event format regardless of source
  switch (event.type) {
    case "payment.completed":
      await markOrderPaid(event.reference, event.amount);
      break;
    case "payment.failed":
      await markOrderFailed(event.reference, event.failure_reason);
      break;
    case "payment.refunded":
      await markOrderRefunded(event.reference, event.refund_amount);
      break;
  }

  res.status(200).send("ok");
});

Signature verification is automatic per-gateway.


๐ŸŒ Refunds, splits, recurring

// Refund
await pay.refund({
  gateway: "fib",
  payment_id: "pay_xyz",
  amount: 25000,                    // Partial refund OK
  reason: "Customer cancelled",
});

// Marketplace split (for multi-vendor stores)
await pay.createPayment({
  gateway: "zaincash",
  amount: 100000,
  splits: [
    { recipient: "vendor_1", amount: 70000 },     // 70%
    { recipient: "vendor_2", amount: 25000 },     // 25%
    { recipient: "platform",  amount: 5000 },     // 5% (your cut)
  ],
});

// Subscriptions (where supported)
await pay.createSubscription({
  gateway: "fib",
  plan: "monthly_50k",
  customer_id: "user_123",
  start_date: new Date(),
});

๐Ÿงช Sandbox / Testing

Every gateway has a sandbox. We auto-route to sandbox when NODE_ENV=test:

const pay = new IraqPay({
  mode: "sandbox",                  // or "production" or "auto"
  // ...
});

// Use these test phone numbers for ZainCash sandbox:
//   +9647712345671  โ†’ always approves
//   +9647712345672  โ†’ always declines
//   +9647712345673  โ†’ timeout
//   +9647712345674  โ†’ 3D Secure required

๐Ÿ–ฅ๏ธ Local Dashboard (no code required)

Don't want to integrate the SDK? Run our local control panel:

docker run -p 8080:8080 -v ~/.iraq-pay:/data ghcr.io/kasimmj/iraq-pay-dashboard

Open http://localhost:8080 and you get a beautiful Arabic+English dashboard with:

  • ๐Ÿ“Š Live transactions โ€” every payment as it happens
  • ๐Ÿ’ธ One-click refunds โ€” no code needed
  • ๐Ÿ“ˆ Per-gateway analytics โ€” which converts best
  • ๐Ÿ”” Webhook tester โ€” simulate callbacks
  • ๐Ÿ› ๏ธ Manual reconciliation โ€” match payments to orders
  • ๐Ÿ“ค CSV export โ€” for accounting
  • ๐Ÿ‡ฎ๐Ÿ‡ถ Full RTL Arabic โ€” for your finance team

Perfect for small shops, accountants, and customer support teams.


๐Ÿ“Š Built-in analytics (SDK)

const stats = await pay.stats({
  from: "2026-05-01",
  to: "2026-05-31",
  group_by: ["gateway", "currency"],
});

// Returns:
[
  { gateway: "zaincash", currency: "IQD", count: 124, total: 6_200_000, success_rate: 0.94 },
  { gateway: "fib",       currency: "IQD", count: 87,  total: 12_800_000, success_rate: 0.97 },
  // ...
]

๐ŸŒ Languages

TypeScript / JavaScript (Node.js)

npm install iraq-pay

Python

pip install iraq-pay
from iraq_pay import IraqPay

pay = IraqPay(zaincash={"merchant_id": "...", "secret": "..."})
session = pay.create_payment(gateway="zaincash", amount=50000, ...)

Flutter / Dart

flutter pub add iraq_pay
final pay = IraqPay(
  zaincash: ZainCashConfig(merchantId: '...', secret: '...'),
);

final session = await pay.createPayment(
  gateway: Gateway.zaincash,
  amount: 50000,
  ...
);

PHP (for WordPress / WooCommerce)

composer require kasimmj/iraq-pay

All four implementations expose the same API surface โ€” switch languages without re-learning.


๐Ÿ‡ฎ๐Ÿ‡ถ Why this matters for Iraqi devs

  • Every Iraqi e-commerce site reinvents this wheel
  • Most existing wrappers are abandoned (last commit 2022)
  • Documentation in Arabic is rare and often outdated
  • This SDK is maintained, versioned, and tested in production (Solar iQ uses it across 6 cities)

๐Ÿค Adding a new gateway

We accept PRs for any registered Iraqi payment provider. To add one:

  1. Read docs/adding-a-gateway.md
  2. Implement the GatewayAdapter interface (8 methods)
  3. Add tests against the gateway's sandbox
  4. Submit PR

We help with the API contracts if you have access to a gateway we don't.


๐Ÿ“œ License

MIT.


Star โญ if you've ever cursed at an Iraqi payment API.

About

๐Ÿ’ณ Unified SDK for all Iraqi payment gateways โ€” ZainCash, FIB, AsiaCell Cash, FastPay, Qi Card. One API, every wallet.

Topics

Resources

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors