Choose an integration method

You can accept Google Pay with either our Drop-in UI or a custom integration.

Drop-in integration

Our Drop-in UI is the fastest way to set up your client-side integration.

For full details, see Drop-in Setup and Integration.

Custom integration

Get the SDK

See the client SDK setup guide for Android v2. While Google Pay has been supported since version 2.7.0, the latest version of the integration shown here requires version 2.20.0 or higher.

Add Google Play Services Wallet

Google Pay is only available with Google Play Services Wallet 16.0.1 or later. If you are not including Google Play Services, add com.google.android.gms:play-services-wallet:16.0.1 to your build.gradle or visit Google's developer documentation for additional information.

Ensure you have also included the wallet enabled meta-data tag in your AndroidManifest.xml:

XML
<meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true"/>

Add Braintree GooglePayment component

Google released a new major version of Google Pay in 2018. To use Google Pay v2, include Braintree's google-payment component in your dependencies:

Groovy
dependencies {
  // Braintree dependencies
  implementation 'com.braintreepayments.api:braintree:2.22.0'
  implementation 'com.braintreepayments.api:google-payment:2.0.1'

  // Google dependencies
  implementation 'com.google.android.gms:play-services-wallet:16.0.1'
}

Without the explicit inclusion of the google-payment dependency, Google Pay v1 will be used. While existing integrations with Google Pay v1 work, keep in mind that Google has removed their Google Pay v1 documentation. In addition, to support PayPal via Google Pay, you must use Google Pay v2.

Initialization

First use a tokenization key or get a client token from your server and initialize BraintreeFragment.

Then register a listener to receive a payment method nonce once the Google Pay flow finishes.

Before showing the Google Pay button, use the GooglePayment#isReadyToPay method to check whether the user's current device is compatible. When this method returns true, show the Google Pay button. When it returns false, display other checkout options.

Java
GooglePayment.isReadyToPay(mBraintreeFragment, new BraintreeResponseListener<Boolean>() {
  @Override
  public void onResponse(Boolean isReadyToPay) {
    if (isReadyToPay) {
      // Show Google Pay button
    }
  }
});

You will need a button element on your page styled according to Google's brand guidelines.

The CARD payment method type is supplied by the Braintree Android SDK as an allowed payment method when making the IsReadyToPayRequest. It also provides the PAYPAL payment method type if you are using Google Pay v2 and currently accept PayPal payments. If you desire different behavior for the IsReadyToPayRequest, you can follow Google's documentation and make the IsReadyToPayRequest outside of the Braintree Android SDK.

Requesting a payment

To accept Google Pay, you can either use our SDK for the entire integration or integrate with Google directly.

Direct integration with Google Play Services can be useful if you already have an existing integration with the Google Payment API or wish to integrate directly for other reasons; otherwise, we recommend using our SDK.

Braintree SDK integration

Google Pay requires a price to be specified using the TransactionInfo object. Build a TransactionInfo object and provide it at the time of payment, along with your Google-provided googleMerchantId for production transactions.

Java
GooglePaymentRequest googlePaymentRequest = new GooglePaymentRequest()
  .transactionInfo(TransactionInfo.newBuilder()
    .setTotalPrice("1.00")
    .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)
    .setCurrencyCode("USD")
    .build())
  // We recommend collecting billing address information, at minimum
  // billing postal code, and passing that billing postal code with all
  // Google Pay card transactions as a best practice.
  .billingAddressRequired(true)
  // Optional in sandbox; if set in sandbox, this value must be a valid production Google Merchant ID
  .googleMerchantId("merchant-id-from-google");

Call GooglePayment#requestPayment when your Google Pay button is clicked to kick off the Google Pay flow.

Java
GooglePayment.requestPayment(mBraintreeFragment, googlePaymentRequest);

If completed successfully, a GooglePaymentCardNonce or PayPalAccountNonce will be passed to your PaymentMethodNonceCreatedListener. If canceled, your BraintreeCancelListener will be called; if unsuccessful, an error will be passed to your BraintreeErrorListener.

Direct Google Play Services integration

For direct integration via Google Pay v2, we recommend reading Google's complete tutorial, and referencing their migration guide to upgrade existing integrations from Google Pay v1 to v2.

To tokenize with the result of a successful direct Google Play Services integration, call GooglePayment#tokenize on the PaymentData received from PaymentsClient#loadPaymentData:

Java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == GOOGLE_PAYMENT_REQUEST_CODE && resultCode == RESULT_OK) {
    GooglePayment.tokenize(mBraintreeFragment, PaymentData.getFromIntent(data))
  }
}

The resulting GooglePaymentCardNonce or PayPalAccountNonce will be returned in your PaymentMethodNonceCreatedListener implementation.

Next Page: Server-side →