paypal android SDK与我的应用程序集成不起作用

时间:2013-11-27 19:46:58

标签: android android-fragments paypal paypal-sandbox

您好我正在尝试将Paypal AndroidSDK 与我的Android应用程序集成。我按照paypal集成文档,并尝试按照说明进行集成。但是当我按购买按钮屏幕时,导航到下面显示的paypal屏幕。 enter image description here

但是当我按下购买按钮而不是 RESULT_OK 后,onActivityResult回调会立即以 resultCode 作为 0(RESULT_CANCELED)付款流程 PaymentConfirmation 结果。

以下是我的代码段。

  public void initPaymentService() {
    try {
        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);
    } catch (Exception e) {
    }
}

public void onBuyPressed(String amount) {
    PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal("1.75"), "USD", "hipster jeans");

    Intent intent = new Intent(this, PaymentActivity.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);

    // It's important to repeat the clientId here so that the SDK has it if Android restarts your 
    // app midway through the payment UI flow.
    intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, "AL7neK4uQk1xTc-YsELHpTAvdkjscvGNJDGHhashc8BLL8nkaTesRWkHOczSmqMkKT"); // **Clientid** from **developer.paypal.com**
    intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "testpaypal@gmail.com");

    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

    startActivityForResult(intent, 0);
}

@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {

     if (resultCode == Activity.RESULT_OK) {
        PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
        if (confirm != null) {
            try {
                Log.i("PaypalTestActivity", confirm.toJSONObject().toString(4));

                // TODO: send 'confirm' to your server for verification.
                // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                // for more details.

            } catch (JSONException e) {
                Log.e("PaypalTestActivity", "an extremely unlikely failure occurred: ", e);
            }
        }
    }
    else if (resultCode == Activity.RESULT_CANCELED) {
        Log.i("PaypalTestActivity", "The user canceled the Transaction.");
    }
    else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
        Log.i("PaypalTestActivity", "An invalid payment was submitted. Please see the docs.");
    }
}
如果我的Activity,

initPaymentService()方法调用来自 onCreate 。 我的按钮位于片段中,活动继承自v4支持库中的FragmentActivity。

请让我知道我做错了什么,为什么会立即调用onActivityResult,而不是通过确认信息来完成付款流程。

如果您知道我的问题的解决方案,请告诉我。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:5)

最后我找到了解决方案。

如果当前(我放置购买按钮)活动的 android:launchMode =“singleInstance”

PayPal androidSDK 集成无效。当我将 launchMode 移除到该活动时,它正常工作。