Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalStateException when requesting payment using Google Pay #1163

Open
oscargrgm opened this issue Sep 24, 2024 · 0 comments
Open

IllegalStateException when requesting payment using Google Pay #1163

oscargrgm opened this issue Sep 24, 2024 · 0 comments

Comments

@oscargrgm
Copy link

Braintree SDK Version

4.49.1

Environment

Production

Android Version & Device

Pixel 8 Pro - Android 14

Braintree dependencies

com.braintreepayments.api:braintree-core:4.49.1
com.braintreepayments.api:data-collector:4.49.1
com.braintreepayments.api:google-pay:4.49.1
com.braintreepayments.api:three-d-secure:4.49.1

Describe the bug

Multiple users are getting an IllegalStateException when trying to pay using Google Pay. We applied previous workarounds such as the proposed in issue 543 but it doesn't seem to work anymore.

Here you can see the logs:

Fatal Exception: java.lang.IllegalStateException
Attempting to launch an unregistered ActivityResultLauncher with contract com.braintreepayments.api.A@17860a and input com.braintreepayments.api.D@a974e7b. You must ensure the ActivityResultLauncher is registered before calling launch().
Fatal Exception: java.lang.IllegalStateException: Attempting to launch an unregistered ActivityResultLauncher with contract com.braintreepayments.api.A@17860a and input com.braintreepayments.api.D@a974e7b. You must ensure the ActivityResultLauncher is registered before calling launch().
       at androidx.activity.result.ActivityResultRegistry$2.launch(ActivityResultRegistry.java:166)
       at androidx.activity.result.ActivityResultLauncher.launch(ActivityResultLauncher.java:47)
       at com.braintreepayments.api.GooglePayLifecycleObserver.launch(GooglePayLifecycleObserver.java:44)
       at com.braintreepayments.api.GooglePayClient$4$1.onResult(GooglePayClient.java:296)
       at com.braintreepayments.api.BraintreeClient.getConfiguration$lambda-1$lambda-0(BraintreeClient.java:190)
       at com.braintreepayments.api.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:30)
       at com.braintreepayments.api.BraintreeClient.getConfiguration$lambda-1(BraintreeClient.java:188)
       at com.braintreepayments.api.AuthorizationLoader.loadAuthorization(AuthorizationLoader.java:12)
       at com.braintreepayments.api.BraintreeClient.getAuthorization(BraintreeClient.kt:206)
       at com.braintreepayments.api.BraintreeClient.getConfiguration(BraintreeClient.kt:186)
       at com.braintreepayments.api.GooglePayClient$4.onAuthorizationResult(GooglePayClient.java:275)
       at com.braintreepayments.api.AuthorizationLoader.loadAuthorization(AuthorizationLoader.java:12)
       at com.braintreepayments.api.BraintreeClient.getAuthorization(BraintreeClient.kt:206)
       at com.braintreepayments.api.GooglePayClient.requestPayment(GooglePayClient.java:271)
       at com.braintreepayments.api.GooglePayClient.requestPayment(GooglePayClient.java:228)
       at com.myapplication.googlepay.impl.service.GooglePayService.requestGooglePayment$lambda$7(GooglePayService.java:337)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8762)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

The implementation of our GooglePayService looks like this:

class GooglePayService @Inject constructor (...) : GooglePayListener {

    private var googlePayClient: GooglePayClient? = null

    fun initGooglePayClient(fragmentActivity: FragmentActivity) {
        ...
        googlePayClient = GooglePayClient(activity, braintreeClient)
            .apply {
                setListener(this@GooglePayService)
            }
    }

    fun requestGooglePayment() {
        ...
        Handler(Looper.getMainLooper()).post {
            googlePayClient?.requestPayment(fragmentActivity, googlePayRequest)
        }
    }
}

The initGooglePayClient function is called in the onCreate method of our FragmentActivity.

The requestGooglePayment is called in the onStart method of the same FragmentActivity.

In both cases, we use the GooglePayService you can see in the logs to do some checks -such as if the FragmentActivity used for creating the instance of the GooglePayClient is the same than the used when requesting Google payment-.

To reproduce

  1. Select Google Pay as the payment method.
  2. The Braintree SDK tries to launch Google Pay.

Expected behavior

The BottomSheet/Activity is launched properly and the user is able to interact with it.

Screenshots

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant