UPI Payment Integration in Android
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.
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.
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.
Step 5: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
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.