Monetization events
One responsibility of the Web Monetization agent is to instrument payments. The agent does this by calling the Open Payments APIs, which are APIs implemented by wallet providers.
The agent makes calls to the /incoming-payments
endpoint at your wallet provider and to the /outgoing-payments
endpoint at your site visitor’s wallet provider.
Each time the agent receives a 201 outgoing payment created
response from the site visitor’s wallet provider, the agent fires a monetization
event on the browser window.
Specifications
Specification |
---|
Web Monetization #events |
Event listeners
When a monetization
event fires, there’s no guarantee that payments will follow or, if they do, how often or how large the payments will be.
A monetization
event indicates that the site visitor’s wallet provider has created the resources needed for it to send a payment.
By adding an event listener to the relevant monetization <link>
element (or one of its ancestors), you can use the monetization
event properties to verify payments. These properties provide:
- Information about the amount and currency of a sent (not received) payment
- A URL representing an incoming payment that can be used to determine the amount received, similar to a receipt
- The URL representing the payment pointer or wallet address that an incoming payment request was sent to
High-level flow
- You add an event listener to a monetization
<link>
. - The site visitor accesses your page.
- The site visitor’s Web Monetization agent calls the Open Payments APIs to begin setting up the payment. More information about these API calls is provided in the How payments work page.
- The Web Monetization agent receives a
201 (outgoing payment created)
response from the site visitor’s wallet provider. - The Web Monetization agent fires a
monetization
event. - Your event listener calls its defined function.
Event properties
amountSent
The amountSent
property returns the value
and currency
of the sent payment.
value
- The amount. A valid decimal monetary value containing the amount that was sent.currency
- The currency code. A well-formed 3-letter ISO4217 code that represents the currency that was sent, such as USD or GBP.
Example using amountSent
Specifications
Specification |
---|
Web Monetization #amountsent-attribute |
incomingPayment
The incomingPayment
property allows you to check whether a payment was received and, if so, the amount received.
The property returns a URL that represents the incoming payment at your wallet provider. By querying the URL, you can get the receivedAmount
.
Example using incomingPayment
This example shows a hypothetical verification method that makes a basic request to the incomingPayment
URL and returns the results. For simplicity, it has no logic for authenticating the request.
Specifications
Specification |
---|
Web Monetization #incomingpayment-attribute |
paymentPointer
The paymentPointer
property returns the URL that represents the payment pointer or wallet address that the payment was sent to. In most cases, the value will be the same as the href
URL in the monetization <link>
.
Example using paymentPointer
Specifications
Specification |
---|
Web Monetization #paymentpointer-attribute |
Example use cases
amountSent
Program your website to show a thank you message to your site visitor when the amountSent
returns a non-zero amount. In this use case, you’re only checking that an amount — any amount — was sent.
incomingPayment
Program your website to remove ads or provide access to exclusive content to your site visitor after receiving a specific amount.
In this use case, you’ll query the URL returned by incomingPayment
to track the receivedAmount
. If appropriate, you can ensure the amount is increasing after each monetization
event to verify that a new payment was received.
paymentPointer
This section describes two use cases: one for vanity payment addresses and one for probabilistic revenue sharing.
Vanity payment address
Let’s say your payment pointer or wallet address is:
That’s hard to remember. Fortunately, your wallet provider offers vanity addresses which act as aliases. Your vanity address is:
You add the vanity address as the href
value in the monetization <link>
. Then, you set up an event listener for paymentPointer
. The value that’s returned will be:
Probabilistic revenue sharing
For this use case, let’s assume you are familiar with probabilistic revenue sharing, which is iteself an advanced use case.
When you use our Probabilistic Revshare Generator, you enter multiple payment pointers and/or wallet addresses and assign each one a weight. When finished, the generator creates a unique URL.
For example, after entering five wallet addresses and weights, the generator creates:
You add the generated URL as the href
value in the monetization <link>
. Then, you set up an event listener for paymentPointer
. The value that’s returned will be which one of the five wallet addresses that the payment was sent to.