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

@bekhruzmm/merchant-api

v1.1.2

Published

The base module for merchants

Downloads

22

Readme

MerchantApi

Description

MerchantAPI module is merchant side Nodejs application which handles incoming requests sent by Paycom gateway. Read docs to know how MerchantAPI internally works

Structure

img

MerchantAPI is based on two main payment type strategy

  1. Cumulative Payment
  2. OneTime Payment

as example, we have provided four Mongodb schemes (Models)

  • Merchant is in form of json as merchant.json which holds array of merchants; Driver object.

    | name | type | description | | :--- | :---: | :---- | | endpoint | String | merchant server endpoint|

    Account object.

    | name | type | description | | :--- | :---: | :---- | | name | String | name of the field which is identifier of a payment. f.e user_id, order_id ... | | title | Object | title of field to display {ru:"", uz:"",en:""}format |

    Merchant object.

    | name | type | description| |:--------- | :--------:| :----- | | name | String | Merchant name | | organization | String | Organization title | | driver | Driver | | | account | Account[] | | | address | String | Address of organization| | logo | String | Logo of Merchant| | test_key | String | To enter SandBox|

[
  {
    "name": "Merchant #1",
    "organization": "my organization",
    "driver": {
      "endpoint": "http://localhost:3001"
    },
    "account": [
      {
        "name": "user_id",
        "title": {
          "ru": "ID пользователя"
        }
      }
    ],
    "address": "Toshkent shahar, Mirzo Ulug'bek",
    "logo": "Logo",
    "test_key": 1
  }
]
  • Account model in the database
{
  "name": "Someone",
  "balance": 5000000.0,
  "status": 1,
  "user_id": "1"
}
  • Transaction (it will be created based on account options)
{
  "create_time": "2021-04-13T10:16:21.000+0000",
  "receivers": [],
  "account": {
    "user_id": "1"
  },
  "amount": 1000,
  "id": "60758e63c3d03f74574bf82d",
  "time": 1618316899120.0,
  "state": 1,
  "cancel_time": "2021-04-13T12:29:24.850+0000",
  "perform_time": "2021-04-13T12:29:18.520+0000",
  "reason": 5,
  "transaction": "60758e63c3d03f74574bf82d"
}

Pre-requisites

  • Node.js environment
  • Mongodb

Example using Express (Node.js framework)

  npm init -y
  npm install @bekhruzmm/merchant-api

inside .env file in the root project directory, will have following environment variables and initialize Account models as given examples above.

APP_PORT=3001
APP_HOST=localhost
APP_NAME=MerchantAPI
APP_MODE=development

then in index.js before project starts, MerchantApi must be imported and initialized.

import {MerchantAPI, errorHandler} from "@bekhruzmm/merchant-api";
import {json} from "body-parser";

app.use(json());
// app.use(cors()); if you have cors errors;

MerchantApi class has two main function to handle authentication and incoming request from Paycom gateway


new MerchantAPI(new NonrelationalStrategy("mongodb://localhost:27017/merchant_test"), 
                new OneTimeStrategy(new OnetimeError()), 
                path.join(__dirname,"merchant.json"))

app.post("/", (req: Request, res: Response, next: NextFunction) => {
        const auth: string = req.headers?.authorization;
        MerchantAPI.getInstance().authHandler(auth);
        next();
    },
    async (req: Request, res: Response, next: NextFunction) => {
        try {
            const result = await MerchantAPI.getInstance().requestHandler(req.body);
            res.status(200).send({result});
        } catch (e) {
            next(e);
        }
    });

app.use(errorHandler);
app.listen(process.env.APP_PORT, () => {
    console.log(`${process.env.APP_NAME} is running on port:${process.env.APP_PORT} with mode:${process.env.APP_MODE}`);
});

Next

  • install sandbox frontend and backend;