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

veritrans

v0.3.0

Published

veritrans integration module for node.js

Downloads

504

Readme

veritrans-node

Veritrans integration module for Node.js platform.

Note: This module is written in ES6 standards, so in order to make it works you have to run your app using Node.js v4.x.x or use --harmony flag to enable ES6 features. Also you can use babel to transpile ES6 codes to ES5 codes if you are working with old version of Node.js.

Veritrans API Documentation

This module follows Veritrans official API documentation. Please see this for API reference.

Install

npm install veritrans

Usage

Examples bellow are using express. Description for transaction / payment payloads can be found on Veritrans official API documentation.

require('veritrans'); returns Veritrans constructor function that should be instantiated using new keyword. It only requires one argument that define its configuration.

Config:

  • serverKey (String) - Used to pass basic auth that is required by Veritrans API.
  • clientKey (String) - Used to pass basic auth that is required by Veritrans API.
  • url (String) - Base url for API call. There are two types of url that can be used for sandbox mode and production mode.

The values for those fields can be obtained through Veritrans MAP.

const config = {
    serverKey: 'Your-Server-Key',
    clientKey: 'Your-Client-Key',
    url: 'https://api.sandbox.veritrans.co.id/v2'
};

const Veritrans = require('veritrans');
const vt = new Veritrans(config);

1. Charge transaction

vt.transaction.charge(transaction, callback) - All payment methods that are provided by Veritrans are supported by this module. Example below is using credit_card payment type.

Params:

  • transaction (Object) - An object representing transaction payload. payment_type, transaction_details fields + one that is named after payment_type value are required.
  • callback(err, response) (Function) - Callback function that will be fired once transaction is finished.
route.post('/pay', (req, res, next) => {
    const transaction = {
        payment_type: 'credit_card',
        transaction_details: {
            order_id: 'sample-order-1',
            gross_amount: '1000000',
        },
        credit_card: {
            token_id: 'your-credit-card-token',
            bank: 'bni',
        },
    };


    vt.transaction.charge(transaction, (err, result) => {
        if (err) {
            console.error(err);

            return res.redirect('/pay/error');
        }

        return res.redirect('/pay/success')
    });
});

2. Check Transaction / Order Status

vt.transaction.status(id, callback) - Check the status of transaction / order that is identified by id.

Params:

  • id (String) - Identifier of a transaction / order.
  • callback(err, response) (Function) - Callback function that will be called once the status is checked.
route.post('/status/:id', (req, res, next) => {
    const id = req.params.id;


    vt.transaction.status(id, (err, result) => {
        if (err) {
            console.error(err);

            return res.redirect('/transaction/' + req.params.id);
        }

        return res.redirect('/transaction/' + req.params.id);
    });
});

3. Capture Transaction

vt.transaction.capture(payload, callback) - Charge a pre-authorized transaction in which transaction_status is authorize.

Params:

  • payload (Object) - Consists of transaction_id and gross_amount fields. transaction_id is required.
  • callback(err, response) (Function) - Callback function that will be called once transaction is captured.
route.get('/capture/:id', (req, res, next) => {
    const payload = {
        transaction_id: req.params.id,
        gross_amount: 100000,
    };


    vt.transaction.capture(payload, (err, result) => {
        if (err) {
            console.error(err);

            return res.redirect('/transaction/' + req.params.id);
        }

        return res.redirect('/transaction/' + req.params.id);
    });
});

4. Approve Transaction

vt.transaction.approve(id, callback) - Accept card payment transaction in which the fraud_status is challenge.

Params:

  • id (String) - Identifier of a transaction / order.
  • callback(err, response) (Function) - Callback function that will be called once the transaction is approved.
route.get('/approve/:id', (req, res, next) => {
    const id = req.params.id;


    vt.transaction.approve(id, (err, result) => {
        if (err) {
            console.error(err);

            return res.redirect('/transaction/' + req.params.id);
        }

        return res.redirect('/transaction/' + req.params.id);
    });
});

5. Cancel Transaction

vt.transaction.cancel(id, callback) - Cancel card payment transaction if the transaction has not been settled yet.

Params:

  • id (String) - Identifier of a transaction / order.
  • callback(err, response) (Function) - Callback function that will be called once the transaction is canceled.
route.get('/cancel/:id', (req, res, next) => {
    const id = req.params.id;


    vt.transaction.cancel(id, (err, result) => {
        if (err) {
            console.error(err);

            return res.redirect('/transaction/' + req.params.id);
        }

        return res.redirect('/transaction/' + req.params.id);
    });
});

6. Expire Transaction

vt.transaction.expire(id, callback) - Expire a transaction which payment has not yet completed by the customer.

Params:

  • id (String) - Identifier of a transaction / order.
  • callback(err, response) (Function) - Callback function that will be called once the transaction is expired.
route.get('/expire/:id', (req, res, next) => {
    const id = req.params.id;


    vt.transaction.expire(id, (err, result) => {
        if (err) {
            console.error(err);

            return res.redirect('/transaction/' + req.params.id);
        }

        return res.redirect('/transaction/' + req.params.id);
    });
});

7. Refund Transaction

vt.transaction.refund(id, callback) - Cancel the completed / settlement payment.

Params:

  • id (String) - Identifier of a transaction / order.
  • callback(err, response) (Function) - Callback function that will be called once the refund process is completed.
route.get('/refund/:id', (req, res, next) => {
    const id = req.params.id;


    vt.transaction.refund(id, (err, result) => {
        if (err) {
            console.error(err);

            return res.redirect('/transaction/' + req.params.id);
        }

        return res.redirect('/transaction/' + req.params.id);
    });
});

License

MIT License