Git Product home page Git Product logo

easyupipayment-android's Introduction

Easy UPI Payment - Android Library 📱💳

Introduction

Hello Everyone, I have developed this Android library to easily implement UPI Payment Integration in Android app.
UPI apps are required to be installed already before using this library because, internally this API calls UPI apps for payment processing. Before using it, make sure that your device is having atleast one UPI app installed. Otherwise it will unable to process the payments.
This API is in beta, there are lot of improvements are still needed.

Demo

1. Start 2. Select UPI App 3. Complete Payment 4. Finish

Implementation

You can clone this repository and just import this project in Android Studio. Sample app is in /app directory.

Gradle

In your build.gradle file of app module, add below dependency to import this library

    dependencies {
      implementation 'com.shreyaspatil:EasyUpiPayment:1.0'
    }

Setting Up Activity

In Android app, make any activity where you want to implement payment integration. Here, I have created MainActivity.java

Initializing EasyUpiPayment :

You can see below code, these are minimum and mandatory calls to enable payment processing. If any of it is missed then error will generated.

        final EasyUpiPayment easyUpiPayment = new EasyUpiPayment.Builder()
                .with(this)
                .setPayeeVpa("EXAMPLE@VPA")
                .setPayeeName("PAYEE_NAME")
                .setTransactionId("UNIQUE_TRANSACTION_ID")
                .setTransactionRefId("UNIQUE_TRANSACTION_REF_ID")
                .setDescription("DESCRIPTION_OR_SMALL_NOT")
                .setAmount("AMOUNT_IN_DECIMAL_XX.XX")
                .build();

Calls and Descriptions :

Method Mandatory Description
with() ✔️ This call takes Activity as a parameter where Payment is to be implemented
setPayeeVpa() ✔️ It takes VPA address of payee for e.g. shreyas@upi
setTransactionId() ✔️ This field is used in Merchant Payments generated by PSPs.
setTransactionRefId() ✔️ Transaction reference ID. This could be order number, subscription number, Bill ID, booking ID, insurance renewal reference, etc. Needed for merchant transactions and dynamic URL generation. This is mandatory because absencse of this field generated error in apps like PhonePe
setDescription() ✔️ To provide a valid small note or description about payment. for e.g.
For Food
setAmount() ✔️ It takes the amount in String decimal format (xx.xx) to be paid.
For e.g. 90.88 will pay Rs. 90.88.
setPayeeMerchantCode() Payee Merchant code if present it should be passed.
build() ✔️ It will build and returns the EasyUpiPayment instance.

Proceed to Payment

To start the payment, just call startPayment() method of EasyUpiPayment and after that transaction is started.

      easyUpiPayment.startPayment();

Event Callback Listeners

To register for callback events, you will have to set PaymentStatusListener with EasyUpiPayment as below.

        easyUpiPayment.setPaymentStatusListener(this);

Description :

  • onTransactionCompleted() - This method is invoked when transaction is completed. It may either SUCCESS, SUBMITTED or FAILED.

NOTE - If onTransactionCompleted() is invoked it doesn't means that payment is successful. It may fail but transaction is completed is the only purpose.

  • onTransactionSuccess() - Invoked when Payment is successful.
  • onTransactionSubmitted() - Invoked when Payment is partially done/In waiting/Submitted/Pending.
  • onTransactionFailed() - Invoked when Payment is unsuccessful/failed.
  • onTransactionCancelled() - Invoked when Payment cancelled (User pressed back button or any reason).
    @Override
    public void onTransactionCompleted(TransactionDetails transactionDetails) {
        // Transaction Completed
        Log.d("TransactionDetails", transactionDetails.toString());
        statusView.setText(transactionDetails.toString());
    }

    @Override
    public void onTransactionSuccess() {
        // Payment Success
        Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
        imageView.setImageResource(R.drawable.ic_success);
    }

    @Override
    public void onTransactionSubmitted() {
        // Payment Pending
        Toast.makeText(this, "Pending | Submitted", Toast.LENGTH_SHORT).show();
        imageView.setImageResource(R.drawable.ic_success);
    }

    @Override
    public void onTransactionFailed() {
        // Payment Failed
        Toast.makeText(this, "Failed", Toast.LENGTH_SHORT).show();
        imageView.setImageResource(R.drawable.ic_failed);
    }

    @Override
    public void onTransactionCancelled() {
        // Payment Cancelled by User
        Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show();
        imageView.setImageResource(R.drawable.ic_failed);
    }

Getting Transaction Details

To get details about transactions, we have callback method onTransactionCompleted() with parameter of TransactionDetails. TransactionDetails instance includes details about previously completed transaction.
To get details, below method of TransactionDetails are useful :

Method Description
getTransactionId() Returns Transaction ID
getResponseCode() Returns UPI Response Code
getApprovalRefNo() Returns UPI Approval Reference Number (beneficiary)
getStatus() Returns Status of transaction.
(Submitted/Success/Failure)
getTransactionRefId() Returns Transaction reference ID passed in input

Hurrah.... We have successfully implemented UPI integration in our Android app. Thank You!

Contribute

We can collaboratively make it happen. So if you have any issues, new ideas about implementations then just raise issue and we are open for Pull Requests. Improve and make it happen.

easyupipayment-android's People

Contributors

patilshreyas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.