LibraPay library for Nodejs


LibraPay library for Nodejs

LibraPay library for Nodejs - integrate Libra Bank online payment gateway using this library for NodeJs.

This library allows to connect with librapay using nodejs. The Github repo for this library can be found here.

Official documentation can be found here.

Initial setup

npm i git+https://github.com/boobo94/libra-pay.git

Usage

You can initialize librapay library as following:

import { LibraPay, BASE_URL_SANDBOX } from 'libra-pay'

const libra = new LibraPay({
    merchantName: '<YOUR VALUE>',
    merchantUrl: '<YOUR VALUE>',
    email: '<YOUR VALUE>',
    key: '<YOUR VALUE>',
    merchant: '<YOUR VALUE>',
    terminal: '<YOUR VALUE>',
    callbackUrl: '<YOUR VALUE>',
    baseUrl: BASE_URL_SANDBOX,
  })

Replace all <YOUR VALUE> values with the configs received from Librabank after registration

Available imports for environment url:

import { BASE_URL_PRODUCTION, BASE_URL_SANDBOX } from 'libra-pay'

Usage express router example

import { Router } from 'express'
import multer from 'multer'
import { LibraPay } from 'libra-pay'

const libra = new LibraPay({
    merchantName: '<YOUR VALUE>',
    merchantUrl: '<YOUR VALUE>',
    email: '<YOUR VALUE>',
    key: '<YOUR VALUE>',
    merchant: '<YOUR VALUE>',
    terminal: '<YOUR VALUE>',
    callbackUrl: '<YOUR VALUE>',
    baseUrl: LibraPay.BASE_URL_SANDBOX,
  })

export default Router()
  .post(
    'hooks',
    multer().none(),
    (req, res, next) => {
      const response = new libra.handleIPN(req.body)
      if (response === '1') {
        console.log('paid with success')
      }

      res.status(200).send(response)
    }
  )

  .get('/card',
    (req, res, next) => {
      const orderId = new Date().getTime().toString()
      const response = libra.generateForm('1.00', orderId, 'comanda online de test', {
        ProductsData: [],
        UserData: {
          Email: '[email protected]',
          Name: 'Nume Prenume',
          Phone: '07537282989',
          BillingEmail: '[email protected]',
          BillingPhone: '07537282989',
          BillingCity: 'Focsani',
          BillingCountry: 'Romania'

        }
      })

      res.status(200).send(response)
    })

  .post('/capture',
    (req, res, next) => {
      const previousOrderId = '1644588481302'
      const res = await libra.captureTransaction('1.00', previousOrderId)

      res.status(200).send({})
    })


  .post('/capture/recurring',
    (req, res, next) => {
      const previousOrderId = '1644588481302'
      const res = await libra.captureRecurringTransaction('100.00', previousOrderId, 'recurring payment')

      res.status(200).send({})
    })

  .post('/cancel/recurring',
    (req, res, next) => {
      const previousOrderId = '1644588481302'
      const res = await libra.cancelRecurringTransaction('100.00', previousOrderId)

      res.status(200).send({})
    })

  .post('/refund',
    (req, res, next) => {
      const previousOrderId = '1644588481302'
      const res = await libra.refundTransaction('1.00', previousOrderId, true)

      res.status(200).send({})
    })

How to test

Card number 4111111111111111

Type VISA

Expiry date: any

Name: any

CVV: any

Newsletter


Related Posts

What I learned to never do in a presentation meeting

What I learned to never do in a presentation meeting. I had a very bad meeting experience with a gateway provider.

Startup graveyard is a series of killed projects that made millions in revenue per year

Startup graveyard is a series of killed projects that made millions in revenue per year. Just watch their graveyard and do it your own. What better validation do you expect.

How do you detect Credit card type based on the number?

How do you detect Credit card type based on the number using JavaScript? Simple solution using only code, no library required.

Download files in Javascript from Node.js server

How to download files in Javascript, either you use Vue.js, React, Angular, jQuery, or Vanilla JS. On the backend side, we run on Node.js using Express.js.

What books to read

The list of books I read. I decided one year ago to challenge myself and read as many books as I can this year. Take a look at this article and find all of them.

Startup tools for a better version

Are you a startup founder and are you looking for startup tools like invoice, planning or just making money with much automation? Check this article, from founder to founders.

How to use express validator?

How to use express validator through full examples. I found express validator very powerful, but having a poor documentation.

How to check DNS propagation

How to check DNS propagation? Did you changed the DNS records recently and now is not working? Stop crying and check the DNS propagation.

Opensource Object Storage with Minio

Opensource Object Storage with Minio using Docker. An alternative to AWS S3, Linode Storage, Google Storage, Azure Storage.

Antiatomic bunker list in Romania

I created an antiatomic bunker list in Romania shared on GitHub repo in CSV and JSON format. Check this out and build your next app using it.