When a user of your app chooses to pay with Google Pay for the first time, Google presents the user with a chooser screen to select the backing card instrument to use for payment.

Google Pay chooser dialog

When you allow preauthorization for your app, Google also displays a checkbox in the account chooser. By selecting "Use selected info for future purchases from this app" option, first-time users can authorize the Google Pay default payment method for your app. If the user authorizes a default payment method, then in future transactions your app's checkout button should lead directly to the confirmation screen. The chooser popup is bypassed, automatically returning your customer's default backing card and optional fields such as shipping address.

This section covers the steps needed to allow preauthorization for the user's choice of a default payment method for Google Pay. This allows the user to skip the chooser screen when paying with Google Pay in the future. If you choose not to set up your app for preauthorization, the user will be presented with the chooser screen for each transaction.

To request for the Google Pay chooser not to be shown to returning users in the purchase flow, the setUiRequired method has to be set to false. With the chooser, no longer showing, you will need to provide an alternative way for users to change their payment method selection. You would implement this by invoking setUiRequired set to true.

Enable preauthorization

To enable preauthorization, obtain a client ID for OAuth 2.0 authorization in the Google API Console Credentials page. The client ID is generated automatically when you register your app. You need the SHA1 fingerprint in your developer's key to generate a client ID.

  1. Go to the Google API Console.
  2. Select a project, or create a new one. The system guides you through the process of choosing or creating a project and registering a new application. For information on creating a new project, see Manage projects in the Console.
  3. In the sidebar on the left, select APIs & Services.
  4. In the sidebar on the left, select Credentials.
  5. To register your certificate, you must get the certificate's SHA1 fingerprint. In a terminal, run the Keytool utility to get the SHA1 fingerprint for your digitally signed .apk file's public certificate.
    keytool -exportcert -alias androiddebugkey -keystore path-to-debug-or-production-keystore -list -v

    The Keytool prints the fingerprint to the shell. For example:

    $ keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v
    Enter keystore password: Type "android" if using debug.keystore
    Alias name: androiddebugkey
    Creation date: Aug 27, 2012
    Entry type: PrivateKeyEntry
    Certificate chain length: 1
    Owner: CN=Android Debug, O=Android, C=US
    Issuer: CN=Android Debug, O=Android, C=US
    Serial number: 503bd581
    Valid from: Mon Aug 27 13:16:01 PDT 2012 until: Wed Aug 20 13:16:01 PDT 2042
    Certificate fingerprints:
       MD5:  1B:2B:2D:37:E1:CE:06:8B:A0:F0:73:05:3C:A3:63:DD
       SHA1: D8:AA:43:97:59:EE:C5:95:26:6A:07:EE:1C:37:8E:F4:F0:C8:05:C8
       SHA256: F3:6F:98:51:9A:DF:C3:15:4E:48:4B:0F:91:E3:3C:6A:A0:97:DC:0A:3F:B2:D2:E1:FE:23:57:F5:EB:AC:13:30
       Signature algorithm name: SHA1withRSA
       Version: 3

    Copy the SHA1 fingerprint, which is highlighted in the example above.

  6. Return to the Google API Console and perform the following steps to create credentials:
    1. From the Credentials view, select the OAuth consent screen tab:
      Google API credentials OAuth consent screen settings
    2. In the OAuth consent screen, enter values for Email address and Product name.
    3. To save your changes, click the Save button.

      The Console returns you to the Credentials view.

    4. From the "Create credentials" drop-down list, select OAuth client ID. The Create client ID view displays:
      Google API credentials Create client ID application type selector
    5. Select the Android option.
    6. In the Signing-certificate fingerprint text input, paste your certificate's SHA1 fingerprint.
    7. In the Package name field, enter your Android app's package name.
    8. Click the Create button.

Send feedback about...

Google Pay API for Android