Instamojo Payment Gateway Integration in PHP Laravel

Instamojo Payment Gateway Integration in PHP Laravel

How to Integrate Instamojo Payment Gateway in Laravel . In this tutorial, we will know you how integrate instamojo payment gateway in php laravel application via 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. This is also work with laravel 5.8 & laravel 5.7.

We will integrate instamojo payment gateway in laravel app without using curl apis. Simply install instamojo php package and integrate in our laravel application in minute. Instamojo all process like refund payment, collect payment, create payment are very easy and simple.


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

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 LaravelInstamojo

Install Instamojo php package

Use the below command and install instamojo php package :

composer require instamojo/instamojo-php

Configuration in .env

In this step, we will set instamojo credential in .env file. Let’s open .env file and put the crendential. 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'),

Create Contoller

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');

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');

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>

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.

Or direct hit in your browser

If you want to remove public or public/index.php from URL In laravel, Click Me

Testing Card Credential

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


In this tutorial, We have successfully integrate instamojo payment gateway in laravel 5.7 Application. Our examples run quickly.

You may like

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

Our example look like this :

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


Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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