PayPal is used by most of the eCommerce website and mobile application to buy something online. In this post, I explain how to integrate PayPal in your android application. This post is very easy to understand and it takes 5 min to setup PayPal in your application and you can start getting payment through PayPal. I assume that you have your PayPal account or PayPal developer account if not then create one on this link, and once you create your account and get Client Id from the account. If you want to learn how to create an account in Paypal Sandbox check this official link.

 

Integrating PayPal in Android

Step 1: Create a new project or open existing one in Android Studio and open the gradle file and add PayPal dependencies in it. Note: your minimum SDK version is 16

If you want to include PayPal Card API you need to remove exclude group: ‘io.card’

Step 2. Now Open AndroidManifest.xml and add required permissions in it

Step 3. Now open activity_main.xml or layout where you want to add Paypal pay button and add click listener on it or you can directly call the function in it.

Step 4. Now open Mainactivity.java and initialize your Paypal in it.

Step 5. Now create pay method when user click on it send a request to PayPal to allow you to make payment.

Step 6. Now, onActivityResult when user completes the payment you can get payment status and also extract PayPal transaction Id.

Now once you get PayPal id and transaction Id you can pass that data to the server and perform other operation.