Skip to content

dasunNimantha/PayHere-Gateway-Nodejs-Intergration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nodejs Implementation of PayHere

This is a payment gateway intergration that created specifically for Sri Lankan users,using express framework and PayHere SDK...

PayHere stays on the leading edge of safety and security. By partnering with Sampath Bank PLC with the approval of Central Bank, PayHere offers layers of trustable security.

  • PayHere Sri Lanka is Central Bank Approved

  • PayHere got Bank-backed Security from Sampath Bank

  • PCI DSS Compliant online payment service provider - PayHere

For more information: payhere.lk

Installation

Clone the git repository and install dependancies

git clone https://github.com/dasunNimantha/PayHere-Gateway-for-Nodejs.git
npm install

Start node server running on http://127.0.0.1:3000 using :

node app

Prerequisites

  • To access the SDK,you need to create a payhere sandbox account from here.

  • You need your PayHere Merchant ID & Merchant Secret to integrate with Checkout API.

     Merchant ID can be found at Settings > Domains & Credentials             
     Merchant Secret can be generated for your domain/app as follows
                 1. Go to Settings > Domains & Credentials
                 2. Click 'Add Domain/App' > Fill details > Click 'Request to Allow'
                 3. Enter 127.0.0.1:3000 to the domain for sandbox
                 4. Wait for the approval for your domain
                 5. Copy the Merchant Secret for your domain/app
    
  • Note: Merchant Secrets are domain/app specific, therefore you need to generate a new Merchant Secret every time you're integrating PayHere on a new domain/app.

For more details : PayHere Documentation

Usage

1.First copy and paste "merchant secret key" to the .env file in the root directory.

2.Then you need to send a post request to the payhere action url with necessary parameters.

###Action Urls

Sandbox - https://sandbox.payhere.lk/pay/checkout
Live    - https://www.payhere.lk/pay/checkout

### Required POST Parameters
merchant_id - PayHere Merchant ID
return_url - URL to redirect users when success
cancel_url - URL to redirect users when cancelled
notify_url - URL to callback the status of the payment (Needs to be a URL accessible on a public IP/domain)
first_name - Customer’s First Name
last_name - Customer’s Last Name
email - Customer’s Email
phone - Customer’s Phone No
address - Customer’s Address Line1 + Line2
city - Customer’s City
country - Customer’s Country
order_id - Order ID generated by the merchant
items - Item title or Order/Invoice number
currency - Currency Code (LKR/USD)
amount - Total Payment Amount
For the demonstration all parameters were hard coded in to the html form of ejs template.You can retrieve and send the above data using a database or any other media.

How to test a payment on Sandbox Mode?

 You can use following test card numbers to test simulated successful payments.

 Visa : 4916217501611292

 MasterCard : 5307732125531191

 AMEX : 346781005510225

 For ‘Name on Card’, ‘CVV’ & ‘Expiry date’ you can enter any valid data.

 Any card except the above test cards will result in a failed payment.
  1. After the transaction is completed you can send a "POST" api request to yourdomain/check to verify the payment response. However for the security concerns,payhere is not sending a notify_url for http connections. Therefore you need to have ssl certified domain to check the response verification.

alt text

alt text

About

Payhere integration for Nodejs applications

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published