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

Google Pay Drop-in integration

Add Google Pay to an existing Drop-in integration.

Our Android Drop-in renders Google Pay in your payment form. When shoppers select Google Pay, Drop-in presents the Google Pay payment sheet where shoppers choose a card they want to use. If shoppers select a card that requires 3D Secure authentication, Drop-in also handles redirecting shoppers to another website to complete the verification.

Before you begin

Before starting your Google Pay integration:

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

    Drop-in uses the countryCode and the amount.currency from your /paymentMethods request to show the available payment methods to your shopper. From your server, make a /paymentMethods request specifying:

    Optional configuration

    When creating an instance of Drop-in, you can optionally include a GooglePayConfiguration object to add custom configuration for Google Pay in your payment form.

    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)
       .build()
    
    val dropInConfiguration =
       DropInConfiguration.Builder(YourContext, YourDropInService::class.java, "YOUR_CLIENT_KEY")
       // 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)
       .addGooglePayConfiguration(googlePayConfig)
       .build()

    Make a payment

    When the shopper proceeds to pay, Drop-in returns the paymentComponentData.paymentMethod.

    1. Pass the paymentComponentData.paymentMethod to your server.

    2. From your server, make a /payments request, specifying:

      • paymentMethod: The paymentComponentData.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. The returnUrl can have a maximum of 1024 characters. 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. If you received an action object, pass the action object to your client app and return it inside a DropInServiceResult.Action.

      If you did not receive an action object, proceed to present the payment result to your shopper.

    Cards with 3D Secure: Check the payment result

    Drop-in redirects the shopper to complete the payment. When the shopper returns back to your app, Drop-in provides the actionComponentData object.

    From your server, make a POST /payments/details request providing:

    • details: The actionComponentData.details object from Drop-in.

    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 in the test environment:

    1. Log in to a Google account and create a Google Pay wallet.
    2. Enrol your wallet in the Google Pay test card suite
    3. Add the details for a real card to the wallet.

    After you make a test payment, you can check the status of a Google Pay test payment in your Customer Area > Transactions > Payments.

    When you test with a real card, it will be masked to one of our test cards, and your card will not be charged. In your Customer Area, your test transactions show test card details of the same brand.

    Limitations apply when testing Google Pay:

    • When testing with a wallet enrolled in the Google test card suite, you cannot test changes to your configuration in the PaymentDataRequest object, because the Google Pay API always returns the same output.
    • When using Google's test cards, only full PAN tokens (FPANs) are returned for test payments, instead of device authenticated tokens, known as Cryptograms.
    • To test 3D Secure 2, you can only 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.

    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