Google Pay

Google Pay

The Google Pay offers a quick and easy path to enable secure, one touch payments in your app.
This guide explains how to process payments with our SDK.

Requirements

  • A Mobile SDK integration (Ready-to-Use UI or SDK & Your Own UI)
  • A Google account, when you're ready to deploy your Google Pay integration, sign-up to get access and test with production credentials.

Configuration

Open the build.gradle file in the app module and add the following to the dependencies block:

dependencies {
    compile 'com.google.android.gms:play-services-wallet:11.4.0'
    compile 'com.android.support:support-v4:24.1.1'
    compile 'com.android.support:appcompat-v7:24.1.1'
}

NOTE: The device must have Google Play Services version 11.4.x or newer installed.

You can find detailed instructions in the Google Payment API.

Adding the Google Pay to your app must be done in one of two ways, depending on whether you are using the Ready-to-Use UI or the SDK & Your Own UI. These two ways are covered in the sections below. Please follow the instructions relevant to the approach you have chosen.

Ready-to-Use UI

Create the CheckoutSettings, and add the PAYWITHGOOGLE payment brand:

Set<String> paymentBrands = new HashSet<String>();
paymentBrands.add("PAYWITHGOOGLE");

CheckoutSettings checkoutSettings = new CheckoutSettings(checkoutId, paymentBrands, Connect.ProviderMode.TEST);

Set the entity id, allowed payment methods and allowed card networks:

checkoutSettings.setEntityId(YOUR_ENTITY_ID);
checkoutSettings.setPayWithGoogleAllowedPaymentMethods(new Integer[] {
        WalletConstants.PAYMENT_METHOD_CARD,
        WalletConstants.PAYMENT_METHOD_TOKENIZED_CARD
});
checkoutSettings.setPayWithGoogleAllowedCardNetworks(new Integer[] {
        WalletConstants.CARD_NETWORK_VISA,
        WalletConstants.CARD_NETWORK_MASTERCARD,
        WalletConstants.CARD_NETWORK_AMEX,
        WalletConstants.CARD_NETWORK_DISCOVER,
        WalletConstants.CARD_NETWORK_JCB
});

If you are using CheckoutActivity, set up the Intent and start the activity:

Intent intent = checkoutSettings.createCheckoutActivityIntent(this);

startActivityForResult(intent, CheckoutActivity.REQUEST_CODE_CHECKOUT);

If you integrate the Google Pay using our drop-in buttons, set the PAYWITHGOOGLE payment brand.

PaymentButtonFragment paymentButtonFragment = new PaymentButtonFragment();

paymentButtonFragment.setPaymentBrand("PAYWITHGOOGLE");

SDK & Your Own UI

Follow this tutorial to integrate the Google Pay into your UI. To make a transaction create the PayWithGooglePaymentParams with a received token:

PaymentParams paymentParams = new PayWithGooglePaymentParams(checkoutId, token);

And submit the transaction:

Transaction transaction = null;

try {
    transaction = new Transaction(paymentParams);
    binder.submitTransaction(transaction);
} catch (PaymentException ee) {
    /* error occurred */
}