Skip to content
  • Github
  • Facebook
  • twitter
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Paytm payment gateway integration example

laravel 6 Paytm payment gateway integration example

Posted on September 25, 2019December 17, 2022 By XpertPhp 1 Comment on laravel 6 Paytm payment gateway integration example

In this tutorial, we will tell you how to integrate the Paytm payment gateway using the Laravel Framework (Laravel 6 Paytm payment gateway integration example).

The Paytm payment gateway is a popular payment gateway method and it is easily used for the project. so many developers prefer that payment gateway method.

Read Also: Laravel 6 Stripe Payment Gateway Integrate Example

Paytm is a secure payment method and it’s work-based using anandsiddharth/laravel-paytm-wallet package. so let’s start In this article using how to integrate the Paytm payment gateway in a simple and easy way.

Overview

Step 1: Install Laravel 6

Step 2: Setting Database Configuration

Step 3: Create Table using migration

Step 4: Install Package

Step 5: Add providers and aliases

Step 6: Configuration of API Key

Step 7: Create Route

Step 8: Create a Model and Controller

Step 9: Create Blade File

Laravel Paytm Payment Gateway Integration Example

Step 1: Install Laravel 6

We are going to install laravel 6, so first open the command prompt or terminal and go to go to xampp htdocs folder directory using the command prompt. after then run the below command.

PHP
1
composer create-project --prefer-dist laravel/laravel larave6_paytm

Step 2: Setting Database Configuration

After the complete installation of laravel. we have to database configuration. now we will open the .env file and change the database name, username, password in the .env file. See below changes in a .env file.

1
2
3
4
5
6
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=Enter_Your_Database_Name(laravel6_paytm)
DB_USERNAME=Enter_Your_Database_Username(root)
DB_PASSWORD=Enter_Your_Database_Password(root)

Step 3: Create Table using migration

Now, We need to create a migration. so we will below command using create the products table migration.

1
php artisan make:migration create_products_table --create=events

After complete migration. we need below changes in the database/migrations/create_events_table file.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEventsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('mobile_number');
$table->integer('amount');
$table->string('order_id');
$table->string('status')->default('pending');
$table->string('transaction_id')->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
Schema::dropIfExists('events');
}
}
?>

Run the below command. after the changes above file.

PHP
1
php artisan migrate

Step 4: Install Package

Now, we are going to install the Paytm package using the below command.

PHP
1
composer require anandsiddharth/laravel-paytm-wallet

Step 5: Add providers and aliases

We will add below providers and aliases in the “config/app.php” file

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'providers' => [
....
Anand\LaravelPaytmWallet\PaytmWalletServiceProvider::class,
],
'aliases' => [
....
'PaytmWallet' => Anand\LaravelPaytmWallet\Facades\PaytmWallet::class,
]

Step 6: Configuration of API Key

Now, we are going to the configuration of the API key in the app/config/services.php file.

PHP
1
2
3
4
5
6
7
8
'paytm-wallet' => [
     'env' => 'production', // values : (local | production)
     'merchant_id' => 'YOUR_MERCHANT_ID',
     'merchant_key' => 'YOUR_MERCHANT_KEY',
     'merchant_website' => 'YOUR_WEBSITE',
     'channel' => 'YOUR_CHANNEL',
     'industry_type' => 'YOUR_INDUSTRY_TYPE',
],

Step 7: Create Route

Add the following route code in the “routes/web.php” file.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
 
use Illuminate\Support\Facades\Route;
 
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
 
Route::get('/', function () {
    return view('welcome');
});
 
Route::get('event', 'EventController@bookEvent');
Route::post('payment', 'EventController@eventOrderGen');
Route::post('payment/status', 'EventController@paymentCallback');
?>

Step 8: Create a Model and Controller

Here below command help to create the controller and model.

PHP
1
php artisan make:controller EventController --resource --model=Event

Event.php

PHP
1
2
3
4
5
6
7
8
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Event extends Model
{
protected $fillable = ['name','mobile_number','amount','status','order_id','transaction_id'];
}
?>

EventController.php

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Event;
use PaytmWallet;
class EventController extends Controller {
/** * Redirect the user to the Payment Gateway.
*
* @return Response
*/
public function bookEvent()
{
return view('book_event');
}
/**
* Redirect the user to the Payment Gateway.
*
* @return Response
*/
public function eventOrderGen(Request $request) {
$this->validate($request, [
  'name' => 'required',
  'mobile_no' =>'required|numeric|digits:10|unique:events,mobile_number',
]);
$input = $request->all();
$input['order_id'] = rand(1111,9999);
$input['amount'] = 50;
Event::insert($input);
$payment = PaytmWallet::with('receive');
$payment->prepare([
  'order' => $input['order_id'],
  'user' => 'user id',
  'mobile_number' => $request->mobile_number,
  'email' => $request->email,
  'amount' => $input['amount'],
  'callback_url' => url('payment/status')
]);
return $payment->receive();
}
    /**
     * Obtain the payment information.
     *
     * @return Object
     */
    public function paymentCallback()
    {
        $transaction = PaytmWallet::with('receive');
        $response = $transaction->response();
        if($transaction->isSuccessful()){
          Event::where('order_id',$response['ORDERID'])->update(['status'=>'success', 'payment_id'=>$response['TXNID']]);
          dd('Payment Successfully Credited.');
        }else if($transaction->isFailed()){
          Event::where('order_id',$order_id)->update(['status'=>'failed', 'payment_id'=>$response['TXNID']]);
          dd('Payment Failed. Try again lator');
        }
    }    
}
?>

Step 9: Create Blade File

Finally, We will create event.blade.php file in the “resources/views/” folder directory and paste below code.

event.blade.php

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <style>
.mt40{
margin-top: 40px;
}
  </style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12 mt40">
<div class="card-header" style="background: #0275D8;">
<h2>Register for Event</h2>
</div>
</div>
</div>
@if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> Something went wrong<br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ url('payment') }}" method="POST" name="add_note">
{{ csrf_field() }}
<div class="row">
<div class="col-md-12">
<div class="form-group">
<strong>Name</strong>
<input class="form-control" name="name" type="text" placeholder="Enter Name" />
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<strong>Mobile Number</strong>
<input class="form-control" name="mobile_number" type="text" placeholder="Enter Mobile Number" />
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<strong>Email Id</strong>
<input class="form-control" name="email" type="text" placeholder="Enter Email id" />
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<strong>Event Fees</strong>
<input class="form-control" name="amount" readonly="readonly" type="text" value="100" placeholder="" /></div>
</div>
<div class="col-md-12">
<button class="btn btn-primary" type="submit">Submit</button></div>
</div>
</div>
</form>
</div>
</body>
</html>

We can start the server and run this example using the below command.

PHP
1
php artisan serve

Now we will run our example using the below Url in the browser.

PHP
1
http://127.0.0.1:8000/event

Testing Card Credential

Card No : 4242424242424242

Month : any future month

Year : any future Year

CVV : 123

Password : 123123

Laravel, MySql Tags:laravel 6, Laravel 6 Eloquent, laravel 6 Payment Gateway Integration, Laravel 6 Routing, payment gateway

Post navigation

Previous Post: Codeigniter Multiple Files Upload Example
Next Post: How to Get The Country Wise Date and Time Using Jquery

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Laravel 10 Ajax CRUD Example Tutorial
  • Laravel 10 CRUD Example Tutorial
  • How to disable button in React js
  • JavaScript Interview Questions and Answers

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch laravel social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com