Copyright © 2021 the Contributors to the Web Monetization Specification, published by the Web Platform Incubator Community Group under the W3C Community Contributor License Agreement (CLA). A human-readable summary is available.
Web Monetization is an API that allows websites to request small payments from users facilitated by the browser and the user's Web Monetization provider.
This specification was published by the Web Platform Incubator Community Group. It is not a W3C Standard nor is it on the W3C Standards Track. Please note that under the W3C Community Contributor License Agreement (CLA) there is a limited opt-out and other conditions apply. Learn more about W3C Community and Business Groups.
This specification is a work in progress within the community on the best shape it should take. Please see the explainer for more info.
The specification reflects the desired end-state of the Web Monetization APIs as currently anticipated and agreed to between the contributors. The specification is being prepared here, in this format, to collect the input of the Web community and prepare the work to ultimately follow the W3C standards track should it have the necessary support to do so.
For the most accurate reflection of the APIs that have been implemented by providers see the API documentation.
GitHub Issues are preferred for discussion of this specification.
This section is non-normative.
This section is non-normative.
The W3C have published two payments related APIs for browsers, the Payment Request API and the Payment Handler API.
The reason this API is not using the Payment Request API directly is that Web Monetization is intended for continuous payments rather than discrete payments. It is also designed to not have any user interaction: It is intended to provide a direct alternative to advertisements, rather than an alternative to traditional e-commerce checkout methods.
In future, some changes will be required to the Payment Request API and the Payment Handler API to support Web Monetization. This API brings the necessary capabilities to user agents in a manner that can integrate with existing payments APIs.
With advertisements, the user agent decides whether to display the ads and the user decides whether to engage with the ads. With Web Monetization, the user's provider decides whether to pay the site and, if so, how much to pay.
Web Monetization makes use of SPSP on top of ILP/STREAM to provide a high-level way to send money and data, while still providing tremendous flexibility.
WebIDLpartial interface Document {
readonly attribute Monetization monetization;
};
This flow refers to the user agent and the user's provider.
state
to "pending".
The
user agent
observes the
head
and looks for a Web Monetization
<meta name="monetization"> tag (specified below).
<meta name="monetization"> tag at any given
time
<meta> Tags Set
MUST be in the
head
of the document.
<meta> Tags Set
MUST be in the top level window (i.e. not
inside an iframe)
Below is repeated for every semantically (consider
meta.content = meta.content) new
<meta name="monetization"> tag seen for the life
of the page:
<meta> Tags Set
are malformed, the browser will stop here. The
user agent
SHOULD report a warning via the console.
<meta name="monetization"> tag is well-formed,
the browser should extract the Payment Setup Endpoint (Payment Pointer
or
SPSP
Url).
destination_account and
shared_secret fetched from the
SPSP query,
a
STREAM
connection is established. A single
STREAM
is opened on this connection, and a positive SendMax is set.
document.monetization.state to
started.
start event is fired.
MonetizationStartEvent
containing the Payment Setup Endpoint and the Monetization ID
as properties.
progress
event from document.monetization, corresponding
to this first packet.
<meta> Tags Set.
MonetizationProgressEvent
on
document.monetization. The event has details of
the packet.
document.monetization.state
MUST be set back to 'pending'
A provider can be implemented as a Payment Handler supporting the 'webmonetization' payment method (The payment method specification for this payment method is still under development as it is dependant on changes to the Payment Handler API that support streaming payments). Communication between the browser and the provider would use this flow.
<meta> Tags Set, the browser
creates a new
PaymentRequest
object with the following
PaymentMethodData
argument.
{
"supportedMethods": "webmonetization",
"data": {
"paymentPointer": "<payment pointer parsed from meta tag>"
}
}
.show() on this PaymentRequest, triggering the
PaymentHandler
for webmonetization. This PaymentHandler is how the
browser communicates to the provider.
.show()
MUST return a Promise, and must also
implement the
EventTarget
interface. The provider will emit
MonetizationStartEvent
and
MonetizationProgressEvent
events from this Promise to communicate to the browser when
payment occurs. The Promise
MUST NOT resolve, because Web
Monetization continues for the entire lifetime of a given meta
tag. The Promise MAY reject if there is
an error preventing the provider from paying and no retries will
occur.
WebIDL[Exposed=Window, SecureContext]
interface Monetization : EventTarget {
readonly attribute MonetizationState state;
attribute EventHandler onstart;
attribute EventHandler onprogress;
};
state
attribute
state
attribute exposes the current state of Web Monetization as a
MonetizationState
enum value.
onstart
attribute
onstart
attribute is an
EventHandler
for a
MonetizationStartEvent
named "start".
onprogress
attribute
onprogress
attribute is an
EventHandler
for an
MonetizationProgressEvent
named "progress".
WebIDLenum MonetizationState {
"pending",
"started"
};
pending"
meta
elements in the document.
started"
"start" event).
This section is non-normative.
| Event name | Interface | Dispatched when… | Target |
|---|---|---|---|
start
|
MonetizationStartEvent
|
The first non-zero payment is successfully sent. |
monetization
attribute
|
progress
|
MonetizationProgressEvent
|
A payment is successfully made to the receiver. |
monetization
|
WebIDL[SecureContext, Exposed=Window]
interface MonetizationStartEvent : Event {
constructor(DOMString type, MonetizationStartEventInit eventInitDict);
readonly attribute DOMString paymentPointer;
readonly attribute DOMString requestId;
};
The
constructor()
for
MonetizationStartEvent
behaves as follows:
When getting, returns the value it was initialized with. See
paymentPointer
member of
MonetizationStartEventInit
for more information.
When getting, returns the value it was initialized with. See
requestId
member of
MonetizationStartEventInit
for more information.
Dispatched once the first ILP packet with a non-zero amount has been fulfilled by the page's SPSP receiver. MUST be dispatched at least once if payment occurs.
WebIDLdictionary MonetizationStartEventInit : EventInit {
required DOMString paymentPointer;
required DOMString requestId;
};
paymentPointer
member
<meta name="monetization"> tag.
requestId
member
Dispatched every time an
ILP packet with a non-zero
amount has been fulfilled by the page's Web Monetization receiver
(including the first time, when start event is also
dispatched).
WebIDL[SecureContext, Exposed=Window]
interface MonetizationProgressEvent : Event {
constructor(DOMString type, MonetizationProgressEventInit eventInitDict);
readonly attribute DOMString amount;
readonly attribute DOMString assetCode;
readonly attribute DOMString assetScale;
readonly attribute DOMString? receipt;
};
The
constructor()
for
MonetizationProgressEvent
behaves as follows:
When getting, returns the value it was initialized with. See
amount
member of
MonetizationProgressEventInit
for more information.
When getting, returns the value it was initialized with. See
assetCode
member of
MonetizationProgressEventInit
for more information.
When getting, returns the value it was initialized with. See
assetScale
member of
MonetizationProgressEventInit
for more information.
When getting, returns the value it was initialized with. See
receipt
member of
MonetizationProgressEventInit
for more information.
WebIDLdictionary MonetizationProgressEventInit : EventInit {
required DOMString amount;
required DOMString assetCode;
required DOMString assetScale;
DOMString receipt;
};
amount
member
assetCode
member
assetScale
member
assetScale of 2 when denominated in
cents.
receipt
member
DEPRECATED: The Web-Monetization-Id header is
deprecated in favor of receipts.
Contains the Monetization ID (currently referred to as
requestId
in the
MonetizationStartEvent) as a a UUID version 4, which the user agent generated. This
header MAY be sent on [SPSP] queries for Web Monetization.
Web-Monetization-Id: dcd479ad-7d8d-4210-956a-13c14b8c67eb
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MAY, MUST, MUST NOT, and SHOULD in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in: