Ola Money Developer Hub

Welcome to the Ola Money developer hub. You'll find comprehensive guides and documentation to help you start working with Ola Money as quickly as possible, as well as support if you get stuck.

Documentation

Integration Guide - Android

This page outlines the customozied integration steps of Ola Money wallet with Android

For those who want a more customised approach

Step 1 : Generate a Bill on your server

Refer to KB article

Refer to KB article Bill Generator

Step 2 : Incorporate a button for Ola Money

Inside your checkout flow, add a button - ‘Pay using Ola Money’, which will initiate the payment flow below once a user clicks on it.

Step 3 : Initiate the payment flow

Intestate the payment flow using the below code snippets. In case OlaCabs app is to installed on the users device, a web view flow will be invoked.

WebView webView;

/*
	bill - JSON bill generated by merchant server
  phoneNumber - Users phone number. Can be null
*/
public void invokeOlaMoney(String bill, String phoneNumber) {
	try {
		Intent intent = new Intent("com.olacabs.olamoney.pay");
		intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
		intent.putExtra("bill", bill);
		intent.setPackage("com.test.olacabs"); //Remember to change this to "com.olacabs.customer" before you go live
		startActivityForResult(intent);
	} catch(ActivityNotFoundException e) {
		/*Activity not found exception - route the flow through webview*/
    invokeOlaMoneyWebViewFlow(bill, phoneNumber)
	}
}

/*
	bill - JSON bill generated by merchant server
  phoneNumber - Users phone number. Can be null
*/
pubic void invokeOlaMoneyWebViewFlow(String bill, String phoneNumber) {
  StringBuffer buffer=new 	StringBuffer("http://sandbox.olamoney.in/olamoney/webview/index.html");
  //Change http://sandbox.olamoney.in to https://om.olacabs.com before you go live
	String base64_bill = Base64.encodeToString(bill.getBytes(), Base64.DEFAULT);
	buffer.append("?bill="+base64_bill);	
	buffer.append("&phone="+URLEncoder.encode(phoneNumber==null ? "":phoneNumber));
	webview.getSettings().setJavaScriptEnabled(true);	
	webView.setWebViewClient(new WebViewClient());
	webView.loadUrl(buffer.toString());
}

The UX/UI for web-view activity is entirely in your control. You can design those activities to reflect your logo/branding guidelines

Now, you can customize the payment experience by sending your logo through the intent. You can do this with the following code:

intent.putExtra("logo",getResources().getResourceEntryName(R.drawable.your_logo));
intent.putExtra("brand",getResources().getResourceEntryName(R.drawable.your_brand_name));

This feature is optional - please follow the guidelines below for the logo you send. We will show a default Ola Money logo here in case you don't send us your logo details through the intent.

Step 4 : Be ready to handle the response from our side

In either flow above, we handle the payment processing on your behalf in a secure manner, and return the transaction result to you.

In case of the native flow (step 4a above), you need to implement an onActivityResult method inside your checkout Activity to handle the transaction results. Here is the code snippet, wherein you need to implement the functions like show_success(), show_failed(), etc.:

protected void onActivityResult (int requestCode, int resultCode, Intent data) {
	switch (resultCode) 
		case 100:
			show_success();
  	case 104:
    	show_failed();
  	default:
    	show_default();
}

In case of the web-view flow (step 4b above), you need to implement the following steps to handle the transaction result.

Step 1: Declare a javascript interface for your web-view:

interface OlaMoneyInteface {
@android.webkit.JavascriptInterface
void onPaymentDone(String jsonResponse);
}

Step 2: Add this javascript interface to the webview:

webView.addJavascriptInterface(new OlaMoneyInteface() {
@Override
@android.webkit.JavascriptInterface
public void onPaymentDone(String jsonResponse) {
/*Control is returned to the native code
  You can get the data in jsonResponse
*/
}
}, "OlaMoney");

Step 3: Modify proguard configuration (Optional)

If you are using proguard, then you need to add the following line to your proguard configuration file:

-keepclassmembers class * {
 @android.webkit.JavascriptInterface <methods>;
}

Step 4: Handle return_url

We will send data to the return_url specified in your bill, and you should invoke the function send_user_native in your javascript once you get the data received from Ola Money, as below:

<script type="text/javascript">
    function send_user_native(data) {
        OlaMoney.onPaymentDone(data); 
    }
</script>

At this point notify_url will be called from our server to your server, with the relevant data as below

Thats all folks!

Integration Guide - Android

This page outlines the customozied integration steps of Ola Money wallet with Android