Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

UPI Payment Integration in Android

  • Difficulty Level : Medium
  • Last Updated : 14 Dec, 2021

If you are selling any product or providing any service in your android application, then you should have integrated a feature in your android application where you can allow users to make payment through your application. In this article, we will take a look at the implementation of payment gateway integration in Android. In this article, we will be using the Easy UPI Payment gateway library for adding this feature. 

What we are going to build in this article? 

We will be creating a simple application in which we will display multiple edit text fields in which we will be allowing users to enter the details for making a payment. After clicking on make payment button we will display a dialog box to our users for making payment through different apps which are installed in users device. Below is the video in which we will get to see what we are going to build in this article. 

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Adding a dependency for easy payment gateway in android 

Navigate to the app > Gradle Scripts > build.gradle(:app) and add the below dependency in the dependencies section. 

implementation ‘com.shreyaspatil:EasyUpiPayment:2.0’

After adding this dependency now sync your project and now we will move towards adding internet permissions. 

Step 3: Adding internet permissions in AndroidManifest.xml. 

Navigate to app > AndroidManifest.xml and add the below code to it. 


<uses-permission android:name="android.permission.INTERNET" />

Step 4: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
    <!--edit text for entering amount to be paid-->
        android:hint="Enter Amount to be paid"
        android:inputType="numberDecimal" />
    <!--edit text for entering the upi id
        to which we have to make payment-->
        android:hint="Enter your UPI Id"
        android:inputType="text" />
    <!--edit text for adding the name of the
        user whom we have to make payment-->
        android:hint="Enter your Name"
        android:inputType="text" />
    <!--edit text for adding the description for
        the payment which we are making-->
        android:hint="Enter Payment Description"
        android:inputType="text" />
    <!--button for making a payment-->
        android:text="Make Payment"
        android:textAllCaps="false" />
    <!--text view for displaying transaction status-->
        android:text="Transaction Details"
        android:visibility="gone" />

Step 5: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.shreyaspatil.EasyUpiPayment.EasyUpiPayment;
import com.shreyaspatil.EasyUpiPayment.listener.PaymentStatusListener;
import com.shreyaspatil.EasyUpiPayment.model.TransactionDetails;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class MainActivity extends AppCompatActivity implements PaymentStatusListener {
    // initializing variables for our edit text and button.
    private EditText amountEdt, upiEdt, nameEdt, descEdt;
    private TextView transactionDetailsTV;
    protected void onCreate(Bundle savedInstanceState) {
        // initializing all our variables.
        amountEdt = findViewById(;
        upiEdt = findViewById(;
        nameEdt = findViewById(;
        descEdt = findViewById(;
        Button makePaymentBtn = findViewById(;
        transactionDetailsTV = findViewById(;
        // on below line we are getting date and then we are setting this date as transaction id.
        Date c = Calendar.getInstance().getTime();
        SimpleDateFormat df = new SimpleDateFormat("ddMMyyyyHHmmss", Locale.getDefault());
        String transcId = df.format(c);
        // on below line we are adding click listener for our payment button.
        makePaymentBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // on below line we are getting data from our edit text.
                String amount = amountEdt.getText().toString();
                String upi = upiEdt.getText().toString();
                String name = nameEdt.getText().toString();
                String desc = descEdt.getText().toString();
                // on below line we are validating our text field.
                if (TextUtils.isEmpty(amount) && TextUtils.isEmpty(upi) && TextUtils.isEmpty(name) && TextUtils.isEmpty(desc)) {
                    Toast.makeText(MainActivity.this, "Please enter all the details..", Toast.LENGTH_SHORT).show();
                } else {
                    // if the edit text is not empty then
                    // we are calling method to make payment.
                    makePayment(amount, upi, name, desc, transcId);
    private void makePayment(String amount, String upi, String name, String desc, String transactionId) {
        // on below line we are calling an easy payment method and passing 
        // all parameters to it such as upi id,name, description and others.
        final EasyUpiPayment easyUpiPayment = new EasyUpiPayment.Builder()
                // on below line we are adding upi id.
                // on below line we are setting name to which we are making oayment.
                // on below line we are passing transaction id.
                // on below line we are passing transaction ref id.
                // on below line we are adding description to payment.
                // on below line we are passing amount which is being paid.
                // on below line we are calling a build method to build this ui.
        // on below line we are calling a start 
        // payment method to start a payment.
        // on below line we are calling a set payment
        // status listener method to call other payment methods.
    public void onTransactionCompleted(TransactionDetails transactionDetails) {
        // on below line we are getting details about transaction when completed.
        String transcDetails = transactionDetails.getStatus().toString() + "\n" + "Transaction ID : " + transactionDetails.getTransactionId();
        // on below line we are setting details to our text view.
    public void onTransactionSuccess() {
        // this method is called when transaction is successful and we are displaying a toast message.
        Toast.makeText(this, "Transaction successfully completed..", Toast.LENGTH_SHORT).show();
    public void onTransactionSubmitted() {
        // this method is called when transaction is done 
        // but it may be successful or failure.
        Log.e("TAG", "TRANSACTION SUBMIT");
    public void onTransactionFailed() {
        // this method is called when transaction is failure.
        Toast.makeText(this, "Failed to complete transaction", Toast.LENGTH_SHORT).show();
    public void onTransactionCancelled() {
        // this method is called when transaction is cancelled.
        Toast.makeText(this, "Transaction cancelled..", Toast.LENGTH_SHORT).show();
    public void onAppNotFound() {
        // this method is called when the users device is not having any app installed for making payment.
        Toast.makeText(this, "No app found for making transaction..", Toast.LENGTH_SHORT).show();

Now run your app and see the output of the app. 

Note: Make sure to run your app on a real device and you should be having an app for making payments. And put the amount in decimal.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!