Set up Google Pay
Shoppers can pay with Google Pay in a web or chat interface, or through an agent that acts on their behalf. Shopper MCP Server handles the Commerce side of the payment. Your application collects the Google Pay token, approves it with PayPal, and places the order.
NOTE
Checkout and payment tools are in early access. Google Pay through Shopper MCP Server is available for Adobe Commerce on cloud infrastructure or on-premises and Adobe Commerce as a Cloud Service.
Prerequisites prerequisites
- Payment Services is onboarded, with Google Pay enabled.
- The Google Pay payment action is set to Authorize or Authorize and Capture (Stores > Settings > Configuration > Sales > Payment Methods > Payment Services > Google Pay). See Configure Google Pay.
- You are responsible for complying with the Google Pay API Terms of Service, Acceptable Use Policy, and brand guidelines.
- The checkout page is served over HTTPS.
Provided by Shopper MCP Server provided
Tool
Use
get_payment_configurationPayPal client ID, merchant ID, and environment
get_cartCart total; confirms that addresses and shipping are set
create_payment_orderCreates the payment order. Returns the PayPal order ID and payments order ID
set_payment_methodSets Google Pay as the cart’s payment method
place_orderPlaces the order. Commerce authorizes or captures the payment
For details about each tool, see the Tools reference.
What you implement implement
Component
Purpose
Google Pay configuration
Call PayPal
GetGooglePayConfig to get the gateway settings for the Google Pay requestToken collection
Web: Google Pay button and payment sheet. Agent: the agent platform returns
paymentMethodDataPayment approval
Call PayPal
ApproveGooglePayPayment to attach the token to the PayPal orderSettlement
Run the payment steps in order, in application code
Payment flow payment-flow
- Set the shipping address, billing address, and shipping method on the cart. See Call order for guest checkout.
- Build the Google Pay request: call
get_payment_configuration, then PayPalGetGooglePayConfig, with the cart total fromget_cartas the final price (totalPriceStatus: FINAL). - Collect the shopper’s Google Pay token (
paymentMethodData). On the web, show the Google Pay button only whenisReadyToPaysucceeds. - Call
create_payment_order. - Call PayPal
ApproveGooglePayPaymentwith the token and the PayPal order ID. - Call
set_payment_methodwith both order IDs. - Call
place_orderand return the order number.
IMPORTANT
Stop at the first error. Do not retry steps 4–7 automatically, because each step creates or changes a payment.
Security and payment handling security
- Send the Google Pay token only to PayPal. Do not log it or pass it to a language model.
- Run settlement in application code, not as tool calls chosen by a language model.
- Handle 3-D Secure when PayPal returns
PAYER_ACTION_REQUIRED. The examples do not cover this.
Testing testing
- Use the PayPal sandbox. Google Pay runs in
TESTmode. See Sandbox testing. - Use PayPal’s Google Pay test cards, for example Visa
4566 2015 6284 9481. - Browsers allow
http://localhostfor local testing.
Example code example-code
call_tool(name, args) is your MCP client call and returns the parsed JSON result. Agents skip the browser example and pass paymentMethodData from the agent platform to settle_google_pay.
Server (Python) server-python
import httpx
METHOD = "payment_services_paypal_google_pay"
PAYPAL = {"sandbox": "https://www.sandbox.paypal.com", "production": "https://www.paypal.com"}
GOOGLE_ENV = {"sandbox": "TEST", "production": "PRODUCTION"}
GET_CONFIG = """
query getGooglePayConfig($clientId: String!, $merchantId: [String]!,
$merchantOrigin: String!) {
googlePayConfig(clientId: $clientId, merchantId: $merchantId,
merchantOrigin: $merchantOrigin) {
isEligible apiVersion apiVersionMinor countryCode
allowedPaymentMethods {
type
parameters { allowedAuthMethods allowedCardNetworks billingAddressRequired
assuranceDetailsRequired billingAddressParameters { format } }
tokenizationSpecification { type parameters { gateway gatewayMerchantId } }
}
merchantInfo { merchantOrigin merchantId }
}
}"""
APPROVE = """
mutation ApproveGooglePayPayment($paymentMethodData: GooglePayPaymentMethodData!,
$orderID: String!, $clientID: String!, $productFlow: String) {
approveGooglePayPayment(paymentMethodData: $paymentMethodData, orderID: $orderID,
clientID: $clientID, productFlow: $productFlow)
}"""
async def paypal(env, operation, query, variables):
async with httpx.AsyncClient(timeout=10) as http:
resp = await http.post(f"{PAYPAL[env]}/graphql?{operation}",
json={"query": query, "variables": variables},
headers={"x-app-name": "sdk-googlepay"})
body = resp.json()
if body.get("errors"):
raise RuntimeError(f"{operation}: {body['errors'][0].get('message')}")
return body["data"]
async def merchant(call_tool):
config = await call_tool("get_payment_configuration", {"location": "CHECKOUT"})
m = next(m for m in config["methods"] if m["code"] == METHOD)
return m["provider_config"], m.get("environment") or "sandbox"
async def google_pay_request(call_tool, cart_id, origin):
provider, env = await merchant(call_tool)
gp = (await paypal(env, "GetGooglePayConfig", GET_CONFIG, {
"clientId": provider["client_id"],
"merchantId": [provider["merchant_id"]],
"merchantOrigin": origin, # e.g. "shop.example.com"
}))["googlePayConfig"]
if not gp["isEligible"]:
raise RuntimeError("Merchant is not eligible for Google Pay")
cart = (await call_tool("get_cart", {"cart_id": cart_id}))["data"]["cart"]
total = cart["prices"]["grand_total"]
return {
"environment": GOOGLE_ENV[env],
"apiVersion": gp["apiVersion"],
"apiVersionMinor": gp["apiVersionMinor"],
"allowedPaymentMethods": gp["allowedPaymentMethods"],
"merchantInfo": gp["merchantInfo"],
"transactionInfo": {
"totalPriceStatus": "FINAL",
"totalPrice": f"{total['value']:.2f}",
"currencyCode": total["currency"],
"countryCode": gp["countryCode"],
},
}
async def settle_google_pay(call_tool, cart_id, payment_method_data):
provider, env = await merchant(call_tool)
order = await call_tool("create_payment_order", {
"cart_id": cart_id, "method_code": METHOD,
"payment_source": "googlepay", "location": "CHECKOUT",
})
await paypal(env, "ApproveGooglePayPayment", APPROVE, {
"paymentMethodData": payment_method_data,
"orderID": order["id"],
"clientID": provider["client_id"],
"productFlow": "CUSTOM_DIGITAL_WALLET",
})
await call_tool("set_payment_method", {
"cart_id": cart_id,
"payment_method": {"code": METHOD, METHOD: {
"payments_order_id": order["mp_order_id"],
"paypal_order_id": order["id"],
"payment_source": "googlepay",
}},
})
placed = await call_tool("place_order", {"cart_id": cart_id})
return {"order_number": placed["number"]}
Browser browser
<div id="google-pay"></div>
<script src="https://pay.google.com/gp/p/js/pay.js"></script>
<script>
async function post(url, body) {
const res = await fetch(url, { method: 'POST',
headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
return res.json();
}
async function showGooglePay(cartId) {
const req = await post('/payments/google-pay/request', { cart_id: cartId });
const client = new google.payments.api.PaymentsClient({ environment: req.environment });
const base = { apiVersion: req.apiVersion, apiVersionMinor: req.apiVersionMinor,
allowedPaymentMethods: req.allowedPaymentMethods };
if (!(await client.isReadyToPay(base)).result) return;
document.getElementById('google-pay').appendChild(client.createButton({
buttonType: 'pay',
allowedPaymentMethods: req.allowedPaymentMethods,
onClick: async () => {
const data = await client.loadPaymentData({ ...base,
merchantInfo: req.merchantInfo, transactionInfo: req.transactionInfo });
const res = await post('/payments/google-pay/complete',
{ cart_id: cartId, payment_method_data: data.paymentMethodData });
alert(`Order #${res.order_number} placed`);
},
}));
}
</script>
recommendation-more-help
commerce-help-shopper-mcp