Instamojo Gateway in PHP


Instamojo is one of the best and user friendly online payment gateway. It comes with all modern payment option like debit card, credit card, net banking, UPI, EMI option etc.

It is very easy to integrate in your website, App. Also you send Payment link for a perticular amount through Instamojo payment button.

Apply Insatmojo by click on this link.
Copy the below files and upload in a folder.
Put your authenication key, private key and working key in the files where it required.
Run the index.php file now.
 

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
		<meta name="description" content="">
		<meta name="author" content="">
		<link rel="icon" href="../../favicon.ico">
		<title>Payment Mojo</title>
		<!-- Latest compiled and minified CSS -->
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
		<!-- Optional theme -->
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >
		<!-- Latest compiled and minified JavaScript -->
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
	</head>
	<body>
    <div class="container">
	<div class="page-header">
        <h1><a href="index.php">Instamojo Payment</a></h1>
		<form action="pay.php" method="POST" accept-charset="utf-8">
			<input type="hidden" name="product_name" value="<?php echo $prd_name; ?>"> 
			<input type="hidden" name="product_price" value="<?php echo $prd_price; ?>"> 
			<div class="form-group">
			<label>Your Name</label>
			<input type="text" class="form-control" name="name" placeholder="Enter your name">	 
			</div>
			<div class="form-group">
			<label>Your Phone</label>
			<input type="text" class="form-control" name="phone" placeholder="Enter your phone number"> 
			</div>
			<div class="form-group">
			<label>Your Email</label>
			<input type="email" class="form-control" name="email" placeholder="Enter you email"> 
			</div>
			<div class="form-group">
			<label>Amount</label>
			<input type="email" class="form-control" name="amount" Value="100" readonly>
			</div>
			<p><input type="submit" class="btn btn-success btn-lg" value="Click here to Pay"></p>
		</form>
 
    
    </div> <!-- /container -->
		</div>


  </body>
</html>

 

<?php 
$purpose = "Payment";
$amount = $_POST["amount"];
$name = $_POST["name"];
$phone = $_POST["phone"];
$email = $_POST["email"];
include 'src/instamojo.php';
$api = new InstamojoInstamojo('29b34070bf5867b7d36bf2586c4f4855', '40d161c14f252cc781066e0c685f5f4d','https://www.instamojo.com/api/1.1/');
try {
    $response = $api->paymentRequestCreate(array(
        "purpose" => $purpose,
        "amount" => $amount,
        "buyer_name" => $name,
        "phone" => $phone,
		"email" => $email,
        "send_email" => true,
        "send_sms" => true,
        'allow_repeated_payments' => false,
        "redirect_url" => "https://studentstutorial.com/instamojo/thankyou.php",
        "webhook" => "https://studentstutorial.com/instamojo/webhook.php"
        ));
   $pay_ulr = $response['longurl'];
    header("Location: $pay_ulr");
    exit();
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}     
 ?>
 
<?php
$data = $_POST;
$mac_provided = $data['mac'];  /* Get the MAC from the POST data*/
unset($data['mac']);  /* Remove the MAC key from the data. */
$ver = explode('.', phpversion());
$major = (int) $ver[0];
$minor = (int) $ver[1];
if($major >= 5 and $minor >= 4){
     ksort($data, SORT_STRING | SORT_FLAG_CASE);
}
else{
     uksort($data, 'strcasecmp');
}
/* You can get the 'salt' from Instamojo's developers page(make sure to log in first): https://www.instamojo.com/developers*/
/* Pass the 'salt' without the <>.*/
$mac_calculated = hash_hmac("sha1", implode("|", $data), "723a3b8f18014441b3a7aead136b6544");

if($mac_provided == $mac_calculated){
   
    if($data['status'] == "Credit"){
       /* Payment was successful, mark it as completed in your database  */
                
                $to = 'YOUR_EMAIL_ADDRESS';
                $subject = 'Website Payment Request ' .$data['buyer_name'].'';
                $message = "<h1>Payment Details</h1>";
                $message .= "<hr>";
                $message .= '<p><b>ID:</b> '.$data['payment_id'].'</p>';
                $message .= '<p><b>Amount:</b> '.$data['amount'].'</p>';
                $message .= "<hr>";
                $message .= '<p><b>Name:</b> '.$data['buyer_name'].'</p>';
                $message .= '<p><b>Email:</b> '.$data['email'].'</p>';
                $message .= '<p><b>Phone:</b> '.$data['phone'].'</p>';
                $message .= "<hr>";
				$headers .= "MIME-Version: 1.0
";
                $headers .= "Content-Type: text/html; charset=ISO-8859-1
";
                /* send email*/
                mail($to, $subject, $message, $headers);
		}
    else{
       /* Payment was unsuccessful, mark it as failed in your database*/
    }
}
else{
    echo "Invalid MAC passed";
}
?>

 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">
	<title>Thank You, Mojo</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" 
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  </head>
	<body>
    <div class="container">
	<div class="page-header">
        <h1><a href="index.php">Instamojo Payment</a></h1>
        <p class="lead">A test payment integration for instamojo paypemnt gateway. Written in PHP</p>
    </div>
	<h3 style="color:#6da552">Thank You, Payment succus!!</h3>
<?php
include 'src/instamojo.php';
$api = new InstamojoInstamojo('YOU_PRIVATE_API_KEY', 'YOUR_PRIVATE_AUTH_TOKEN','https://test.instamojo.com/api/1.1/');
$payid = $_GET["payment_request_id"];
try {
    $response = $api->paymentRequestStatus($payid);
	echo "<h4>Payment ID: " . $response['payments'][0]['payment_id'] . "</h4>" ;
    echo "<h4>Payment Name: " . $response['payments'][0]['buyer_name'] . "</h4>" ;
    echo "<h4>Payment Email: " . $response['payments'][0]['email'] . "</h4>" ;
echo "<pre>";
   print_r($response);
echo "</pre>";
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}
?>
</div> <!-- /container -->
</body>
</html>

Required Knowledge Points 20


Share the post

Leave Comment

All Projects

Title Logo Download Times Cost in Knowledge Points
Send Beautiful Emails in PHP  Send Beautiful Emails in PHP  26 5
Export Data from Database to Excel Sheet Export Data from Database to Excel Sheet 13 1
Forget Password Panel in Login Registration Forget Password Panel in Login Registration 20 10
Login Registration in PHP Mysql Login Registration in PHP Mysql 22 5
Faculty Feedback system in PHP Mysql Faculty Feedback system in PHP Mysql 17 20
Farm Management System Farm Management System 24 20
Result Processing System in Php mysql Result Processing System in Php mysql 36 20
Sending Activation Link to Email in Php mysql Sending Activation Link to Email in Php mysql 26 20
E Commerce Software in PHP Mysql E Commerce Software in PHP Mysql 47 20
Examination Management System Examination Management System 27 20
Online Certificate Generation Online Certificate Generation 41 20
Matrimonial Management System Matrimonial Management System 14 20
Blogging Portal in PHP Mysql Blogging Portal in PHP Mysql 69 20
Course Registration Course Registration 23 20
Bill Generation Bill Generation 34 20
Employee Leave Management System in PHP Mysql Employee Leave Management System in PHP Mysql 57 20
Callender Management System Callender Management System 15 1
Hostel Management System in PHP Mysql Hostel Management System in PHP Mysql 38 20
Blood Donation in PHP MySql Blood Donation in PHP MySql 28 20
Library Management System Library Management System 28 20
Complain Management System in PHP Mysql Complain Management System in PHP Mysql 21 20
Online Ticket Booking System in PHP Mysql Online Ticket Booking System in PHP Mysql 46 20
Self Captcha in PHP Mysql Self Captcha in PHP Mysql 17 20
Hospital Management System in PHP MYSQL Hospital Management System  in PHP MYSQL 64 20
JOB PORTAL in PHP Mysql JOB PORTAL in PHP Mysql 44 20
Time Table Mgment System Time Table Mgment System 25 20
Tourism Management system in PHP MySql Tourism Management system in PHP MySql 37 20
Customer Relationship Management system in PHP MySql Customer Relationship Management system in PHP MySql 39 20
Students Attendance Management System Students Attendance Management System 60 5
Beauty Parlour / Saloon Managemeng System in PHP MySql Beauty Parlour / Saloon Managemeng System in PHP MySql 40 20
Cyber Cafe Management System in php mysql Cyber Cafe Management System in php mysql 67 20
Shopping Cart in PHP MySql Shopping Cart in PHP MySql 91 20
Address Book in PHP Mysql Address Book in PHP Mysql 33 20
Time Table Management System Time Table Management System 44 20
Instamojo Gateway in PHP Instamojo  Gateway in PHP 45 20
Generation of Certificate in pdf Generation of Certificate in pdf 34 20
Sending OTP SMS in Php Mysql Sending OTP SMS in Php Mysql 70 20
POS ( INVENTORY ) in PHP Mysql POS ( INVENTORY ) in PHP Mysql 66 20
Pharmacy Management System in PHP Mysql Pharmacy Management System in PHP Mysql 65 20
Point of Sale in PHP Mysql Point of Sale in PHP Mysql 66 20
Examination System Examination System 66 20
School Management System in PHP Mysql School Management System in PHP Mysql 175 20
Online Voting system in PHP Mysql Online Voting system in PHP Mysql 64 20
Payroll Management System Payroll Management System 118 20