Get to know MDN better
The Payment Request API provides a browser-based method of connecting users and their preferred payment systems and platforms to merchants that they want to pay for goods and services. This article is a guide to making use of the Payment Request API, with examples and suggested best practices.
This section details the basics of using the Payment Request API to make a payment.
Note: The code snippets from this section are from our Feature detect support demo.
A payment request always starts with the creation of a new PaymentRequest object — using the PaymentRequest() constructor. This takes two mandatory parameters and one option parameter:
So for example, you could create a new PaymentRequest instance like so:
The functions invoked inside the constructor return the required object parameters:
Once the PaymentRequest object has been created, you call the PaymentRequest.show() method on it to initiate the payment request. This returns a promise that fulfills with a PaymentResponse object if the payment is successful:
This object provides the developer with access to details they can use to complete the logical steps required after the payment completes, such as an email address to contact the customer, a shipping address for mailing goods out to them, etc. In the code above, you'll see that we've called the PaymentResponse.complete() method to signal that the interaction has finished — you'd use this to carry out finishing steps, like updating the user interface to tell the user the transaction is complete, etc.
There are some other useful payment request methods worth knowing about.
PaymentRequest.canMakePayment() can be used to check whether the PaymentRequest object is capable of making a payment before you start the payment process. It returns a promise that fulfills with a boolean indicating whether it is or not, for example:
PaymentRequest.abort() can be used to abort the payment request if required.
You can effectively detect support for the Payment Request API by checking if the user's browser supports PaymentRequest, i.e., if (window.PaymentRequest).
In the following snippet, a merchant page performs this check, and if it returns true updates the checkout button to use PaymentRequest instead of legacy web forms.
Note: See our Feature detect support demo for the full code.
Checking whether users can make payments is always useful. Here's a couple of related techniques.
One useful technique to employ is customizing the payment request button depending on whether users can make payments.
In the following snippet we do just this — depending on whether the user can make a fast payment or needs to add payment credentials first, the title of the checkout button changes between "Fast Checkout with W3C" and "Setup W3C Checkout". In both cases, the checkout button calls PaymentRequest.show().
Note: See our Customizing the payment button demo for the full code.
If the checkout flow needs to know whether PaymentRequest.canMakePayment() will return true even before all line items and their prices are known, you can instantiate PaymentRequest with dummy data and pre-query .canMakePayment(). If you call .canMakePayment() multiple times, keep in mind that the first parameter to the PaymentRequest constructor should contain the same method names and data.
Note: See our Checking user can make payments before prices are known demo for the full code.
If you select to pay with the BobBucks demo payment provider on this merchant page, it tries to call PaymentRequest.show(), while intercepting the NotSupportedError DOMException. If this payment method is not supported, it redirects to the signup page for BobBucks.
The code looks something like this:
Note: See our Recommending a payment app when user has no apps demo for the full code.
If the merchant desires to collect additional information not part of the API (e.g., additional delivery instructions), the merchant can show a page with additional <input type="text"> fields after the checkout.
Note: See our Show additional user interface after successful payment demo for the full code.
Some use cases (e.g., paying for fuel at a service station) involve pre-authorizing payment. One way to do this is through a Web-based Payment Handler (see the Web-based Payment Handler API). At the time of writing, that specification includes a canmakepayment event that a Web-based Payment Handler could make use of to return authorization status.
The merchant code would look like this:
The web-based payment handler would include the following code:
This payment handler would need to live in a service worker at https://example.com/preauth scope.
Note: See our Pre-authorizing transactions demo for the full code.
This page was last modified on Mar 8, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.