user2927881
user2927881

Reputation: 27

Paypal integration to android application using paypal sdk: PaymentActivity class issue

PaymentActivity is unable to get any of these method. i have registered it in menifest file .i haved added the paypal sdk to lib folder.can anyone help me??I have attached the image which is showing the the error i am having.thanx in advance.enter image description here

Upvotes: 0

Views: 4591

Answers (2)

Kashfa Khan
Kashfa Khan

Reputation: 2493

Integrating paypal is very with the official paypal sdk. First create a sandbox account and a rest api app at paypal developers website. Now in your android studio add the paypal sdk. You can use the following code for your gradle file.

compile 'com.paypal.sdk:paypal-android-sdk:2.14.2'

Now for the java part you can use the following code for paypal.

//Paypal Configuration Object
private static PayPalConfiguration config = new PayPalConfiguration()
        // Start with mock environment.  When ready, switch to sandbox (ENVIRONMENT_SANDBOX)
        // or live (ENVIRONMENT_PRODUCTION)
        .environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
        .clientId(PayPalConfig.PAYPAL_CLIENT_ID)

Add the above code inside your class. And you need to start paypal service inside onCreate() method.

Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intent);

Paypal is configured now to accept payment you can use the following code.

private void getPayment() {
    //Getting the amount from editText
    paymentAmount = editTextAmount.getText().toString();

    //Creating a paypalpayment 
    PayPalPayment payment = new PayPalPayment(new BigDecimal(String.valueOf(paymentAmount)), "USD", "Simplified Coding Fee",
            PayPalPayment.PAYMENT_INTENT_SALE);

    //Creating Paypal Payment activity intent 
    Intent intent = new Intent(this, PaymentActivity.class);

    //putting the paypal configuration to the intent 
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

    //Puting paypal payment to the intent 
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);

    //Starting the intent activity for result
    //the request code will be used on the method onActivityResult 
    startActivityForResult(intent, PAYPAL_REQUEST_CODE);
}

Also don't forget to stop the service on onDestroy method. Source: Android Paypal Integration Tutorial

Upvotes: 1

user2927881
user2927881

Reputation: 27

I was following the below given tutorial and it is no more valid because several changes in PayPal SDK have been made. https://devblog.paypal.com/working-with-the-new-android-sdk/

if some wants to integrate the PayPal SDK for its inapp payments he/she can use following sample app: https://github.com/paypal/PayPal-Android-SDK/tree/master/SampleApp

Upvotes: 1

Related Questions