Setup paypal in your android code

suggest change

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-

<service
       android:name="com.paypal.android.sdk.payments.PayPalService"
       android:exported="false" />
   <activity android:name="com.paypal.android.sdk.payments.PaymentActivity" />
   <activity android:name="com.paypal.android.sdk.payments.LoginActivity" />
   <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" />
   <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" />
   <activity android:name="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity" />
   <activity android:name="com.paypal.android.sdk.payments.FuturePaymentConsentActivity" />
   <activity android:name="com.paypal.android.sdk.payments.FuturePaymentInfoActivity" />
   <activity
       android:name="io.card.payment.CardIOActivity"
       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);
startService(intent);

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", "androidhub4you.com",
                                 PayPalPayment.PAYMENT_INTENT_SALE);
                             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-

@Override
          protected void onActivityResult(int requestCode, int resultCode, Intent data) {
              if (requestCode == REQUEST_PAYPAL_PAYMENT) {
                  if (resultCode == Activity.RESULT_OK) {
                      PaymentConfirmation confirm = data
                              .getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
                      if (confirm != null) {
                          try {
                          System.out.println("Responseeee"+confirm);
                              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.");
                  }
              }
             
              
        }

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Paypal Gateway Integration:
* Setup paypal in your android code

Table Of Contents
2 Gradle
5 Intent
17 Service
19 WebView
31 SQLite
35 Glide
37 Dialog
38 ACRA
44 Handler
53 Toast
63 Menu
65 Picasso
70 Volley
71 Widgets
78 Realm
90 Spinner
95 OkHttp
108 TextView
109 ListView
111 Loader
118 Xposed
119 Security
121 ImageView
123 Doze Mode
130 Drawables
131 Colors
134 Fresco
139 AdMob
145 Keyboard
146 Button
150 EditText
151 Paypal Gateway Integration
155 Vk SDK
163 ExoPlayer
169 XMPP
175 OpenCV
177 Threads
184 ORMLite
186 TabLayout
190 LruCache
192 Zip files
194 Fastlane
199 FileIO
202 Moshi
210 VideoView
216 Paint
218 ProGuard
226 CleverTap
228 ADB shell
229 Ping ICMP
230 AIDL
234 Context
240 JCodec
242 Okio
249 FuseView
254 Looper
261 Fastjson
263 Jackson
267 Smartcard