android - paypal android SDK 与我的应用程序集成无法正常工作

标签 android android-fragments paypal paypal-sandbox

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

但是当我按下购买按钮而不是 RESULT_OK 完成带有 PaymentConfirmation 结果的付款流程。

以下是我的代码 fragment 。

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

initPaymentService() 方法调用来自 onCreate 如果我的 Activity 。 我的按钮在 fragment 中, Activity 继承自 v4 支持库中的 FragmentActivity。

请告诉我我做错了什么,为什么 onActivityResult 会立即被调用,而不是 onCompletion 带有确认信息的付款流程。

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

最佳答案

终于找到了解决办法。

如果当前(我放置购买按钮的位置) Activity 的 android:launchMode="singleInstance"

PayPal androidSDK 集成将不起作用。当我删除该 Activity 的 launchMode 时,它工作正常。

关于android - paypal android SDK 与我的应用程序集成无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20251713/

相关文章:

php - 循环支付 IPN 请求 rp_invoice_id 字段

ruby-on-rails - 使用 ActiveMerchant 自定义 Paypal Express 的评论页面

android - Webview没有清除缓存

java - 我怎样才能在android中取消注册接收器?

Android Fragments 我应该重复使用 1 个 fragment 还是创建新实例?

android - 清除 fragment 中的操作栏

java - 无法解析 Android Studio 中的符号 'view'

php - PayPal Chained Payment(钱不去二次)

android - 模拟器不启动

javascript - 从 spring 后端调用/userinfo (auth0)