The Payment Request API lets a web page open the payment sheet of the browser instead of showing its own card form. In Chrome that sheet is Google Pay; in Safari it is Apple Pay. The user picks a card they have already saved, confirms, and the page receives a token it can send to its payment provider. In this two-part series we look at how the API works today, where it runs and what you still have to build yourself.
What the API does, and what it does not do
The API does three things:
- it shows a payment sheet that the browser draws, so it looks the same on every site;
- it collects the payment credentials and, if you ask for them, the payer’s name, email, phone and shipping address;
- it hands all of that back to your page in a
PaymentResponseobject.
It does not charge anyone. The token in the response has to go to your server, and your server charges it through your payment provider (Stripe, Adyen, Braintree, your bank’s gateway…). The API only replaces the checkout form.
Where it works in 2026
| Browser | Payment Request API | Payment methods |
|---|---|---|
| Chrome (desktop and Android) | Yes, since Chrome 60 (53 on Android) | Google Pay and other third-party payment apps |
| Edge | Yes | Depends on the payment apps available |
| Safari (macOS and iOS) | Yes, since Safari 11.1 | Apple Pay only |
| Firefox | No, only behind the dom.payments.request.enabled flag | — |
Google’s own documentation puts it plainly: Chrome is currently the only browser that supports the Payment Request API with third-party payment methods, Google Pay included. If you need Google Pay in other browsers, Google’s JavaScript library for Google Pay is the way to go; the Payment Request API is the browser-native route.
Two requirements apply everywhere:
- HTTPS: the API only exists in secure contexts (
localhostcounts, which is handy for testing); - a user action:
show()only works in response to a click or a key press. Calling it on page load fails with aSecurityError.
What happened to basic-card
The 2023 version of this tutorial listed basic-card, a method that let the browser itself collect card numbers. The W3C Web Payments Working Group discontinued that specification in August 2021, and browsers no longer offer it. Cards now reach the payment sheet through a wallet such as Google Pay or Apple Pay. If you copy an old example that only lists basic-card, show() rejects with a NotSupportedError.
A minimal example with Google Pay in test mode
The page only needs two elements: a button with the id pay-button, hidden at first with the hidden attribute so that it only appears if the browser can pay, and an empty paragraph with the id result for the messages. You can see the whole page, HTML included, and try it in the CodePen demo.
The JavaScript:
const button = document.getElementById('pay-button');
const result = document.getElementById('result');
// Google Pay, in the format Google documents for the Payment Request API (API version 2).
// environment: 'TEST' returns dummy cards: nothing is charged.
const googlePay = {
supportedMethods: 'https://google.com/pay',
data: {
environment: 'TEST',
apiVersion: 2,
apiVersionMinor: 0,
merchantInfo: {
merchantName: 'Example Merchant'
// merchantId: '12345678901234567890' (Google gives you this one for production)
},
allowedPaymentMethods: [{
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['MASTERCARD', 'VISA']
},
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
parameters: {
gateway: 'example',
gatewayMerchantId: 'exampleGatewayMerchantId'
}
}
}]
}
};
const details = {
total: { label: 'Total', amount: { currency: 'EUR', value: '100.00' } },
displayItems: [
{ label: 'Product A', amount: { currency: 'EUR', value: '50.00' } },
{ label: 'Product B', amount: { currency: 'EUR', value: '50.00' } }
]
};
// 1. Show the button only if the browser has the API and can use the method
async function setUp() {
if (!window.PaymentRequest) {
return; // keep your normal checkout
}
const request = new PaymentRequest([googlePay], details);
if (await request.canMakePayment()) {
button.hidden = false;
}
}
// 2. On click, open the payment sheet
button.addEventListener('click', async () => {
const request = new PaymentRequest([googlePay], details);
try {
const response = await request.show();
const charged = await sendToServer(response);
await response.complete(charged ? 'success' : 'fail');
result.textContent = charged ? 'Thank you for your purchase.' : 'The payment could not be completed.';
} catch (error) {
if (error.name === 'AbortError') {
result.textContent = 'Payment cancelled.';
} else if (error.name === 'NotSupportedError') {
result.textContent = 'This browser has no payment method we accept.';
} else {
console.error(error);
result.textContent = 'Something went wrong.';
}
}
});
// 3. Demo only: in a real shop this POSTs response.details to your server,
// which charges the token through your payment provider
async function sendToServer(response) {
console.log(response.methodName, response.details);
return true;
}
setUp(); The example, step by step
The payment methods
The first argument of new PaymentRequest() is an array of payment methods. Each one has a supportedMethods string, an identifier such as 'https://google.com/pay' or 'https://apple.com/apple-pay', and a data object whose format is set by whoever owns that method. For Google Pay, data is the same request object as in Google’s own Pay API: apiVersion: 2, a merchantInfo block and an allowedPaymentMethods array of objects. The tokenizationSpecification says which payment provider will receive the token; your provider tells you the exact gateway and gatewayMerchantId values.
Older tutorials, including the first version of this one, wrote supportedMethods as an array and allowedPaymentMethods as ['TOKENIZED_CARD', 'CARD']. That was Google Pay’s first API version; the current one expects the objects shown above.
The payment details
The second argument describes what the user is paying for: the total, which is required, and optionally a list of displayItems that the sheet shows as a breakdown. Amounts are strings ('100.00'), not numbers, and the currency is an ISO 4217 code. With Google Pay you put the total here and leave out the transactionInfo field that Google Pay uses outside this API.
Checking before showing the button
canMakePayment() tells you whether the browser can handle at least one of the methods you listed. It needs no click, so the example calls it when the page loads and keeps the button hidden otherwise. Firefox users, for instance, never see a button that would only fail.
Showing the sheet and finishing
Inside the click handler the example creates a new request and calls show(). The promise resolves with a PaymentResponse when the user confirms. The order of the next two steps matters:
- send the response to your server and wait for the charge to succeed or fail;
- only then call
response.complete('success')orresponse.complete('fail'), which closes the sheet.
The 2023 version called complete('success') first and processed the payment afterwards, which tells the user everything went fine before the charge has even been tried.
Cancellations and errors
When the user closes the sheet, show() does not resolve with an empty value: it rejects with an AbortError. That is why the example handles cancellation in the catch block and checks error.name. NotSupportedError means none of your methods is available, and SecurityError usually means show() was called without a click.
What comes back in the response
response.methodName tells you which method the user chose, for example 'https://google.com/pay'. response.details holds the data of that method. With Google Pay it is a payment data object whose paymentMethodData.tokenizationData.token is what your provider needs to charge the card. If you asked for contact details, they come in payerName, payerEmail and payerPhone; we cover that in part 2.
Apple Pay
In Safari the method is 'https://apple.com/apple-pay', but it needs more than a block of data: an Apple Pay merchant account, a verified domain and a merchant validation step that your server completes with Apple every time the sheet opens. Part 2 shows how that step fits into the same code.
Should you call the API directly?
For learning how browser payments work, yes: the whole flow fits in a page of code. In a production shop most teams use the button or checkout component of their payment provider, which handles the formats of each wallet, the merchant validation and the fallbacks for browsers without the API. Knowing what happens underneath still helps when something fails.
In part 2 we ask the payer for their name, email and shipping address, update the price when the address changes and add Apple Pay.
Further reading
- Payment Request API, PaymentRequest and PaymentResponse on MDN
- Google Pay with the Payment Request API, Google’s tutorial
- Can I use: Payment Request API