Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Full Working Example — Paytm Integration in Laravel

I’ll give you a full working Paytm Payment Gateway integration example in Laravel — step-by-step, including payment page, initiate payment, callback handling, and success/failure handling.


🚀 Full Working Example — Paytm Integration in Laravel (Latest)

1. Install Laravel Paytm Package

First, install a Paytm SDK/library.
I recommend using "anandsiddharth/laravel-paytm-wallet" (easy and popular):

composer require anandsiddharth/laravel-paytm-wallet
Code language: JavaScript (javascript)

2. Configure Paytm Keys in .env

Add your Paytm credentials in your .env file:

PAYTM_MERCHANT_ID=YourMerchantID
PAYTM_MERCHANT_KEY=YourMerchantKey
PAYTM_ENVIRONMENT=local  # use 'production' for live
PAYTM_MERCHANT_WEBSITE=WEBSTAGING
PAYTM_CHANNEL=WEB
PAYTM_INDUSTRY_TYPE=Retail
Code language: PHP (php)

3. Create Paytm Configuration File

Publish the config if needed:

php artisan vendor:publish --provider="Anand\LaravelPaytmWallet\PaytmWalletServiceProvider"
Code language: JavaScript (javascript)

It will create a config/paytm-wallet.php file.

Check it and ensure environment variables are correctly mapped.


4. Create Paytm Controller

Now, create a controller to handle payment:

php artisan make:controller PaytmPaymentController
Code language: CSS (css)

Now edit app/Http/Controllers/PaytmPaymentController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Anand\LaravelPaytmWallet\Facades\PaytmWallet;

class PaytmPaymentController extends Controller
{
    public function initiatePayment()
    {
        return view('paytm-payment');
    }

    public function pay(Request $request)
    {
        $payment = PaytmWallet::with('receive');

        $payment->prepare([
            'order' => 'ORDER_' . uniqid(),
            'user' => auth()->id() ?? 1, // or your user id
            'mobile_number' => '7777777777', // dummy or real
            'email' => 'test@example.com', // dummy or real
            'amount' => $request->amount, // dynamic
            'callback_url' => route('paytm.callback')
        ]);

        return $payment->receive(); // Redirect to Paytm payment page
    }

    public function callback()
    {
        $transaction = PaytmWallet::with('receive');
        $response = $transaction->response(); // Response from Paytm

        if ($transaction->isSuccessful()) {
            // Payment Successful
            return redirect()->route('payment.success')->with('message', 'Payment Successful');
        } elseif ($transaction->isFailed()) {
            // Payment Failed
            return redirect()->route('payment.failed')->with('message', 'Payment Failed');
        }
    }

    public function success()
    {
        return view('payment-success');
    }

    public function failed()
    {
        return view('payment-failed');
    }
}
Code language: HTML, XML (xml)

5. Create Routes in web.php

Add these routes:

use App\Http\Controllers\PaytmPaymentController;

Route::get('/paytm-payment', [PaytmPaymentController::class, 'initiatePayment'])->name('paytm.initiate');
Route::post('/paytm-payment', [PaytmPaymentController::class, 'pay'])->name('paytm.pay');
Route::post('/paytm-callback', [PaytmPaymentController::class, 'callback'])->name('paytm.callback');

Route::get('/payment-success', [PaytmPaymentController::class, 'success'])->name('payment.success');
Route::get('/payment-failed', [PaytmPaymentController::class, 'failed'])->name('payment.failed');
Code language: PHP (php)

6. Exclude Callback from CSRF (Important!)

In app/Http/Middleware/VerifyCsrfToken.php, add:

protected $except = [
    '/paytm-callback',
];
Code language: PHP (php)

✅ This fixes the 419 error you were facing.


7. Create Blade View for Payment Page

Create a blade file: resources/views/paytm-payment.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Paytm Payment Gateway</title>
</head>
<body>

<h2>Paytm Payment</h2>

<form method="POST" action="{{ route('paytm.pay') }}">
    @csrf
    <label>Amount:</label>
    <input type="text" name="amount" value="100" required>
    <br><br>
    <button type="submit">Pay Now</button>
</form>

</body>
</html>
Code language: HTML, XML (xml)

8. Create Success and Failure Pages

resources/views/payment-success.blade.php

<h1>Payment Successful!</h1>
<p>{{ session('message') }}</p>
Code language: HTML, XML (xml)

resources/views/payment-failed.blade.php

<h1>Payment Failed!</h1>
<p>{{ session('message') }}</p>
Code language: HTML, XML (xml)

📋 Full Flow

StepDescription
/paytm-paymentUser visits payment page and enters amount.
/paytm-payment (POST)User submits, redirected to Paytm payment page.
Paytm Payment PageUser makes payment (success/failure).
/paytm-callback (POST)Paytm server sends callback after payment.
Success or Failure pageUser redirected accordingly.

🎯 Summary

ItemStatus
Paytm credentials loaded from .env ✅
Laravel Paytm package installed ✅
CSRF excluded for callback ✅
Payment form, controller, routes done ✅
User sees success/failure after payment ✅

📌 Bonus Tips

  • Always log the Paytm callback response for debugging.
  • Validate Paytm signature (CHECKSUMHASH) if needed (package does internally).
  • Use unique order IDs every time.
  • Move Paytm keys into a secure vault if in production.

🎯 Quick Commands for Copying

composer require anandsiddharth/laravel-paytm-wallet
php artisan make:controller PaytmPaymentController
Code language: JavaScript (javascript)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Team Foundation Server 2015 Installation Guide (SQL Express + Update 3)

Install Team Foundation Server 2015 using the original Microsoft download paths, with clear guidance for online, offline, and ISO-based setup. This revised guide also includes an installation workflow, command example, and practical pitfalls to avoid.

Read More

How to Access a Running Docker Container Shell: docker exec vs docker attach

Need a shell inside a running container that is already in detached mode? This updated guide shows the correct workflow, compares docker exec and docker attach, and explains when SSH does and does not make sense.

Read More

Host Your Own NuGet Feed: Local Source vs NuGet.Server vs NuGetGallery

Learn how to host a private NuGet feed using three practical approaches: a local folder source, NuGet.Server, and NuGetGallery. This revised guide includes setup steps, command examples, and a workflow diagram to help you choose the right model.

Read More

Publish NuGet Packages to NuGet.org: CLI Steps, Workflow, and CI Example

Learn how to publish a NuGet package to NuGet.org using either nuget.exe or the dotnet CLI. This revised guide includes a workflow diagram, command comparison, and a CI-friendly example.

Read More

How to Create NuGet Packages with nuget.exe (Assembly, .nuspec, and .csproj Methods)

Learn three practical ways to build NuGet packages using nuget.exe: from an existing assembly, from a convention-based folder layout, or directly from a Visual Studio project. This guide includes commands, folder conventions, token behavior, and common pitfalls.

Read More

Virtualization in DevOps: Using Vagrant, Docker, and Cloud Platforms Together

This guide explains how VM-based workflows, containers, and cloud platforms complement each other in DevOps. It includes a practical workflow, trade-off table, and command examples for day-to-day use.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x