Payment Request API Integration

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    823
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Implementation of Payment Request API on Website

Payment Request API is browser standard allowing to invoke native payment dialog with cards saved in browser or system. On iOS Safari this is Apple Pay, on Chrome — Google Pay or saved cards from Google Chrome. User sees one dialog instead of card form — mobile conversion 20–40% higher than classic form.

When Applicable

Payment Request API works only over HTTPS. Supported in Chrome 61+, Safari 11.1+ (iOS), Edge 16+. Firefox only behind flag. For production need to check canMakePayment() before showing button — else appears where it doesn't work.

Basic Implementation

const paymentRequest = new PaymentRequest(
    [
        { supportedMethods: 'basic-card', data: { supportedNetworks: ['visa', 'mastercard'] } },
    ],
    {
        total: { label: 'Total', amount: { currency: 'RUB', value: '1500.00' } },
        displayItems: [
            { label: 'Product 1', amount: { currency: 'RUB', value: '1200.00' } },
            { label: 'Delivery',  amount: { currency: 'RUB', value: '300.00' } },
        ],
        shippingOptions: [
            {
                id: 'standard',
                label: 'Standard delivery (3–5 days)',
                amount: { currency: 'RUB', value: '300.00' },
                selected: true,
            },
        ],
    },
    { requestShipping: true, requestPayerEmail: true, requestPayerPhone: true }
);

// Check before showing button
const canPay = await paymentRequest.canMakePayment();
if (canPay) {
    document.getElementById('payment-request-btn').style.display = 'block';
}

Handling Response and Sending to Server

paymentRequest.addEventListener('paymentmethodchange', async (event) => {
    // Recalc cost on card change (e.g. corporate card)
    event.updateWith({ total: { label: 'Total', amount: { currency: 'RUB', value: '1500.00' } } });
});

paymentRequest.addEventListener('shippingaddresschange', async (event) => {
    const address = event.target.shippingAddress;
    const newShipping = await fetchShippingCost(address);
    event.updateWith({
        shippingOptions: newShipping.options,
        total: { label: 'Total', amount: { currency: 'RUB', value: newShipping.total } },
    });
});

try {
    const paymentResponse = await paymentRequest.show();

    // Send data to server
    const result = await fetch('/api/checkout/payment-request', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
            methodName: paymentResponse.methodName,
            details:    paymentResponse.details,     // card token
            shippingAddress: paymentResponse.shippingAddress,
            payerEmail: paymentResponse.payerEmail,
            payerPhone: paymentResponse.payerPhone,
        }),
    });

    const data = await result.json();

    if (data.success) {
        await paymentResponse.complete('success');
        window.location.href = `/orders/${data.orderId}/confirmation`;
    } else {
        await paymentResponse.complete('fail');
        showError(data.message);
    }
} catch (e) {
    if (e.name !== 'AbortError') {
        console.error('Payment failed', e);
    }
}

AbortError — user closed dialog. Normal, don't show error.

Integration with Payment Gateways

Payment Request API returns tokenized card data — not card number plaintext. This token sent to gateway. Stripe has native integration via @stripe/stripe-js:

import { loadStripe } from '@stripe/stripe-js';

const stripe = await loadStripe(STRIPE_PUBLIC_KEY);
const { paymentRequest, elements } = stripe.paymentRequest({
    country: 'RU',
    currency: 'rub',
    total: { label: 'Order #123', amount: 150000 },
    requestPayerName: true,
    requestPayerEmail: true,
});

const prButton = elements.create('paymentRequestButton', { paymentRequest });
const canUse = await paymentRequest.canMakePayment();
if (canUse) {
    prButton.mount('#payment-request-button');
}

paymentRequest.on('paymentmethod', async (ev) => {
    const { error } = await stripe.confirmCardPayment(clientSecret, {
        payment_method: ev.paymentMethod.id,
    });
    ev.complete(error ? 'fail' : 'success');
});

Stripe Payment Request Button auto shows Apple Pay on iOS Safari, Google Pay on Android Chrome — one component, two providers.

Server-side

Server handler receives token (for basic-card — encrypted card data from browser, for Stripe — paymentMethod.id) and sends to gateway as regular card payment. Logic no different from standard card payment, only token source different.

Polyfill and Fallback

Payment Request API not supported everywhere. Implementation must always have classic form as fallback. "Quick pay" button appears only on canMakePayment() === true. For others — standard card entry form without changes.