Suche…


Bemerkungen

Paypal stellt uns eine eigene Bibliothek zur Verfügung, so dass es jetzt sehr sicher und einfach in unserer Anwendung implementiert werden kann. Nachfolgend finden Sie den wichtigen Schritt.

Richten Sie paypal in Ihrem Android-Code ein

1) Gehen Sie zunächst die Paypal Developer-Website durch und erstellen Sie eine Anwendung.

2) Öffnen Sie nun Ihre Manifestdatei und erteilen Sie die folgenden Berechtigungen

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

3) Und einige erforderliche Aktivitäten und Dienstleistungen

 <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) Öffnen Sie Ihre Aktivitätsklasse und legen Sie die Konfiguration für Ihre Anwendung fest.

//set the environment for production/sandbox/no netowrk
 private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_PRODUCTION;

5) Legen Sie nun die Client-ID aus dem Paypal-Entwicklerkonto fest. 6) Innerhalb der onCreate-Methode rufen Sie den Paypal-Service auf. Intent Intent = New Intent (diese PayPalService.class); intent.putExtra (PayPalService.EXTRA_PAYPAL_CONFIGURATION, config); startService (Absicht);

7) Nun können Sie eine Zahlung tätigen, indem Sie einfach die

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) Und schließlich von der onActivityResult erhalten Sie die Zahlungsantwort-

 @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.");
                   }
               }
              
               
         }


Modified text is an extract of the original Stack Overflow Documentation
Lizenziert unter CC BY-SA 3.0
Nicht angeschlossen an Stack Overflow