Skip to content

superuserdev/WebPayment

Repository files navigation

WebPayment

Build Status


Progressive enhancement for the Web Payment API

Creates a payment form, complete with autocomplete attributes, in a <dialog> to provide a polyfill for the Web Payment API.

import PaymentRequest from './PaymentRequest.js';
document.getElementById('buy-now').addEventListener('click', async () => {
  try {
    const endpoint = new URL('/pay/', location.origin);
    const pay = new PaymentRequest(/* ... */);
    const payment = await pay.show();
    const resp = await fetch(endpoint, {
      method: 'POST',
      body: payment
    });
  } catch(error) {
    console.error(error);
  }
});

Releases

No releases published

Packages

No packages published