Paytabs Nodejs Rest API
PayTabs rest API for NodeJs is a package which implements the public API for create paypage of PayTabs. The package covers the following functions:
- validate_secret_key Validate your secret key API
- create_pay_page - Create PayPage API
- verify_payment - Verify Payment API
Installation
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 = ;/*** Please refere to Paytabs Documentation to understand all variables and different payment methods https://dev.paytabs.com/docs/paypage.htmlYou can get your email and secret key from paytabs merchant dashboard* https://www.paytabs.com/login/*/paytabs; { ifresultresponse_code == 4012 //Redirect your merchant to the payment link console; else //Handle the error console; }
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 = ;/*** Please check this Paytabs API for more information* https://dev.paytabs.com/docs/paypage.html#verify-payment*/paytabs;{console;}
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 = ;paytabs;{ifresultresponse_code ==4000//Validconsole;else//Failedconsole;}
Note
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.