Ultimate Guide : Integration of Instamojo Payment Gateway Into Your PHP Web Applications

Ajoft is a software development company which develops software’s for small to mid sized business to increase their professionalism, productivity and profitability. Recently our team has added support for instamojo payment gateway in our hotel reservation software. You can download the Instamojo payment gateway patch for Ajoft Hotelare from download section of the members area.

Instamojo is one of the best payment gateway of India helping more than 40,000+ business to accept payments online. Payment gateways are one of the most important ingredient when you develop eCommerce portal. Instamojo provides both live mode as well as test mode to test your payment gateway integration before it goes live. Its always advised to do test integration first and then change it to live mode. This tutorial caters to the needs of PHP developers, however, integration in other programming languages are more or less the same.

Requirements:

For perfectly completing the integration of Instamojo payment gateway you will need below details:

  • API credentials which includes a private key, private auth key & private salt. These details can be obtained from instamojo site after logging in. Please remember that since instamojo has different site for live and test environment, you will have register on both the website to obtain live and test credentials. For live API details, you can register on https://www.instamojo.com/ and for test/sandbox API details you can create your account on https://test.instamojo.com/.
  • One Email on which payment response can be sent. Since Instamojo sends payments notifications to webhook url it is advised to do the integration on live url and not on localhost or 127.0.0.1, so you need to have an online server.
  • Instamojo PHP SDK for integration, can be downloaded from here

Test Credit Card Details For Instamojo

How Instamojo Works?

Instamojo Payment gateway has a very straightforward way of accepting payments and getting paid. Its one of the easiest payment gateway available out there.

Payment on Instamojo is a 3 step process

  • Customer chooses Instamojo for online payment
  • Customer is handed over to instamojo and sees various payment options
  • Customer chooses a payment option and completes payment

After payment, customer is redirected back to your app/website.

How to Integrate Instamojo Payment Gateway in your website?

Integrating Instamojo is a simple 3 step process.

  1. Create a payment request
  2. Show payment form to buyer in your app/site & receive payment.
  3. Redirect to website.

1: Create A payment Request

Instamojo is extremely simple. Once you are registered & approved on Instamojo live website, you can receive payments right away. Instamojo provides you a personalized url which looks something like https://www.instamojo.com/@username/ (username is your instamojo username), you can use this url to send it to your clients and they can fill in the purpose and amount which they want to pay and they can pay right away.

Now, incase your application needs a customized payment url with prefilled amount and purpose you would need to integrate Instamojo API. Instamojo payments work by creating payment request URLs which can accept payments. Creating a request is as simple as passing an amount and a purpose. This step generates a Payment Request ID.Amount and Purpose are mandatory parameters needed to generate payment request ID.

Once a request is created, you can use the request URL to accept a payment in your mobile app, website or application.

Using the Payment Request ID you can display a payment form to your customers. Your customer can choose a payment method of their choice and make a payment. Once a payment is made, you will receive a Payment ID.

Get the final amount from your cart total and call the Create a Request endpoint of instamojo API. The values of fields like amount, buyer_name, email, and phone are straight-forward an they are optional. The values of send_email and send_sms should be false if you don’t want users to get email and sms from instamojo.

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. You can send invoice id, transaction id or any unique id which determines your order. This variable can be manipulated later on success page.

Also it must be remembered that there can be multiple payments ID for a single payment request ID, if customer has made payments multiple times.

How to generate Instamojo Payment Request ID & URL?

Generating payment request url is pretty simple. PHP code example of generating payment request url is given below:

In the code above, you see few parameters are passed when creating a payment request, we explain the Payment Request Creation Parameters below:

Required

  • purpose: Purpose of the payment request. (max-characters: 30)
  • amount: Amount requested (min-value: 9 ; max-value: 200000)

Optional

  • buyer_name: Name of the payer. (max-characters: 100)
  • email: Email of the payer. (max-characters: 75)
  • phone: Phone number of the payer.
  • send_email: Set this to true if you want to send email to the payer if email is specified. If email is not specified then an error is raised. (default value: false)
  • send_sms: Set this to true if you want to send SMS to the payer if phone is specified. If phone is not specified then an error is raised. (default value: false)
  • redirect_url: set this to a thank-you page on your site. Buyers will be redirected here after successful payment.
  • webhook: set this to a URL that can accept POST requests made by Instamojo server after successful payment.
  • allow_repeated_payments: To disallow multiple successful payments on a Payment Request pass false for this field. If this is set to false then the link is not accessible publicly after first successful payment, though you can still access it using API(default value: true).

How to show the payment response on success page?

Once the payment has been been made, instamojo redirects you to the redirect url. Now you have to show the success or failure message to the user so that they can know the current status of their payment and order.

How to manage & utilize webhook url?

Webhook url is one of the best way to receive payment notifications to the website admins or log payment responses from payment gateway.

You can download the entire code for this tutorial using the link below.

Incase you want us to integrate Instamojo payment gateway on your website as per your requirement, you can click this link to buy instamjo payment gateway integration service.

Spread the love
Ashish
Ashish
Ashish is working as CTO at Ajoft Technologies, Involved in conceptualizing and creating new technology oriented software.

Leave a Reply

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