API Reference
Log In
Devsupport AI - Ionic Integration

Devsupport AI - Ionic Integration

At Instamojo, we recently decided to support Ionic integrations.

What all can I expect?

With this SDK, your customers would be able to pay using:

  1. Credit / Debit Cards
  2. EMI
  3. Netbanking
  4. Wallets
  5. UPI

What do I need?

  1. Back end server (We currently support PHP & Python.)
  2. Client Id, and Client Secret from dashboard.
  3. Ionic setup on your machine with Android or iOS emulator

❗️

Important!

You are responsible for your client id and client secret. They are to be embedded in your server script. DO NOT use them in your client side code.

📘

Not Using PHP or Python?

If you are using other languages, take a look at this section: [Other Back end Technologies]

Step 1:

Download Devsupport AI from here. Install the .exe if you are on Windows, mac.zip if you are on Mac and .deb if you are on Linux.

Step 2:

Link your Ionic project and proceed with integration. Type Instamojo when asked which product you'd like to integrate.

Step 3:

Proceed with back end integration first. Choose either PHP or Python, fill your client_id and client_secret, and download the file generated by the tool. Host this file on your server and keep it's URL handy.

If you use other back end technologies, refer Other Back end Technologies

Step 4:

Proceed to Ionic integration and paste the access_token URL when the tool asks. E.g. https://iamironman.com/access_token.php or https://iambatman.com/access_token.py

Step 5:

Run these three commands:

  1. npm install
  2. ionic cordova plugin add cordova-plugin-advanced-http
  3. ionic cordova plugin add cordova-plugin-inappbrowser

Other Back end Technologies

Devsupport AI tool expects an access token generated on your server.

How do I get access token?

var qs = require("querystring");
var http = require("https");

var options = {
  "method": "POST",
  "hostname": "test.instamojo.com",
  "port": null,
  "path": "/oauth2/token/",
  "headers": {
    "content-type": "application/x-www-form-urlencoded",
    "cache-control": "no-cache"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(qs.stringify({ grant_type: 'client_credentials',
  client_id: 'test',
  client_secret: 'test' }));
req.end();
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "grant_type=client_credentials&client_id=test&client_secret=test");
Request request = new Request.Builder()
  .url("https://test.instamojo.com/oauth2/token/")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

  url := "https://test.instamojo.com/oauth2/token/"

	payload := strings.NewReader("grant_type=client_credentials&client_id=test&client_secret=test")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("content-type", "application/x-www-form-urlencoded")
	req.Header.Add("cache-control", "no-cache")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}

Access Token looks like this:


{
  "access_token": "tyDkRjkirDEmF4PP8AHNrS3NnGwrt6",
  "expires_in": 36000,
  "token_type": "Bearer",
  "scope": "read write payouts:read payments:read payments:fulfil payments:refund"
}

Read access_token and prepend your environment to it.

E.g if you are testing on Test environment, access token should look like this: testtyDkRjkirDEmF4PP8AHNrS3NnGwrt6

If you are on Production environment, access token should look like this:
productiontyDkRjkirDEmF4PP8AHNrS3NnGwrt6

Host your script on server, keep it's URL ready and proceed to the bot for Android integration.

When publicly accessed, this url should output the access token. E.g. testtyDkRjkirDEmF4PP8AHNrS3NnGwrt6 or productiontyDkRjkirDEmF4PP8AHNrS3NnGwrt6

Initiate the payment with the method:
payNow()
Remember to change the below data fields per your logic.

data.purpose = "Test";
data.amount = 9;

Handle the response with the code snippet:

this.instamojoClient.payNow(data).then(response => {
      // alert("Payment complete: " + JSON.stringify(response));
    }).catch(err => {
      // alert("Payment failed: " + JSON.stringify(err));
      throw err;
});

RESPONSE FORMAT:
Success Response:

status=success:orderId=a089f02724ed4a8db6c069f6d30b3245:txnId=None:paymentId=MOJO7918005A76494611:token=qyFwLidQ0aBNNWlsmwHx1gHFhlt6A1

Failure Response:
code - Failure Code
Reason - Reason in String

🚧

Important!

Once you receive success callback, process the order. For your records, store token, orderid and payment id on your server.

Need help?

Drop us an email at [email protected] or [email protected] with the exact problem you are facing. We will help you out.