How to integrate Paypal in Android Application

If you wish to sell something through your app, then you need to integrate a payment method in your app.One of the worldwide used payment method is Paypal.

This article shall guide you on integrating payment method in your app, using the SDK provided by Paypal.

Sandbox Feature:

Paypal allows a sandbox feature to test payments since testing with actual money wouldn’t have been possible. Start by creating two sandbox accounts. The first one being the ‘Personal Account’ from where you shall pay. And the second one being the ‘business Account’ from where you shall receive the payment.

  • Open up this link and login with your paypal account.
  • Fill up the form to create accounts. Two accounts should be created, for the first one select ‘Personal’ in the Account Type. And for the second one select ‘Business’.

Creating Paypal App:

  • Now open up this link to create a Paypal app.

  • Next you will see your client ID which you should copy somewhere.

Creating Android Project:

  • First create a new Android Project. We created PayPalIntegration.
  • Now create a class named in your package and write the following code:


  • Now we shall add a Paypal SDK to our project.
  • Go inside the app level build.gradle file under the Gradle Scripts.
  • You’ll see the dependencies block inside the app level build.gradle file. Add your Paypal SDK here, by adding the following code:



  • Next sync your project.
  • As a demo, we shall be creating a simple EditText where you can put the payment amount to pay.
  • Go inside the acitivity_main.xml and write the following code:



  • You shall see the following UI with the above given code:

  • Come inside and declare objects for views and add listener to the button:


  • Initialize the views and add listener to the buttons inside the onCreate() function:


  • Next create a method named getPayment() and call it on button click:


  • Now we need a PayPal Configuration Object and a Request Code to get Payment from PayPal:


  • Start PayPalService inside onCreate() method:

  • When the app closes, the service should be destroyed:


  • Now complete the method getPayment() with the following code:


  • This  method invokes the onActivityResult() method after completion. So override onActivityResult() and write the following code instead:


  • We can see the string paymentDetails  in the above code. It is in json format as follows. It contains the payment detail with a unique payment id:


  • Next we shall another activity to show the payment details. So create a new empty activity, we created
  • Inside layout file for this activity write the following xml code:


  • In the write the following code:


Now run the application and if you see the status as approved, means it is working and you can verity the payment at your sandbox paypal account.

Your app with an integrated payment method is now good to go!

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Buzzing your life from assorted Coding,tips and general life opinion. Made your life Buzz by BuzzMyCode articles, share with world.

What is Buzzmycode, we had started this website to give tech savy the new way of life by reading our fresh organic content on every technology and applications.

Copyright © 2017 SyncSaS. Theme by SyncSaS Themes, powered by BuzzMyCode.

To Top