Zoeken…


Opmerkingen

Paypal biedt ons hun eigen bibliotheek voor betaling, dus het is nu veel veilig en gemakkelijk te implementeren in onze applicatie. Hieronder staan de belangrijke stappen om te doen.

Stel paypal in op je Android-code

1) Ga eerst door de Paypal Developer-website en maak een applicatie aan.

2) Open nu uw manifestbestand en geef de onderstaande machtigingen

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

3) En enkele vereiste activiteiten en 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 uw activiteitsklasse en stel Configuratie in voor uw app-

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

5) Stel nu de klant-ID in van het Paypal-ontwikkelaarsaccount - private statische finale String CONFIG_CLIENT_ID = "ZET UW KLANT-ID"; 6) Binnenste onCreate-methode bel de Paypal-service - Intent intent = new Intent (this, PayPalService.class); intent.putExtra (PayPalService.EXTRA_PAYPAL_CONFIGURATION, config); startService (intent);

7) Nu bent u klaar om een betaling uit te voeren, gewoon op de knop, bel de Betalingsactiviteit-

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) En tot slot van de onActivityResult krijgt u de betalingsreactie-

 @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
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow