PayPal is one of the famous payment gateway integration which is one of the famous payment gateways across the world used in so many applications and websites. In this article, we will take a look at implementing this PayPal SDK in our app.
What we are going to build in this article?
We will be building a simple application in which we will be displaying a simple EditText and a Button. From that EditText we will be getting the amount entered by the user and then after clicking on the button we will call PayPal to make payment. With the help of the PayPal UI, we will be able to make payments from the card as well as the PayPal account. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.
Step by Step Implementation for Generating a Client ID
Step 1: Navigate to the URL below to create your sandbox account
Navigate to this URL and log in with your PayPal username and password. After that, you will get to see the below page. On that page, we have to create our SandBox account with some basic details which are shown in the below form.
After filling in all the details. Click on Create Account option to create your SandBox account.
Step 2: Creating a new app to generate Client ID
Navigate to this URL and inside this add your app name
Inside this screen, we have to add our App Name and select it as Merchant and then click on Create app option to create a new app. After that, you will get to see the Client ID which we have to use in our application. Now we will move towards Android Part.
Step by Step Implementation in Android
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 dependency in build.gradle
Navigate to the app > Gradle Scripts > build.gradle and add the below dependency in the dependencies section.
After adding this dependency now sync your project and we will move towards working with the XML file.
Step 3: 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 4: 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: As my PayPal account is not verified so the payments will not be done on my side.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.