On this page
No Headings
Last updated: June 4, 2026
Google Pay enables merchants to accept fast payments in using PayPal's Javascript SDK v6. This integration supports setup in test and production environments and provides a streamlined checkout experience for customers.
Before beginning your integration, meet these requirements:
Note: You'll use your sandbox credentials to create a
.envfile during the Development setup.
Configure your local development environment with the required dependencies and credentials. For reference, see this Google Pay demo.
cd client/components/googlePayPayments/oneTimePayment/html
npm install# .env file
PAYPAL_SANDBOX_CLIENT_ID=your_client_id
PAYPAL_SANDBOX_CLIENT_SECRET=your_client_secretnpm startTo load the application, see http://localhost:3000.
Implement Google Pay by following the detailed steps.
Create your basic HTML page and include the Google Pay and PayPal SDK scripts.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>One-Time Payment - Google Pay - PayPal JavaScript SDK</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<h1>One-Time Payment Google Pay Integration</h1>
<div class="buttons-container">
<div id="googlepay-button-container"></div>
</div>
<!-- Load Google Pay SDK -->
<script src="https://pay.google.com/gp/p/js/pay.js"></script>
<script src="app.js"></script>
<!-- Load PayPal SDK -->
<script
async
src="https://www.sandbox.paypal.com/web-sdk/v6/core"
onload="onPayPalWebSdkLoaded()"
></script>
</body>
</html>Set up the PayPal SDK with Google Pay components once it loads.
async function onPayPalWebSdkLoaded() {
try {
// Create PayPal SDK instance with Google Pay component
const sdkInstance = await window.paypal.createInstance({
clientId: "YOUR_CLIENT_ID",
components: ["googlepay-payments"],
pageType: "checkout",
});
setupGooglePayButton(sdkInstance);
} catch (error) {
console.error(error);
}
}Create the Google Pay session and set up the payment button.
async function setupGooglePayButton(sdkInstance) {
// Create Google Pay session
const googlePaySession = sdkInstance.createGooglePayOneTimePaymentSession();
const purchaseAmount = "10.00";
try {
// Initialize Google Pay client
const paymentsClient = new google.payments.api.PaymentsClient({
environment: "TEST", // Use "PRODUCTION" for live transactions
paymentDataCallbacks: {
onPaymentAuthorized: (paymentData) =>
onPaymentAuthorized(purchaseAmount, paymentData, googlePaySession),
},
});
// Get Google Pay configuration from PayPal
const googlePayConfig = await googlePaySession.getGooglePayConfig();
// Check if Google Pay is available
const isReadyToPay = await paymentsClient.isReadyToPay({
allowedPaymentMethods: googlePayConfig.allowedPaymentMethods,
apiVersion: googlePayConfig.apiVersion,
apiVersionMinor: googlePayConfig.apiVersionMinor,
});
if (isReadyToPay.result) {
// Create and append Google Pay button
const button = paymentsClient.createButton({
onClick: () =>
onGooglePayButtonClick(
purchaseAmount,
paymentsClient,
googlePayConfig,
),
});
document.getElementById("googlepay-button-container").appendChild(button);
}
} catch (error) {
console.error("Setup error:", error);
}
}Set up the Google Pay payment data request with transaction details.
async function getGooglePaymentDataRequest(purchaseAmount, googlePayConfig) {
const {
allowedPaymentMethods,
merchantInfo,
apiVersion,
apiVersionMinor,
countryCode,
} = googlePayConfig;
const baseRequest = {
apiVersion,
apiVersionMinor,
};
const paymentDataRequest = Object.assign({}, baseRequest);
paymentDataRequest.allowedPaymentMethods = allowedPaymentMethods;
paymentDataRequest.transactionInfo = getGoogleTransactionInfo(
purchaseAmount,
countryCode,
);
paymentDataRequest.merchantInfo = merchantInfo;
paymentDataRequest.callbackIntents = ["PAYMENT_AUTHORIZATION"];
return paymentDataRequest;
}Define the transaction details and pricing breakdown for the Google Pay request.
function getGoogleTransactionInfo(purchaseAmount, countryCode) {
const totalAmount = parseFloat(purchaseAmount);
const subtotal = (totalAmount * 0.9).toFixed(2);
const tax = (totalAmount * 0.1).toFixed(2);
return {
displayItems: [
{
label: "Subtotal",
type: "SUBTOTAL",
price: subtotal,
},
{
label: "Tax",
type: "TAX",
price: tax,
},
],
countryCode: countryCode,
currencyCode: "USD",
totalPriceStatus: "FINAL",
totalPrice: purchaseAmount,
totalPriceLabel: "Total",
};
}Process the payment authorization and complete the transaction.
async function onPaymentAuthorized(
purchaseAmount,
paymentData,
googlePaySession,
) {
try {
// Create PayPal order payload
const orderPayload = getPayPalOrderPayload(purchaseAmount);
const id = await createOrder(orderPayload);
// Confirm order with Google Pay payment data
const { status } = await googlePaySession.confirmOrder({
orderId: id,
paymentMethodData: paymentData.paymentMethodData,
});
if (status !== "PAYER_ACTION_REQUIRED") {
// Capture the order
const orderData = await captureOrder({ orderId: id });
console.log(JSON.stringify(orderData, null, 2));
}
return { transactionState: "SUCCESS" };
} catch (err) {
console.error("Payment authorization error:", err);
return {
transactionState: "ERROR",
error: {
message: err.message,
},
};
}
}Configure a PayPal order with the Google Pay payment source.
function getPayPalOrderPayload(purchaseAmount) {
return {
intent: "CAPTURE",
purchaseUnits: [
{
amount: {
currencyCode: "USD",
value: purchaseAmount,
breakdown: {
itemTotal: {
currencyCode: "USD",
value: purchaseAmount,
},
},
},
},
],
paymentSource: {
googlePay: {
attributes: {
verification: {
method: "SCA_WHEN_REQUIRED",
},
},
},
},
};
}The integration requires these server-side endpoints.
// POST /paypal-api/checkout/orders/create
async function createOrder(orderPayload) {
const response = await fetch("/paypal-api/checkout/orders/create", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(orderPayload),
});
const { id } = await response.json();
return id;
}// POST /paypal-api/checkout/orders/{orderId}/capture
async function captureOrder({ orderId }) {
const response = await fetch(
`/paypal-api/checkout/orders/${orderId}/capture`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
},
);
const data = await response.json();
return data;
}| Key component | Purpose | Details |
|---|---|---|
| PayPal SDK instance | Main entry point for PayPal functionality |
|
| Google Pay session | Manages Google Pay payment flow |
|
| Google Pay client | Interface with Google Pay API |
|