braintree_android icon indicating copy to clipboard operation
braintree_android copied to clipboard

URGENT!!: OnPayPalSuccess is never Called on Pixel Android Devices

Open TheArchitect123 opened this issue 1 year ago • 1 comments

Braintree SDK Version

4.42.0

Environment

Sandbox

Android Version & Device

Google Pixel

Braintree dependencies

com.braintreepayments.api:paypal:4.42.0 com.braintreepayments.api:data-collector:4.42.0

Describe the bug

Hi,

I have a PayPalService component that's been injected as a Singleton service via iOC using Koin Dependency injection.

Everything works perfectly on devices that don't destroy the activity (Non Google Pixel Devices), however with Pixel once the user invokes the function tokenizePayPalAccount and returns back to the activity, the device automatically destroys the activity as part of its internal lifecycle, and OnPaymentSuccess is never called on the PayPalClient Listener.

However when I reinvoke the tokenizePayPalAccount again, with the new activity, the data from the previous PayPal Session is then passed back, and a new browser session is created.

The issue here I'm finding is that the tokenizePayPalAccount is trying to return a result back to an Activity which no longer exists.

I've tried using the ApplicationContext as much as possible, however tokenizePayPalAccount since it's navigation, it requires the Activity Context or a Fragment Context. But these contexts will be disposed internally by the Android device.

I've managed to retrieve data via onNewIntent. The intent works fine on all devices, however there is no API I can use to retrieve a Nonce Object from it.

All I found was this method, however the Metadata object does not contain any information that exposes the user's Refresh token + Access Token. There is nothing in it I can use. val result = payPalClient.parseBrowserSwitchResult(Activity, intent)

Do you have an API available that I can convert the intent from onNewIntent into a PayPalAccountNonce object?

Here's some sample code of what I'm doing on the PayPalService. I've also tried using DataCollector but even that never gets called once the user has finished adding Paypal.

   val brainTreeClient =
            BraintreeClient(AppContextInitializer.coreApp, DroidClientTokenProvider())
      val  payPalClient =
            PayPalClient(brainTreeClient)
        payPalClient.setListener(object : PayPalListener {
            override fun onPayPalSuccess(payPalAccountNonce: PayPalAccountNonce) {
                val t = "";
            }

            override fun onPayPalFailure(error: java.lang.Exception) {
               logError(error)
            }
        })

        DataCollector(brainTreeClient).collectDeviceData(AppContextInitializer.coreApp) { deviceData, error ->
            val q = deviceData
        }

To reproduce

Use a Google Pixel Device, and try to invoke tokenizePayPalAccount. Add a listener into the PayPalClient object, and you'll see OnPayPalSuccess never gets called.

Expected behavior

I expect that the OnPayPalSuccess gets called after a user finishes tokenizePayPalAccount, and OnPayPalFailure to get called if a user cancels or fails in the process.

Screenshots

No response

TheArchitect123 avatar Mar 19 '24 04:03 TheArchitect123

Hi @TheArchitect123 we offer a manual browser switching integration pattern for scenarios like this. Can you try this out to see if it fits your use case?

sshropshire avatar Mar 19 '24 14:03 sshropshire

Closing this due to inactivity - please reopen if you are still experiencing this issue after updating to the suggested manual browser switching integration pattern!

sarahkoop avatar May 09 '24 14:05 sarahkoop