Giter Club home page Giter Club logo

payme-merchant-integrator's Introduction

Payme merchant api integration with mongodb database based application

Author

Install

npm install tslib // also to work in javascript
npm install payme-merchant-integrator

Usage

Import PaymeIntegrator class

import { PaymeIntegrator } from 'payme-merchant-integrator';

And initialize paymeIntegrator object based class

const paymeIntegrator = new PaymeIntegrator({
    db_str: process.env.MONGODB_URL,
    collection: 'payme_transactions', // collection name to save transactions
    type: 'cumulative', // enum ['one-time', 'cumulative'] one time fee or cumulative
    password: process.env.PAYME_PASSWORD,
    isAccountExist,
    markAsPaid,
    getPayingCost, // optional for 'cumulative' type
    canCancel, // method to check cancellation
    markAsCancel, // method to mark as cancel
})

There two types of paymeIntegrator

  • to pay for balance increase cumulative fee
  • to pay for check means one-time fee

And add methods below for cumulative fee

Check account if exists or not argument account is an object that created in payme cabinet
For example phone added to account object like this:

plot

then isAccountExist method should be

const isAccountExist = async (account) => {
    const is_user_exist = await UserModel.findOne({phone: account.phone});
    if(!is_user_exist) return false;
    return true;
}

To increase balance after payment

const markAsPaid = async (account, amount) => {
    await UserModel.findOneAndUpdate(
        {phone: account.phone},
        { $inc: { balance: amount } }
    );
}

To check cancel after payment

const canCancel = async (account) => {
    return false; // for no cancellation;
    // or check and return true or false 
}

To mark as cancel after cancellation

const markAsCancel = async (account) => {
    // write function to update balance or cancel paid transaction 
}

And add methods below for one-time fee

then isAccountExist method should be

const isAccountExist = async (account) => {
    const is_user_exist = await CheckModel.findOne({check_id: account.check_id});
    if(!is_user_exist) return false;
    return true;
}

To get get paying cost

const getPayingCost = async (account) => {
    const check = await CheckModel.findOne({check_id: account.check_id});
    return check.cost;
}

mark as paid

const markAsPaid = async (account, amount) => {
    await CheckModel.findOneAndUpdate(
        {check_id: account.check_id},
        { $set: { paid: true } }
    );
}

Then use from route and middleware

Fastify example

const authenticate = async (request, reply) => {
    await paymeIntegrator.authenticate(request, reply);
}

const handler = async (request, reply) => {
    return await paymeIntegrator.handler(request, reply);
}
fastify.post(
    '/payme',
    { preValidation: [authenticate] },
    handler
);

And test your endpoint with PaymeTester

Official documentation Payme Merchant

payme-merchant-integrator's People

Contributors

mryusufjon avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.