The Payment Request API in 2026: Payer Details, Retries and Apple Pay (Part 2)

The Payment Request API in 2026: Payer Details, Retries and Apple Pay (Part 2)

Updated in November 2026. The 2023 version of this part used an old Google Pay format, closed the payment sheet with complete('success') before the payment was processed and had a cancellation branch that never ran. The code below replaces it.

In part 1 we built a payment request that works: Google Pay in test mode, a button that only appears when the browser can pay, and proper handling of cancellations. In this part we ask the payer for their contact details, look at shipping, handle payments that fail on the server, add Apple Pay and put everything together in a demo you can try.

Asking for the payer’s details

new PaymentRequest() takes a third, optional argument: an object of options that tells the payment sheet what else to collect. All of them are false by default.

const options = {
  requestPayerName: true,   // the payer’s name
  requestPayerEmail: true,  // their email address
  requestPayerPhone: false  // their phone number
};

const request = new PaymentRequest([googlePay], details, options);

When the user confirms, the values come back in the response as payerName, payerEmail and payerPhone. Google recommends collecting the email, phone and shipping address through these browser options rather than through the Google Pay API, so that they work the same with every payment method, and using Google Pay only for the payment credentials and, if you need it, the billing address.

Ask only for what you will use. Every extra field is one more thing the user has to check before paying.

Shipping: it still works, but it is on its way out

The API can also collect a shipping address and let the user choose a shipping option, with the price updated in the sheet. You switch it on with requestShipping and describe the options inside the payment details:

const options = { requestShipping: true, shippingType: 'shipping' }; // or 'delivery', 'pickup'

const details = {
  total: { label: 'Total', amount: { currency: 'EUR', value: '100.00' } },
  shippingOptions: [
    { id: 'standard', label: 'Standard (3-5 days)', amount: { currency: 'EUR', value: '0.00' }, selected: true },
    { id: 'express', label: 'Express (24 h)', amount: { currency: 'EUR', value: '9.90' } }
  ]
};

Two events tell you when the user changes something. In both, you answer with event.updateWith(), passing the new details or a promise that resolves to them:

request.addEventListener('shippingaddresschange', (event) => {
  event.updateWith(updateForAddress(request.shippingAddress));
});

request.addEventListener('shippingoptionchange', (event) => {
  event.updateWith(updateForOption(request.shippingOption));
});

function updateForAddress(address) {
  if (address.country !== 'ES') {
    // an empty list means we cannot ship to this address
    return { error: 'Sorry, we only ship to Spain.', shippingOptions: [] };
  }
  return { total: details.total, shippingOptions: details.shippingOptions };
}

function updateForOption(optionId) {
  const shipping = optionId === 'express' ? 9.9 : 0;
  return {
    shippingOptions: details.shippingOptions.map((option) => ({ ...option, selected: option.id === optionId })),
    total: { label: 'Total', amount: { currency: 'EUR', value: (100 + shipping).toFixed(2) } }
  };
}

Three details catch people out:

  • the total is not recalculated for you: when the shipping option changes, you send the new total yourself;
  • while the sheet is open, the browser may hide part of the address for privacy, so base the calculation on the country or postal code and check the full address in the final response;
  • Safari gives you 30 seconds to resolve updateWith(); after that the payment times out.

Now the status. MDN marks shippingaddresschange, shippingoptionchange and the related properties (shippingAddress, shippingOption, shippingType) as deprecated and not part of the standard. Chrome (since version 60) and Safari (since 11.1) still support them, so existing integrations keep working. For a new shop it is safer not to depend on them: collect the address in your own form before the payment step, or let your payment provider’s checkout component handle it.

When the payment fails on the server: retry()

The user can confirm in the sheet and the charge can still fail: a card is declined, an email address is not valid. Instead of closing the sheet and starting again, response.retry() shows the same sheet again with your error message so the user can fix it. The promise resolves when they confirm again, and the same response object now holds the new data. Chrome supports it since version 78 and Safari since 12.1.

let outcome = await sendToServer(response);

while (!outcome.ok && typeof response.retry === 'function') {
  try {
    await response.retry({ error: outcome.message });
  } catch (error) {
    return; // the user closed the sheet
  }
  outcome = await sendToServer(response);
}

await response.complete(outcome.ok ? 'success' : 'fail');

Besides a general error, retry() accepts errors for specific fields, for example { payer: { email: 'This email address is not valid.' } }, which the sheet shows next to the field. In browsers without retry(), the loop is skipped and the payment ends with complete('fail').

Adding Apple Pay

Safari only offers Apple Pay through this API. The method goes in the same array as Google Pay; each browser uses the methods it supports and ignores the rest:

const applePay = {
  supportedMethods: 'https://apple.com/apple-pay',
  data: {
    version: 3,
    merchantIdentifier: 'merchant.com.example',
    merchantCapabilities: ['supports3DS', 'supportsCredit', 'supportsDebit'],
    supportedNetworks: ['amex', 'discover', 'masterCard', 'visa'],
    countryCode: 'ES'
  }
};

const request = new PaymentRequest([googlePay, applePay], details, options);

Before this works you need an Apple Pay merchant identifier (the merchant.com.example above) and a server set up to process Apple Pay payments. Apple’s guide on configuring the environment lists the steps.

Then there is merchant validation. Before Safari shows the Apple Pay sheet, your site has to obtain a payment session from Apple. Shortly after you call show(), Safari fires a merchantvalidation event with a validationURL. Your server requests the session from that URL and your page passes it, or a promise of it, to event.complete():

request.onmerchantvalidation = (event) => {
  event.complete(fetchPaymentSession(event.validationURL));
};

async function fetchPaymentSession(validationURL) {
  const answer = await fetch('/apple-pay/session', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ validationURL })
  });
  return answer.json();
}

The /apple-pay/session endpoint is yours: it contacts Apple with your merchant credentials and returns the session. This event is also marked as deprecated and non-standard on MDN, and Chrome does not support it, but it is how Safari handles Apple Pay. After the user authorises the payment, response.details contains the Apple Pay token for your payment provider, and you finish with complete('success') or complete('fail') exactly as with Google Pay.

The complete demo

The CodePen demo puts it all together with Google Pay in test mode, so nothing is charged. It needs a button with the id pay-button, hidden at first, and an empty paragraph with the id result. Apple Pay is not in the demo, because merchant validation needs a server and a real merchant account. This is its JavaScript:

const button = document.getElementById('pay-button');
const result = document.getElementById('result');

// Google Pay in TEST mode, in the format Google documents for the Payment Request API
const googlePay = {
  supportedMethods: 'https://google.com/pay',
  data: {
    environment: 'TEST',
    apiVersion: 2,
    apiVersionMinor: 0,
    merchantInfo: { merchantName: 'Example Merchant' },
    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' } }
  ]
};

const options = { requestPayerName: true, requestPayerEmail: true };

async function setUp() {
  if (!window.PaymentRequest) {
    return;
  }
  const request = new PaymentRequest([googlePay], details, options);
  if (await request.canMakePayment()) {
    button.hidden = false;
  }
}

button.addEventListener('click', async () => {
  const request = new PaymentRequest([googlePay], details, options);
  let response;
  try {
    response = await request.show();
  } catch (error) {
    if (error.name === 'AbortError') {
      result.textContent = 'Payment cancelled.';
    } else {
      console.error(error);
      result.textContent = 'Something went wrong.';
    }
    return;
  }

  let outcome = await sendToServer(response);
  while (!outcome.ok && typeof response.retry === 'function') {
    try {
      await response.retry({ error: outcome.message });
    } catch (error) {
      result.textContent = 'Payment cancelled.';
      return;
    }
    outcome = await sendToServer(response);
  }

  await response.complete(outcome.ok ? 'success' : 'fail');
  result.textContent = outcome.ok
    ? 'Thank you, ' + response.payerName + '. The receipt goes to ' + response.payerEmail + '.'
    : outcome.message;
});

// Demo only: a real shop POSTs response.details, payerName and payerEmail to its server,
// which charges the token through its payment provider and answers with ok or an error message
async function sendToServer(response) {
  console.log(response.methodName, response.details, response.payerName, response.payerEmail);
  return { ok: true };
}

setUp();

Before going live

  • Serve the page over HTTPS and keep your normal checkout for browsers without the API, Firefox among them.
  • Never trust the total that comes from the browser: the server recalculates the order and charges that amount.
  • Call complete() only after the server has answered.
  • Treat AbortError as a cancellation, not as an error.
  • Test with Google Pay’s TEST environment first, then switch to PRODUCTION with the merchant ID that Google gives you.

Further reading