How to integrate paytm payment gateway in the laravel 6 application. In this tutorial, we’ll discuss step by step how to integrate paytm payment gateway in our laravel 6 App using anandsiddharth/laravel-paytm-wallet package. In this example, we will integrate the paytm payment gateway in a simple and easy way.
And this paytm payment gateway example also works with laravel 5.8, 5.7 version.
Paytm is a very popular company. Paytm provide a payment gateway in many different languages like PHP, Java, .Net, Node.js, Ruby on Rails, Perl, Python, Express.
Sometimes we found invalid checksum error in paytm payment gateway SDK. We have resolved invalid checksum error in integrating the paytm payment gateway.
Content
- Install laravel 6 Fresh Setup
- Configuration .env file
- Install Anandsiddharth paytm package
- Generate Migration and Create Model
- Make Route
- Create Controller
- Create Blade View file
- Start Development Server
- Conclusion
Install laravel 6 Fresh Project
We need to install laravel 6 fresh application using below command, Open your command prompt and run the below command :
composer create-project --prefer-dist laravel/laravel blog
After successfully install laravel 6 Application, Go to your project .env file and set up database credential and move next step.
Configuration in .env
In this step, we will set database credential in .env file. Let’s open .env file.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your database name here
DB_USERNAME=database username here
DB_PASSWORD=database password here
Install Anandsiddharth paytm package
Use the below command and install the package :
composer require anandsiddharth/laravel-paytm-wallet
After successfully install the package, we need to register the provider and alias. Go to the app/config/app.php and put the below lines here :
'providers' => [
// Other service providers…
Anand\LaravelPaytmWallet\PaytmWalletServiceProvider::class,
],
'aliases' => [
// Other aliases
'PaytmWallet' => Anand\LaravelPaytmWallet\Facades\PaytmWallet::class,
],
We need to set a paytm credential like below. Go to the app/config/services.php and set the paytm credential.
'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',
],
All the credentials mentioned are provided by Paytm after signing up as a merchant.
Generate Migration and Create Model
Now we will Create table name notes and it’s migration file. use the below command :
php artisan make:model Event -m
Its command will create one model name Event and also create one migration file for the events table. After successfully run the command go to database/migrations file and put the below here :
<?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'); } }
Next, migrate the table using the below command.
php artisan migrate
Now, add the fillable property inside the Event.php file.
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Note extends Model { protected $fillable = ['name','mobile_number', 'amount','status', 'order_id','transaction_id']; }
Make Route
<?php Route::get('event', '[email protected]'); Route::post('payment', '[email protected]'); Route::post('payment/status', '[email protected]');
Create Controller
Create the controller name EventController using the below command.
php artisan make:controller EventController
Go to app/HTTP/Controller/EventController and put the below code :
<?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'); } } }
Create Blade View file
We need to create blade views file, Go to app/resources/views/ and create one file name event.blade.php :
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta name="csrf-token" content="{{ csrf_token() }}"> <title>Paytm Payment Gateway Integrate - Tutsmake.com</title> <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet"> <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="paytm"> {{ csrf_field() }} <div class="row"> <div class="col-md-12"> <div class="form-group"> <strong>Name</strong> <input type="text" name="name" class="form-control" placeholder="Enter Name"> </div> </div> <div class="col-md-12"> <div class="form-group"> <strong>Mobile Number</strong> <input type="text" name="mobile_number" class="form-control" placeholder="Enter Mobile Number"> </div> </div> <div class="col-md-12"> <div class="form-group"> <strong>Email Id</strong> <input type="text" name="email" class="form-control" placeholder="Enter Email id"> </div> </div> <div class="col-md-12"> <div class="form-group"> <strong>Event Fees</strong> <input type="text" name="amount" class="form-control" placeholder="" value="100" readonly=""> </div> </div> <div class="col-md-12"> <button type="submit" class="btn btn-primary">Submit</button> </div> </div> </form> </div> </body> </html>
Start Development Server
In this step, we will use the PHP artisan serve command. It will start your server locally
php artisan serve
If you want to run the project diffrent port so use this below command
php artisan serve --port=8080
Now we are ready to run our example so run bellow command to quick run.
http://localhost:8000/event
Or direct hit in your browser
http://localhost/blog/public/event
Testing Card Credential
Card No : 4242424242424242
Month : any future month
Year : any future Year
CVV : 123
Password : 123123
Conclusion
In this tutorial, We have successfully integrated paytm payment gateway in the laravel 6 Application. Our examples run quickly.
Note
If you found any invalid checksum issue in this laravel paytm package. Go to App/vendor/anandsiddharth/laravel-paytm-wallet/lib/encdec_paytm.php file. Next, file the function checkString_e() and replace the function to below code here :
function checkString_e($value) {
$myvalue = ltrim($value);
$myvalue = rtrim($myvalue);
if (in_array($myvalue, ['null', 'NULL']))
$myvalue = '';
return $myvalue;
}
after putting the code and run your project again. if you still found this issue contact on paytm customer support and active your wallet credential.
If you have any questions or thoughts to share, use the comment form below to reach us.
I think this is among the most important information for me.
And i am glad reading your article. But should remark
on few general things, The site style is ideal, the articles is really great : D.
Good job, cheers
my webpage: Jesus
You really make it seem so easy with your presentation but I
find this topic to be really something which I think I would never understand.
It seems too complex and very broad for me. I am looking
forward for your next post, I’ll try to get the hang of it!
Here is my webpage … cheap flights
Hi there! I realize this is sort of off-topic but I needed to ask.
Does building a well-established website like yours
require a large amount of work? I’m brand new to operating a
blog but I do write in my journal everyday. I’d like to start a blog so I can share my own experience and views
online. Please let me know if you have any suggestions or tips
for brand new aspiring blog owners. Appreciate it!
My web blog … cheap flights
These are actually impressive ideas in about blogging.
You have touched some good points here. Any way keep
up wrinting.
Review my page: cheap flights – http://tinyurl.com,
I blog frequently and I really thank you for your content. Your article has truly peaked my interest.
I will bookmark your blog and keep checking for new information about once a week.
I subscribed to your Feed too.
Feel free to visit my webpage … cheap flights
Hi there to every , because I am in fact keen of reading this website’s post to be updated regularly.
It contains good information.
My website – cheap flights, tinyurl.com,
Thank you for the auspicious writeup. It if truth be told was once a leisure account it.
Glance complex to far delivered agreeable from you!
However, how can we be in contact?
My web page: cheap flights – http://tinyurl.com,
Oh my goodness! Amazing article dude! Thank you so much, However I am
encountering problems with your RSS. I don’t know the reason why I cannot join it.
Is there anyone else getting identical RSS problems?
Anybody who knows the answer can you kindly respond?
Thanx!!
Here is my homepage: Maxie
Please refer to the updated date and time information above the odds
listings.
Here is my website; free online sports betting
It is safe to say that decimal odds are the most
well known system for displaying odds out there.
my page; online casino games
Hi, i think that i saw you visited my website thus i came to
“return the favor”.I am trying to find things to enhance my website!I suppose its ok to use a few of your ideas!!
Also visit my web blog … mega888 ios (cashflowandflip.com)
The organization said added announcements will be forthcoming.
my web-site; click here
I blog often and I genuinely appreciate your content.
The article has truly peaked my interest. I will take a
note of your website and keep checking for new information about once a week.
I opted in for your Feed too.
My page – online game xe88
During this time EA formed EA Sports, a brand name utilized for sports
games they made.
Review my site – betting advice
The full odds are then paid to the divided stake with the remainder
of the revenue being lost.
Look at my web-site: sports betting services
Hi to every one, since I am actually eager of reading this webpage’s post to be updated daily.
It includes pleasant stuff.
my site: poppers uk
In some, there are no restrictions, when other people prohibit betting
on any in-state programs or events.
Here is my site … online sports books
Locating worth is one of the secrets to making money from something
in life.
Feel free to visit my web site – 메이저토토사이트
The successor of a title that gave birth to an whole genre, DOTA 2 is the second-largest MOBA title on the esports scene.
Also visit my web-site; world cup spread betting
I wanted to thank you for this good read!! I absolutely enjoyed every bit of it.
I have got you book-marked to look at new stuff you post…
My webpage … download mega888 ios
It’s not my first time to pay a quick visit this web site, i am browsing
this website dailly and take fastidious facts from here daily.
Feel free to surf to my web blog :: Room Aromas
Wow, awesome weblog format! How long have you been blogging
for? you make blogging look easy. The total look of your
web site is excellent, let alone the content!
Here is my blog post: xe88
The 1st time in history that an intervention that the US government has thrown billions of
dollars at has been described as a victory “against
all odds”.
Feel free to surf to my webpage: online sports books
Hmm is аnyone else haing problems with the pictures on this blog
loading? I’m trying to figure out if itts a problem
on my end or if it’s the blog. Any resⲣ᧐nsеs woulԀ be greatly аppreciated.
my page:pasang baja ringan atap spandek
On the net casinos aren’t all that various from their brick-and-mortar counterparts.
my web blog best online casino
Right here is the perfect webpage for anybody who would like to understand this topic.
You understand a whole lot its almost tough to argue with you (not that I actually would want
to…HaHa). You certainly put a new spin on a topic that’s been discussed for a
long time. Excellent stuff, just great!
Here is my site Odell
Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
You clearly know what youre talking about, why waste
your intelligence on just posting videos to your site when you could
be giving us something informative to read?
My homepage; Lonny
Good day! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to
get my blog to rank for some targeted keywords but I’m
not seeing very good results. If you know of any please share.
Appreciate it!
My blog post … Marcia
But as other states like neighboring Mississippi move
promptly to legalize sports gambling, he said, “we’re behind everybody.”
Also visit my blog post … find online casino
A prop bet is an further way to wager on a game or occasion, with quite a few
props revolving around player performances.
My web site: usa online casino
It’s as uncomplicated as navigating to a webpage to make your bets.
Here is my webpage … 스포츠토토
Integrated in the live system will be a trip to Fenway Park to
see the Red Sox play.
Here is my web-site – play online
By the 90s, there was considerable stress to reconsider the legality of slots,
especially due to competitors from neighboring states.
My web site; betting sports