Android9/28/2020

How to Integrate UPI Payment Gateway in Android Using EasyUpiPayment Library

UPI (Unified Payments Interface) is one of the most widely used digital payment systems in India.

Many Android applications now support UPI payments for:

  • E-commerce payments
  • Subscription services
  • Donation systems
  • Recharge applications
  • Local business payments

In this tutorial, we will learn how to integrate UPI payments in Android using the EasyUpiPayment library.


What Is EasyUpiPayment?

EasyUpiPayment is an Android library that simplifies UPI payment integration.

It helps developers:

  • Launch UPI payment apps
  • Handle payment responses
  • Track transaction status
  • Reduce boilerplate code

Features of UPI Integration

  • Works with multiple UPI apps
  • Supports Google Pay, PhonePe, Paytm, BHIM
  • Easy transaction handling
  • Simple integration process

Important Requirements

  • Minimum SDK should be 19 or higher
  • Real device recommended for testing
  • At least one UPI app must be installed

Step 1 — Add Dependency

Open your build.gradle file and add:


implementation 'com.shreyaspatil:EasyUpiPayment:3.0.0'

Then sync your Gradle project.


Step 2 — Create Layout File

Create the UI inside activity_main.xml.


<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp">

    <Button
        android:id="@+id/id_pay_using_upi_app"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Pay Using UPI App"
        android:layout_gravity="center"/>

</FrameLayout>

Step 3 — Implement UPI Payment Logic

Open MainActivity.java and add the following code:


package com.example.upiintegration;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.shreyaspatil.easyupipayment.EasyUpiPayment;
import com.shreyaspatil.easyupipayment.listener.PaymentStatusListener;
import com.shreyaspatil.easyupipayment.model.PaymentApp;
import com.shreyaspatil.easyupipayment.model.TransactionDetails;

public class MainActivity extends AppCompatActivity
        implements PaymentStatusListener {

    private EasyUpiPayment easyUpiPayment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.id_pay_using_upi_app)
                .setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        startUpiPayment();
                    }
                });
    }

    private void startUpiPayment() {

        String transactionId =
                "TID" + System.currentTimeMillis();

        String transactionRefId =
                "TREF" + System.currentTimeMillis();

        EasyUpiPayment.Builder builder =
                new EasyUpiPayment.Builder(this)
                        .with(PaymentApp.ALL)
                        .setPayeeVpa("example@upi")
                        .setPayeeName("Salil Jha")
                        .setTransactionId(transactionId)
                        .setTransactionRefId(transactionRefId)
                        .setDescription("Demo Payment")
                        .setAmount("100.00");

        try {

            easyUpiPayment = builder.build();

            easyUpiPayment.setPaymentStatusListener(this);

            easyUpiPayment.startPayment();

        } catch (Exception e) {

            e.printStackTrace();

            Toast.makeText(
                    this,
                    e.getMessage(),
                    Toast.LENGTH_SHORT
            ).show();
        }
    }

    @Override
    public void onTransactionCompleted(
            TransactionDetails transactionDetails
    ) {

        Toast.makeText(
                this,
                "Transaction Successful",
                Toast.LENGTH_SHORT
        ).show();
    }

    @Override
    public void onTransactionCancelled() {

        Toast.makeText(
                this,
                "Transaction Cancelled",
                Toast.LENGTH_SHORT
        ).show();
    }
}

How UPI Payment Flow Works

The payment flow is:

  1. User clicks payment button
  2. UPI payment app opens
  3. User completes payment
  4. UPI app returns transaction response
  5. Application receives payment status

Supported UPI Applications

The EasyUpiPayment library supports:

  • Google Pay
  • PhonePe
  • Paytm
  • BHIM
  • Other installed UPI apps

Important UPI Parameters

Parameter Description
Payee VPA Receiver UPI ID
Payee Name Name of receiver
Transaction ID Unique transaction identifier
Amount Payment amount

Common Mistakes Developers Make

1. Invalid UPI ID

Incorrect VPA format may cause payment failures.


2. Testing on Emulator

UPI apps usually do not work correctly on Android emulators.


3. Missing Transaction Verification

Frontend success messages alone are not secure for production applications.


Production-Level Security Recommendations

For real production systems:

  • Verify transactions on backend
  • Store transaction logs securely
  • Validate transaction IDs
  • Use payment webhooks
  • Prevent duplicate transactions

Backend Verification Importance

Frontend payment success should never be treated as final confirmation.

Production applications should always verify:

  • Transaction status
  • Payment amount
  • Transaction reference
  • Receiver account

This prevents fraud and fake payment confirmations.


Modern UPI Integration Improvements

Modern Android applications can improve UPI integration using:

  • Kotlin
  • MVVM architecture
  • Jetpack Compose
  • Backend transaction verification
  • Payment analytics

FAQ

Does UPI integration require a payment gateway?

Basic intent-based UPI integration does not require a gateway, but production systems should use proper backend verification.

Can I test UPI payments on emulator?

UPI testing works best on physical Android devices with installed UPI apps.

Is EasyUpiPayment suitable for production apps?

Yes, for basic UPI integration. However, production applications should implement backend transaction validation.


Conclusion

UPI integration allows Android applications to support fast and simple digital payments.

The EasyUpiPayment library simplifies payment integration and reduces development complexity.

For production-grade applications, developers should combine frontend payment flow with secure backend verification systems.


About the Author

Salil Jha is a Full Stack and Mobile Developer with experience in Android, React Native, fintech applications, blockchain systems, scalable SaaS platforms, and payment integrations.

CodeChain Dev — Build Modern Products. Solve Real Problems.

Deep Structural Diagnostics.

Mastering JSON is only the first step. Use our industrial-grade workbench to format, validate, and synthesize models for your production APIs.