1.2.13 • Published 2 years ago

payme-merchant-integrator v1.2.13

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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

1.2.12

2 years ago

1.2.13

2 years ago

1.2.10

2 years ago

1.2.11

2 years ago

1.2.9

2 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.1.2

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

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