In 2025, digital payments are growing rapidly, and the integration of a robust payment gateway including Instamojo is a must for every PHP-based web application or online store.
Instamojo is one of the best payment gateways in India and supports UPI, EMI, wallet, and net banking. In this post, we will discuss an easy and complete Instamojo payment gateway integration in PHP.
Why Choose Instamojo?
Before we get into the technical steps, here’s why Instamojo is a preferred payment gateway for Indian businesses:
- Easy onboarding
- Fast settlement
- UPI, wallets, cards, net banking support
- Simple API for integration
- Developer-friendly documentation

Requirements for Integration
To begin with, make sure you have the following:
- A verified Instamojo account (https://www.instamojo.com)
- PHP 7.x or later
- Composer (for dependency management)
- cURL enabled on your server
Step 1: Install Instamojo PHP SDK via Composer
First, create a new PHP project folder (if you haven’t already) and install the Instamojo SDK:
composer require instamojo/instamojo-php
Step 2: Get Your API Credentials
Log in to your Instamojo dashboard and navigate to the API & Plugins section. There, you’ll find your:
- API Key
- Auth Token
- API Endpoint (use
https://test.instamojo.com/api/1.1/
for testing)
Use these credentials securely in your PHP project.
Step 3: Create a Payment Request (Code Example)
Here is a working PHP example to generate a payment request using Instamojo:
<?php
require’vendor/autoload.php’;
use Instamojo\Instamojo;
$api = new Instamojo(
‘YOUR_API_KEY’,
‘YOUR_AUTH_TOKEN’,
‘https://test.instamojo.com/api/1.1/’// Use live URL in production
);
try {
$response = $api->paymentRequestCreate(array(
“purpose” => “Test Payment”,
“amount” => “500”,
“buyer_name” => “John Doe”,
“phone” => “9999999999”,
“send_email” => true,
“send_sms” => true,
“email” => “john@example.com”,
“redirect_url” => “https://yourdomain.com/payment-success.php”
));
// Redirect to payment page
header(‘Location: ‘ . $response[‘longurl’]);
exit();
} catch (Exception$e) {
print(‘Error: ‘ . $e->getMessage());
}
?>
Step 4: Handle Payment Response
Following the payment, Instamojo will direct the user to the redirect_url URL provided by you. You capture the answer as follows:
<?php
if (isset($_GET[‘payment_status’]) && $_GET[‘payment_status’] == ‘Credit’) {
echo”Payment Successful!”;
// You can verify the payment here using the payment ID
} else {
echo”Payment Failed or Cancelled!”;
}
?>
Final Thoughts:
It’s also easy to set up the Instamojo payment gateway with PHP using Instamojo’s official PHP SDK. Whether you’re building an e-commerce store, a course website, or a service-based site, Instamojo makes it easy to collect payments with basic code.
Read also:-