1.1.2 • Published 3 years ago

@bekhruzmm/merchant-api v1.1.2

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
3 years ago

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.

    nametypedescription
    endpointStringmerchant server endpoint

    Account object.

    nametypedescription
    nameStringname of the field which is identifier of a payment. f.e user_id, order_id ...
    titleObjecttitle of field to display {ru:"", uz:"",en:""}format

    Merchant object.

    nametypedescription
    nameStringMerchant name
    organizationStringOrganization title
    driverDriver
    accountAccount[]
    addressStringAddress of organization
    logoStringLogo of Merchant
    test_keyStringTo 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;
1.1.1

3 years ago

1.1.0

3 years ago

1.1.2

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.14-s

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago