1

嘿,我正在尝试将 Paypal MPL API 集成到 android 中,但我遇到了很多麻烦......我已经完成了所有https://www.x.com/developers/paypal/how-to-guides/how-accept-payments -android-app-using-mpl步骤,但是当我运行我的项目时,出现此错误:

java.lang.NoClassDefFoundError: com.paypal.android.MEP.PayPalPayment

我已经在我的项目中集成了 mpl.jar 文件。

这是代码:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
public void initLibrary() {
      PayPal pp = PayPal.getInstance();
      if (pp == null) { 
        pp = PayPal.initWithAppID(this, "APP-80W284485P519543T", PayPal.ENV_NONE);
        pp.setLanguage("en_US");
        pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
        pp.setShippingEnabled(true);
      }
    }
private void showPayPalButton() {
      PayPal pp = PayPal.getInstance();
      final CheckoutButton launchPayPalButton;
      launchPayPalButton = pp.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);
      launchPayPalButton.setOnClickListener((OnClickListener) this);
      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(10);
      ((RelativeLayout) findViewById(R.id.rlayout)).addView(launchPayPalButton);
      ((RelativeLayout) findViewById(R.id.rlayout)).setGravity(Gravity.CENTER_HORIZONTAL);
    }
public void PayPalButtonClick(View arg0) {
      PayPalPayment payment = new PayPalPayment();
      payment.setCurrencyType("USD");
      payment.setRecipient("nons3nsedevelopment@gmail.com");
      payment.setSubtotal(new BigDecimal(10));
      payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);
      PayPalInvoiceData invoice = new PayPalInvoiceData();
      invoice.setTax(new BigDecimal(5));
    }
public void PayPalActivityResult(int requestCode, int resultCode, Intent intent) {
      switch (resultCode) {
        case Activity.RESULT_OK:
          String payKey = intent.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
          //this.paymentSucceeded(payKey);
          break;
        case Activity.RESULT_CANCELED:
          //this.paymentCanceled();
          break;
        case PayPalActivity.RESULT_FAILURE:
          String errorID = intent.getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
          String errorMessage = intent.getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
          //this.paymentFailed(errorID, errorMessage);
      }
    }

我在这里没有发现错误...

4

2 回答 2

1

复制 PayPal 最新的 SDK jar 文件将 libs 文件夹粘贴到您的项目中,然后右键单击 jar 文件添加到构建路径,

试试下面的代码。

公共类 MainActivity 扩展 Activity{

 private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_NO_NETWORK;

    // note that these credentials will differ between live & sandbox environments.
    private static final String CONFIG_CLIENT_ID = "AVLi6hDi_hTrqeVnADnRQ6jOF8VIj1b8nWbRof2ciyWhOKaOxnJr6wJKf7mi"; //"credential from developer.paypal.com";

    private static final int REQUEST_CODE_PAYMENT = 1;
    private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;

    private static PayPalConfiguration config = new PayPalConfiguration()
    .environment(CONFIG_ENVIRONMENT)
    .clientId(CONFIG_CLIENT_ID)
    // The following are only used in PayPalFuturePaymentActivity.
    .merchantName("Hipster Store")
    .merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
    .merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     Intent intent = new Intent(this, PayPalService.class);
        intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
        startService(intent);

        }
 public void onBuyPressed(View pressed) {
     PayPalPayment thingToBuy = getThingToBuy(PayPalPayment.PAYMENT_INTENT_SALE);

        Intent intent = new Intent(MainActivity.this, PaymentActivity.class);

        intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

        startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}

 private PayPalPayment getThingToBuy(String environment) {
        return new PayPalPayment(new BigDecimal(String.valueOf(100)), "USD", "Android Mobile",
                environment);
    }

}

于 2014-05-14T11:27:17.533 回答
0

MPL 正在被弃用。建议您改用新的PayPal Android SDK

于 2013-06-05T17:38:56.040 回答