braintree / braintree_android

Braintree SDK for Android
https://developer.paypal.com/braintree/docs/start/hello-client/android/v4
MIT License
409 stars 233 forks source link

Migration paypal v5: PayPalPaymentAuthResult - NoResult #1184

Open javier-28 opened 2 weeks ago

javier-28 commented 2 weeks ago

Braintree SDK Version

5.0

Environment

Sandbox

Android Version & Device

Pixel 4 XL API 34

Braintree dependencies

com.braintreepayments.api:paypal

Describe the bug

I am in the process of updating the PayPal library to version 5.0. I am founding the following issue:

The WebView is displayed, and we can authenticate on the PayPal platform. You can select the payment method and press continue. The deeplink opens, and it redirects back to the app, but the success case is not reached. The result of the method is PayPalPaymentAuthResult.NoResult.

I don't understand why it's always reaching this scenario.

I would like to know at least what situations cause the result of thepayPalLauncher.handleReturnToApp() function to be PayPalPaymentAuthResult.NoResult so I can follow that thread and review the implementation.

The project is a React native application with a Native module for braintree payments

To reproduce

I have been able to reproduce it in two different ways.

The first one by launching a new activity from the native RN module, and the second by implementing the PayPal flow within an RN module.

The fact that I can reproduce the issue from two different scenarios makes me think that the problem might be caused by some external factor that I am not seeing. I can provide the full code for both scenarios if you think it’s necessary.

        payPalClient.createPaymentAuthRequest(reCurrentActivity!!, request) { paymentAuthRequest ->
            when (paymentAuthRequest) {
                is PayPalPaymentAuthRequest.ReadyToLaunch -> {
                    val pendingRequest = payPalLauncher.launch(reCurrentActivity!!, paymentAuthRequest)
                    when (pendingRequest) {
                        is PayPalPendingRequest.Started -> {
                            pendingString = pendingRequest.pendingRequestString
                        }

                        is PayPalPendingRequest.Failure -> {
                            mPromise.reject("BraintreeSDK Error", pendingRequest.error.message)
                        }
                    }
                }

                is PayPalPaymentAuthRequest.Failure -> {
                    mPromise.reject("BraintreeSDK Error",paymentAuthRequest.error.message)

                }
            }
        }

    private fun handleReturnToApp(intent: Intent) {
        // fetch stored PayPalPendingRequest.Success
        if(this::pendingString.isInitialized){
            when (val paymentAuthResult = payPalLauncher.handleReturnToApp(PayPalPendingRequest.Started(pendingString), intent)) {
                is PayPalPaymentAuthResult.Success -> {
                    completePayPalFlow(paymentAuthResult)
                    // clear stored PayPalPendingRequest.Success
                }
                is PayPalPaymentAuthResult.NoResult -> {
                    // user returned to app without completing PayPal flow, handle accordingly
                    mPromise.reject("BraintreeSDK Error","NO RESULT")

                }
                is PayPalPaymentAuthResult.Failure ->  {

                    mPromise.reject("BraintreeSDK Error", paymentAuthResult.error.message)
                    // handle error case
                }
            }
        }
    }

Expected behavior

Enter the Success case of PayPalPaymentAuthResult.

Screenshots

https://github.com/user-attachments/assets/4dcce35b-108b-44b1-b827-dde42ea52da7

javier-28 commented 4 days ago

hi, any news?

saperi22 commented 9 hours ago

@javier-28 unfortunately, we do not test for or support react native integrations. That being said, please let us know if this integration fails for native modules too.