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

zaincash

v1.0.5

Published

a package that will handel the payment through zaincash payment method

Downloads

60

Readme

ZainCash Nodejs Package

A nodejs package that will help you adding ZainCash as a payment method in your website. This package works with express & jesonwebtoken.

Installation

Install the zaincash package by running this command:

  $ npm i zaincash

Other Packages to install

  • You have to install express.js to have a running server for your website.
  • You also need to install JWT.
  • And install request library in order to get redirected to ZainCash payment page.

Quick Start !

  • You have to create a route handler that will handle the payment process.
  • Require zaincash package inside your app.
  • ZainCash package exporting a class so you will have to create a new instance from it
  • Call zaincash init function to initialize the payment, this function will return a promise so you will have to handle it.
  • init function will return a ZainCash transaction id that you can send as a parameter to pay function in order to get redirected to ZainCash payment page.

plase check the simple code below

const express = require('express');
const app = express();
const ZC = require('zaincash');

// preparing payment data
const paymentData = {
  amount: 250,
  orderId: 'some id',
  serviceType: 'some serviceType',
  redirectUrl: 'example.com/redirect',
  production: false,
  msisdn: '964****',
  merchantId: '5a647d843321dcd9cbc771c',
  secret: '$2y$10$9eaqimBisY15ZJZSSvC3Z.Ar1ET1.7Kgm8p7jysY1X.I8.RuwS.',
  lang: 'ar'
}

// payment route handler
app.post('/pay', (req, res) => {
  let zc = new ZC(paymentData);
  zc.init().then(transactionId => {
    //  Save the transactionId in your DB
    console.log(transactionId);
    zc.pay(transactionId, res);
  }).catch(err => {
    res.status(400).send(err);
  });
});
//  starting a server
app.listen(3000);

Payment Data

There are some data that you have to get it from ZainCash and there are others that you are free to fill them

| Property | Description | | ------ | ------ | | amount | The amount of money that the customer will pay, has to be more than 250 | | orderId | Any text or number you want to add, usualy this will be your order id from your DB (ZainCash will returned to you once the payment completed) | | serviceType | Any text you want to add such as your website name | | redirectUrl | The url that ZainCash will send the payment information to once the payment completed | | production | Boolean that will tell the packge to use the test environment or the production one | | msisdn | The merchant number (your ZainCash wallet number) | | merchantId | String that ZainCash will provide you with | | secret | String that ZainCash will provide you with | | lang | Your website language, ZainCash supports 3 languages 'ar', 'en', 'ku' stands for Arabic, English, and Kurdish |

What to do more

You will have to create a redirect handler, this will work as an endpoint you will send it to zaincash by setting it to the redirectUrl it will be such as 'http://yourhost/redierct' zaincash will return a token contains the payment status to this endpoint, ie: 'http://yourhost/redierct?token=XXXX' You will have to decode this JWT token and check the payment status Check the simple code below:

const jwt = require('jsonwebtoken');

//  Handeling the redierct
app.get('redirect', (req, res) => {
  const token = req.body.token;
  if(token){
    try {
      var decoded = jwt.verify(token, process.env.SECRET);
    } catch(err) {
      // err
    }
    if(decoded.status == 'success'){
      // Do whatever you like
    }else {
      //  Do other things
    }
  }
});

Redirect Token Content

The Token will be encoded with the same secret shared by ZainCash, and it will contain:

| Property | Description | | ------ | ------ | | status | String that will be equal to 'success' or 'failed' | | orderId | Any text or number you have added when you initialized the payment | | id | ZainCash transaction id, it will be string ie: '58650f0f90c6362288da08cf' | | iat | TimeStamp of token creation | | exp | TimeStamp of token expiry | | msg | In case of failure this will return the reason, ie: 'Invalid credentials for requester' |