In-App Payments SDK

Enable Google Pay

This document provides step-by-step instructions for integrating Google Pay with the In-App Payments SDK on an Android device.

Java (Android)



To enable Google Pay with In-App Payments SDK on Android, the following must be true:

Step 1: Add Google Pay build dependencies

  1. Add the Google Pay binary dependency to the build.gradle file of your :app module.
dependencies {
 implementation ''
 implementation ''
  1. Update your AndroidManifest.xml file to include the following <meta-data/> element.
    android:value="true" />

Step 2: Add a Google Pay item to your activity layout

Add a clickable item to your activity layout for starting a Google Pay payment.
In Step 5, you will add an onClickListener to this control.

Step 3: Declare fields in your activity that support Google Pay

  private static final String LOCATION_ID = "LOCATION_ID";
  private static final int LOAD_PAYMENT_DATA_REQUEST_CODE = 1;
  private PaymentsClient paymentsClient;
  private Button googlePayButton;

Step 4: Enable Google Pay in your activity onCreate method

  1. Create a Google Pay payments client that is configured for a testing environment.

See the Google Pay tutorial for more information about creating a client.

paymentsClient = Wallet.getPaymentsClient(
  new Wallet.WalletOptions.Builder()
  1. Set Google Pay button onClickListener.

Replace YOUR_ACTIVITY_CLASS_NAME with the type name of the your activity and YOUR_LOCATION_ID string in the example code with a valid Square location ID. The available location IDs for a Square account can be found on the Locations tab of the Square Developer Portal.

googlePayButton.setOnClickListener((view) -> {
      (YOUR_ACTIVITY_CLASS_NAME) view.getContext(),
  1. Request "ready to pay" status and enable Google Pay button if ready to pay. See the Google Pay tutorial for more information about getting pay status.
        .addOnCompleteListener(this, (task) ->

Step 5: Get Google Pay token in your activity onActivityresult method

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == LOAD_PAYMENT_DATA_REQUEST_CODE) {
    if (resultCode == Activity.RESULT_OK) {
      PaymentData paymentData = PaymentData.getFromIntent(data);
      if (paymentData != null && paymentData.getPaymentMethodToken() != null) {
        String googlePayToken = paymentData.getPaymentMethodToken().getToken();

        //Request a nonce, save Card on File, and take a payment
        GooglePayToSquare googlePayToSquare = new GooglePayToSquare();
        googlePayToSquare.activity = this;

Step 6: Add a class to collect payment card information and return a nonce.

public final class GooglePayToSquare {

  @Nullable Activity activity;
  String nonce;

  public void createNonce(String googlePayToken) {
    GooglePay.requestGooglePayNonce(googlePayToken).enqueue(result -> {
      if (activity == null) {
      if (result.isSuccess()) {
        nonce = result.getSuccessValue().getNonce();
     // MyBackendServiceResponse response = ...// TODO Call your backend service
     // with the nonce. See Square In-App Payments Server Quick Start for a backend
     // service example.

      } else if (result.isError()) {


  private void takePayment(String nonce, Long paymentAmount) {
   //Make a server API call to take the payment

Step 7: Prepare to distribute your app in production

When your Google Pay integration has passed your testing procedures and you are ready to distribute your app in a production environment, complete the following tasks:

  1. Set the client environment to production by using WalletConstants.ENVIRONMENT_PRODUCTION.
paymentsClient = Wallet.getPaymentsClient(
  new Wallet.WalletOptions.Builder()
  1. Complete the Google Pay Integration checklist. If you have integrated Google Pay as described in the setup guide steps, the exit criteria for basics and branding testing checklist items will be met. The exit criteria for Functional testing checklist items 4 – 9 can only be met by your application logic.

  2. Complete a Google Pay API Production Access Enablement Request Form.

    • The Tokenization Method must be "gateway".
    • The Payment Processor or Gateway form field must contain "square".

Contact Developer Support, join our Slack channel, or ask for help on Stack Overflow