Payu Payment Gateway Integration In Laravel 12
Are you a freelancer, startup, or agency in India looking to integrate PayU payment gateway in your Laravel application without relying on third-party packages? This guide will walk you through step-by-step integration of PayU in Laravel using test mode, without using any external libraries.
Whether you're building an e-commerce platform, donation system, or subscription-based SaaS, this manual PayU integration offers you complete control over the payment flow.
Before starting the blog please make sure that you have created your account at payu if not please visit this URL - https://onboarding.payu.in/app/account/signin?redirect_to=https%3A%2F%2Fpayu.in%2Fbusiness
Here you have to create your account, this page will looks like the below one
Now after registration go to the developer setting. to collect your merchant key and salt
Now let's begin the integration
π οΈ What Is PayU and Why Use It?
PayU is a leading Indian payment gateway trusted by 450,000+ businesses. It supports:
- Credit/Debit Cards
- UPI
- Wallets
- Net Banking
- EMI
- Buy Now Pay Later (BNPL)
By using PayU Test Mode, you can simulate transactions without real money. This is ideal for developers and QA teams before going live.
π§© Requirements
Before starting, ensure:
- Laravel 8/9/10 installed
- Routes, Controllers, Views ready
- You have PayU Test Credentials:
- Merchant Key
- Merchant Salt
- Test URL:
https://test.payu.in/_payment
π Folder Structure Overview
Here's what weβll build:
π Step 1: PayU Route Setup (web.php)
Add these routes to your routes/web.php
file:
/payu/payment
: Initiates the payment form
/payu/success
: Callback for successful payments
/payu/failure
: Callback for failed transactions
π§ Step 2: Generate PayU Hash (PayuController.php)
Now create the PayuController
in app/Http/Controllers
:
Paste the following code:
β
Tip: Use uniqid()
for generating unique transaction IDs during testing.
π Step 3: Create Redirect Form (Blade View)
In resources/views/payu/
, create redirect.blade.php
:
This form auto-submits to PayU with hidden fields.
π Step 4: Add Environment Variables (.env)
In your .env
file, add:
Replace values with the credentials from your PayU test dashboard.
π§ͺ Step 5: Test Your Integration
Now visit:
You should:
- Be redirected to the PayU payment page (test mode)
- Choose "Test Card" to simulate the payment
- Be redirected back to success/failure URL
When you hit the above URL you have the screen like the below one
π Optional: Debugging and Logs
To debug issues:
- Check Laravel logs:
storage/logs/laravel.log
- Ensure
.env
variables are correct - Confirm the hash format follows the sequence:
β Conclusion: What Youβve Built
Youβve successfully integrated PayU payment gateway into your Laravel application without any third-party package, entirely in test mode.
This manual integration provides:
- Full control over payment data
- Better debugging
- No package dependency
π Download the Complete Source Code
To make your integration even easier, we have prepared a ready-to-use Laravel 12 project with PayU payment gateway integration in test mode. You can download the entire source code from our GitHub repository:
π https://github.com/codehunger-team/integrate-payu-payment-gateway-in-laravel-12.git
Clone the repo, set your .env
variables for merchant key, salt, and merchant ID, and youβre good to go!
If you're looking to go live with production PayU payments, stay tuned for our next blog on Production PayU integration with Laravel.
π’ Need help with custom Laravel payment integration? Contact CodeHunger β your trusted development partner for India and beyond.