Laravel 7/6 Instamojo Payment Gateway Integration Example

Laravel 7/6 Instamojo Payment Gateway Integration Example

How to Integrate Instamojo Payment Gateway in Laravel 7/6. In this tutorial, we will know you how to integrate the instamojo payment gateway in the php laravel application via the instamojo PHP package. In this simple example, we will tell you each thing step by step. After successfully install instamojo in our laravel application we will test it with testing card credentials.

We will integrate instamojo payment gateway in the laravel app without using curl APIs. Simply install instamojo PHP package and integrate into our lastest laravel based application. Instamojo all processes like refund payments, collect a payment, create payment are very easy and simple.

Laravel 7/6 Instamojo Payment Gateway Integration Example

  • Install Laravel Fresh Setup
  • Install Instamojo PHP package
  • Configuration .env file
  • Create Controller
  • Make Route
  • Create Blade View file
  • Start Development Server

Step 1: Install Laravel Fresh Project

We need to install Laravel fresh application using below command, Open your command prompt and run the below command :

composer create-project --prefer-dist laravel/laravel blog

Step 2: Install Instamojo PHP package

Use the below command and install instamojo PHP package :

composer require instamojo/instamojo-php

Step 3: Configuration in .env

In this step, we will set the instamojo credential in the .env file. Let’s open .env file and put the credentials. Below the credential is testing credentials. You want your instamojo credential so you can go and signup or sign in instomojo and get it credential there.


Next, Go to the app/config/services.php and put the below code here.

'instamojo' => [
'api_key' => env('IM_API_KEY'),
'auth_token' => env('IM_AUTH_TOKEN'),
'url' => env('IM_URL'),

Step 4: Create Controller

Create the controller name PayController using the below command.

php artisan make:controller PayController

Go to app/Http/Controller/PayController and put the below code :


namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PayController extends Controller
   public function index()
        return view('event');
   public function pay(Request $request){

     $api = new \Instamojo\Instamojo(

    try {
        $response = $api->paymentRequestCreate(array(
            "purpose" => "FIFA 16",
            "amount" => $request->amount,
            "buyer_name" => "$request->name",
            "send_email" => true,
            "email" => "$request->email",
            "phone" => "$request->mobile_number",
            "redirect_url" => ""
            header('Location: ' . $response['longurl']);
    }catch (Exception $e) {
        print('Error: ' . $e->getMessage());

 public function success(Request $request){
     try {

        $api = new \Instamojo\Instamojo(

        $response = $api->paymentRequestStatus(request('payment_request_id'));

        if( !isset($response['payments'][0]['status']) ) {
           dd('payment failed');
        } else if($response['payments'][0]['status'] != 'Credit') {
             dd('payment failed');
      }catch (\Exception $e) {
         dd('payment failed');

Step 5: Make Route

We need to create three routes. let’s create our routes.

Route::get('event', 'PayController@index');
Route::post('pay', 'PayController@pay');
Route::get('pay-success', 'PayController@success');

Step 6: 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>
  <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>Instamojo Payment Gateway Integrate -</title>
    <link href="" rel="stylesheet">
            margin-top: 40px;
<div class="container">
<div class="row">
    <div class="col-lg-12 mt40">
        <div class="card-header" style="background: #0275D8;">
            <h2>Register for Event</h2>
@if ($errors->any())
    <div class="alert alert-danger">
        <strong>Opps!</strong> Something went wrong<br>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
<form action="{{ url('pay') }}" method="POST" name="laravel_instamojo">
    {{ csrf_field() }}
     <div class="row">
        <div class="col-md-12">
            <div class="form-group">
                <input type="text" name="name" class="form-control" placeholder="Enter Name" required>
        <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" required>
        <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" required>
        <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 class="col-md-12">
                <button type="submit" class="btn btn-primary">Submit</button>

Step 7: 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 different 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.

 Or direct hit in your browser

Testing Card Credential

 Card No : 4242424242424242
Month : any future month
Year : any future Year
CVV : 111
Password : 1221


In this tutorial, We have successfully integrated the instamojo payment gateway in the laravel 6 Application. Our examples run quickly.

You may like

  1. Laravel Stripe Payment Gateway Integration Example Tutorial
  2. Laravel 6 Paytm Payment Gateway Integration E.g. Tutorial
  3. Laravel 6 Razorpay Payment Gateway Integration Tutorial E.g.
  4. Angular 8 – Stripe Payment Gateway Example

Our example looks like this :

If you have any questions or thoughts to share, use the comment form below to reach us.


My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *