Skip to main content
https://www.studytutorial.in/payubiz-android-payubiz-payment-gateway-integration-tutorial



This tutorial explains, how to integrate PayUBiz payment gateway with in your Android Application.

Introduction

PayUBiz is a B2B payment gateway provider that used to collect online payment. PayUBiz provides Web API and Mobile SDK to integrate Website and Android App to collect online payment.

Types Of PayUBiz

We will integrate two types of PayUBiz:
  • Non-Seamless Integration(Using PayU SDK’s UI)

  • In this type, we are using PayU SDK’s UI and flows during the transaction. On the SDK payment option, customer will need to select the payment option and fill the respective card details. After this, SDK will launch the desired bank webpage (on the native webview) for further authentication.
  • Seamless Integration(Using Custom UI)

  • In this type, we will design our custom UI to collect customer details and pass it to the PayU SDK by calling appropriate APIs which then launches the selected bank webpage.
This tutorial explains about Non-Seamless Integration.

Create an Account

To integrate PayUBiz, you need to create an account on PayUBiz. It provides Merchant Key and Salt that will be use in Android App.

Create a New Project

Create a new Project in android Studio goto File ⇒ New ⇒ New Projects.


Add SDKUI (Payu sdk) as a module in your project

We need to add sdkui as module in your project. Download PayUBiz SDK and follow below step to add as a module.
Right click on the app go toNew ⇒ Module and select Import Gradle Project then click on the next button then browse to your sdkui directory then click on finish button.
Add Android Module
Add Module
Add Module SDKUI

Compile SDKUI in Project

We need to compile SDKUI module, so add below code in the dependency of build.gradle(app module) file.
1
compile project(':sdkui')

Configure PayU Environment

Add merchant key and salt as constant. We need to set Instance of PayU and set Environment of PayUBiz to make successful Payment.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class MainActivity extends AppCompatActivity {
    private String merchantKey = "Your Merchant KEY", salt = "UzUTFOHh", userCredentials;
    // These will hold all the payment parameters
    private PaymentParams mPaymentParams;
    // This sets the configuration
    private PayuConfig payuConfig;
    // Used when generating hash from SDK
    private PayUChecksum checksum;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        Button onlinePayment = (Button) findViewById(R.id.onlinePayment);
 
        Payu.setInstance(this);
 
        int environment = PayuConstants.PRODUCTION_ENV;
        payuConfig = new PayuConfig();
        payuConfig.setEnvironment(environment);
 
        mPaymentParams = new PaymentParams();
 
        onlinePayment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 
                setParameter();
                generateHashFromSDK(mPaymentParams, salt);
            }
        });
    }
}

Add data to PaymentParams object

We need to add data to PaymentParams.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public void setParameter() {
        mPaymentParams.setKey(merchantKey);
        mPaymentParams.setAmount("100");
        mPaymentParams.setProductInfo("product_info");
 
        mPaymentParams.setFirstName("Cutomer Name");
 
        mPaymentParams.setEmail("test@gmail.com");
        mPaymentParams.setPhone("8448217808");
        mPaymentParams.setAddress1("Customer Address");
        mPaymentParams.setZipCode("Customer ZipCode");
        //Set Your transaction ID. example- "USER ID "+System.currentTimeMillis()
        mPaymentParams.setTxnId(System.currentTimeMillis()+"");
 
        /**
         * Surl --> Success url is where the transaction response is posted by PayU on successful transaction
         * Furl --> Failre url is where the transaction response is posted by PayU on failed transaction
         */
        mPaymentParams.setSurl("https://payu.herokuapp.com/success");
        mPaymentParams.setFurl("https://payu.herokuapp.com/failure");
        mPaymentParams.setNotifyURL(mPaymentParams.getSurl());  //for lazy pay
 
        mPaymentParams.setUdf1("udf1");
        mPaymentParams.setUdf2("udf2");
        mPaymentParams.setUdf3("udf3");
        mPaymentParams.setUdf4("udf4");
        mPaymentParams.setUdf5("udf5");
 
        /**
         * These are used for store card feature. If you are not using it then user_credentials = "default"
         * user_credentials takes of the form like user_credentials = "merchant_key : user_id"
         * here merchant_key = your merchant key,
         * user_id = unique id related to user like, email, phone number, etc.
         * */
        userCredentials = merchantKey + ":" + "Your CUSTOMER UNIQUE ID";
        mPaymentParams.setUserCredentials(userCredentials);
        //mPaymentParams.setUserCredentials(PayuConstants.DEFAULT);
    }
  • IF you do not have any data to set field like Product description, Product Discount, UDF1 – UDF5(User Define Fields) fields then put empty string “”.

Generate Hash Key

For successful transaction, it is compulsory to set Hash Key. You can generate has key From Mobile SDK or send above data to Your Web Service to generate Hash Key. Using below code, you can Generate Hash Key from App.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
public void generateHashFromSDK(PaymentParams mPaymentParams, String salt) {
        PayuHashes payuHashes = new PayuHashes();
        PostData postData = new PostData();
 
        // payment Hash;
        checksum = null;
        checksum = new PayUChecksum();
        checksum.setAmount(mPaymentParams.getAmount());
        checksum.setKey(mPaymentParams.getKey());
        checksum.setTxnid(mPaymentParams.getTxnId());
        checksum.setEmail(mPaymentParams.getEmail());
        checksum.setSalt(salt);
        checksum.setProductinfo(mPaymentParams.getProductInfo());
        checksum.setFirstname(mPaymentParams.getFirstName());
        checksum.setUdf1(mPaymentParams.getUdf1());
        checksum.setUdf2(mPaymentParams.getUdf2());
        checksum.setUdf3(mPaymentParams.getUdf3());
        checksum.setUdf4(mPaymentParams.getUdf4());
        checksum.setUdf5(mPaymentParams.getUdf5());
 
        postData = checksum.getHash();
        if (postData.getCode() == PayuErrors.NO_ERROR) {
            payuHashes.setPaymentHash(postData.getResult());
        }
 
        // checksum for payemnt related details
        // var1 should be either user credentials or default
        String var1 = mPaymentParams.getUserCredentials() == null ? PayuConstants.DEFAULT : mPaymentParams.getUserCredentials();
        String key = mPaymentParams.getKey();
 
        if ((postData = calculateHash(key, PayuConstants.PAYMENT_RELATED_DETAILS_FOR_MOBILE_SDK, var1, salt)) != null && postData.getCode() == PayuErrors.NO_ERROR) // Assign post data first then check for success
            payuHashes.setPaymentRelatedDetailsForMobileSdkHash(postData.getResult());
        //vas
        if ((postData = calculateHash(key, PayuConstants.VAS_FOR_MOBILE_SDK, PayuConstants.DEFAULT, salt)) != null && postData.getCode() == PayuErrors.NO_ERROR)
            payuHashes.setVasForMobileSdkHash(postData.getResult());
 
        // getIbibocodes
        if ((postData = calculateHash(key, PayuConstants.GET_MERCHANT_IBIBO_CODES, PayuConstants.DEFAULT, salt)) != null && postData.getCode() == PayuErrors.NO_ERROR)
            payuHashes.setMerchantIbiboCodesHash(postData.getResult());
 
        if (!var1.contentEquals(PayuConstants.DEFAULT)) {
            // get user card
            if ((postData = calculateHash(key, PayuConstants.GET_USER_CARDS, var1, salt)) != null && postData.getCode() == PayuErrors.NO_ERROR) // todo rename storedc ard
                payuHashes.setStoredCardsHash(postData.getResult());
            // save user card
            if ((postData = calculateHash(key, PayuConstants.SAVE_USER_CARD, var1, salt)) != null && postData.getCode() == PayuErrors.NO_ERROR)
                payuHashes.setSaveCardHash(postData.getResult());
            // delete user card
            if ((postData = calculateHash(key, PayuConstants.DELETE_USER_CARD, var1, salt)) != null && postData.getCode() == PayuErrors.NO_ERROR)
                payuHashes.setDeleteCardHash(postData.getResult());
            // edit user card
            if ((postData = calculateHash(key, PayuConstants.EDIT_USER_CARD, var1, salt)) != null && postData.getCode() == PayuErrors.NO_ERROR)
                payuHashes.setEditCardHash(postData.getResult());
        }
 
        if (mPaymentParams.getOfferKey() != null) {
            postData = calculateHash(key, PayuConstants.OFFER_KEY, mPaymentParams.getOfferKey(), salt);
            if (postData.getCode() == PayuErrors.NO_ERROR) {
                payuHashes.setCheckOfferStatusHash(postData.getResult());
            }
        }
 
        if (mPaymentParams.getOfferKey() != null && (postData = calculateHash(key, PayuConstants.CHECK_OFFER_STATUS, mPaymentParams.getOfferKey(), salt)) != null && postData.getCode() == PayuErrors.NO_ERROR) {
            payuHashes.setCheckOfferStatusHash(postData.getResult());
        }
 
        // we have generated all the hases now lest launch sdk's ui
        launchSdkUI(payuHashes);
    }
 
    private PostData calculateHash(String key, String command, String var1, String salt) {
        checksum = null;
        checksum = new PayUChecksum();
        checksum.setKey(key);
        checksum.setCommand(command);
        checksum.setVar1(var1);
        checksum.setSalt(salt);
        return checksum.getHash();
    }

Launch PayU UI

Now we just need to pass above data to PayUBaseActivity using intent.
1
2
3
4
5
6
7
8
9
10
public void launchSdkUI(PayuHashes payuHashes) {
 
        mPaymentParams.setHash(payuHashes.getPaymentHash());
        Intent intent = new Intent(this, PayUBaseActivity.class);
        intent.putExtra(PayuConstants.PAYU_CONFIG, payuConfig);
        intent.putExtra(PayuConstants.PAYMENT_PARAMS, mPaymentParams);
        intent.putExtra(PayuConstants.PAYU_HASHES, payuHashes);
        startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE);
 
}

Payment Gateway

This will open Payu payment UI. After you have completed the above steps, you should be successfully redirected to the payment gateway page.
PayUbizSDKUI
PayUNetBanking

Comments

Popular posts from this blog

web2apk

http://web2apk.com/create.aspx Create App   Intro   About   Changes   MalWare ?   Contact   Privacy Useful Links Bluetooth Mini Keyboards Android Mini PC Reset Android URL App Title Icon or

Android Bar Chart Using MpAndroidChart Library Tutorial

https://www.numetriclabz.com/android-bar-chart-using-mpandroidchart-library-tutorial/ Android Bar Chart Using MpAndroidChart Library Tutorial Objective In this tutorial we learn how to implement Bar Chart using MpAndroidChart Library in your Android App. Download Source Code       Step 1 Contents ·        1  Introduction ·        2  Creating Bar chart o    2.1  Create a new Project o    2.2  Adding library in Project o    2.3  Create Layout o    2.4  To Plot Bar Chart §   2.4.1  Initialize the graph id §   2.4.2  Creating a Dataset §   2.4.3  Defining X-axis labels §   2.4.4  Set the data §   2.4.5  Add the description to the chart §   2.4.6  Run your App § ...

how to retrieve image from sqlite database in android and display in listview

 Android platform provides several ways to store data in our application. 1. SQLite database 2. SharedPreferences etc For our post, we will only work with SQLite database. First and foremost, we need to understand what an SQLite database is? SQLite database  is an open source SQL database that stores data to a text file on a device. It executes SQL Commands to perform a set of functions, that is, create, read, update and delete operations. On my previous post, I showed how to  store data in SQLite database from edit text, retrieve and populate it in a listview . For this post, I will show the SQLite CRUD operations with images from gallery and text from EditText. We need to understand this; images are stored in SQLite database as BLOB data type. A BLOB is a large binary object that can hold a variable amount of data.  Note, we can only store images in the database as BLOB data type. We need to convert our image path to a bitmap th...