Google Pay

import { LoadFilesGoogleCodeBlock } from '~/components/CodeBlockInstances/GooglePay/LoadFiles.tsx'

Client-Side Implementation

Important
The SSL certificates for Braintree Mobile (iOS and Android) SDKs are set to expire on March 30, 2026. This will impact existing versions of the SDK in published versions of your app. To reduce the impact, upgrade the iOS SDK to version 6.17.0+Android SDK to version 4.45.0+ or version 5.0.0+ for the new SSL certifications. If you do not decommission your app versions that include the older SDK versions or force upgrade your app with the updated certificates by the expiration date, 100% of your customer traffic will fail.

Choose an integration methodAnchorIcon

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

Drop-in integrationAnchorIcon

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 integrationAnchorIcon

Get the SDKAnchorIcon

Add the following in your app-level build.gradle:

  1. Kotlin
  2. Groovy
dependencies { implementation("com.braintreepayments.api:google-pay:4.49.1") }

InitializationAnchorIcon

First, create a BraintreeClient with a ClientTokenProvider or Tokenization Key. Then construct a GooglePayClient. Before showing the Google Pay button, use the GooglePayClient#isReadyToPay method to check whether the user's current device is compatible. When the result is true, show the Google Pay button. When the result is false, display other checkout options.

  1. Kotlin
  2. Java
braintreeClient = BraintreeClient(this, ExampleClientTokenProvider()) googlePayClient = GooglePayClient(this, braintreeClient) googlePayClient.isReadyToPay(this) { isReadyToPay, error -> 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 paymentAnchorIcon

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. Implement a GooglePayListener to receive results, and call 'requestPayment' to invoke the payment flow.

  1. Java
  2. Kotlin
public class MyActivity extends AppCompatActivity implements GooglePayListener { private BraintreeClient braintreeClient; private GooglePayClient googlePayClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); braintreeClient = new BraintreeClient(this, new ExampleClientTokenProvider()); googlePayClient = new GooglePayClient(this, braintreeClient); googlePayClient.setListener(this); } public void onGooglePayButtonClick(View view) { GooglePayRequest googlePayRequest = new GooglePayRequest(); googlePayRequest.setTransactionInfo(TransactionInfo.newBuilder() .setTotalPrice("1.00") .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL) .setCurrencyCode("USD") .build()); googlePayRequest.setBillingAddressRequired(true); googlePayClient.requestPayment(this, googlePayRequest); } @Override public void onGooglePaySuccess(@NonNull PaymentMethodNonce paymentMethodNonce) { // send paymentMethodNonce.getString() to server } @Override public void onGooglePayFailure(@NonNull Exception error) { if (error instanceof UserCanceledException) { // user canceled } else { // handle error } } }

Get the SDKAnchorIcon

Add the following in your app-level build.gradle:

  1. Kotlin
  2. Groovy
dependencies { implementation("com.braintreepayments.api:google-pay:5.2.0") }

InitializationAnchorIcon

Create a GooglePayLauncher inside of your Activity's onCreate(). The GooglePayLauncherCallback is invoked after the buyer leaves the Google Pay Flow. Create a GooglePayClient with a Tokenization Key or Client Token. Before showing the Google Pay button, use the GooglePayClient.isReadyToPay() function to check whether the user's current device is compatible. When the result is GooglePayReadinessResult.ReadyToPay, show the Google Pay button. When the result is not GooglePayReadinessResult.ReadyToPay, display other checkout options.

  1. Kotlin
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // GooglePayLauncher must be initialized in onCreate googlePayLauncher = GooglePayLauncher(this) { // Handle GooglePayPaymentAuthResult } // can initialize the GooglePayClient outside of onCreate if desired googlePayClient = GooglePayClient(this, "[TOKENIZATION_KEY or CLIENT_TOKEN]") googlePayClient.isReadyToPay(this) { googlePayReadinessResult -> if (googlePayReadinessResult is GooglePayReadinessResult.ReadyToPay) { // 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 calling isReadyToPay(). 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 than isReadyToPay(), you can follow Google's documentation and make the IsReadyToPayRequest outside of the Braintree Android SDK.

Requesting a paymentAnchorIcon

After the user clicks the Google Pay button, create a GooglePayRequest and call GooglePayClient.createPaymentAuthRequest() and handle its result. If the result is ReadyToLaunch, invoke GooglePayLauncher.launch() to launch the Google Pay flow. If the result is Failure, handle the error.

  1. Kotlin
private fun onGooglePayButtonClick() { val googlePayRequest = GooglePayRequest( currencyCode = "USD", totalPrice = "12.34", totalPriceStatus = GooglePayTotalPriceStatus.TOTAL_PRICE_STATUS_FINAL ) googlePayClient.createPaymentAuthRequest(googlePayRequest) { googlePayPaymentAuthRequest -> when (googlePayPaymentAuthRequest) { is GooglePayPaymentAuthRequest.ReadyToLaunch -> { googlePayLauncher.launch(googlePayPaymentAuthRequest) } is GooglePayPaymentAuthRequest.Failure -> { // Handle error } } } }
When the user completes or cancels the Google Pay flow, the GooglePayLauncherCallback will be invoked. Inside of that callback call GooglePayClient.tokenize(), passing in the GooglePayPaymentAuthRequest. Handle the GooglePayResult returned in the GooglePayTokenizeCallback.
  1. Kotlin
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) googlePayLauncher = GooglePayLauncher(this) { googlePayPaymentAuthResult -> googlePayClient.tokenize(googlePayPaymentAuthResult) { googlePayResult -> when (googlePayResult) { is GooglePayResult.Failure -> { /* handle error */ } is GooglePayResult.Cancel -> { /* handle cancel */ } is GooglePayResult.Success -> { /* handle nonce */ } } } } }

Complete IntegrationAnchorIcon

  1. Kotlin
class MyActivity : AppCompatActivity() { private lateinit var googlePayLauncher: GooglePayLauncher private lateinit var googlePayClient: GooglePayClient override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // GooglePayLauncher must be initialized in onCreate googlePayLauncher = GooglePayLauncher(this) { googlePayPaymentAuthResult -> googlePayClient.tokenize(googlePayPaymentAuthResult) { googlePayResult -> when (googlePayResult) { is GooglePayResult.Failure -> { /* handle error */ } is GooglePayResult.Cancel -> { /* handle cancel */ } is GooglePayResult.Success -> { /* handle nonce */ } } } } // can initialize the GooglePayClient outside of onCreate if desired googlePayClient = GooglePayClient(this, "[TOKENIZATION_KEY or CLIENT_TOKEN]") googlePayClient.isReadyToPay(this) { googlePayReadinessResult -> if (googlePayReadinessResult is GooglePayReadinessResult.ReadyToPay) { // show Google Pay button } } } private fun onGooglePayButtonClick() { val googlePayRequest = GooglePayRequest( currencyCode = "USD", totalPrice = "12.34", totalPriceStatus = GooglePayTotalPriceStatus.TOTAL_PRICE_STATUS_FINAL ) googlePayClient.createPaymentAuthRequest(googlePayRequest) { googlePayPaymentAuthRequest -> when (googlePayPaymentAuthRequest) { is GooglePayPaymentAuthRequest.ReadyToLaunch -> { googlePayLauncher.launch(googlePayPaymentAuthRequest) } is GooglePayPaymentAuthRequest.Failure -> { // Handle error } } } } }

If you accept cookies, we’ll use them to improve and customize your experience and enable our partners to show you personalized PayPal ads when you visit other sites. Manage cookies and learn more