Requirements

  1. Node 8, 10 or higher.
  2. NPM

Installation

  1. Via npm (Recomended)
npm i chargily-epay-js
# or 
yarn add chargily-epay-js

Quick start

Add CHARGILY_APP_KEY and CHARGILY_APP_SECRET in .env file with the secret key and app key from [ePay Dashboard][api-keys]

#Usage The package needs to be configured with your account’s secret key, which is available in the [ePay Dashboard][api-keys]. Require it with the key’s value:

const chargily = require('chargily-epay-js')
const dotenv = require('dotenv')
const {Invoice, Mode} = require("chargily-epay-js/lib/configuration");

dotenv.config()

const order = new Invoice()
order.invoiceNumber = "100" // must be integer or string
order.mode = Mode.EDAHABIA // or Mode.CIB
order.backUrl = "https://www.exemple.org/" // must be a valid and active URL
order.amount = 5000 // must be integer , and more or equal 75
order.webhookUrl = "https://www.exemple.org/webhook-validator" // this URL where receive the response 
order.client = "chawki mahdi" 
order.discount = 10 // by percentage between [0, 100]
order.clientEmail = "client@example.com" // email of customer where he will receive the Bill
order.appKey = process.env.CHARGILY_APP_KEY 

// createPayment is promise function (async, await ), so you will need to use then to receive the checkoutURL

const checkoutUrl = chargily.createPayment(order).then( res => {
   return res.checkout_url // redirect to this url to proccess the checkout 
})

Configurations

  • Available Configurations
keydescriptionredirect urlprocess url
CHARGILY_APP_KEYmust be string given by organizationrequiredrequired
CHARGILY_APP_SECRETmust be string given by organizationrequiredrequired
back_urlmust be string and valid urlrequirednot required
webhook_urlmust be string and valid url _requiredrequired
modemust be in CIB,EDAHABIArequirednot required
invoice_numberstring or intrequirednot required
client_namestringrequirednot required
clientEmailmust be valid email This is where client receive payment receipt after confirmationrequirednot required
amountmust be numeric and greather or equal than 75requirednot required
discountmust be numeric and between 0 and 99 (discount in %)requirednot required
descriptionmust be string_requirednot required

Testing Webhook signing

You can use DefaultSignatureValidator.isValid() to validate incoming webhook.


const {DefaultSignatureValidator} = require("chargily-epay-js/lib/Webhook");
const express = require('express');
const app = express()
const port = 3000
app.use(express.json());

app.post('/webhook-validator', (req, res)=>{
  let signature = req.header('Signature')

   let rs = DefaultSignatureValidator.isValid(
            signature, 
            process.env.CHARGILY_APP_SECRET,
            req.body) // return boolean
   
   res.send(rs)
 })