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 🙏

© 2024 – Pkg Stats / Ryan Hefner

edahab-sdk

v1.3.0

Published

This is edahab API package for node with TypeScript.

Downloads

12

Readme

eDahab API User Guide

This is edahab API package for node with TypeScript.

If you’re new to TypeScript, checkout this handy cheatsheet

Installing

To install edahab-api, use:

npm intall edahab # or yarn add edahab

There are three available methods in the edahab api, Generating invoices, Checking Invoices and Crediting Account

Generating Invoices

In order to generate invoices, you need to have two things available, Your Secret Key, Your API-KEY and Request Body as JSON. The secret key and API-key are already given you by the edahab team.

To achieve that we are using createInvoice. And it takes, SECRET-KEY, REQ_BODY and IS_PRODUCTION.

An example of create an Invoices with express:

...
import { eDahabAPI } from "edahab-sdk";

const app: Express = express();
const port = 3001;

const YOUR_SECRET_KEY = "your_secret_key";
const DAHAB_API = new eDahabAPI(
  YOUR_SECRET_KEY,
  true, // -> IS_PRODUCTION
  );

app.post("/generate", async (req: Request, res: Response, next) => {
  try {
    const apiKey = "your_api_Key";
    const response = await DAHAB_API.createInvoice({
      ...req.body,
      apiKey,
    });

    console.log("result: " + JSON.stringify(response));
    res.status(200).json(response);
  } catch (e) {
    console.log(e);

    res.status(400).send(e);
  }
});

...

And here is an example of the request body:

{
    "edahabNumber": "62XXXXXXX",
    "amount": 1,
    "currency": "SLSH", // -> Optional (Default USD), also accepts SLSH
    "agentCode": "12345",
    "ReturnUrl": "https://www.facebook.com" // -> must start with https://
}

When it is done, it will return this:

{
    "InvoiceId": 1122334,
    "StatusCode": 0,
    "RequestId": 332211,
    "StatusDescription": "Success",
    "ValidationErrors": null
}

If you did correct, the secret key or the api-key it will probably go through success. StatusCode is in 0 to 6, here is what they are:

0 : Success
1 : Api Error
2 : Invalid Json
3 : Validation_Error
4 : Invalid_Api_Credentials
5 : Insufficient_Customer_Balance
6 : Invoice_Not_Found

There are probably two ways for the payment go through success, it is either WEB or Pop-UP. In POP-UP, you don't have to do nothing, it will send a pop-up to phone number holder and it'll listen the response from the action the user, is it cancelled?, is it success?, probably status code will told you that as we mentioned before. in WEB, The invoiceId is the one that you'd use for the edahab's web payment portal. e.g in browser type this url:

https://edahab.net/API/Payment?invoiceId={{invoiceId}} #-> change with generated invoiceId from the response

then you'll the see eDahab's payment website with an order, saying enter the PIN number. When its done, it will redirect to returnUrl as we already entered, for now it is Facebook.com

Checking Invoices

To check if the invoice is in pending, or success we are using checkInvoice. And it takes, SECRET-KEY, REQ_BODY and IS_PRODUCTION.

An example of check an Invoice:

...

app.post("/check", async (req: Request, res: Response, next) => {
  try {
    const apiKey = "your_api_key";
    const { invoiceId } = req.body;
    const response = await DAHAB_API.checkInvoice({
      apiKey,
      invoiceId,
    });

    console.log("result: " + JSON.stringify(response));
    res.status(200).json(response);
  } catch (e) {
    console.log(e);

    res.status(400).send(e);
  }
});

...

And here is an example of the body:

{
  "invoiceId": 1122334
}

When it is done the operation, it will return this:

{
    "InvoiceStatus": "Pending",
    "TransactionId": null,
    "InvoiceId": 0,
    "StatusCode": 0,
    "RequestId": 33221,
    "StatusDescription": "Success",
    "ValidationErrors": null
}

If the invoiceId is correct, it is either pending or success. Otherwise it will return InvoiceId not found.

Credit to Account

This method is for when you want to withdraw your money from Edahab API to your account. Your account is either regular account or merchant account

An example of crediting to an account:

...

app.post("/credit", async (req: Request, res: Response, next) => {
  try {
    const apiKey = "your_api_key";
    const { phoneNumber, transactionAmount, currency } = req.body;
    const response = await DAHAB_API.creditAccount({
      apiKey,
      phoneNumber,
      transactionAmount,
      currency
    });

    console.log("result: " + JSON.stringify(response));
    res.status(200).json(response);
  } catch (e) {
    console.log(e);

    res.status(400).send(e);
  }
});

...

And here is an example of the body:

{
  "phoneNumber": "62XXXXXXX",
  "transactionAmount": 1,
  "currency": "USD" //-> optional, it also accepts SLSH
}

When it is done the operation, it will return this:

{
    "TransactionStatus": "Approved",
    "TransactionMesage": "...", //-> SMS, look alike text
    "PhoneNumber": "62XXXXXXX",
    "TransactionId": "CX23322.4444.S22222"
}

Support

This packages will be open source, feel free to contribute.