DEV Community

Cover image for Building a Real-Time Payment Gateway Integration with PHP, PayHere, ngrok, and MySQL
Dulan Nithila Liyanarachchi
Dulan Nithila Liyanarachchi

Posted on Originally published at linkedin.com AI-assisted

Building a Real-Time Payment Gateway Integration with PHP, PayHere, ngrok, and MySQL

Recently, I built a complete real-time payment gateway integration using PHP, PayHere Sandbox, ngrok, and MySQL to simulate and test online payments in a local development environment.

This project covered:

  • Secure PayHere checkout integration
  • Real-time payment callback handling through ngrok
  • Transaction logging and MySQL database storage
  • Email notifications using PHPMailer
  • PDF receipt generation using mPDF

One of the most interesting parts of the project was using ngrok to expose localhost securely, allowing PayHere to communicate with local callback URLs such as notify_url, return_url, and cancel_url.

The project structure was designed to keep the workflow clean and modular, with separate files for checkout processing, notifications, verification, configuration, and database handling.

This implementation was a great hands-on experience in understanding how real-world payment systems work behind the scenes, from hash generation and callback verification to preventing duplicate transactions and securely handling payment confirmations.

Repository

GitHub Repository: https://github.com/NithilaLD/Building-a-Real-Time-Payment-Gateway-Integration-with-PHP-PayHere-ngrok-and-MySQL/

The repository includes the complete project resources, including the full implementation guide in PDF format, source code files for the payment gateway integration, and database setup scripts required to configure and run the application locally.

Tech Stack

PHP | MySQL | PayHere Sandbox | ngrok | Composer | PHPMailer | mPDF

Also Published On

This article is also available on the following platforms:

Top comments (0)