MindOrks
Published in

MindOrks

💳UPI Payment Integration in Android with EasyUpiPayment library📱

Hello everyone, in this article we will learn to implement UPI payment integration easily in any android app.

  • At least one UPI app should installed on Device.

See Demo Output :

  1. Implement a caller to start transaction/payment.
  2. User will choose UPI app to pay with.
  3. User will complete the procedure of payment using UPI PIN.
  4. Transaction Details will get on the app and finished.
Demo of EasyUpiPayment Android Library

💻 Getting Started :

Gradle Setup

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

App Setup

Initializing EasyUpiPayment :

Initializing EasyUpiPayment instance.
  • with() : Mandatory and this call take Activity as a parameter and.
  • setPayeeVpa() : Mandatory and takes VPA address of payee for e.g. shreyas@upi
  • setTransactionId() : Mandatory and used in Merchant Payments generated by PSPs.
  • setTransactionRefId() : Mandatory 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. It's mandatory because some apps like PhonePe generates the error if this field is absent.
  • setDescription() : Mandatory and have to provide a valid small note or description about payment. for e.g. For Food
  • setAmount() : Mandatory and 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.

App-Specific Payment

  • PaymentApp.BHIM_UPI
  • PaymentApp.AMAZON_PAY
  • PaymentApp.GOOGLE_PAY
  • PaymentApp.PHONE_PE
  • PaymentApp.PAYTM
easyUpiPayment.setDefaultPaymentApp(PaymentApp.BHIM_UPI);

Proceed to Payment

easyUpiPayment.startPayment();

Event Callback Listeners

easyUpiPayment.setPaymentStatusListener(this);
  • onTransactionCompleted() - This method is invoked when a transaction is completed. It may either SUCCESS, SUBMITTED or FAILED.
  • onTransactionSuccess() - Invoked when Payment is successful.
  • onTransactionFailed() - Invoked when Payment is unsuccessful/failed.
  • onTransactionCancelled() - Invoked when Payment cancelled (User pressed back button or any reason).
  • onAppNotFound() - Invoked when app specified with setDefaultPaymentApp() is not exists on device.

Getting Transaction Details

  • 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 the input.

Remove Listener

easyUpiPayment.detachListener();

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shreyas Patil

Google Developer Expert for Android, 👨‍💻Engineer @ Paytm Insider❤️ Android & Kotlin 💻Organizer @KotlinMumbai | More info: https://shreyaspatil.dev