Paytm payment gateway integration in Laravel

Kishan Rank
4 min readJun 10, 2020

--

Hello Web artisans, hope you are doing well. Here in this post, I will let you know how to integrate Paytm payment gateway integration in Laravel.

There are many payment gateways options available to integrate into your laravel applications like Paypal, Stripe, Braintree, Paytm etc. Here I will tell you one of the famous payment system in India PAYTM.

Nowadays Paytm is used by most of the people in India. So it is the best option to integrate it in your website.

Paytm

So let’s follow below few step to get it.

Step 1: Install Laravel

We will install laravel application using composer command in cmd, so open your terminal and hit the below command.

composer create-project — prefer-dist laravel/laravel paytm

Step 2 : Install Package

To integrate Paytm in laravel we require anandsiddharth/laravel-paytm-wallet package, so lets install it using terminal in our project directory.

composer require anandsiddharth/laravel-paytm-wallet

After successfully install package, open config/app.php file and add service provider in it.

config/app.php

'providers' => [Anand\LaravelPaytmWallet\PaytmWalletServiceProvider::class,],'aliases' => ['PaytmWallet' => Anand\LaravelPaytmWallet\Facades\PaytmWallet::class,],

Step 3 : Login into Paytm developer website and generate api key and secret. Click Here

API data from paytm developer dashboard

After getting your api data from paytm developer website put it in .env file.

PAYTM_ENVIRONMENT=localPAYTM_MERCHANT_ID=YOUR_MERCHANT_IDPAYTM_MERCHANT_KEY=YOUR_MERCHANT_KEYPAYTM_MERCHANT_WEBSITE=YOUR_MERCHANT_WEBSITEPAYTM_CHANNEL=YOUR_MERCHANT_CHANNELPAYTM_INDUSTRY_TYPE=Retail

Also add this configuration to config/services.php file like below.

‘paytm-wallet’ => [‘env’ => env(‘PAYTM_ENVIRONMENT’),‘merchant_id’ => env(‘PAYTM_MERCHANT_ID’),‘merchant_key’ => env(‘PAYTM_MERCHANT_KEY’),‘merchant_website’ => env(‘PAYTM_MERCHANT_WEBSITE’),‘channel’ => env(‘PAYTM_CHANNEL’),‘industry_type’ => env(‘PAYTM_INDUSTRY_TYPE’),],

Step 4 : Create Model and Migration

To generate Model and Migration execute the following command.

php artisan make:model Paytm -m

Put below code in your in Model class of Paytm.

Path for model is App/Paytm.php

Now in your migration file put below code in it.

database/migrations

Now run bellow command for migration:

php artisan migrate

Step 5 : Create a Web Routes

In this step we will create 3 routes for our application as per below.

Step 6 : Create Controller

In this step we have to create new controller and their methods, So let’s create PaytmController and put bellow code:

php artisan make:controller PaytmController

app/Http/Controllers/PaytmController.php

Step 6 : Create View File

In this step, we will create paytm blade file and we create form with name, mobile number and email. So, let’s create paytm.blade.php file and put bellow code:

recources/views/paytm.blade.php

Now we are ready to run our project so run below command to start server.

php artisan serve

Go to the following url and you will see below form as shown in photo.

http://127.0.0.1:8000/initiate

form for accepting payment

Fill the form and click on submit button it will redirect to the Paytm payment page.

Paytm payment page

Now select any option and complete process.

Paytm provides dummy credit card data to perform test transaction. Select credit card and put below detail.

Use below CC detail to perform transaction and click on Pay.

Credit Card No. : 4242–4242–4242–4242
Expiry date : 01/24 //should be greater then current date
cvv : 123

As you click on Pay it will show page like below,

Now click on successful and you will be redirected to form page that display a success message.

successful message page

You can check your transaction in paytm developer dashboard and you will also receive a sms and e-mail notification.

That’s it. Payment done!!!

Thanks for reading.

Github : https://github.com/kishanrank/paytm_laravel

--

--

Kishan Rank

Hey there, I’m Kishan Rank, an Software developer from India. PHP lover! https://github.com/kishanrank