Skip to content
Sample project that shows how to integrate Google Pay with Datatrans
Branch: master
Clone or download
Latest commit 197ddec Mar 25, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.mvn/wrapper Initial Commit Apr 13, 2018
doc docs Apr 13, 2018
src Update to GooglePay API V2 Nov 8, 2018
target Initial Commit Apr 13, 2018
.gitignore gitignore Apr 13, 2018 Update Mar 25, 2019
datatrans-merchants-showcase.iml Initial Commit Apr 13, 2018
mvnw Initial Commit Apr 13, 2018
mvnw.cmd Initial Commit Apr 13, 2018

Google Pay Web Sample App

Sample project that shows how to integrate Google Pay with Datatrans

Getting Started

Google Pay allows merchants to collect payments with the Payment Request API. It enables merchants to receive encrypted payment information which can be forwarded to their Payment Processor. This Guide is intended for merchants who would like to integrate Google Pay with Datatrans. For more Information on Google Pay visit:

(Optional) Please also read the Google Pay Guide for Developers to understand flows and technology:


  1. Java installed on your local dev system
  2. Maven installed on your local dev system
  3. Google Chrome, Mozilla Firefox, Apple Safari, or UCWeb UC Browser
  4. A google account that has a payment method installed (
  5. Some basic experience with Spring Boot
  6. Some understanding of Google Pay and Payment Request API

Sample Application Flow

This sample application demonstrates following parts of collecting a payment with Google Pay.

  1. Determine if the browser can use Google Pay and if there are payment methods available.
  2. If so create a payment request object
  3. Populate the payment request
  4. Request payment from the user
  5. Forward the encrypted payment data to the "back-end"
  6. Create an XML request to authorize the transaction with Datatrans
  7. Forward the Google Pay data with the XML request to the Datatrans XML API
  8. Display the results.


  1. Clone the repository
   $ git clone
   $ cd google-pay-web-sample
  1. Open it with your favorite IDE / text editor
  2. Install the project
mvn clean install

Running the app

This sample app uses Spring Boot and Embedded Tomcat. The server is listening on port 8080.

To run the app execute the main class

Open http://localhost:8080/ in Google Chrome.

Testing the app

Google Pay can be tested using any supported web browser: Google Chrome, Mozilla Firefox, Apple Safari, Opera, or UCWeb UC Browser on a PC or mobile device. However if you need to make this web app available for your mobile device, a tool to expose your local webserver through a public URL is for example Ngrok. Ngrok.


  1. Open the URL you defined in your browser.
  2. Fill the inputs and tap/click Build Google Pay Request
  3. Click the Google Pay button that has been enabled
  4. Select your payment method (omitted in Screenshots due to security policies)
  5. Result is displayed

Sample Screenshots

On your Android device / Google account it's easiest if you just configure a real credit card. Authorizations whith real cards will be declined on the Datatrans test system ( So don't worry, your card will not be charged. In order to get some successful transactions Datatrans has the following logic in place (only on the test system obviously):

If a valid Google Pay token is sent we do the following replacements:

cardno=4242 4242 4242 4242 expm=12 expy=21

Authorization with Datatrans

Check out src/main/java/ch/datatrans/examples/googlepay/client/ to see how the authorization is done.

Sample request:

<?xml version="1.0" encoding="UTF-8" ?>
<authorizationService version="1">
  <body merchantId="$merchantId">
    <transaction refno="$refno">

Sample response:

<?xml version="1.0" encoding="UTF-8" ?>
<authorizationService version="1">
  <body merchantId="$merchantId" status="accepted">
    <transaction refno="$refno" trxStatus="response">

A successful call will return <body>’s attribute status="accepted" and <transaction>’s trxStatus="response" as well as a new <response> element containing the responseCode. A responseCode equal to "01" or "02" indicates an authorized transaction. Elements aliasCC, expy and expm will be returned only if the merchant uses credit card aliases.


  • This is sample code! Never ever use this code in production!
  • If you have questions please raise an issues and add the label "question".


Datatrans APIs

Built With

You can’t perform that action at this time.