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 🙏

© 2025 – Pkg Stats / Ryan Hefner

adonis-midtrans

v1.1.0

Published

Midtrans Payment Gateway for Adonis Framework

Readme

Adonis Midtrans 💸

This package is an Payment Gateway built on top of midtrans-nodejs-client and inspired by laravel-midtrans

Getting Started

Install the package using the adonis CLI.

> adonis install adonis-midtrans

Instruction: (Click Here).

Configure

Configure token inside the config/midtrans.js

module.exports = {
  isProduction : Env.get('MIDTRANS_IS_PRODUCTION', false) === 'true',
  serverKey : Env.get('MIDTRANS_SERVER_KEY', null),
  clientKey : Env.get('MIDTRANS_CLIENT_KEY', null)
}

or inside .env

MIDTRANS_IS_PRODUCTION=false
MIDTRANS_SERVER_KEY=SB-Mid-server-xxXiKXXLpXXiKi6xxx
MIDTRANS_CLIENT_KEY=SB-Mid-client-xpTOkxxxxSsWTxxx

NB: Get your client key and server key from Midtrans Dashboard

Usage

Sample Snap Token / Redirect

You can see another parameter (transaction_data) here.

'use strict'

const Midtrans = use('Midtrans')
const moment = require('moment')

class ExampleController {
  async charge() {
    let transaction_data = {
      transaction_details: {
        order_id: Math.floor(Date.now() / 1000),
        gross_amount: 30000
      },
      customer_details: {
        first_name: 'Mr. Awesome',
        email: '[email protected]'
      },
      customer_expiry: {
        start_time: moment().format('Y-MM-DD HH:mm:ss Z'),
        unit: 'day',
        duration: 2
      },
      item_details: [
        {
          id: 'PROD-1',
          quantity: 1,
          name: 'Product-1',
          price: 10000
        },
        {
          id: 'PROD-2',
          quantity: 1,
          name: 'Product-2',
          price: 20000
        }
      ],
      credit_card_option: {
        secure: true,
        channel: 'migs'
      }
    }


    // result: 3bfdd6d4-d757-4b01-a547-fe3b862d1aaa
    const token = await Midtrans.getSnapToken(transaction_data)
    
    // or
    // result: https://app.sandbox.midtrans.com/snap/v2/vtweb/token
    const redirect_url = await Midtrans.vtwebCharge(transaction_data)

    // choice one, token or redirect_url
    return token
    // return redirect_url
  }
}

Sample Handle HTTP Notification

'use strict'

const Midtrans = use('Midtrans')

class ExampleController {
  async charge({request, response}) {
    const notification = request.all()
    // notification = JSON value 
    //  example: 
    //  {
    //    transaction_id: 'event-1214'
    //    ...
    //  }

    const statusResponse = await Midtrans.notification(notification)
    /**
      {
        "transaction_time": "2019-02-08 18:56:35",
        "gross_amount": "12200.00",
        ...
      }
     */

    let orderId = statusResponse.order_id;
    let transactionStatus = statusResponse.transaction_status;
    let fraudStatus = statusResponse.fraud_status;

    console.log(`Transaction notification received. Order ID: ${orderId}. Transaction status: ${transactionStatus}. Fraud status: ${fraudStatus}`);

    // Sample transactionStatus handling logic

    if (transactionStatus == 'capture'){
        if (fraudStatus == 'challenge'){
            // TODO set transaction status on your databaase to 'challenge'
        } else if (fraudStatus == 'accept'){
            // TODO set transaction status on your databaase to 'success'
        }
    } else if (transactionStatus == 'cancel' ||
      transactionStatus == 'deny' ||
      transactionStatus == 'expire'){
      // TODO set transaction status on your databaase to 'failure'
    } else if (transactionStatus == 'pending'){
      // TODO set transaction status on your databaase to 'pending' / waiting payment
    }
  }

Transaction Action

Get Status

const myOrderId = 'justexample'
const status = await Midtrans.status(myOrderId)

Approve Transaction

const myOrderId = 'justexample'
const status = await Midtrans.approve(myOrderId)

Deny Transaction

const myOrderId = 'justexample'
const status = await Midtrans.deny(myOrderId)

Cancel Transaction

const myOrderId = 'justexample'
const status = await Midtrans.cancel(myOrderId)

Expire Transaction

const myOrderId = 'justexample'
const status = await Midtrans.expire(myOrderId)

Refund Transaction

const parameters = {
  amount: 5000,
  reason: "Item out of stock"
}
const myOrderId = 'justexample'
const status = await Midtrans.refund(myOrderId, parameters)

Helper

Error

  • still process

Example

  • still process

Official