Cordova / Ionic

This plugin lets you use Payabbhi native SDKs for Android & iOS to enable seamless integration of Payabbhi Checkout with your Cordova / Ionic / PhoneGap applications.

Supported Cordova platforms

  • Android
  • iOS
  • Browser

Add one or more supported platform/s to your project.

Refer to Checkout workflows for Android SDK, iOS SDK and Browser.


Installation

cd your-project-folder

Add Payabbhi cordova plugin to your project.

Ionic

ionic cordova plugin add cordova-plugin-payabbhi --save

Cordova

cordova plugin add cordova-plugin-payabbhi --save

PhoneGap

phonegap plugin add cordova-plugin-payabbhi --save


Usage

Make sure you have signed up for your Payabbhi Account and downloaded the API keys from the Portal.

Step 1 : Declaration

Ionic v3, v4

e.g. src/declaration.d.ts

declare module "*";

declare var PayabbhiCheckout: any;

Step 1.1: Checkout configuration options

Ionic v3.5

let payabbhiOptions = {
  access_id: "<ACCESS_ID>",
  order_id: "<ORDER_ID>", //order_id is a unique identifier of the Order created using Payabbhi Order API
  amount: 100, //100 paisa = Rs 1
  name: "Merchant Name",
  prefill: {
    name: "Bruce Wayne",
    email: "bruce@wayneinc.com",
    contact: "999999999999"
  },
  notes: {
    merchant_order_id: "ordRefNo123456"
  }
};

Step 1.2 : Implement callback functions

Add callback functions to handle Payment outcome/s.

Ionic v3.5

var successCallback = function(response) {
  /**
   * Add your logic here for processing the Payment response on successful payment
   * It is expected that you would pass the Payment response
   * to your Server-side code (eg. Mobile Backend) for further processing
   */
};

var errorCallback = function(error) {
  /**
   * Add your logic here to handle scenarios where the Checkout did not result in a successful Payment
   */
  alert(error.message + "(" + error.code + ")");
};

Step 2: Initiate payment using Payabbhi

You will need to instantiate PayabbhiCheckout and pass the Checkout Configuration options as below.

Ionic v3.5

PayabbhiCheckout.open(payabbhiOptions, successCallback, errorCallback);

Ionic v4

PayabbhiCheckout.open(
  this.payabbhiOptions,
  this.successCallback,
  this.errorCallback
);

It is expected that Server-side code (eg. Mobile Backend) would create an Order using Payabbhi Order API and pass the unique order_id in the Checkout configuration.

TIP: You can generate a unique order_id using curl and then pass it as param during development phase:

curl https://payabbhi.com/api/v1/orders \
  -u access_id:secret_key \
  -d amount=5000 \
  -d merchant_order_id=ordRefNo123456 \
  -d currency=INR

PayabbhiCheckout.open() displays the Checkout form where the customer is able to provide his Card details or choose other payment options like NetBanking, UPI, Wallets etc.


Step 3.1 : successCallback

Once the payment is successfully completed, Payabbhi will return the Signed Payment response via callback to successCallback function

Ionic v3.5

var successCallback = function(response) {
  response.payment_id;
  response.order_id;
  response.payment_signature;
  /**
   * Add your logic here for processing the Payment response on successful payment
   * It is expected that you would pass the Payment response
   * to your Server-side code (eg. Mobile Backend) for further processing
   */
};

Ionic v4

successCallback(response) {
  console.log(response.payment_id);
  console.log(response.order_id);
  console.log(response.payment_signature);
  /**
   * Add your logic here for processing the Payment response on successful payment
   * It is expected that you would pass the Payment response
   * to your Server-side code (eg. Mobile Backend) for further processing
   */
}

Step 3.2 : errorCallback

Checkout may return an error code via a callback to errorCallback function.

Ionic v3.5

var errorCallback = function(error) {
  if (PayabbhiCheckout.PAYMENT_CANCELED == error.code) {
    // Handle scenario when payment is canceled
  }
};

Ionic v4

errorCallback(error) {
  console.log(error.code);
  if (PayabbhiCheckout.PAYMENT_CANCELED == error.code) {
    // Handle scenario when payment is canceled
  }
}

Error Codes

The error codes that may be returned in the errorCallback method are:

Error Code Description
PayabbhiCheckout.INVALID_ARGUMENTS Invalid or missing Checkout Configuration options
PayabbhiCheckout.PAYMENT_CANCELED User cancelled the payment (e.g., by pressing back button or tapping on the back option).
PayabbhiCheckout.NETWORK_ERROR A network-related error occurred (e.g., loss of internet connectivity, connection timeout etc).

NOTE

Payabbhi iOS framework

  • iOS Payabbhi.framework included in the plugin is built using XCode version 9.3
  • You may download suitable version as per iOS SDK Download & Install steps and replace the existing framework in the cordova-plugin-payabbhi directory e.g. /payabbhi-ionic-4-sample-app/plugins/cordova-plugin-payabbhi/src/ios
  • Run the following commands to update the iOS platform with the manually downloaded iOS Payabbhi.framework
ionic cordova platform rm ios
ionic cordova platform add ios

Browser

<meta
  http-equiv="Content-Security-Policy"
  content="default-src 'self' https://*.payabbhi.com https://payabbhi.com data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"
/>

Ionic applications

  • It is not possible for us to support ionic serve at the moment due to the intrinsic design of the ionic framework. Please try ionic run browser instead of ionic serve, as ionic serve may not support cordova plugins for browser at the moment. Reference: driftyco/ionic-cli#354.

Android Platform

Prerequisite: Background reading

Recommendation: In Android, the OS can kill activities in the background to free up resources. Payabbhi plugin launches a new activity in Android, which temporarily pushes the Cordova activity to the background. In order to handle the scenario when the Cordova activity may get destroyed by the OS, add the following code snippet to ensure a receipt of payment response as and when cordova activity is recreated after being destroyed:

// Register an event listener in the `resume` event
document.addEventListener('resume', onResume, false);
var onResume = function(event) {
                  // Pass the event, payment success and error callbacks to PayabbhiCheckout
                  PayabbhiCheckout.onResume(event, successCallback, errorCallback);
              };

Bare Cordova application

For android platform, make sure minSdkVersion is set to 19 in AndroidManifest.xml

e.g. payabbhi-ionic-3-sample-app/platforms/android/app/src/main/AndroidManifest.xml