sandor
sandor

Reputation: 671

PaymentActivity.EXTRA_PAYMENT is invalid

I'm developing an android app, and I try to create a button to paypal to get some thank you money :), I don't use donations because of the regulations. Anyway, I try to use PayPal-Android-SDK (https://github.com/paypal/PayPal-Android-SDK) and I always recieve an error in my Logcat when either I use ENV_NONE, ENV_SANDBOX, ENV_LIVE: PaymentActivity.EXTRA_PAYMENT is invalid.

I use the following code

protected void onCreate(Bundle savedInstanceState) {
...
Intent intent = new Intent(this, PayPalService.class);

intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startService(intent);
initLibrary();
showPayPalButton();
}

public void initLibrary() {
PayPal pp = PayPal.getInstance();
if (pp == null) {  // Test to see if the library is already initialized
// This main initialization call takes your Context, AppID, and target server
pp = PayPal.initWithAppID(this,"<mycode/deleted from post>", PayPal.ENV_NONE);
// Required settings:
// Set the language for the library
pp.setLanguage("en_US");
// Some Optional settings:
// Sets who pays any transaction fees. Possible values are:
// FEEPAYER_SENDER, FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER, and       FEEPAYER_SECONDARYONLY
pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
// true = transaction requires shipping
pp.setShippingEnabled(true);
_paypalLibraryInit = true;
}
}


private void showPayPalButton() {
// Generate the PayPal checkout button and save it for later use
PayPal pp = PayPal.getInstance();
launchPayPalButton = pp.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);
// The OnClick listener for the checkout button
launchPayPalButton.setOnClickListener(this);

// Add the listener to the layout
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams     (LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params.bottomMargin = 10;
    launchPayPalButton.setLayoutParams(params);
    launchPayPalButton.setId(PAYPAL_BUTTON_ID);
((LinearLayout)     findViewById(R.id.insert_expense_layout)).addView(launchPayPalButton);
((LinearLayout) findViewById(R.id.insert_expense_layout)).setGravity(Gravity.CENTER_HORIZONTAL);
}

public void PayPalButtonClick(View arg0) {

// Create a basic PayPal payment
PayPalPayment payment = new PayPalPayment();

// Set the currency type
payment.setCurrencyType("USD");

// Set the recipient for the payment (can be a phone number)

// Set the payment amount, excluding tax and shipping costs
payment.setSubtotal(new BigDecimal(1));

Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
//intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, ""); //with this line uncommented it also fails
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
startActivityForResult(intent, 0);

}

public void PayPalActivityResult(int requestCode, int resultCode, Intent intent) {
....        
}

@Override
public void onClick(View v) {
PayPalButtonClick(v);
}

I'm out of ideas, I haven't find anything useful in documentations..

Thanks for your help in advance!

Upvotes: 0

Views: 1884

Answers (1)

Matt Jacunski
Matt Jacunski

Reputation: 381

Please check that you are importing the correct payment class:

com.paypal.android.sdk.payments.PayPalPayment

The SampleApp shows how this class should be instantiated:

PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal("1.75"), "USD", "hipster jeans");

Upvotes: 1

Related Questions