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

payme-merchant-integrator

v1.2.13

Published

Integration with payme

Downloads

26

Readme

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