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

How to install Kali Linux in UTM Virtual Machine on M2 Macbook

How I installed a UTM virtual machine with Kali Linux on a Macbook PRO M2 chip

Validating CIF for Romanian Company in JS

Validate CIF for Romanian companies in JS. Easily verify company information with our user-friendly tool. Ensure accuracy and reliability.

My cat ruin my SaaS LoyalXpert

After half year, LoyalXpert, the loyalty system builder for coffee shop oweners is shutdown

TikTok Ads Strategy from a SaaS founder

Here's a short tutorial from my disrupting strategy of doing Tiktok Ads as a SaaS Founder

Curated SEO Resources: Essential Tools and Tips

Discover a handpicked selection of indispensable SEO resources, including tools and tips, to optimize your website's performance.

A Week in the Life of an Invoice Wrangler: Navigating Ridesharing and Food Delivery Chaos

As an app founder in the ridesharing and food delivery industry, I found myself knee-deep in invoice reports from companies like Bolt, Uber, Glovo, and Bolt Food

Free HTML templates list for Startups

Free HTML templates list for startup. A complete list with free resources to build your next startup's website and gain the traction to the sky.

Deal with client requests in SaaS

How to deal with client requests in Saas which are seeing only their interests, not the product interest.

The first client of LoyalXpert is not answering anymore

Trying to implement LoyalXpert app, I lost my first customer, he's not answering anymore

Experiments with Tiktok Ads

Recently tried out TikTok ads for the first time and here are some of my learnings and challenges