Payment Request API is a new, streamlined way to collect payment and shipping details from the user. Its primary goal is to eliminate checkout forms by standardizing the payment communication flow as much as possible. Some benefits of using Payment Request API over traditional checkout forms are:
- - Platform native and familiar for the user
- If the user gives consent, the payment data can be synced between desktop and mobile
- It’s simple to use from the developer’s point of view
Many third-party vendors have provided online payment solutions to tackle some of those issues, but the usage of third-party solutions comes with a user limitation: whether or not they have accounts with those third parties, and whether their platform and devices support it. Some developers went with the extreme of adding all possible "checkout" buttons to their forms, which is not helpful from a user experience point of view.
With a standardized API, you no longer need to rely on a specific vendor, and you can eliminate the unneeded checkout buttons. However, it’s important to notice that the standard payment request API is not a payment gateway and does not process the credit card data. It’s merely moving the issue to the server, in which you can easily choose your preferred vendor to process the card data without any hassle to your users.
Payment request add-on for Vaadin
If you are using Vaadin Flow, here is an add-on available that you can use right away.
Start by adding the maven dependency:
And here is a sample code to use it:
// Define payment methods:
PaymentMethod paymentMethod = new PaymentMethod();
// Show items to pay for:
PaymentItem paymentItem = new PaymentItem();
// Add a slot for payment total:
PaymentItem paymentTotal = new PaymentItem();
// Define the buy button:
Button buyButton = new Button("Buy");
// Define the Payment Request:
PaymentRequest paymentRequest = new PaymentRequest();
// Add payment methods and items to the request:
// Add the component to the UI:
There is also another similar add-on that uses the same approach but written differently.
Bring your own implementation to Vaadin
You can also write your style of handling the payment request on the browser in a form or a standard web compoent.
The add-on mentioned above is based on a community-driven web component. Check out the steps needed to create this add-on.
Implement payment API
Followed by using the
PaymentRequest constructor, and call the object’s
const request = new PaymentRequest(
The constructor has two mandatory arguments: supported methods of payment and payment details. The
show method returns a promise which is fulfilled with the payment data once the user has authorized the payment. You can read more about the API variants and the other parameters that you can use, and also this tutorial on how to integrate a client-side web component into Vaadin Flow.
Source code on GitHub.