API Reference
Log In

Integration steps:

  • Create a Payment request
  • Redirect payer to request link
  • Handle successful/failed payments
  • Webhook
  • Redirect
  • Query status of a Payment requests
  • Additional features
  • Refunds
  • Light Checkout

Create a Payment Request:

Get the final amount from your cart total and call the Create a Request endpoint of our API. The values of fields like amount, buyer_name, email, and phone are straight-forward. The values of send_email and send_sms should be false.

The purpose field can be used to pass the custom data (unique identifier) created on your end. This is going to be useful later on to identify the order using this custom data (unique identifier) for which a particular payment was made.

Redirect payer to request link:

The Payment link creation will return a longurl, this URL can be used to get the payment from the user. You need to redirect the buyer to this Payment link programmatically by using redirection statements in your respective programming language.

Post payment processing:

1. Redirection:

Once the payment is done user will be redirected to the redirect_url specified during the link creation and we will append three more query arguments with it: payment_id, payment_request_id and payment_status.

Example:

If your redirect_url was http://www.example.com then the user will be redirected to something like: http://www.example.com?payment_id=MOJO5a06005J21512197&payment_status=Credit&payment_request_id=d66cb29dd059482e8072999f995c4eef

Now using the payment_request_id and payment_id you can query our Get Payment Details endpoint to get the details related to the Request and Payment.

2. Webhook:

Webhook is the URL to which we send the payment details as a POST request. Note that the content type of this request is application/x-www-form-urlencoded.

Following fields are sent with the webhook request:

FieldDescriptionExample value
amountAmount related to the payment2500.00
buyerBuyer's email[email protected]
buyer_nameBuyer's nameJohn Doe
buyer_phoneBuyer's phone number9999999999
currencyCurrency related to the paymentINR
feesFees charged by Instamojo125.00
longurlURL related to the payment requesthttps://www.instamojo.com/@ashwch/d66cb29dd059482e8072999f995c4eef
macMessage Authentication code of this webhook request1ddf3b78f84d071324c0bf1d3f095898267d60ee
payment_idID of the paymentMOJO5a06005J21512197
payment_request_idID of the payment requestd66cb29dd059482e8072999f995c4eef
purposePurpose of the Payment requestFIFA 16
shorturlShort URL of the payment requesthttps://imjo.in/NNxHg
statusStatus of the Payment. This can be either "Credit" or "Failed".Credit

For more information on how to validate the webhook request using mac read: What is the Message Authentication Code in Webhook?

<?php

/*
Basic PHP script to handle Instamojo RAP webhook.
*/

$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 <>
$mac_calculated = hash_hmac("sha1", implode("|", $data), "<YOUR_SALT>");
if($mac_provided == $mac_calculated){
    if($data['status'] == "Credit"){
        // Payment was successful, mark it as successful in your database.
        // You can acess payment_request_id, purpose etc here. 
    }
    else{
        // Payment was unsuccessful, mark it as failed in your database.
        // You can acess payment_request_id, purpose etc here.
    }
}
else{
    echo "MAC mismatch";
}

?>
import hmac
import hashlib 
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
import urlparse


PORT = 8000
 
class MojoHandler(BaseHTTPRequestHandler):

  def do_POST(self):

      content_length = int(self.headers['content-length'])
      querystring = self.rfile.read(content_length)
      data = urlparse.parse_qs(querystring)
      mac_provided = data.pop('mac')
      message = "|".join(v for k, v in sorted(data.items(), key=lambda x: x[0].lower()))
      # Pass the 'salt' without the <>.
      mac_calculated = hmac.new("<YOUR_SALT>", message, hashlib.sha1).hexdigest()
      if mac_provided == mac_calculated:
          if data['status'] == "Credit":
              # Payment was successful, mark it as completed in your database.
          else:
              # Payment was unsuccessful, mark it as failed in your database.
          self.send_response(200)
      else:
          self.send_response(400)
      self.send_header('Content-type', 'text/html')
      self.end_headers()

httpd = HTTPServer(('', PORT), MojoHandler)
httpd.serve_forever()

We recommend passing both webhook and redirect_url URLs while creating the Payment link because users sometimes close the tab before redirection can happen and in that case webhook request comes in handy and will save you from manual updation of database.

ADDITIONAL FEATURES:

1. Light Checkout:

With Light Checkout, the payment form loads faster and takes the payer directly to the final payment page. The payer is taken to the final payment page only if buyer_name, email and phone were supplied during request creation, else the payer will have to fill these details in before paying.

To use light checkout, simply append ?embed=form at the end of your request URL.

Standard request URL: https://www.instamojo.com/@ashwch/d66cb29dd059482e8072999f995c4eef
Light checkout URL: https://www.instamojo.com/@ashwch/d66cb29dd059482e8072999f995c4eef?embed=form

2. Floating Checkout:

Allow customers to pay without leaving your website.

Create an embeddable checkout with just a few lines of code.
Just replace REQUEST_URL with your Request URL in the snippet below and you're good to go.

<a href="REQUEST_URL" rel="im-checkout" data-behaviour="remote" data-style="light" data-text="Checkout With Instamojo"></a>
<script src="https://d2xwmjc4uy2hr5.cloudfront.net/im-embed/im-embed.min.js"></script>

The above code stylizes the button with the default light green for light backgrounds with (data-style="light")

All styling options

  • For light backgrounds (Green button): data-style="light"
  • For dark backgrounds (Yellow button) : data-style="dark"
  • Flat button for light backgrounds : data-style="flat"
  • Flat button for dark backgrounds : data-style="flat-dark"
  • No styling : data-style="no-style"