webpayments

1.0.0 • Public • Published

webpayments-polyfill

Experimental web payments polyfill

WARNING: The Web Payments spec is still under heavy development. This implementation (and its API) will change often and without notice.

Example

navigator.requestPayment(['interledger'], {
  amount: '100',
  currencyCode: 'USD',
  countryCode: 'US'
}, {
  interledger: {
    account: 'https://localhost:3001/accounts/mellie'
  }
})

Installation

Quickstart

The fastest way to include the polyfill is with a script tag:

<script src="https://web-payments.net/polyfill.js"></script>

Webpack/Browserify

If you are using a tool like webpack or browserify, you can also just install this library from NPM:

npm install -S webpayments

Async embed code

The basic script tag method will be blocking. A non-blocking alternative is the following embed code:

<script>
(function(w,e,b,p,a,y) {
  w[p] = w[p] || (function (cb) { this.push(cb); return this }).bind([]);
  a = e.createElement(b); a.async = 1; a.src = '//web-payments.net/polyfill.js';
  y = e.getElementsByTagName(b)[0]; y.parentNode.insertBefore(a,y);
})(window,document,'script','WebPaymentsOnLoad');
</script> 

You can then register a callback to be called when the polyfill has been loaded:

<script>
WebPaymentsOnLoad(function () {
  navigator.requestPayment(/* ... */)
})
</script> 

Usage

TODO: Add API documentation

For now, please see the spec: http://discourse.wicg.io/t/rfc-proposal-for-new-web-payments-api/1100

Package Sidebar

Install

npm i webpayments

Weekly Downloads

4

Version

1.0.0

License

ISC

Last publish

Collaborators

  • justmoon