Google Pay™ Integration Guide
The Ecart Pay SDK provides a complete integration with the Google Pay API, allowing merchants to offer Google Pay as a payment method on their websites. As a supported Payment Service Provider (PSP), Ecart Pay handles all token decryption and payment processing on your behalf.
Table of Contents
- Getting Started
- Google Pay Policies & Terms
- Installation
- Quick Start
- Required Parameters
- Optional Parameters
- Tokenization & Gateway Configuration
- Supported Authentication Methods (allowedAuthMethods)
- 3D Secure for PAN_ONLY Credentials
- Supported Card Networks (allowedCardNetworks)
- Billing Address Parameters
- Shipping Address
- Handling the Payment Response
- Events
- Button Customization
- Complete Example
- Testing
- Going to Production
- Resources
🚀 Getting Started
Prerequisites
Before integrating Google Pay through the Ecart Pay SDK, ensure:
| Requirement | Description |
|---|---|
| Ecart Pay Account | Active merchant account with the card payment method enabled |
| HTTPS | Your website must be served over HTTPS |
| Order ID | You can create orders via the Ecart Pay Orders API |
☝️ Google Pay Policies & Terms
All merchants using Google Pay through Ecart Pay must complete the following essential steps:
Comply with Google Policies
- Follow the Google Pay API Acceptable Use Policy.
- Accept the terms defined in the Google Pay API Terms of Service.
- Comply with the Google Pay Web Brand Guidelines.
📦 Installation
Add the Ecart Pay SDK <script> tag to your HTML page:
<!-- Production Environment -->
<script src="https://ecartpay.com/sdk/pay.js"></script>
<!-- Sandbox Environment (For testing purposes) -->
<script src="https://sandbox.ecartpay.com/sdk/pay.js"></script>Note: Use the sandbox version for development and testing. Switch to the production script only when you're ready to go live.
The SDK automatically loads the Google Pay JavaScript client library when Pay.GooglePay.render() is called. No additional script tags are needed.
The SDK generates the IsReadyToPayRequest and PaymentDataRequest objects on your behalf using your Ecart Pay account configuration. You do not need to build these requests manually.
⚡ Quick Start
<div id="google-pay-button"></div>
<script src="https://ecartpay.com/sdk/pay.js"></script>
<script>
// 1. Listen for events
Pay.GooglePay.on('ready', function () {
console.log('Google Pay button is ready');
});
Pay.GooglePay.on('success', function (event) {
console.log('Payment successful:', event.detail);
if (event.detail.redirect_url) {
window.location.href = event.detail.redirect_url;
}
});
Pay.GooglePay.on('error', function (event) {
console.error('Error:', event.detail.message);
});
Pay.GooglePay.on('cancel', function () {
console.log('Payment cancelled by user');
});
// 2. Render the button
Pay.GooglePay.render({
container: '#google-pay-button',
orderId: 'YOUR_ORDER_ID',
amount: 100.00,
currency: 'MXN',
countryCode: 'MX',
});
</script>📋 Required Parameters
| Parameter | Type | Description |
|---|---|---|
container | string | CSS selector or DOM element where the Google Pay button will be rendered |
orderId | string | The Ecart Pay order ID (obtained from the Orders API) |
amount | number | Total amount to charge |
currency | string | ISO 4217 currency code (e.g., MXN, USD, EUR) |
countryCode | string | ISO 3166-1 alpha-2 country code (e.g., MX, US) |
🧩 Optional Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
allowedCardNetworks | array | ['VISA', 'MASTERCARD', 'AMEX'] | Card networks to accept. See Supported Card Networks |
allowedAuthMethods | array | ['PAN_ONLY', 'CRYPTOGRAM_3DS'] | Authentication methods. See Supported Authentication Methods |
merchantName | string | Your Ecart Pay account name | Displayed on the payment sheet |
emailRequired | boolean | false | Request the customer's email |
shippingAddressRequired | boolean | false | Request a shipping address |
shippingAddressParameters | object | — | Restrict shipping countries |
billingAddressRequired | boolean | false | Request a billing address. See Billing Address Parameters |
billingAddressParameters | object | — | Configure billing address format. See Billing Address Parameters |
totalPriceStatus | string | 'FINAL' | 'FINAL' or 'ESTIMATED' |
buttonColor | string | 'default' | 'default', 'black', or 'white' |
buttonType | string | 'pay' | 'pay', 'buy', 'checkout', 'donate', 'order', 'plain' |
buttonSizeMode | string | 'fill' | 'fill' or 'static' |
buttonLocale | string | 'en' | Button language code |
buttonRadius | number | — | Corner radius in pixels |
💳 Tokenization & Gateway Configuration
As a supported Google Pay PSP, Ecart Pay uses the PAYMENT_GATEWAY tokenization type. The SDK configures this automatically.
When you integrate with Google Pay through the Ecart Pay SDK, the following values are set in the TokenizationSpecification object:
| Parameter | Value | Description |
|---|---|---|
gateway | ecartpay | The gateway ID registered with Google during onboarding |
gatewayMerchantId | Your Ecart Pay Account ID | Unique identifier assigned to your merchant account |
The SDK generates this configuration internally:
{
"tokenizationSpecification": {
"type": "PAYMENT_GATEWAY",
"parameters": {
"gateway": "ecartpay",
"gatewayMerchantId": "<Your Ecart Pay Account ID>"
}
}
}Note: You do not need to set these values manually. The SDK retrieves them from Ecart Pay's configuration endpoint when
render()is called.
🔐 Supported Authentication Methods (allowedAuthMethods)
allowedAuthMethods)The Ecart Pay integration with Google Pay supports two card authentication methods that merchants must define in the allowedAuthMethods property. These determine how the card credentials are provided:
| Method | Description | 3DS Required | Supported Countries |
|---|---|---|---|
PAN_ONLY | Physical card details (PAN) stored in the user's Google Pay account. The actual card number is returned in the encrypted payload. | Yes — Ecart Pay applies 3D Secure step-up authentication on every PAN_ONLY credential. See 3D Secure for PAN_ONLY. | All countries where Ecart Pay operates |
CRYPTOGRAM_3DS | Device-tokenized card. A virtual token with a 3DS cryptogram is returned. The device (e.g., Android phone) has already performed authentication. | No — authentication is performed by the device via Google Pay. | All countries where Ecart Pay operates |
Both methods are enabled by default. You can restrict to one if needed:
Pay.GooglePay.render({
// ...
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
});Important: If you only accept
CRYPTOGRAM_3DS, the Google Pay button will not appear for users who don't have a device-tokenized card. We recommend enabling both methods for maximum compatibility.
🛡️ 3D Secure for PAN_ONLY Credentials
PAN_ONLY CredentialsWhen a customer pays with a PAN_ONLY credential from Google Pay, Ecart Pay evaluates the transaction through its risk engine and may apply 3D Secure (3DS) step-up authentication to verify the cardholder's identity before processing the payment. This is required because PAN_ONLY returns the raw card PAN without device-level authentication.
How it works
- The customer authorizes the payment on the Google Pay sheet.
- Google Pay returns an encrypted
PAN_ONLYpayload containing the card number (PAN), expiration date, and billing information. - Ecart Pay decrypts the payload and runs the transaction through the risk evaluation engine.
- The risk engine calculates a risk score based on configurable rules (see below).
- Based on the risk score and your account's 3DS rules, Ecart Pay decides whether to trigger 3DS:
- If 3DS is triggered, a step-up authentication challenge is initiated with the card issuer.
- If 3DS is not required (low risk), the payment is processed directly.
- If 3DS authentication is successful, Ecart Pay processes the payment with the acquiring gateway including the 3DS indicators (ECI, cryptogram).
- If 3DS authentication fails, the payment is declined and the SDK emits an
errorevent. - If the risk score is extremely high (
highestlevel), the transaction is blocked automatically before reaching the gateway.
Risk evaluation engine
Before processing any PAN_ONLY payment, Ecart Pay evaluates the transaction against your account's risk rules. The engine analyzes the last 7 days of transaction history and assigns a cumulative risk score based on patterns such as:
| Rule | Description |
|---|---|
| Repeated email | Same customer email used across multiple transactions |
| Repeated phone | Same phone number used across multiple transactions |
| Repeated card | Same card (first6 + last4) used across multiple transactions |
| Device fingerprint | Same device fingerprint across multiple transactions |
| Card from different country | The card's issuing country differs from the merchant's country |
Each rule has a configurable score weight. The total risk score determines the risk level:
| Risk Score | Risk Level | Action |
|---|---|---|
| 0 - 40 | low | Payment processed normally |
| 41 - 60 | medium | 3DS may be triggered (depends on account rules) |
| 61 - 80 | high | 3DS is triggered |
| 81+ | highest | Transaction is blocked automatically |
When is 3DS triggered?
3DS is applied to a PAN_ONLY Google Pay transaction when any of the following conditions are met:
- The account's 3DS rule is set to "always" (3DS on every transaction).
- The transaction amount exceeds the threshold amount configured for the transaction currency.
- The risk score exceeds the 3DS risk threshold (default: 40).
For CRYPTOGRAM_3DS credentials
CRYPTOGRAM_3DS credentials3DS is not applied to CRYPTOGRAM_3DS transactions because the device has already performed authentication via Google Pay. The cryptogram and ECI indicators from the device token are passed directly to the acquiring gateway.
Merchant configuration
No additional configuration is required by the merchant to enable 3DS for Google Pay. The risk rules and 3DS thresholds are managed through your Ecart Pay account settings. You can adjust risk rule weights and 3DS behavior from the Ecart Pay dashboard under Settings > Risk list.
For more details on how 3DS works in Ecart Pay, see the 3D Secure (3DS) Payment Flow documentation.
🌐 Supported Card Networks (allowedCardNetworks)
allowedCardNetworks)Merchants must define the card networks they accept using the allowedCardNetworks parameter. The Ecart Pay integration with Google Pay supports the following networks:
| Network | Value | Status |
|---|---|---|
| Visa | VISA | Supported |
| Mastercard | MASTERCARD | Supported |
| American Express | AMEX | Supported |
| Discover | DISCOVER | Not currently supported |
| Interac | INTERAC | Not currently supported |
| JCB | JCB | Not currently supported |
Default: ['VISA', 'MASTERCARD', 'AMEX']
Note: Only
VISA,MASTERCARD, andAMEXare currently supported by Ecart Pay. Do not include unsupported networks inallowedCardNetworksas transactions with those cards will not be processed.
Pay.GooglePay.render({
// ...
allowedCardNetworks: ['VISA', 'MASTERCARD', 'AMEX'],
});Note: Only define the networks that your Ecart Pay account supports. Contact Ecart Pay support if you need to enable additional networks. Refer to the Google Pay Web Developer Documentation for the full list of supported values.
🏠 Billing Address Parameters
If your payment flow requires a billing address for verification (e.g., AVS checks), you must enable it in the Google Pay configuration using billingAddressRequired and billingAddressParameters.
Configuration
| Parameter | Type | Description |
|---|---|---|
billingAddressRequired | boolean | Set to true to request a billing address from the customer |
billingAddressParameters.format | string | 'MIN' (name, country, postal code) or 'FULL' (full street address) |
billingAddressParameters.phoneNumberRequired | boolean | Set to true to also request a phone number |
Example
Pay.GooglePay.render({
// ...
billingAddressRequired: true,
billingAddressParameters: {
format: 'FULL',
phoneNumberRequired: true,
},
});This generates the following structure in the Google Pay API request:
{
"allowedPaymentMethods": [
{
"type": "CARD",
"parameters": {
"billingAddressRequired": true,
"billingAddressParameters": {
"format": "FULL",
"phoneNumberRequired": true
},
"allowedCardNetworks": ["VISA", "MASTERCARD", "AMEX"],
"allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"]
},
"tokenizationSpecification": {
"type": "PAYMENT_GATEWAY",
"parameters": {
"gateway": "ecartpay",
"gatewayMerchantId": "<Your Ecart Pay Account ID>"
}
}
}
]
}For the full specification, see BillingAddressParameters in the Google Pay documentation.
📦 Shipping Address
To request a shipping address from the Google Pay payment sheet:
Pay.GooglePay.render({
// ...
shippingAddressRequired: true,
shippingAddressParameters: {
allowedCountryCodes: ['MX', 'US', 'CA'],
phoneNumberRequired: true,
},
});💸 Handling the Payment Response
The SDK handles the entire payment flow. You only need to listen for events.
Payment Data Flow
| Step | Description |
|---|---|
| 1 | Customer authorizes payment on the Google Pay sheet |
| 2 | Google Pay returns an encrypted token |
| 3 | SDK extracts the token from paymentMethodData.tokenizationData.token |
| 4 | SDK sends the encrypted token to Ecart Pay POST /api/process-payment |
| 5 | Ecart Pay decrypts the token, validates data, and processes the transaction |
| 6 | SDK emits success or error event with the result |
Pay.GooglePay.on('success', function (event) {
var result = event.detail;
console.log('Payment status:', result.status);
if (result.redirect_url) {
window.location.href = result.redirect_url;
}
});Best Practice: Always use the order status from the Orders API (
GET /api/orders/:id) as the source of truth for your business logic. Do not rely solely on the SDK event.
📡 Events
| Event | Description | event.detail |
|---|---|---|
ready | Button rendered, Google Pay is available | {} |
unavailable | Google Pay is not available on this device/browser | { message: string } |
success | Payment processed successfully | { status, redirect_url } |
error | Error during initialization or payment | { message: string } |
cancel | Customer cancelled the payment sheet | {} |
Pay.GooglePay.on('ready', function () { /* button is visible */ });
Pay.GooglePay.on('unavailable', function (e) { /* hide section */ });
Pay.GooglePay.on('success', function (e) { /* redirect */ });
Pay.GooglePay.on('error', function (e) { /* show error */ });
Pay.GooglePay.on('cancel', function () { /* user closed */ });🎨 Button Customization
The SDK uses the official Google Pay createButton() method, which renders a fully compliant button that:
- Personalized — displays the user's saved card info when available
- Localized — automatically translates to the user's browser language
- Compliant — always uses official Google Pay assets
Pay.GooglePay.render({
// ...
buttonColor: 'black',
buttonType: 'pay',
buttonSizeMode: 'fill',
buttonLocale: 'es',
buttonRadius: 8,
});Important: Do not create your own Google Pay buttons or alter the official assets. Always use the button rendered by the SDK, in compliance with the Google Pay Web Brand Guidelines.
🧪 Complete Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Google Pay Checkout - Ecart Pay</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f5; }
.checkout { max-width: 480px; margin: 40px auto; padding: 24px; background: #fff; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
#gpay-container { min-height: 48px; margin: 16px 0; }
.status { padding: 12px; border-radius: 8px; margin-top: 12px; display: none; font-size: 14px; }
.status.success { display: block; background: #d1fae5; color: #065f46; }
.status.error { display: block; background: #fee2e2; color: #991b1b; }
</style>
</head>
<body>
<div class="checkout">
<h2>Checkout</h2>
<p>Total: <strong>$100.00 MXN</strong></p>
<div id="gpay-container"></div>
<div id="status" class="status"></div>
</div>
<script src="https://ecartpay.com/sdk/pay.js"></script>
<script>
var statusEl = document.getElementById('status');
Pay.GooglePay.on('success', function (event) {
statusEl.className = 'status success';
statusEl.textContent = 'Payment successful!';
if (event.detail.redirect_url) {
window.location.href = event.detail.redirect_url;
}
});
Pay.GooglePay.on('error', function (event) {
statusEl.className = 'status error';
statusEl.textContent = 'Error: ' + event.detail.message;
});
Pay.GooglePay.on('cancel', function () {
statusEl.className = 'status error';
statusEl.textContent = 'Payment cancelled.';
});
// Replace YOUR_ORDER_ID with a real order ID from the Ecart Pay Orders API
Pay.GooglePay.render({
container: '#gpay-container',
orderId: 'YOUR_ORDER_ID',
amount: 100.00,
currency: 'MXN',
countryCode: 'MX',
buttonColor: 'black',
buttonType: 'pay',
buttonLocale: 'es',
buttonRadius: 4,
allowedCardNetworks: ['VISA', 'MASTERCARD', 'AMEX'],
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
billingAddressRequired: true,
billingAddressParameters: {
format: 'MIN',
phoneNumberRequired: true,
},
});
</script>
</body>
</html>Note: You can copy and paste this into an
.htmlfile and run it locally to test a full Google Pay checkout flow. Remember to use the sandbox SDK for testing.
🧪 Testing
Use the Sandbox environment for testing:
<script src="https://sandbox.ecartpay.com/sdk/pay.js"></script>In sandbox mode, the Google Pay button operates in TEST environment, allowing testing with the Google Pay Test Card Suite without processing real payments.
🚀 Going to Production
Before going live with Google Pay, merchants must complete the following steps:
| Step | Action |
|---|---|
| 1 | Comply with the Google Pay API Acceptable Use Policy and accept the Google Pay API Terms of Service |
| 2 | Switch to production SDK: <script src="https://ecartpay.com/sdk/pay.js"></script> |
| 3 | Verify your Ecart Pay account is active and the card payment method is enabled |
| 4 | Test the complete flow with real cards before going live |
Note: As a Payment Service Provider (PSP), Ecart Pay is already registered with Google Pay and manages the production access on behalf of all merchants. You do not need to register your business separately in the Google Pay & Wallet Console or obtain your own
merchantId. Ecart Pay's gateway registration with Google covers all merchants using the Ecart Pay SDK.However, if you want to display your own business name on the Google Pay payment sheet, or if you process more than 50 domains, you may optionally register in the Google Pay & Wallet Console and provide your
merchantIdto Ecart Pay support to configure it for your account.
🔎 Resources
Google Pay Documentation
| Resource | Link |
|---|---|
| Web Developer Docs | developers.google.com/pay/api/web |
| Web Integration Checklist | Integration Checklist |
| Web Brand Guidelines | Brand Guidelines |
| Google Pay & Wallet Console | pay.google.com/business/console |
| Android Developer Docs | developers.google.com/pay/api/android |
| Android Integration Checklist | Integration Checklist |
| Android Brand Guidelines | Brand Guidelines |
| Acceptable Use Policy | AUP |
| Terms of Service | ToS |
Ecart Pay Documentation
| Resource | Link |
|---|---|
| SDK JS Documentation | docs.ecartpay.com/docs/sdks |
| Orders API | docs.ecartpay.com/docs/orders |
| 3D Secure Flow | docs.ecartpay.com/docs/3d-secure |
| Apple Pay Guide | Apple Pay Integration Guide |
Updated about 1 month ago