Payment-method icon

Google Pay Component integration

Add Google Pay to an existing Components integration.

When the shopper selects Google Pay, the Android Component shows the Google Pay payment form where the shopper selects the card they want to use.

This page is for v5.0.0, released in October 2023. If you are using an earlier version, use the guide for earlier versions instead.

Requirements

Choose which server-side flow your integration uses.

API reference

No additional fields are required for GooglePay when you make the /sessions request. You can check if there are optional additional fields for GooglePay.

Set up the Component

Google Pay has additional steps when you set up the Component:

1: Check if Google Pay is available

After configuring the Component, check that Google Pay is available:

  1. Implement ComponentAvailableCallback:

    Implement the callback to check availability
    Expand view
    Copy link to code block
    Copy code
    Copy code
    override fun onAvailabilityResult(isAvailable: Boolean, paymentMethod: PaymentMethod) {
    if (isAvailable) {
    // Show the Google Pay button in the UI.
    } else {
    // Google Pay is unavailable.
    }
    }
  2. Call isAvailable:

    Check if Google Pay is available
    Expand view
    Copy link to code block
    Copy code
    Copy code
    // Get the Google Pay payment method.
    val paymentMethod = checkoutSession.getPaymentMethod(PaymentMethodTypes.GOOGLE_PAY)
    GooglePayComponent.PROVIDER.isAvailable(
    applicationContext = application,
    paymentMethod = paymentMethod,
    configuration = checkoutConfiguration,
    callback = callback, // The ComponentAvailableCallback that you implemented.
    )

If Google Pay isn't available, do not launch the Component or show the Google Pay button.

2: Show the Google Pay button

If Google Pay is available, show the Google Pay button.

  1. Add the Google Pay button dependency:

    Google Pay button dependency
    Expand view
    Copy link to code block
    Copy code
    Copy code
    implementation 'com.google.pay.button:compose-pay-button:PAY_BUTTON_VERSION'
  2. Configure the button:

    Google Pay button configuration
    Expand view
    Copy link to code block
    Copy code
    Copy code
    @Composable
    fun GooglePayButton() {
    PayButton(
    onClick = { /* Start the Component. */ },
    allowedPaymentMethods = allowedPaymentMethods, // Get this when you launch the component, using googlePayComponent.getGooglePayButtonParameters().allowedPaymentMethods
    theme = ButtonTheme.Dark, // Optional.
    type = ButtonType.Pay, // Optional.
    )
    }

Launch Google Pay

When the shopper selects the Google Pay button, launch Google Pay and start the payment flow.

Pass your activity and the request code. The request code is a constant integer value that you need to handle the activity result in the next step.

Launch Google Pay
Expand view
Copy link to code block
Copy code
Copy code
googlePayComponent.startGooglePayScreen(activity, REQUEST_CODE)

Handle the activity result

Implement onActivityResult in your activity:

Handle the activity result
Expand view
Copy link to code block
Copy code
Copy code
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode == REQUEST_CODE) {
googlePayComponent.handleActivityResult(resultCode, data)
}
}

The Component completes the payment flow.

Test and go live

To start testing Google Pay, log in to a Google account and create a Google Pay wallet.

There are two approaches to using this wallet for testing:

Enroll your wallet in Google's test card suite. Test card suite pre-populates your wallet with a group of cards to use in the TEST environment. These are related to Adyen's collection of test cards, and cover scenarios including:

  • Cards stored as FPAN
  • Cards stored as DPAN (only when testing through native Android and Chrome on Android)
  • Cards enabled for 3DS2

When you start the payment flow and open the list of test cards, each card is marked with the applicable scenario.

You can check the status of a Google Pay test payment in your Customer Area > Transactions > Payments, whether you used a card from the test card suite or or not. Remember that cards outside the test card suite are mapped to an Adyen test card of the same brand.

For more information, see Google Pay's test environment for Android.

Before you go live

We recommend that you test the scenarios described in Google Pay’s API reference for Android in your live environment.

  1. Make sure that your API credential has the API Clientside Encryption Payments role. Check this in your live Customer Area or ask your Admin user to verify.
  2. Go to your live Customer Area to configure your Google Merchant ID.
  3. Complete all the steps in the Google Pay API deploy to production documentation for Android.

In the live environment, note that Google Pay will only be available if:

  • The shopper is logged in to their Google account.
  • The shopper has at least one valid payment method on their Google Pay account.

See also