The navigator.monetization interface exposes the monetization API as defined in the Web Monetization specification. It allows web developers to retrieve basic information about the current monetization stream and to listen to events describing that stream.
See the Spec Questions page for the current discussions.
navigator.monetization has the following properties:
navigator.monetization.state Read onlynavigator.monetization.pointernavigator.monetization.onstatechangenavigator.monetization has the following events:
monetizationWhen a succesful Interledger payment is made the receiver is notified by a receipt. If the browser receives such a receipt it fires a monetization event. Since receipts may be received every second or so, this event will fire many times.
The monetization event is useful if you are waiting for a particular payment, for instance a tip. Although the current monetization implementation does not support tipping, future ones will. This would for instance allow you to ask for a tip of at least $1 in order to read an article. You would listen to the monetization event until this amount comes in in one single receipt, and then reveal the article.
The monetization event has the following properties in event.detail:
amountassetCodeassetScalereceiptrequestIdurlThe last three properties are not very important to web developers. You need them only if you have to dive into the Interledger details.
The first three attributes contain the amount of money the page just received. The assetScale specifies the scale of the amount. The formula is
let receivedSum = amount * 10^-assetScale
Thus, with an amount of 6 and an assetScale of 3 you received 6 * 10 ^-3 or 0.006 of whatever currency is specified in assetCode.
Example script here or refer to Web Monetization tutorials?