MonetizationEvent
The MonetizationEvent
DOM events provide information about payments sent to WM receivers.
The monetization
event fires when a WM agent successfully creates an outgoing payment request at the WM provider. There’s no guarantee that any payments will follow or, if they do, how often or how large the payments will be.
By listening for monetization
events, you can use the returned details to verify the receipt of a payment. You can then choose to have the page programmatically respond to successful payments. For example, you could remove ads or provide access to exclusive content.
Bubbles | Yes |
---|---|
Cancelable | No |
Interface | MonetizationEvent |
Event handler property | onmonetization |
Current attributes
- amountSent - Returns the amount and currency code of the sent payment
- incomingPayment - Returns the incoming payment URL
- paymentPointer - A URL representing the payment pointer endpoint
Deprecated attributes
- amount - An integer amount delivered by an Interledger packet
- assetCode - A string representing the currency code of the received amount
- assetScale - The scale of the received amount
- receipt - The base-64 encoded Interledger STREAM receipt that the browser received
Example
<link rel="monetization" href="https://wallet.example/alice" />
<script>
// Checking via DOMTokenList
const link =
document.querySelector('link[rel="monetization"]') ||
document.createElement('link')
if (link.relList.supports('monetization')) {
console.log('Web Monetization is supported.')
}
// Checking global scope for MonetizationEvent
if (window.MonetizationEvent) {
console.log('Web Monetization is supported.')
}
// Checking if it's a global event handler
if (window.hasOwnProperty('onmonetization')) {
console.log('Web Monetization is supported.')
}
</script>
Specifications
Specification |
---|
Web Monetization #monetizationevent-interface |