Skip to main content

Google Pay

Google Pay integration enables customers to pay using cards stored on their Google account. The payment is processed natively in the browser or app, without the need to enter card details.

Flow diagram

Step 1: Register the payment

Register the transaction using the standard method:

curl -X POST https://api-payments.dpay.pl/api/v1_0/payments/register \
-H "Content-Type: application/json" \
-d '{
"transactionType": "transfers",
"service": "abc123",
"value": "49.99",
"url_success": "https://myshop.com/success",
"url_fail": "https://myshop.com/error",
"url_ipn": "https://myshop.com/api/ipn",
"checksum": "..."
}'

Save the transactionId from the response.

Step 2: Configure the Google Pay button

Add the Google Pay API script and configure the button on your page:

<script src="https://pay.google.com/gp/p/js/pay.js"></script>
<div id="google-pay-button"></div>

JavaScript configuration

// Google Pay configuration
const googlePayConfig = {
apiVersion: 2,
apiVersionMinor: 0,
allowedPaymentMethods: [
{
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['VISA', 'MASTERCARD'],
},
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
parameters: {
gateway: 'aciworldwide',
gatewayMerchantId: 'YOUR_MERCHANT_ID', // ID provided by dpay support
},
},
},
],
};

// Payment request configuration
const paymentDataRequest = {
...googlePayConfig,
transactionInfo: {
totalPriceStatus: 'FINAL',
totalPrice: '49.99',
currencyCode: 'PLN',
countryCode: 'PL',
},
merchantInfo: {
merchantName: 'My Shop',
merchantId: 'BCR2DN4T...', // Your Google Merchant ID
},
};

Initialization and button display

let paymentsClient;

async function initGooglePay() {
paymentsClient = new google.payments.api.PaymentsClient({
environment: 'PRODUCTION', // or 'TEST' for testing
});

// Check if Google Pay is available
const isReadyToPay = await paymentsClient.isReadyToPay(googlePayConfig);

if (isReadyToPay.result) {
const button = paymentsClient.createButton({
onClick: onGooglePayClicked,
buttonColor: 'black',
buttonType: 'pay',
buttonLocale: 'pl',
});
document.getElementById('google-pay-button').appendChild(button);
}
}

async function onGooglePayClicked() {
try {
const paymentData = await paymentsClient.loadPaymentData(paymentDataRequest);
await processGooglePayPayment(paymentData);
} catch (error) {
console.error('Google Pay error:', error);
}
}

// Initialize after page load
google.payments.api.PaymentsClient && initGooglePay();

Step 3: Send the token to dpay.pl

After the customer approves the payment in Google Pay, send the received token to dpay.pl:

POST https://api-payments.dpay.pl/api/v1_0/cards/payment/{transactionId}/pay/google-pay
Content-Type: application/json

Request parameters

{
"xPayType": "GOOGLE_PAY",
"paymentData": {
"apiVersion": 2,
"apiVersionMinor": 0,
"paymentMethodData": {
"type": "CARD",
"tokenizationData": {
"type": "PAYMENT_GATEWAY",
"token": "... token from Google Pay ..."
}
}
},
"deviceInfo": {
"browserJavaEnabled": false,
"browserLanguage": "pl-PL",
"browserColorDepth": "24",
"browserScreenHeight": "1080",
"browserScreenWidth": "1920",
"browserTZ": "-60",
"browserUserAgent": "Mozilla/5.0 ...",
"browserAcceptHeader": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"browserJavascriptEnabled": true
}
}

JavaScript - payment processing

async function processGooglePayPayment(paymentData) {
const transactionId = '...'; // From Step 1

const deviceInfo = {
browserJavaEnabled: navigator.javaEnabled ? navigator.javaEnabled() : false,
browserLanguage: navigator.language || 'pl-PL',
browserColorDepth: String(screen.colorDepth),
browserScreenHeight: String(screen.height),
browserScreenWidth: String(screen.width),
browserTZ: String(new Date().getTimezoneOffset()),
browserUserAgent: navigator.userAgent,
browserAcceptHeader: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
browserJavascriptEnabled: true,
};

const response = await fetch(`/api/pay/google-pay`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
transactionId,
paymentData,
deviceInfo,
}),
});

const result = await response.json();

if (result.error) {
alert('Payment error: ' + result.msg);
} else if (result.redirectType === 'FORM') {
// Handle 3D Secure
handle3DSRedirect(result);
} else {
window.location.href = result.url_success || '/success';
}
}

Server (Node.js) - proxy to dpay.pl

app.post('/api/pay/google-pay', async (req, res) => {
const { transactionId, paymentData, deviceInfo } = req.body;

const response = await axios.post(
`https://api-payments.dpay.pl/api/v1_0/cards/payment/${transactionId}/pay/google-pay`,
{
xPayType: 'GOOGLE_PAY',
paymentData,
deviceInfo,
}
);

res.json(response.data);
});

API response

Success

{
"error": false,
"status": "paid",
"transactionId": "abc-def-123-456"
}

3D Secure required

{
"error": false,
"status": "3DS_REQUIRED",
"redirectType": "FORM",
"redirectUrl": "https://acs-bank.example.com/3ds",
"redirectParams": { ... }
}

Test environment

For testing, use the TEST environment in the Google Pay configuration:

const paymentsClient = new google.payments.api.PaymentsClient({
environment: 'TEST',
});

In the test environment, Google Pay returns fictitious tokens that can be used to test the integration.

Requirements
  • Your website must be accessible via HTTPS
  • You must have a verified Google Merchant ID (for production)
  • Your domain must be registered in the Google Pay & Wallet Console