Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including paytabs_api with all npm packages installed. Try it out:

var paytabsApi = require("paytabs_api")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

paytabs_api v1.0.0

Paytabs Nodejs Rest API


Build Status

PayTabs rest API for NodeJs is a package which implements the public API for create paypage of PayTabs. The package covers the following functions:


To install this package please run

npm i paytabs_api

Create PayPage

The concept behind the PayTabs rest API is to create invoice using this API and redirect your merchant to that invoice to collect the payment and here is how to do it.

const  paytabs = require('paytabs_api');
* Please refere to Paytabs Documentation to understand all variables and different payment methods
You can get your email and secret key from paytabs merchant dashboard
    'merchant_email':'<YOUR EMAIL>',
    'secret_key':'<YOUR SECRET KEY>',
    'currency':'USD',//change this to the required currency
    'amount':'10',//change this to the required amount
    'site_url':'<YOUR SITE URL>',//change this to reflect your site
    'title':'Order for Shoes',//Change this to reflect your order title
    'quantity':1,//Quantity of the product
    'unit_price':10, //Quantity * price must be equal to amount
    'products_per_title':'Shoes | Jeans', //Change this to your products
    'return_url':'<YOUR SITE CALLBACK URL>',//This should be your callback url
    'cc_first_name':'Samy',//Customer First Name
    'cc_last_name':'Saad',//Customer Last Name
    'cc_phone_number':'00973', //Country code
    'phone_number':'12332323', //Customer Phone
    'billing_address':'Address', //Billing Address
    'city':'Manama',//Billing City
    'state':'Manama',//Billing State
    'postal_code':'1234',//Postal Code
    'country':'BHR',//Iso 3 country code
    'email':'<CUSTOMER EMAIL>',//Customer Email
    'ip_customer':'<CUSTOMER IP>',//Pass customer IP here
    'ip_merchant':'<MERCHANT IP>',//Change this to your server IP
    'address_shipping':'Shipping',//Shipping Address
    'city_shipping':'Manama',//Shipping City
    'state_shipping':'Manama',//Shipping State
    'other_charges':0,//Other chargs can be here
    'reference_no':1234,//Pass the order id on your system for your reference
    'msg_lang':'en',//The language for the response
    'cms_with_version':'Nodejs Lib v1',//Feel free to change this

function createPayPage(result){
    if(result.response_code == 4012){
        //Redirect your merchant to the payment link
        //Handle the error

Verify Payment

After the payment is done you need to verify if it was successfull or not, so in the call back url PayTabs will reply with Payment Reference and status, using this reference you can run the following code to make sure it's Paid.

const  paytabs = require('paytabs_api');
 * Please check this Paytabs API for more information
    'payment_reference':'<PAYPAGE ID>'

function verifyPayment(result){

Validate Secret Key

In some cases you will need to validate your secret key, for example if you are allowing to change the secret key infromation through your website control panel, so it's better to validate it before saving. This can be achived using this API

const  paytabs = require('paytabs_api');
    'merchant_email':'<Your Email>',
    'secret_key':'<Your Secret Key>',

function validateSecretKey(result){
   if(result.response_code ==4000){


You have to handle the call back URL through your application, in which PayTabs will reply to your site with the payment result and then you can call verify payment api.

That's it. Please use the package github page to report any issue or suggestion.


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free