How to Integrate PhonePe Payment Gateway in Laravel: A Step-by-Step Guide
Integrating a reliable payment gateway is crucial for any online business. With the increasing popularity of UPI and wallet-based payments in India, PhonePe has emerged as one of the top choices for developers and merchants alike. In this blog, we’ll walk through how to integrate the PhonePe payment gateway into a Laravel application, enabling you to accept payments via UPI, debit/credit cards, and PhonePe wallet.
Whether you're building an eCommerce store, a donation platform, or a service booking site, this guide will help you connect your Laravel backend with PhonePe’s secure payment APIs.
Before moving ahead you must have the client ID and client Secret received from the phonepay
First all of you have create your phonepay account by clicking on this URL - https://business.phonepe.com/register
After the creation of account you will able to see the dashboard, in the right side there will be developer option click on that to get the client ID and secret.
Prerequisites
Before you start, make sure you have:
- Laravel 8 or newer installed
- Composer set up
- A registered PhonePe Merchant account with access to the PhonePe API documentation
- Your unique
Client ID And Client Secret
Step-by-Step Integration of PhonePe Payment Gateway in Laravel
Step 1: Setup Your Laravel Project
composer create-project laravel/laravel phonepe-integration
Step 2: Create Payment Controller
Run the following command to generate a controller:
Step 3: Configure PhonePe Payment Parameters
Add your CLIENT_SECERT
, and CLIENT_ID
to .env
:
Step 4: Create a Payment Request
Inside your controller:
Step 5: Define Routes
In routes/web.php
:
Step 6: Testing the flow
first run cache clear command
then run the development mode command
Then visit the below URL in your browser, it will redirect you to the payment page directly
after visiting this URL it will be redirected to the below like page
On the successful payment you can see the screen something like the below one
Project GIT URL - https://github.com/codehunger-team/integrate-phonepay-payment-gateway-in-laravel-12
Conclusion
Integrating the PhonePe payment gateway in Laravel is straightforward once you understand the API workflow and secure checksum generation. By following the steps outlined above, you can provide your users with a fast and secure payment experience via UPI, wallets, and cards.
Be sure to thoroughly test your integration in the sandbox environment before going live, and always handle responses securely to prevent fraud or data leakage.