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

gateway-mv-js

v1.0.2

Published

javascript api to generate transaction requests for the Bank of Maldives and Maldives Islamic Bank online payment gateway endpoints

Downloads

10

Readme

Javascript Payment Gateway API for BML and MIB

This is an approximate javascript port of this PHP library by Ahmed Khusaam.

This library provides a class with methods to generate transaction requests to the bank's endpoint and parse subsequent responses from the bank posted to the merchant's callback url.

Warning

Although this is a javascript library, it is meant to be used on the server-side, specifically in a node js environment. Please do NOT attempt to use this in a client-side application as it would expose the shared secret between you and the bank to the client.

Installation

npm install gateway-mv-js

Usage

Configuration and Instantiation

The main class can be imported by simply requiring the package. The class can be instantiated by calling it with the new operator. The constructor expects two arguments. The first argument is a string that represents the bank, which can be either 'BML' for the Bank of Maldives endpoint, or 'MIB' for the Maldives Islamic Bank endpoint. The second argument is a configuration object.

const Gateway = require('gateway-mv-js')

const config = {
  // Required Fields
  Host: 'bml.com.mv',
  MerRespURL: 'https://thebackdoor.ca/response',
  AcqID: '0123',
  MerID: '3210',
  MerPassword: 'some password',

  // Optional Fields Set to Defaults
  PurchaseCurrency: '462',
  PurchaseCurrencyExponent: '2',
  Version: '1.1', // for MIB the default is '1'
  SignatureMethod: 'SHA1'
}

let gateway = new Gateway('BML', config)

Preparing a New Transaction Request

A new transaction request can be generated by calling generateTransactionRequest. It expects the first argument to be the value of the transaction in the currency that was set in the configuration step. The second argument is a unique transaction ID. The transaction ID should never be repeated, even for transactions that are being retried. The function returns an object containing the POST parameters that should be included in the POST request to the bank's endpoint

const transaction = gateway.generateTransactionRequest(150.99, 'XD09928')

Verifying the bank's response to a given transaction

The verification method, verifyResponseSignature is called once the bank calls back with its response to a particular transaction request. The first argument is the relevant transaction id. The second argument is an object containing POST parameters sent back by the bank to the callback url. The function returns a boolean; true if the signature sent by the bank checks out, false if not.

const verified = gateway.verifyResponseSignature('XD09928', response)