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

ecocash

v1.0.10

Published

Ecocash Javascript SDK

Downloads

16

Readme

Ecocash Javascript Library

This is a Javascript SDK library for Ecocash Open API.

Installation

npm i ecocash

[!NOTE] You can use whichever package manager you prefer, it should work.

For development

Run build and start scripts concurrently:

npm run dev

Or run build and start scripts separately:

npm run build
npm run start

Usage

The basic follow is as follows:

Step 1: Create an Ecocash object

You can create an Ecocash object as follows:

const Ecocash = require("ecocash");

const merchant = new Ecocash("<apiKey>", "<merchant code>");

Step 2: Initialize a payment

const response = await merchant.initPayment("26377854266", 20.05, "bread");

Response:

{
    phone: '26377854266',
    amount: 20.05,
    reason: 'bread',
    currency: 'USD',
    sourceReference: '325a802f-943e-47c2-addf-010285f09cea'
}

Step 3: Poll for transaction status

You can poll for transaction status as follows:

Known statuses(for now):

  • SUCCESS
  • PENDING_VALIDATION
const transaction = await merchant.lookupTransaction(response.sourceReference, response.phone);

if (transaction.paymentSuccess) {
    console.log("Transaction successful");
}

Response:

{
    amount: { amount: 100, currency: 'USD' },
    customerMsisdn: '263778548832',
    reference: '325a802f-943e-47c2-addf-010285f09cea',
    ecocashReference: 'MP250908.1537.A22242',
    status: 'SUCCESS',
    transactionDateTime: '2025-09-08 15:37:16'
}

[!NOTE] The default lookupTransaction method requires you to add poll logic by yourself. But with the pollTransaction method, you can poll for transaction status as follows:

merchant.pollTransaction(response, strategy, options);

Where:

  • response: The response from the initPayment method
  • strategy: The strategy to use for polling (SIMPLE, INTERVAL, BACKOFF)
  • options: The options to use for polling (interval, backoff, multiplier, sleep)

NB: The default strategy is INTERVAL. NB: Options are optional and default to { interval: 10, multiplier: 2, sleep: 1000 }.

Polling examples

Interval strategy:

// Poll for transaction status with interval
const transaction = await merchant.pollTransaction(response, PollStrategies.INTERVAL, { interval: 10 });

if (transaction.paymentSuccess) {
    console.log("Transaction successful");
}

Backoff strategy:

// Poll for transaction status with backoff
const transaction = await merchant.pollTransaction(response, PollStrategies.BACKOFF, { multiplier: 2, interval: 15, sleep: 2000 });

if (transaction.paymentSuccess) {
    console.log("Transaction successful");
}

Simple strategy:

// Poll for transaction status with simple strategy
const transaction = await merchant.pollTransaction(response, PollStrategies.SIMPLE);

if (transaction.paymentSuccess) {
    console.log("Transaction successful");
}

Step 4: Refunding a payment

const response = await merchant.refundPayment({
    reference: "reference",
    phone: "263778548266",
    amount: 20.05,
    clientName: "bread",
    reason: "The bread was rotten"
});

Full Example

const Ecocash = require("ecocash");

const merchant = new Ecocash("apiKey", "merchant");
const response = await merchant.initPayment("26377854266", 20.05, "bread");

console.log(response);

// Poll for transaction status
const transaction = await merchant.pollTransaction(response);

if (transaction.paymentSuccess) {
    console.log("Transaction successful");
}

Going Live

To go live, you can set the mode to "live" as follows:

const merchant = new Ecocash("<apiKey>", "<merchant>", "live");     

OR

const merchant = new Ecocash("<apiKey>", "<merchant>");     
merchant.setLiveMode();

Contributing

Contributions are welcome! Please read our contributing guidelines for more information.

Special Thanks