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

midtrans-nodex

v0.1.1

Published

Midtrans integration module for Node JS. Support for multiple payment account.

Downloads

7

Readme

midtrans-node

Promise based Midtrans integration module for Node JS. Written in ES6 and support multiple payment account.

Why multiple account? Currently midtrans not yet support multiple bank account number, and we need to separate some purchases pool for some reason.

Prerequisites

  • Node 6

Installation

$ npm install midtrans-nodex

Usage

Note: For detail description about payload and responses, please refer to Official Midtrans documentation.

Setup

Instantiate by assigning the module using new keyword into variable. See below for examples.

Single Account

For single account, pass configuration object with properties clientKey, serverKey, and isProduction. This configuration can be seen at Midtrans MAP > Configuration

const Midtrans = require('midtrans-node');

const mds = new Midtrans({
    "clientKey": "Your-Midtrans-Client-Key",
    "serverKey": "Your-Midtrans-Server-Key",
    "isProduction": false
  });
Multiple Account

For multiple account, pass array of object containing configuration like single account plus additional properties name.

const Midtrans = require('midtrans-node');

const mdm = new Midtrans([
  {
    "name": "store-wahid",
    "clientKey": "Your-Midtrans-Client-Key",
    "serverKey": "Your-Midtrans-Server-Key",
    "isProduction": false
  },
  {
    "name": "store-isnan",
    "clientKey": "Your-Midtrans-Client-Key",
    "serverKey": "Your-Midtrans-Server-Key",
    "isProduction": false
  }
]);

API Reference

Core

Get Transaction Status

Send transaction_id / order_id of previous purchase to get the transaction status.

  • Single -- mds.transaction.status(id)
  • Multiple -- mdm.transaction.status(id, name)

Params:

  • id (String) - A string representing the order_id or transaction_id.
  • name (String) - A string representing property name that passed when instantiating multiple account, to determine which account will be used.

Example:

  • Single

    mds.transaction.status('ORDER-101')
    .then((res) => {
      console.log(res.data);
    })
    .catch((err) => {
      console.log(err);
    });
  • Multiple

    mdm.transaction.status('ORDER-101', 'store-isnan')
    .then((res) => {
      console.log(res.data);
    })
    .catch((err) => {
      console.log(err);
    });

SNAP

Get Snap Token

Send payload information about transactions to get SNAP_TOKEN. The SNAP_TOKEN is required to show pop up midtrans payment.

  • Single -- mds.snap.transactions(payload)
  • Multiple -- mdm.snap.transactions(payload, name)

Params:

  • payload (Object) - An object representing transaction details.

    Minimum payload:

    {
      "transaction_details": {
        "order_id": "ORDER-101",
        "gross_amount": 10000
      }
    }

    All possible payload and details can be seen here.

  • name (String) - A string representing property name that passed when instantiating multiple account, to determine which account will be used.

Example:

  • Single

    mds.snap.transactions({
      "transaction_details": {
        "order_id": "ORDER-101",
        "gross_amount": 10000
      }
    })
    .then((token) => {
      console.log(token);
    })
    .catch((err) => {
      console.log(err);
    });
  • Multiple

    mdm.snap.transactions({
      "transaction_details": {
        "order_id": "ORDER-101",
        "gross_amount": 10000
      }
    }, 'store-wahid')
    .then((token) => {
      console.log(token);
    })
    .catch((err) => {
      console.log(err);
    });

Notification

Verify Payload Notification

Midtrans will post payload data to our specified url, this API making sure the payload data is truly sent by midtrans, by comparing the received data signature key with the signature key data response from status API.

  • Single -- mds.notification.verify(orderId, signatureKey)
  • Double -- mdm.notification.verify(orderId, signatureKey, name)

Params:

  • orderId (String) - A string representing the order_id or transaction_id.
  • signatureKey (String) - A string representing signature_key received from midtrans notification.
  • name (String) - A string representing property name that passed when instantiating multiple account, to determine which account will be used.

Example:

  • Single

    mds.notification.verify('ORDER-101', '833c8afeb91f9d913a38304ef1849ed7dbbad5d78ff2892af6f6e472d5f3b61e803ba92c198cb587f3222a746821ad71eda22a594f5b21445a0822d807fc4097')
    .then((res) => {
      console.log(res);
      // If genuine
      // {
      //   status: true,
      //   data: {
      //     // response object like check status transaction
      //   }
      // }
    })
    .catch((err) => {
      console.log(err);
    })
  • Multiple

    mdm.notification.verify('ORDER-101', '833c8afeb91f9d913a38304ef1849ed7dbbad5d78ff2892af6f6e472d5f3b61e803ba92c198cb587f3222a746821ad71eda22a594f5b21445a0822d807fc4097', 'store-wahid')
    .then((res) => {
      console.log(res);
      // If not genuine
      // {
      //   status: false,
      //   data: {
      //     // response object like check status transaction
      //   }
      // }
    })
    .catch((err) => {
      console.log(err);
    });