PaymentActivity.EXTRA_PAYMENT无效

时间:2014-01-26 18:22:58

标签: android paypal

我正在开发一个Android应用程序,我尝试创建一个按钮来支付宝贝以获得一些谢谢你的钱:),我不会因为规定而使用捐款。无论如何,我尝试使用PayPal-Android-SDK(https://github.com/paypal/PayPal-Android-SDK),当我使用ENV_NONE,ENV_SANDBOX,ENV_LIVE时,我总是在我的Logcat中收到错误:PaymentActivity.EXTRA_PAYMENT无效。

我使用以下代码

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);
}

我没有想法,我在文档中找不到任何有用的东西..

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

请检查您是否导入了正确的付款类别:

com.paypal.android.sdk.payments.PayPalPayment

SampleApp显示了如何实例化此类:

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