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

@zygrec/moncash

v1.1.0

Published

The secure, official-quality Node.js SDK for Digicel MonCash payments in Haiti

Readme

MonCash

@zygrec/moncash

Le SDK Node.js sécurisé pour Digicel MonCash — conçu pour Haïti 🇭🇹

The secure Node.js SDK for Digicel MonCash — built for Haiti 🇭🇹

npm version license tests

Official-quality Node.js wrapper for the Digicel MonCash API. Handles OAuth2 authentication, payment creation, transaction capture, fund transfers, customer status checks, and prefunded account operations in HTG.

Demo app : github.com/schneiderjoseph/moncash-demo/node

Installation

npm install @zygrec/moncash

Quick Start

const Moncash = require('@zygrec/moncash');

const moncash = new Moncash({
  clientId: process.env.MONCASH_CLIENT_ID,
  clientSecret: process.env.MONCASH_CLIENT_SECRET,
  mode: 'sandbox' // or 'live'
});

// Create a payment
const payment = await moncash.payment.create({
  amount: 500,
  orderId: 'ORDER-001'
});

// Redirect the user
const url = moncash.payment.redirectUri(payment);
res.redirect(url);

// Capture / verify
const capture = await moncash.capture.getByOrderId('ORDER-001');
console.log(capture.status); // 'SUCCESS'

Never hardcode credentials. Copy .env.example to .env and load values from environment variables.

API Reference

moncash.payment.create({ amount, orderId })Promise<object>

Creates a new MonCash payment. Currency is HTG only.

const payment = await moncash.payment.create({
  amount: 500,
  orderId: 'ORDER-001'
});

moncash.payment.redirectUri(payment)string

Builds the MonCash redirect URL from a payment response.

const url = moncash.payment.redirectUri(payment);

moncash.capture.getByTransactionId(id)Promise<object>

Retrieves a payment by MonCash transaction ID.

const capture = await moncash.capture.getByTransactionId('12874820');

moncash.capture.getByOrderId(id)Promise<object>

Retrieves a payment by merchant order ID.

const capture = await moncash.capture.getByOrderId('ORDER-001');

moncash.transfert.create({ receiver, amount, desc, reference })Promise<object>

Sends funds to a MonCash wallet. Backend-only — payouts are irreversible.

const result = await moncash.transfert.create({
  receiver: '50912345678',
  amount: 50,
  desc: 'Supplier payment',
  reference: 'TX-001' // unique per transfer (idempotency key)
});

moncash.transfer is a deprecated alias for moncash.transfert.

moncash.customer.getStatus(account)Promise<object>

Checks whether a phone number is registered on MonCash. Backend-only — do not expose from a public frontend (account enumeration risk).

const status = await moncash.customer.getStatus('50912345678');

moncash.prefunded.getTransactionStatus(reference)Promise<object>

Tracks a prefunded transfer by merchant reference. Requires a prefunded account activated by Digicel.

const status = await moncash.prefunded.getTransactionStatus('TX-001');

moncash.prefunded.getBalance()Promise<object>

Returns the merchant prefunded account balance. Backend-only — sensitive financial data.

const balance = await moncash.prefunded.getBalance();

Pay with MonCash Button

The SDK ships the official MonCash payment button image. After npm install, use it in your frontend:

const Moncash = require('@zygrec/moncash');
const path = require('path');
const express = require('express');

// Serve the button (Express example)
app.get('/moncash-button.png', (req, res) => {
  res.sendFile(Moncash.getButtonPath());
});
<form method="POST" action="/pay">
  <button type="submit" style="background:none;border:none;padding:0;cursor:pointer">
    <img src="/moncash-button.png" alt="Pay with MonCash" height="48">
  </button>
</form>

Or copy the file into your static folder:

const fs = require('fs');
fs.copyFileSync(Moncash.getButtonPath(), './public/moncash-button.png');

Configuration

| Option | Type | Required | Description | |----------------|----------|----------|--------------------------------------| | clientId | string | Yes | MonCash API client ID | | clientSecret | string | Yes | MonCash API client secret | | mode | string | No | sandbox (default) or live | | version | string | No | API version (default: v1) |

const moncash = new Moncash({
  clientId: process.env.MONCASH_CLIENT_ID,
  clientSecret: process.env.MONCASH_CLIENT_SECRET,
  mode: 'sandbox'
});

Get credentials from the MonCash merchant dashboard.

Input Validation

All inputs are validated client-side before any API request is sent.

| Resource | Field | Rules | |-----------|------------------|-----------------------------------------------------------------------| | Payment | amount | Positive finite number, rounded to 2 decimals, minimum 1 HTG | | Payment | orderId | Non-empty string, max 128 characters | | Capture | transactionId | Non-empty string, max 128 characters | | Capture | orderId | Non-empty string, max 128 characters | | Transfert | amount | Positive finite number, rounded to 2 decimals, minimum 1 HTG | | Transfert | receiver | Haitian phone format: 509XXXXXXXX or XXXXXXXX (8 digits) | | Transfert | desc | Non-empty string, max 255 characters | | Transfert | reference | Non-empty string, max 64 chars, alphanumeric + -_ only (required) | | Customer | account | Haitian phone format: 509XXXXXXXX or XXXXXXXX | | Prefunded | reference | Non-empty string, max 64 chars, alphanumeric + -_ only |

Invalid input throws a MoncashError with a descriptive message.

Payouts and Prefunded Account

| Operation | Direction | Risk | |-----------|-----------|------| | payment.create | Customer pays merchant | Low — standard checkout | | transfert.create | Merchant sends HTG to wallet | High — irreversible | | customer.getStatus | Check if wallet exists | Medium — PII enumeration | | prefunded.getBalance | Read merchant balance | High — sensitive data |

Rules:

  • Never call transfert, customer, or prefunded from a public frontend — server-side only.
  • reference must be unique per transfer — reusing it may cause conflicts on the MonCash side.
  • Prefunded account must be activated by Digicel before payouts work.
  • Test payouts in sandbox only — never send real funds during development.
  • If a transfer fails with a 403 "Maximum Account Balance", the recipient wallet has reached its balance limit.
  • Always verify prefunded.getTransactionStatus(reference) before retrying a failed payout.

Error Handling

const { errors } = moncash;

try {
  await moncash.payment.create({ amount: 500, orderId: 'ORDER-001' });
} catch (err) {
  if (err.type === errors.UnauthorizedError) {
    console.error('Invalid credentials');
  } else if (err.type === errors.BadRequestError) {
    console.error('Invalid request');
  } else {
    console.error(err.message);
  }
}

Error types

MoncashError, APIError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, RequestTimeoutError, TooManyRequestsError, UnexpectedError

Security

This SDK includes hardened security for production payment flows:

  • OAuth2 mutex prevents concurrent token refresh races
  • 30-second HTTP timeout prevents indefinite hangs
  • Credentials are redacted from all error messages
  • Axios error internals (config, auth, headers) are stripped before propagation
  • No hardcoded credentials in source or tests

Report vulnerabilities via SECURITY.md. Use .env.example as a template for local credentials.

Legacy Callback Support

Callback style is supported for backward compatibility but deprecated. Prefer async/await.

// @deprecated — use async/await instead
moncash.payment.create({ amount: 500, orderId: 'ORDER-001' }, (err, payment) => {
  if (err) return console.error(err.message);
  console.log(moncash.payment.redirectUri(payment));
});

Development

npm install
npm test

Tests use network mocks (nock). To run with your own sandbox credentials:

export MONCASH_TEST_CLIENT_ID='your_client_id'
export MONCASH_TEST_CLIENT_SECRET='your_client_secret'
npm test

License

GPL-3.0

Links