Are you looking for test card numbers?

Would you like to contact support?

No momento, esta página não está disponível em português
Payment-method icon

Google Pay Component

Add Google Pay to an existing Components integration.

Our Google Pay Component renders Google Pay in your payment form. When the shopper selects Google Pay, Drop-in invokes the payment sheet, where shoppers select the card they want to use, and completes the payment.

When building your Google Pay integration, you also need to handle the redirect if the the shopper makes a payment with a card that requires 3D Secure authentication.

Before you begin

Before starting your Google Pay integration:

  • Build a Components integration.
  • Follow the setup steps in the Google Pay documentation.
  • Add Google Pay in your Customer Area.
  • Show Google Pay in your payment form

    To show Google Pay Component in your payment form, you need to:

    1. Specify in your /paymentMethods request:

    2. Deserialize the response from the /paymentMethods call and get the object with type: googlepay.

    3. Add the Google Pay Component:

      a. Import the Google Pay Component to your build.gradle file.

      implementation "com.adyen.checkout:googlepay:<latest-version>"

      Check the latest version on GitHub.

      b. Create a GooglePayConfiguration object, passing your client key. You can also include optional configuration, for example to add the amount on the Pay button.

      val amount = Amount()
         // Optional. In this example, the amount is EUR&nbsp;10.
          amount.currency = "EUR"
          amount.value = 10_00
      
      val googlePayConfig = GooglePayConfiguration.Builder(YourContext, "YOUR_CLIENT_KEY")
         .setAmount(amount)
         // When you're ready to accept live payments, change the value to one of our live environments (for example, Environment.LIVE).
         .setEnvironment(Environment.TEST)
         // Required for versions earlier than v4.5.0. When you're ready to accept live payments, change the value to ENVIRONMENT_PRODUCTION.
         .setGooglePayEnvironment(WalletConstants.ENVIRONMENT_TEST)
         .build()

      c. Check if Google Pay is available on the shopper's device. If available, initialize the Component and present a Google Pay button according to Google Pay specifications.

      var googlePayComponent: GooglePayComponent
      GooglePayComponent.PROVIDER.isAvailable(application, paymentMethod, googlePayConfiguration) {
              isAvailable: Boolean, paymentMethod: PaymentMethod, config: GooglePayConfiguration? ->
          if (isAvailable) {
              googlePayButton.visibility = View.VISIBLE
              googlePayComponent = GooglePayComponent.PROVIDER.get(YourContext, paymentMethod, googlePayConfiguration)
          }
      }

      d. When the shopper selects the Google Pay button, call startGooglePayScreen.

      googlePayComponent.startGooglePayScreen(YourContext, googlePayRequestCode)

      e. Pass the result to the Component, and wait to be notified by the observer.

      override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
          super.onActivityResult(requestCode, resultCode, data)
          if (requestCode == googlePayRequestCode) {
              googlePayComponent.observe(YourContext) { googlePayComponentState ->
                  if (googlePayComponentState?.isValid == true) {
                      // When the shopper proceeds to pay, pass the `paymentComponentState.data` to your server to send a /payments request
                      sendPayment(googlePayComponentState.data)
                  }
              }
              googlePayComponent.handleActivityResult(resultCode, data)
          }
      }

    Make a payment

    When the shopper proceeds to pay, the Component returns the paymentComponentState.data.paymentMethod.

    1. Pass the paymentComponentState.data.paymentMethod to your server.
    2. From your server, make a /payments request, specifying:

      • paymentMethod.type: The paymentComponentState.data.paymentMethod from your client app.
      • browserInfo: Required if you want to trigger 3D Secure authentication.
      • returnURL: URL where the shopper will be redirected back to after completing a 3D Secure authentication. Get this URL from the Component in the RedirectComponent.getReturnUrl(context).

      The response contains the result of the payment.

      If the shopper used a card that requires 3D Secure authentication before the payment can be completed, you receive an action.type redirect in the response.

    1. Pass the action object to your client app. You need this to initialize the Redirect Component.

    Cards with 3D Secure: Handle the redirect

    If the shopper makes a payment with a card that requires 3D Secure authentication, use the Redirect Component to redirect the shopper to another website to complete the authentication. After the shopper returns to your app, make a POST /payments/details request from your server, providing:

    • details: The actionComponentData.details object from the Redirect Component.

    You receive a response containing:

    • resultCode: Use this to present the payment result to your shopper.
    • pspReference: Our unique identifier for the transaction.

    Present the payment result

    Use the resultCode that you received in the /payments or /payments/details response to present the payment result to your shopper.
    The resultCode values you can receive for Google Pay are:

    resultCode Description Action to take
    Authorised The payment was successful. Inform the shopper that the payment has been successful.
    Error There was an error when the payment was being processed. Inform the shopper that there was an error processing their payment. The response contains a refusalReason, indicating the cause of the error.
    Refused The payment was refused by the shopper's bank. Ask the shopper to try the payment again using a different payment method.

    Recurring payments

    To make recurring Google Pay payments, you first need to create a shopper token and then make subsequent recurring transactions with the token.
    Refer to Tokenization for more information and detailed instructions.

    Test and go live

    To test Google Pay, log in to a Google account, create a Google Pay wallet and add the details for a real card.

    When you test with this card it will be masked to one of our test cards, so there are no charges to your card. Your test transactions show test card details of the same brand in your Customer Area.

    You can enrol your wallet in the Google Pay test card suite to use their test cards, which cover a limited number of scenarios. For example, you cannot test changes to your configuration in the PaymentDataRequest object using the Google Pay test card suite because Google Pay API always returns the same output.

    Currently, Google Pay wallets enrolled in the Test Card Suite return only full PAN tokens (FPANs) for test payments, and not device authenticated tokens AKA Cryptograms.

    To test 3D Secure 2, you can use American Express or Discover cards, which trigger 3D Secure 2 challenge flows in the test environment. You cannot use any other card brands or any of Google Pay's test cards to test 3D Secure 2.

    You can check the status of a Google Pay test payment in your Customer Area > Transactions > Payments.

    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 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