Web Monetization

Draft Community Group Report

Latest published version:
https://www.w3.org/web-monetization/
Latest editor's draft:
https://webmonetization.org/specification
Editors:
Adrian Hope-Bailie (Coil Technologies Inc.)
Ben Sharafian (Coil Technologies Inc.)
Nick Dudfield (Coil Technologies Inc.)
Feedback:
GitHub wicg/webmonetization (pull requests, new issue, open issues)

Abstract

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.

Status of This Document

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.

Warning

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.

1. Terminology

User:
the party who is accessing the web-monetized website.
Website:
the web-monetized website.
Web Monetization provider:
the party making payments on behalf of the user.
Web Monetization receiver:
the party receiving payments on behalf of the website.
User agent:
the web browser used by the user.

2. Goals

This section is non-normative.

3. Relation to other protocols

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.

4. Extensions to the Document interface

WebIDLpartial interface Document {
  readonly attribute Monetization monetization;
};

5. Flow

This flow refers to the user agent and the user's provider.

  1. The user agent sets state to "pending".
  2. The user agent observes the head and looks for a Web Monetization <meta name="monetization"> tag (specified below).

    • There MUST be only one <meta name="monetization"> tag at any given time
    • The <meta> Tags Set MUST be in the head of the document.
    • The <meta> Tags Set MUST be in the top level window (i.e. not inside an iframe)
  3. Below is repeated for every semantically (consider meta.content = meta.content) new <meta name="monetization"> tag seen for the life of the page:

    • If any of the Web Monetization <meta> Tags Set are malformed, the browser will stop here. The user agent SHOULD report a warning via the console.
    • If the Web Monetization <meta name="monetization"> tag is well-formed, the browser should extract the Payment Setup Endpoint (Payment Pointer or SPSP Url).
    • The user agent generates a fresh random UUID (version 4) and uses this as a Monetization ID. This MUST be regenerated upon dynamic changes to the meta tags and MUST be unique per page load in order to avoid user tracking.
    • The user agent passes these payment details to the user's provider (see Payment Handler Flow).
    • The provider resolves the Payment Setup Endpoint and begins to pay. The provider MAY be acting from a different machine from the user. Cookies and session information MUST NOT be carried with any requests made to resolve the Payment Setup Endpoint, with the exception of the Monetization ID.
      • With the 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.
      • The provider SHOULD set their SendMax high enough that it is never reached, and make payment adjustments by limiting throughput.
    • Once the STREAM connection has fulfilled an ILP packet with a non-zero amount, the provider notifies the browser:
      • The user agent sets document.monetization.state to started.
      • This MUST occur before the start event is fired.
      • This event is a MonetizationStartEvent containing the Payment Setup Endpoint and the Monetization ID as properties.
      • The user agent also emits a progress event from document.monetization, corresponding to this first packet.
    • Payment continues for the lifetime of a given meta tag (or semantically equivalent)
      • The provider MAY decide to stop/start payment at any time, e.g. if the user is idle, backgrounds the page, or instructs the browser to do so.
      • If the STREAM connection is severed, the provider will redo the SPSP query to the same Payment Setup Endpoint as before with the same Monetization ID. The user agent MUST NOT re-process the <meta> Tags Set.
      • Each time a packet with a non-zero amount is fulfilled, the provider notifies the browser, and the browser emits a MonetizationProgressEvent on document.monetization. The event has details of the packet.
      • When a stream is closed the document.monetization.state MUST be set back to 'pending'

5.1 Payment Handler Flow

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.

{
  "supportedMethods": "webmonetization",
  "data": {
    "paymentPointer": "<payment pointer parsed from meta tag>"
  }
}

6. Specification

6.1 Meta Tags Set

The <meta> Tags Set MUST be in the document's head. The <meta> Tags Set allows the user agent to pay a site via Web Monetization by specifying a Payment Pointer or SPSP url.

The name of the <meta> tags all start with monetization. The table below lists the different names and the formats of their content. Currently there is only one tag, but this may be expanded in the future so care MUST be given to altering a Tags Set such that <meta name="monetization"> is the last one modified.

Name Required? Format Description
monetization Yes Payment Setup Endpoint The Payment Pointer or SPSP url that the user agent will pay to.

6.1.1 Examples

6.1.1.1 Web Monetization Meta Tag
<meta name="monetization" content="$wallet.example.com/alice">

6.2 Monetization interface

WebIDL[Exposed=Window, SecureContext]
interface Monetization : EventTarget {
  readonly attribute MonetizationState state;
  attribute EventHandler onstart;
  attribute EventHandler onprogress;
};
state attribute
A state attribute exposes the current state of Web Monetization as a MonetizationState enum value.
onstart attribute
A onstart attribute is an EventHandler for a MonetizationStartEvent named "start".
onprogress attribute
A onprogress attribute is an EventHandler for an MonetizationProgressEvent named "progress".

6.3 MonetizationState enum

WebIDLenum MonetizationState {
  "pending",
  "started"
};
"pending"
Indicates that monetization has not yet started. This is set even if there are no Web Monetization meta elements in the document.
"started"
Indicates that monetization has started (i.e. the user agent fired the "start" event).

6.4 Events

6.4.1 Summary

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

6.4.2 MonetizationStartEvent interface

WebIDL[SecureContext, Exposed=Window]
interface MonetizationStartEvent : Event {
  constructor(DOMString type, MonetizationStartEventInit eventInitDict);
  readonly attribute DOMString paymentPointer;
  readonly attribute DOMString requestId;
};
6.4.2.1 constructor()

The constructor() for MonetizationStartEvent behaves as follows:

  1. ...TBW...
6.4.2.2 paymentPointer attribute

When getting, returns the value it was initialized with. See paymentPointer member of MonetizationStartEventInit for more information.

6.4.2.3 requestId attribute

When getting, returns the value it was initialized with. See requestId member of MonetizationStartEventInit for more information.

6.4.2.4 MonetizationStartEventInit dictionary

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
A string representing the Payment Pointer resolved from the <meta name="monetization"> tag.
requestId member
The Monetization ID (UUID V4) generated by the browser (see 5. Flow).

6.4.3 MonetizationProgressEvent interface

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;
};
6.4.3.1 constructor()

The constructor() for MonetizationProgressEvent behaves as follows:

  1. ...TBW...
6.4.3.2 amount attribute

When getting, returns the value it was initialized with. See amount member of MonetizationProgressEventInit for more information.

6.4.3.3 assetCode attribute

When getting, returns the value it was initialized with. See assetCode member of MonetizationProgressEventInit for more information.

6.4.3.4 assetScale attribute

When getting, returns the value it was initialized with. See assetScale member of MonetizationProgressEventInit for more information.

6.4.3.5 receipt attribute

When getting, returns the value it was initialized with. See receipt member of MonetizationProgressEventInit for more information.

6.4.3.6 MonetizationProgressEventInit dictionary
WebIDLdictionary MonetizationProgressEventInit : EventInit {
  required DOMString amount;
  required DOMString assetCode;
  required DOMString assetScale;
  DOMString receipt;
};
amount member
The destination amount received as specified in the ILP packet.
assetCode member
The three letter asset code describing the amount's units.
assetScale member
The scale of the amount. For example, USD would have an assetScale of 2 when denominated in cents.
receipt member
base64-encoded STREAM Receipt issued by the Web Monetization receiver to the Web Monetization provider as proof of the total amount received in the stream.

6.5 HTTP Headers

6.5.1 Web-Monetization-Id

Warning

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

A. Conformance

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.

B. References

B.1 Normative references

[dom]
DOM Standard. Anne van Kesteren. WHATWG. Living Standard. URL: https://dom.spec.whatwg.org/
[html]
HTML Standard. Anne van Kesteren; Domenic Denicola; Ian Hickson; Philip Jägenstedt; Simon Pieters. WHATWG. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[Receipt]
STREAM Receipt. URL: https://interledger.org/rfcs/0039-stream-receipts/
[RFC2119]
Key words for use in RFCs to Indicate Requirement Levels. S. Bradner. IETF. March 1997. Best Current Practice. URL: https://www.rfc-editor.org/rfc/rfc2119
[RFC8174]
Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words. B. Leiba. IETF. May 2017. Best Current Practice. URL: https://www.rfc-editor.org/rfc/rfc8174
[SPSP]
Simple Payments Setup Protocol. URL: https://interledger.org/rfcs/0009-simple-payment-setup-protocol
[STREAM]
STREAM. URL: https://interledger.org/rfcs/0029-stream/
[webidl]
Web IDL Standard. Edgar Chen; Timothy Gu. WHATWG. Living Standard. URL: https://webidl.spec.whatwg.org/

B.2 Informative references

[Interledger]
Interledger Protocol (ILP). URL: https://interledger.org/rfcs/0027-interledger-protocol-4/
[Payment-Handler]
Payment Handler API. Adrian Hope-Bailie; Ian Jacobs; Rouslan Solomakhin; Jinho Bang. W3C. 25 January 2023. W3C Working Draft. URL: https://www.w3.org/TR/payment-handler/
[payment-Request]
Payment Request API. Marcos Caceres; Rouslan Solomakhin; Ian Jacobs. W3C. 8 September 2022. W3C Recommendation. URL: https://www.w3.org/TR/payment-request/