Saturday, July 26, 2014

Android Paypal Gateway Example | Paypal demo in android | Pay inside App using Paypal and Credit card

Hi Friends, in past we were using third party library for Paypal payment but now Paypal provide us their own library for payment so it is now much secure and easy to implement in our application. Below are the important step to do -

1)First go through Paypal Developer web site and create an application.

2)Now open your manifest file and give the below permissions-

<uses-permission android:name="android.permission.INTERNET" />

     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

3)And some required Activity and Services-

            android:exported="false" />

        <activity android:name="" />
        <activity android:name="" />
        <activity android:name="" />
        <activity android:name="" />
        <activity android:name="" />
        <activity android:name="" />
        <activity android:name="" />
            android:configChanges="keyboardHidden|orientation" />
        <activity android:name="io.card.payment.DataEntryActivity" />

4)Open your Activity class and set Configuration for your app-
//set the environment for production/sandbox/no netowrk
       private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_PRODUCTION;

5)Now set client id from the Paypal developer account-
     private static final String CONFIG_CLIENT_ID = "PUT YOUR CLIENT ID";

6)Inside onCreate method call the Paypal service-
Intent intent = new Intent(this, PayPalService.class);
        intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

7)Now you are ready to make a payment just on button press call the Payment Activity-
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(1),"USD", "",

                             Intent intent = new Intent(MainActivity.this, PaymentActivity.class);

                             intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

                             startActivityForResult(intent, REQUEST_PAYPAL_PAYMENT);    

8)And finally from the onActivityResult get the payment response-
           protected void onActivityResult(int requestCode, int resultCode, Intent data) {
               if (requestCode == REQUEST_PAYPAL_PAYMENT) {
                   if (resultCode == Activity.RESULT_OK) {
                       PaymentConfirmation confirm = data
                       if (confirm != null) {
                           try {
                               Log.i("paymentExample", confirm.toJSONObject().toString());

                               JSONObject jsonObj=new JSONObject(confirm.toJSONObject().toString());
                               String paymentId=jsonObj.getJSONObject("response").getString("id");
                               System.out.println("payment id:-=="+paymentId);
                               Toast.makeText(getApplicationContext(), paymentId, Toast.LENGTH_LONG).show(); 

                           } catch (JSONException e) {
                               Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
                   } else if (resultCode == Activity.RESULT_CANCELED) {
                       Log.i("paymentExample", "The user canceled.");
                   } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
                       Log.i("paymentExample", "An invalid Payment was submitted. Please see the docs.");

For any query or suggestion please post your feedback.



  1. Replies
    1. This comment has been removed by the author.

    2. good and hope u will post some more --------

    3. Yes sure i will post and thank you..

  2. is it against google policy to accept money via pay pal?

    1. No.. is it mention any where? If it is against goole policy then why paypal have libray for android? As per my knowladge paypal is accepted by google.

    2. No.. is it mention any where? If it is against goole policy then why paypal have libray for android? As per my knowladge paypal is accepted by google.

    3. just wanted to know coz goofle has monopoly they can ban u for no reason