How to Integrate PayKun Payment Gateway in an Android Application

Why is the payment gateway integration in Android important?

The global pandemic has played a significant role in drifting the economy towards digital payment adoption. Mobile application commerce is in the driver’s seat alongside the digital payments that have been gaining control.

payment gateway integration in Android

India being a mobile-first country has made it kind of mandatory for the eCommerce businesses to also adopt m-commerce (mobile commerce). This is when the business and other institutes would have a sheer need for an ideal payment gateway integration in Android apps. Due to the ready PayKun Android SDKs, PayKun android integration is smooth and the easiest.

PayKun Payment Gateway Integration in Android

The merchants can collect secure and simple online payments from their domestic and international customers through the PayKun android integration to their apps.

They can provide multiple payment modes including debit cards, credit cards, wallets, net banking, QR code, UPI, and even credit card EMI. PayKun provides a smooth and sleek checkout experience to the customers helping in reducing customer dropouts.

You need to get your registered PayKun Merchant Account activated to process the payments in live mode through your android app.

[You may get the demo app from here – Paykun Demo Android App]

1.  Installing PayKun Android SDK in your app

Our SDK is distributed via the Maven Central Repository.

Our latest PayKun SDK can be added directly to your build.gradle file in the dependency section with-

implementation ‘com.paykun.sdk:paykun-checkout-lib:1.1.13’

2.  Implementing SDK into your Android APP

Test Mode Access:

  • Login to the PayKun Dashboard using Sandbox Mode
  • Get your Merchant ID and Access Token from there
  • Pass the below details to SDK –

merchant id, access token, customer name, customer email, customer phone, product name, order no, and amount to SDK.

Note: order number needs to be unique; the duplicate order number will result in the invalid request

  • Create Json object with the following key and values
JSONObject object = new JSONObject();
try {
    object.put("customer_name","Bhavik Makvana");
    object.put("order_no",System.currentTimeMillis()); // order no. should have 10 to 30 character in numeric format
    object.put("amount","10");  // minimum amount should be 10
    object.put("isLive",false); // need to send false if you are in sandbox mode
} catch (JSONException e) {
  • Send Json object to Paykun API
new PaykunApiCall.Builder(MainActivity.this).sendJsonObject(object); 
// Paykun api to initialize your payment and send info.
  • You will get the result in getResults() Method after sending your data to Paykun.
  • In order to get the result, you have to register GlobalBus in your onStart() Method of activity.
protected void onStart() {
    // Register this activity to listen to event.
  • Unregister GlobalBus in your activity’s OnStop() method.
protected void onStop() {
    // Unregister from activity
  • Implementation of getResults() method – get your result of success or failed in the getResults() method.
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void getResults(Events.PaymentMessage message) {
        // do your stuff here
        // message.getTransactionId() will return your failed or succeed transaction id
        /* if you want to get your transaction detail call message.getTransactionDetail()
        *  getTransactionDetail return all the field from server and you can use it here as per your need
        *  For Example you want to get Order id from detail use message.getTransactionDetail().order.orderId */
        if(!TextUtils.isEmpty(message.getTransactionId())) {
            Toast.makeText(MainActivity.this, "Your Transaction is succeed with transaction id : "+message.getTransactionId() , Toast.LENGTH_SHORT).show();
            Log.v(" order id "," getting order id value : "+message.getTransactionDetail().order.orderId);
    else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_FAILED)){
        // do your stuff here
        Toast.makeText(MainActivity.this,"Your Transaction is failed",Toast.LENGTH_SHORT).show();
    else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_SERVER_ISSUE)){
        // do your stuff here
    }else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_ACCESS_TOKEN_MISSING)){
        // do your stuff here
        Toast.makeText(MainActivity.this,"Access Token missing",Toast.LENGTH_SHORT).show();
    else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_MERCHANT_ID_MISSING)){
        // do your stuff here
        Toast.makeText(MainActivity.this,"Merchant Id is missing",Toast.LENGTH_SHORT).show();
    else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_INVALID_REQUEST)){
        Toast.makeText(MainActivity.this,"Invalid Request",Toast.LENGTH_SHORT).show();
    else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_NETWORK_NOT_AVAILABLE)){
        Toast.makeText(MainActivity.this,"Network is not available",Toast.LENGTH_SHORT).show();
  • Proguard rules
-keepattributes *Annotation*
-keepclassmembers class * {
    @org.greenrobot.eventbus.Subscribe <methods>;
-keep enum org.greenrobot.eventbus.ThreadMode { *; }

# Only required if you use AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {

PayKun provides free integration assistance, simply drop an email at or contact your account manager. You can view the video tutorial for PayKun Android Integration here

You May Also Like

About the Author: admin