This site requires javascript to be enabled.

Google Pay

Results for

Results for Searching
Page topics

We also offer Google Pay for native Android applications. Our client Android SDK will help you implement Google Pay in your app and we decrypt the sensitive payment data for you.

You need to take care of the following steps:

  • Enable Google Pay with us
  • Follow the setup guidelines provided by Google
  • Implement Google Pay in your app
  • Apply with Google for production access (on Google's side)

Enabling Google Pay on your account with us

First make sure Google Pay is enabled for the account (merchantId) you have with us. To do so contact your account manager who will work together with your implementation manager. They will be able to set the product up for you. You will also need to have regular card products configured in case you use Google Pay, as Google Pay allows consumers to pay with regular PANs. The transactions which are paid with regular PANS will be processed as regular card payments and it is highly recommended to apply 3-D Secure and fraud validations on these transactions.

Follow the setup guidelines provided by Google

Google has a clear overview of the prerequisites you need to follow before you implement the Google Pay API, which are described on the setup section of the Google documentation. This includes adhering to the Google Pay API Acceptable Use Policy as well as the Google Play developer policy. In case Google processes payments for you or in case you sell digital goods, such as movies or games, you should use Google Play In-app Billing.

Implementing Google Pay in your app

Next you can start with the technical integration. Google offers a very clear and concise tutorial on how to implement Google Pay in your app. The technical integration section on this page, explains you the additional steps you need to take to add Google Pay to your native app.

Since you use us for decrypting the sensitive payment data, the type to use in  tokenizationSpecification as referred to by Google is: PAYMENT_GATEWAY and the gateway to use is returned in the response of the Get payment product call, in the paymentProduct320SpecificData.gateway property.

1. Retrieve Google Pay via the payment product(s) API

As with Google Pay on the web payments, Google Pay may not always be available for your customer. The client Android SDK makes it easy for you by simply hiding the Google Pay payment product from the get Payment Product(s) responses. So if Google Pay is not available for the current payment, based on the user's device, it will not be returned. For the get Payment Product call this means that a null value will be returned instead.

Check availability of Google Pay
private void getGooglePayPaymentProduct() {
    // session is an already initialized instance of the SDK's GcSession object
    session.getPaymentProduct(
        this,     // Instance of Android ApplicationContext 
        Constants.PAYMENTPRODUCTID_GOOGLEPAY,
        paymentContext, 
        this.     // Implementation of OnPaymentProductCallCompleteListener
); } /** * Implementation of the callback method for retrieving a payment product */ @Override public void onPaymentProductCallComplete(PaymentProduct paymentProduct) { if (paymentProduct != null) { if (Constants.PAYMENTPRODUCTID_GOOGLEPAY.equals(paymentProduct.getId())) { // Google Pay is available, render the Google Pay button. } else { // A different product was retrieved.. } } else { // Google Pay is not available, we should not render it. } }

2. Strong Customer Authentication (SCA) compliance

In case you use an acquirer that is based in one of the European Economic Area (EEA) countries, you need to make sure that you provide information about the country of the acquirer in transactionInfo.countryCode towards Google, to be compliant with the PSD2 Strong Customer Authentication (SCA) requirements. Google Pay will return the appropriate credentials for transactions based on the country of the acquirer used for this transaction.

The acquirerCountry which you need to provide to Google can be retrieved by a payment product call via the server-to-server API or the client-to-server API. This code snippet below shows you how to obtain the acquirerCountry for the transactionInfo object. You also need to include the totalPrice, the totalPriceStatus and the merchantName parameters as described in step 7 of the Google Pay tutorial as well as in the Strong Customer Authentication section on Google's documentation site.

More information on Strong Customer Authentication compliance for Google Pay can be found at Google Pay API documentation.

Obtain Google Pay parameters
private JSONObject initializeGooglePayValues(PaymentContext paymentContext, PaymentProduct googlePayProduct) {
    
    JSONObject paymentRequest = new JSONObject();
    try {


        // Initialize other payment request values.


        JSONObject transactionInfo = new JSONObject();
        transactionInfo.put("totalPriceStatus", "FINAL");
        String totalPrice = formatAmount(paymentContext.getAmountOfMoney().getAmount().toString());
        transactionInfo.put("totalPrice", totalPrice);
        transactionInfo.put("currencyCode", paymentContext.getAmountOfMoney().getCurrencyCode().toString());
        if (paymentProduct.getAcquirerCountry() != null) {
            transactionInfo.put("countryCode", googlePayProduct.getAcquirerCountry());
        }
        paymentRequest.put("transactionInfo", transactionInfo);
        
    } catch (JSONException e) {
        // Something went wrong when generating the JSON payment input.
    }
    
    return paymentContext;
}

/**
 * Formats the amount used in the Connect platform to the format Google is expecting.
 */
private String formatAmount(String amount) {
    String formattedAmount = "00" + amount;
    formattedAmount = formattedAmount.substring(0, formattedAmount.length() - 2)
            + "."
            + formattedAmount.substring(formattedAmount.length() - 2);
    return formattedAmount;
}

3. Rendering the Google Pay button

Google provides a tutorial for implementing Google Pay in Android. The tutorial shows you how to render the Google Pay button, bring up the payment sheet and receive the payment token as soon as your consumer is done paying.

4. Preparing and sending the payment token

When you receive the response data from the Google Pay payment sheet, some data needs to be extracted to create a payment with us. The code sample below shows how to extract the Google Pay payment token from the PaymentData object.

Extracting the payment token
/**
 * This method extracts the Google Pay payment token from the PaymentData object that 
 *    is returned when the user has authorized the payment in the payment sheet.
 * @param paymentData The Google Pay paymentData object that is returned by the payment sheet.
 * @return The payment token as a String in the format that is accepted by the Connect
 *    Create Payment API.
 */
private String getGooglePayTokenFromPaymentData(PaymentData paymentData) {
    String json = paymentData.toJson();
    if (json != null && !json.isEmpty()) {
        try {
            JSONObject paymentDataJson = new JSONObject(json);
            return paymentDataJson
                    .getJSONObject("paymentMethodData")
                    .getJSONObject("tokenizationData")
                    .getString("token");
        } catch (JSONException e) {
            Log.e(TAG, "Payment Token is not in a valid JSON format");
        }
    } else {
        Log.e(TAG, "Only PaymentData in JSON format is accepted.");
    }
    return null;
}

The Google Pay payment token has to be send to your servers. Your backend server can use the server-to-server SDK to make a call to the create Payment API. Depending on your preferences you can provide the Google Pay payment token in the Create Payment API in the following ways:

  1. encryptedCustomerInput This is the default option for providing payment data from clients. The field is normally used for providing payment details that are not already encrypted, such as credit card details provided through input fields. When you already use our Android SDK to process payments in your app, this is probably the most convenient option to provide the token. Below is an example how to prepare the token in case you send it in the encryptedCustomerInput.

    Encrypt payment details
    private void createPreparedPaymentRequestGooglePay(String token, PaymentProduct googlePay) {
        PaymentRequest paymentRequest = new PaymentRequest();
        paymentRequest.setPaymentProduct(googlePay); // This is the Google Pay PaymentProduct object, which is the result of the getPaymentProduct call that was done before
        
        if (token != null && !token.isEmpty()) {
            paymentRequest.setValue(Constants.GOOGLE_PAY_TOKEN_FIELD_ID, token);
        
            // Prepare the payment request by encrypting the payment values
            session.preparePaymentRequest(
                paymentRequest, 
                this,     // Instance of Android ApplicationContext 
                this      // Implementation of OnPaymentRequestPreparedListener 
    ); } else { // Notify the user that an error has occurred } } /** * Implementation of the callback for encrypting the payment values */ @Override public void onPaymentRequestPrepared(PreparedPaymentRequest preparedPaymentRequest) { if (preparedPaymentRequest != null) { String encryptedFields = preparedPaymentRequest.getEncryptedFields(); // Send the encryptedFields to your backend } else { // Something went wrong, notify the user } }
    From your backend server, send a Create Payment request via our server to server API.
    Create Payment with encryptedCustomerInput
    {
        "order" : {
            "amountOfMoney" : {
                "currencyCode" : "EUR",
                "amount" : 2980
            },
            "customer" : {
                "locale" : "en_US",
                "merchantCustomerId" : "1234",
                "billingAddress": {
                    "countryCode": "NL"
                }
            }
        },
        "mobilePaymentMethodSpecificInput": {
            "paymentProduct320SpecificInput": {
                "threeDSecure": {
                    "challengeCanvasSize": "full-screen",
                    "redirectionData": {
                        "returnUrl": "myapp://myapp.com"
                    }
                }
            }
        },
        "encryptedCustomerInput": "<The encryptedFields>"
    }
  2. mobilePaymentMethodSpecificInput.encryptedPaymentData This field can be used to send the Google Pay payment token as obtained in the examples above, without further processing. If you use this field, simply send the payment token to your backend server as is. When creating the payment, make sure to also provide the mobilePaymentMethodSpecificInput.paymentProductId field.
    Create Payment with encryptedPaymentData
    {
        "order" : {
            "amountOfMoney" : {
                "currencyCode" : "EUR",
                "amount" : 2980
            },
            "customer" : {
                "locale" : "en_US",
                "merchantCustomerId" : "1234",
                "billingAddress": {
                    "countryCode": "NL"
                }
            }
        },
        "mobilePaymentMethodSpecificInput": {
            "encryptedPaymentData": "<Payment token>",
            "paymentProductId": 320,
            "paymentProduct320SpecificInput": {
                "threeDSecure": {
                    "challengeCanvasSize": "full-screen",
                    "redirectionData": {
                        "returnUrl": "myapp://myapp.com"
                    }
                }
            }
        }
    }
  3. 5. Apply with Google for production access

    After implementation of Google Pay on your own website, you need to register with Google, obtain your merchant ID and get approval for the usage of Google Pay on your checkout page. It is highly recommended to follow the integration checklist provided by Google. You can find the details on Google's documentation site in the section "Request production access" as well as "deploy production environment".