Collecting payment information through Google Pay

    Allow customers to securely make payments using Google Pay on their Android devices. Google Pay allows customers to make payments in your app or website using any credit or debit card saved to their Google Account, including ones from Google Play, YouTube, Chrome or an Android device.

    Setting up your integration with Google Pay

    To use Google Pay, first enable the Google Pay API by adding the following to the <application> tag of your AndroidManifest.xml:

        android:value="true" />

    You must also be using Google Play Services 11.4.0 or later:

    dependencies {
      compile ''
      // You'll also need the support-v4 and appcompat-v7 libraries
      compile ''
      compile ''

    Next, create an instance of PaymentsClient in your Activity. This allows you to access the Payments APIs. Do this before you start the payment flow, such as in onCreate.

    PaymentsClient paymentsClient =
        new Wallet.WalletOptions.Builder().setEnvironment(WalletConstants.ENVIRONMENT_TEST)

    After creatingPaymentsClient, create an instance of IsReadyToPayRequest to see whether or not to display Google Pay as an option.

    private void isReadyToPay() {
      IsReadyToPayRequest request = IsReadyToPayRequest.newBuilder()
      Task<Boolean> task = paymentsClient.isReadyToPay(request);
          new OnCompleteListener<Boolean>() {
            public void onComplete(Task<Boolean> task) {
              try {
                boolean result =
                if(result == true) {
                  //show Google as payment option
                } else {
                  //hide Google as payment option
              } catch (ApiException exception) { }

    When the user is ready to pay, create a PaymentDataRequest object. The PaymentDataRequest object is a Parcelable representing a request for methods of payment (such as a credit card) and other details. It provides the necessary information to support a payment.

    To create a PaymentDataRequest object using Stripe as your gateway, create a PaymentMethodTokenizationParameters object with your credentials.

    private PaymentMethodTokenizationParameters createTokenizationParameters() {
      return PaymentMethodTokenizationParameters.newBuilder()
        .addParameter("gateway", "stripe")
        .addParameter("stripe:publishableKey", "pk_test_TYooMQauvdEDq54NiTphI7jx")
        .addParameter("stripe:version", "2018-11-08")

    Once you have your tokenization parameters, create the PaymentDataRequest object with the information relevant to the purchase.

    private PaymentDataRequest createPaymentDataRequest() {
      PaymentDataRequest.Builder request =

    Now that you’ve established a way to create the payment data request, hook up that method to your “Buy” button’s click handler.

      new View.OnClickListener() {
        public void onClick(View view) {
          PaymentDataRequest request = createPaymentDataRequest();
          if (request != null) {
              // LOAD_PAYMENT_DATA_REQUEST_CODE is a constant integer of your choice,
              // similar to what you would use in startActivityForResult

    Invoking the AutoResolveHelper’s resolveTask function with a PaymentDataRequest will launch Google Pay. In order to handle the result of this action, listen for it in the onActivityResult function of your Activity.

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
      switch (requestCode) {
          switch (resultCode) {
            case Activity.RESULT_OK:
              PaymentData paymentData = PaymentData.getFromIntent(data);
              // You can get some data on the user's card, such as the brand and last 4 digits
              CardInfo info = paymentData.getCardInfo();
              // You can also pull the user address from the PaymentData object.
              UserAddress address = paymentData.getShippingAddress();
              // This is the raw JSON string version of your Stripe token.
              String rawToken = paymentData.getPaymentMethodToken().getToken();
              // Now that you have a Stripe token object, charge that by using the id
              Token stripeToken = Token.fromString(rawToken);
              if (stripeToken != null) {
                  // This chargeToken function is a call to your own server, which should then connect
                  // to Stripe's API to finish the charge.
            case Activity.RESULT_CANCELED:
            case AutoResolveHelper.RESULT_ERROR:
              Status status = AutoResolveHelper.getStatusFromIntent(data);
               // Log the status for debugging
               // Generally there is no need to show an error to
               // the user as the Google Payment API will do that
              // Do nothing.
        break; // Breaks the case LOAD_PAYMENT_DATA_REQUEST_CODE
          // Handle any other startActivityForResult calls you may have made.
          // Do nothing.

    Going live with Google Pay

    1. Build your app in ENVIRONMENT_TEST mode and use the test credentials from Stripe.

    2. Reach out to Google support.
    3. Send the APK pointing to ENVIRONMENT_TEST to Google support when requested.

    4. Google assesses the app against their integration checklist and provides feedback if needed.
    5. Google provides instructions on how to agree to their Terms of Service and ensure production access is granted.
    6. Send your final production APK pointing to ENVIRONMENT_PRODUCTION to Google for a real-world test which includes a few transactions.

    7. If all tests pass, Google clears you to publish the APK.
    8. Notify Google support when your APK is 100% visible to users.


    We're always happy to help with code or other questions you might have! Search our documentation, contact support, or connect with our sales team. You can also chat live with other developers in #stripe on freenode

    Was this page helpful? Yes No


    Thank you for helping improve Stripe's documentation. If you need help or have any questions, please consider contacting support.