stripe-android
stripe-android copied to clipboard
[BUG] [Google Pay] Google pay no show in test environment
Summary
The google account has been added to the Google Pay API Test Cards Allowlist. In the Test environment, the Google pay option is not displayed.
Code to reproduce
Android version
Impacted devices
Installation method
Dependency Versions
kotlin: stripe-android: Android Gradle Plugin: Gradle:
SDK classes
Video
Other information
@ningkanggithub can you provide more details, such as code to reproduce, the android version and device you are using?
I use Finalize payments on the server + SetupIntent + FlowController flow.
At present, the google pay button cannot be displayed in the test environment. Looking at the source code, it seems to be caused by the default value of existingPaymentMethodRequired being true, but I have no way to modify it.
This question is not directly related to android version and device
My question is why does the google play option show that it is directly related to whether there is a card under the account? And it cannot be changed
Please take a look at this question Because I think it is unreasonable to only display the Google pay button when the user actually adds a valid credit card. It is more reasonable to let the user add a card manually if there is no card when the user clicks.
@ningkanggithub can you please provide sample code? It is hard to diagnose the issue without any example code.
val googlePayConfiguration = PaymentSheet.GooglePayConfiguration(
environment = PaymentSheet.GooglePayConfiguration.Environment.Test,
countryCode = "US",
currencyCode = localCurrency // Required for Setup Intents, optional for Payment Intents
)
val configResult = suspendCancellableCoroutine { coroutine ->
flowController.configureWithIntentConfiguration(
intentConfiguration = PaymentSheet.IntentConfiguration(
mode = PaymentSheet.IntentConfiguration.Mode.Setup(
currency = localCurrency,
),
),
configuration = configuration,
callback = { success, error ->
val option = flowController.getPaymentOption()
paymentOptionCallback.invoke(option)
if (success) {
Tracker.v("config flow success:$option")
configSuccess = true
coroutine.resume(true)
} else {
Tracker.e("config flow fail:${error?.localizedMessage}")
configSuccess = false
configFailCallback.invoke(error, echoFail)
coroutine.resume(false)
}
},
)
}
My google account has been added to the Google Pay API Test Cards Allowlist. In the Test environment, The Google Pay options are never shown.
See Google Pay API docs here:
Note: In the TEST environment, if you set existingPaymentMethodRequired to true
in an IsReadyToPay() request, the response always returns true.
Currently the Stripe only supports the case where the user has an existing card. If you are having trouble seeing the Google Pay button, make sure that your Google Pay account has existing payment methods. If it has existing payment methods make sure that the following is true:
For PAN_ONLY (alone or with CRYPTOGRAM_3DS), 'IsReadyToPay' will return a) true if 'existingPaymentMethodRequired' is not set or false (as the user can log in / add a card), b) true if 'existingPaymentMethodRequired' is true and the user has a matching card type.
For DPAN only - CRYPTOGRAM_3DS, 'IsReadyToPay' will return a) false if the user has no matching device DPAN (regardless of 'existingPaymentMethodRequired' status), b) true if the user has a matching device DPAN (regardless of 'existingPaymentMethodRequired' status).
If all of the above is true and you are still not seeing the Google Pay button, try using a real device, as I have also noticed issues seeing the Google Pay button on emulators.
As for my case, Google Pay option didn't show if I use PaymentSheet.GooglePayConfiguration.Environment.Test with PaymentSheet.
paymentSheet.presentWithPaymentIntent(
paymentIntentClientSecret = ...,
configuration = PaymentSheet.Configuration(
merchantDisplayName = ...,
customer = ...,
googlePay = PaymentSheet.GooglePayConfiguration(
environment = PaymentSheet.GooglePayConfiguration.Environment.Test, // <--
countryCode = "US",
),
)
)
The solution was to 1) install Google Pay app (https://play.google.com/store/search?q=google+pay&c=apps) and 2) add a payment to Google Pay app.
Note that Google Pay app doesn't work on a rooted device nor an emulator, even if the emulator has Play Store app.
If you want to handle Google Pay transaction yourself (i.e. not as a part of PaymentSheet) consider using GooglePayLauncher (https://github.com/stripe/stripe-android/blob/master/example/src/main/java/com/stripe/example/activity/GooglePayLauncherComposeActivity.kt).
Thanks for the response solamour. We ensure google pay is setup before showing it.