Click here to search the entire website

Google Pay

Everything you need to take Google Pay payments via an app:

How it works

  1. You request the encrypted payload from your app

  2. Google Pay returns the encrypted payload following shopper authentication

  3. You send the encrypted payload to your server

  4. You send an XML Direct request to Worldpay containing the encrypted data

  5. We send you the payment response

  6. You inform the shopper of the outcome

Setup

Prerequisites

You need:

  • A Direct integration to Worldpay

  • A Google account

  • Worldpay to enable Google Pay on your account

  • To contact Google in order to add your app to their system for production use.

Merchant ID

When Google Pay is enabled on your Worldpay account, you can generate your own Merchant ID using the Worldpay MAI.

Set up Google Pay

For detailed instructions on how to configure Google Pay for in-app payments, see: https://developers.google.com/payments/setup

Integrate with Google Pay

See the Google Payment API guide - https://developers.google.com/payments/mobile-web-tutorial

Set the allowedCardNetworks property

Worldpay only supports Google Pay payments with Visa, Mastercard and American Express (Amex) cards.

private PaymentDataRequest createPaymentDataRequest() {

  PaymentDataRequest.Builder request =

    PaymentDataRequest.newBuilder()

      .setTransactionInfo(

        TransactionInfo.newBuilder()

          .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)

          .setTotalPrice("10.00")

          .setCurrencyCode("USD")

          .build())

      .addAllowedPaymentMethod(WalletConstants.PAYMENT_METHOD_CARD)

      .addAllowedPaymentMethod(WalletConstants.PAYMENT_METHOD_TOKENIZED_CARD)

      .setCardRequirements(

        CardRequirements.newBuilder()

          .addAllowedCardNetworks(

            Arrays.asList(

              WalletConstants.CARD_NETWORK_AMEX,

              WalletConstants.CARD_NETWORK_VISA,

              WalletConstants.CARD_NETWORK_MASTERCARD))

          .build());

 

  PaymentMethodTokenizationParameters params =

    PaymentMethodTokenizationParameters.newBuilder()

      .setPaymentMethodTokenizationType(

        WalletConstants.PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY)

      .addParameter("gateway", "worldpay")

      .addParameter("gatewayMerchantId", "MerchantIdProvidedByWorldpay")

      .build();

 

  request.setPaymentMethodTokenizationParameters(params);

  return request.build();

}

Extract the payload data

Extract the data from the Android device payload using the following:

@Override

public void onActivityResult(int requestCode, int resultCode, Intent data) {

  switch (requestCode) {

    case LOAD_PAYMENT_DATA_REQUEST_CODE:

      switch (resultCode) {

        case Activity.RESULT_OK:

          PaymentData paymentData = PaymentData.getFromIntent(data);

          String token = paymentData.getPaymentMethodToken().getToken();

 

          JSONObject obj = new JSONObject(token);

          // Data below goes into the XML message

          String signature = obj.getString("signature");

          String protocolVersion = obj.getString("protocolVersion");

          String signedMessage = obj.getString("signedMessage");

...

Integrate with Worldpay

Prerequisite:  You've successfully integrated with Google Pay to your app, and can generate an encrypted payload.

When you've generated an encrypted payload, and have passed this to your server, send the payload to us within <PAYWITHGOOGLE-SSL>.

Example XML request

Select

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE paymentService PUBLIC "-//WorldPay/DTD WorldPay PaymentService v1//EN"

  "http://dtd.worldpay.com/paymentService_v1.dtd">

<paymentService version="1.4" merchantCode="YOUR_MERCHANT_CODE">

  <submit>

    <order orderCode="YOUR_ORDER_CODE" shopperLanguageCode="en">

      <description>GOOGLE_PAY_TEST_ORDER</description>

      <amount value="100" currencyCode="GBP" exponent="2"/>

      <orderContent>

        <![CDATA[]]>

      </orderContent>

      <paymentDetails>

        <PAYWITHGOOGLE-SSL>

          <protocolVersion>AAAAAA...</protocolVersion>

          <signature>AAAAAA...</signature>

          <signedMessage>AAAAAA...</signedMessage>

        </PAYWITHGOOGLE-SSL>

      </paymentDetails>

      <shopper>

        <shopperEmailAddress>shopper@worldpay.com</shopperEmailAddress>

      </shopper>

    </order>

  </submit>

</paymentService>

Example payload

Here's an example of the payload within <PAYWITHGOOGLE-SSL>:

<PAYWITHGOOGLE-SSL>

  <protocolVersion>ECv1</protocolVersion>

  <signature>TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ</signature>

  <signedMessage>{"encryptedMessage":"qrnk5KIV1syX8xuaJYpjAxjvTmAfH4arrxK+5wT4XNsn+K/21QC5KyNyXVnaZsfz+FjYeZcZyTDsAXMGp01u9Psq3wp/9aJJyZ9PS9+G2sVJ+symppSvIHhPYxfcFLyvDxcU7J2ZUIU2o7ZAsHkc9eUL0zqcjTfRxxyladBQmP3mjy7OtIZbXodSr5vZZqKrRm0MqmPo/ISYor0gPmv+l+wRdLmCugdhBrg6mFGMuMBtnIjdtOZ+o4iSl4NqYo4BnI1py4GXG78FPHAlqU9Im+a9V6CtOsVG1eiLCn616fI8WorvPU46bDL7UApF/+vRF6lJviV9Ie9pUJHejO5Z17GPTfBuxO8ZAPWqcPY\u003d","ephemeralPublicKey":"BJ8xDzqkngvLUZcOAkqgkYpwGIHi2TzOXO6ZDJpKHPJCnJZ5WZOTO0HtNrTiOgiVc2gdZQ+TWmcy2Y1KnNsAGpg\u003d","tag":"5t5pipJgyhxJUg9XcymYcdcKmtBxQ71VvF2uhnempbs\u003d"}</signedMessage>

</PAYWITHGOOGLE-SSL>

Response

The response message is the same as our standard XML responses.

Test

Google Pay is supported in the Worldpay Sandbox. Please use the WalletConstants.ENVIRONMENT_TEST parameter for any test transactions and the WalletConstants.ENVIRONMENT_PRODUCTION parameter for production transactions.

Worldpay’s Sandbox environment is set up to recognise dummy details and simulate a successful AUTHORISED transaction.

Google provide further testing details at: https://developers.google.com/payments/test-and-deploy

Useful links

General

Google Payment API - Guides and Tutorials: https://developers.google.com/payments/

Software development links

Android Studio: http://developer.android.com/sdk/index.html

Android Tutorial: https://developers.google.com/payments/tutorial

Android Test and Deploy: https://developers.google.com/payments/test-and-deploy

Android Developer Support library: https://developer.android.com/topic/libraries/support-library/setup.html

Google's GitHub sample: https://github.com/android-pay/paymentsapi-quickstart