Copyright © 2016 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and permissive document license rules apply.
This specification describes a web API to allow merchants (i.e. web sites selling physical or digital goods) to easily accept payments from different payment methods with minimal integration. User agents (e.g., browsers) will facilitate the payment flow between merchant and user.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
The working group maintains a list of all bug reports that the group has not yet addressed. This draft highlights some of the pending issues that are still to be discussed in the working group. No decision has been taken on the outcome of these issues including whether they are valid. Pull requests with proposed specification text for outstanding issues are strongly encouraged.
This specification was derived from a report published previously by the Web Platform Incubator Community Group.
This document was published by the Web Payments Working Group as a Working Draft. This document is intended to become a W3C Recommendation. If you wish to make comments regarding this document, please send them to public-payments-wg@w3.org (subscribe, archives). All comments are welcome.
Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 1 September 2015 W3C Process Document.
This section is non-normative.
Buying things on the web, particularly on mobile, can be a frustrating experience for users. Every web site has its own flow and its own validation rules, and most require users to manually type in the same set of information over and over again. Likewise, it is difficult and time consuming for developers to create good checkout flows that support various payment schemes.
This specification describes an API that allows user agents (e.g., browsers) to act as an intermediary between the three key parties in every transaction: the merchant (e.g., an online web store), the buyer (e.g., the user buying from the online web store), and the Payment Method (e.g., credit card). Information necessary to process and confirm a transaction is passed between the Payment Method and the merchant via the user agent with the buyer confirming and authorizing as necessary across the flow.
In addition to better, more consistent user experiences, this also enables web sites to take advantage of more secure payment schemes (e.g., tokenization and system-level authentication) that are not possible with standard JavaScript libraries. This has the potential to reduce liability for the merchant and helps protect sensitive user information.
The API described in this document forms part of the Payment Request system described in the Payment Request Architecture [PAYMENT-ARCH] document.
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, SHOULD, and SHOULD NOT are to be interpreted as described in [RFC2119].
This specification defines one class of products:
A user agent MUST behave as described in this specification in order to be considered conformant. In this specification, user agent means a Web browser or other interactive user agent as defined in [HTML5].
User agents MAY implement algorithms given in this specification in any way desired, so long as the end result is indistinguishable from the result that would be obtained by the specification's algorithms.
A conforming Payment Request API user agent MUST also be a conforming implementation of the IDL fragments of this specification, as described in the “Web IDL” specification. [WEBIDL]
This specification relies on several other underlying specifications.
TypeError, JSON.stringify, and JSON.parse are defined by [ECMA-262-2015].
This document uses the format object@[[slotname]] to mean the internal slot [[slotname]] of the object object.
The term JSON-serializable object used in this specification means an object that can be serialized to a string using JSON.stringify and later deserialized back to an object using JSON.parse with no loss of data.
Event type and the terms fire an event, dispatch flag,
stop propagation flag, and stop immediate propagation flag are defined by [DOM4].
DOMException and the following DOMException types from [DOM4] are used:
| Type | Message (optional) |
|---|---|
AbortError |
The payment request was aborted |
InvalidStateError |
The object is in an invalid state |
NotSupportedError |
The payment method was not supported |
SecurityError |
The operation is only supported in a secure context |
The term extended attribute is defined by [WEBIDL].
[Constructor(sequence<PaymentMethodData> methodData, PaymentDetails details, optional PaymentOptions options),
SecureContext]
interface PaymentRequest : EventTarget {
Promise<PaymentResponse> show();
Promise<void> abort();
readonly attribute PaymentAddress? shippingAddress;
readonly attribute DOMString? shippingOption;
// Supports "shippingaddresschange" event
attribute EventHandler onshippingaddresschange;
// Supports "shippingoptionchange" event
attribute EventHandler onshippingoptionchange;
};
A web page creates a to make a payment request. This is typically associated with the user initiating a payment process (e.g., selecting a "Power Up" in an interactive game, pulling up to an automated kiosk in a parking structure, or activating a "Buy", "Purchase", or "Checkout" button). The PaymentRequest allows the web page to exchange information with the
user agent while the user is providing input before approving or denying a payment request.
PaymentRequest
The shippingAddress and shippingOption attributes are populated during processing if the flag is set.
requestShipping
The [SecureContext] extended attribute means that the is only exposed within a secure context and won't be accessible elsewhere.
PaymentRequest
The following example shows how to construct a and begin the user interaction:PaymentRequest
var payment = new PaymentRequest(methodData, details, options);
payment.addEventListener("shippingaddresschange", function (changeEvent) {
// Process shipping address change
});
payment.show().then(function(paymentResponse) {
// Process paymentResponse
// paymentResponse.methodName contains the selected payment method
// paymentResponse.details contains a payment method specific response
paymentResponse.complete("success");
}).catch(function(err) {
console.error("Uh oh, something bad happened", err.message);
});
The is constructed using the supplied PaymentRequestmethodData list including any payment method specific data, the payment details, and the payment options.
The methodData sequence contains dictionaries containing the payment method identifiers for the payment methods that the web site accepts and any associated payment method specific data.PaymentMethodData
[
{
supportedMethods: ["visa","bitcoin"]
},
{
supportedMethods: ["bobpay.com"],
data: {
merchantIdentifier: "XXXX",
bobPaySpecificField: true
}
}
]The details object contains information about the transaction that the user is being asked to complete such as the line items in an order.
{
displayItems: [
{
label: "Sub-total",
amount: { currency: "USD", value : "55.00" }, // US$55.00
},
{
label: "Sales Tax",
amount: { currency: "USD", value : "5.00" }, // US$5.00
}
],
total: {
label: "Total due",
amount: { currency: "USD", value : "60.00" }, // US$60.00
}
}The options object contains information about what options the web page wishes to use from the payment request system.
{
requestShipping: true
}methodData, details, and data should be combined into a single object.
The constructor MUST act as follows:
PaymentRequest
methodData sequence is zero, then throw a TypeError.
PaymentMethodData dictionary, if the length of the
supportedMethods sequence is zero, then throw a TypeError.
SecurityError.
There is an open issue about requiring a top-level browsing context for using PaymentRequest. Requiring one is a mitigation for a user being tricked into thinking a trusted site is asking for payment when in fact an untrusted iframe is asking for payment. The problem is some iframes may have a legitimate reason to request payment.
details does not contain a value for total, then throw a
TypeError.
details.total.amount.value is U+002D HYPHEN-MINUS, then throw a
TypeError. total MUST be a non-negative amount.
methodData or details.modifiers sequences, then throw a TypeError.
PaymentMethodData in methodData, if the data field is supplied but is not a JSON-serializable object, then throw a TypeError.
PaymentDetailsModifier in details.modifiers, if the total field is supplied and the first character of total.amount.value is U+002D HYPHEN-MINUS, then throw a
TypeError. total MUST be a non-negative amount.
PaymentRequest.methodData into request@[[methodData]].
The methodData supplied to the constructor
SHOULD be in the order of preference of the caller. Implementations MAY show payment methods in this order if possible but SHOULD prioritize the preference of the user when presenting payment methods.
PaymentRequest
details into request@[[details]].options into request@[[options]].shippingAddress attribute on request to null.
shippingOption attribute on request to null.
details contains a shippingOptions sequence and if any PaymentShippingOption in the sequence has the selected field set to true, then set
shippingOption to the id of the last ShippingOption in the sequence with selected set to true.
The show method is called when the page wants to begin user interaction for the payment request. The show method will return a Promise that will be resolved when the
user accepts the payment request. Some kind of user interface will be presented to the user to facilitate the payment request after the show method returns.
The method MUST act as follows:
show
PaymentRequest object on which the method is called.
InvalidStateError.supportedMethods sequences from each
PaymentMethodData in the request@[[methodData]] sequence.
NotSupportedError.
The abort method may be called if the web page wishes to tell the
user agent to abort the payment request and to tear down any user interface that might be shown. abort can only be called after the method has been called and before the request@[[acceptPromise]] has been resolved. For example, a web page might choose to do this if the goods they are selling are only available for a limited amount of time. If the user does not accept the payment request within the allowed time period, then the request will be aborted.
show
A user agent might not always be able to abort a request. For example, if the user agent has delegated responsibility for the request to another app. In this situation, abort will reject the returned Promise.
The architecture document suggests that payment apps may take numerous forms, including as web-based apps. This specification should describe how the user-agent will pass the payment request data and the complete signal to a web-based payment app and also how it will receive the payment response from the payment app.
This specification should describe how the user agent will pass the payment request data and the complete signal to a native payment app and also how it will receive the payment response from the payment app.
The method MUST act as follows:abort
PaymentRequest object on which the method is called.
InvalidStateError.InvalidStateError and abort this algorithm.AbortError.undefined.The internal slot [[state]] follows the following state transitions:
shippingAddress is populated when the user provides a shipping address. It is null by default. When a user provides a shipping address, the shipping address changed algorithm runs.
onshippingaddresschange is an EventHandler for an
Event named shippingaddresschange.
shippingOption is populated when the user chooses a shipping option. It is null by default. When a user chooses a shipping option, the shipping option changed algorithm runs.
onshippingoptionchange is an EventHandler for an
Event named shippingoptionchange.
Instances of are created with the internal slots in the following table:PaymentRequest
| Internal Slot | Description (non-normative) |
|---|---|
| [[methodData]] | The methodData supplied to the constructor. |
| [[details]] |
The current for the payment request initially supplied to the constructor and then updated with calls to .
|
| [[options]] | The supplied to the constructor. |
| [[state]] | The current state of the payment request. |
| [[updating]] |
true is there is a pending call to update the payment request and false otherwise.
|
| [[acceptPromise]] |
The pending Promise created during that will be resolved if the user accepts the payment request.
|
dictionary PaymentMethodData {
required sequence<DOMString> supportedMethods;
object data;
};
A dictionary is used to indicate a set of supported payment
methods and any associated payment method specific data for those methods.
PaymentMethodData
The following fields are part of the dictionary:PaymentMethodData
supportedMethodssupportedMethods is a required sequence of strings containing payment method identifiers for
payment methods that the merchant web site accepts.datadata is a JSON-serializable object that provides optional information that might be needed by the supported payment methods.dictionary PaymentCurrencyAmount {
required DOMString currency;
required DOMString value;
};
A dictionary is used to supply monetary amounts. The following fields MUST be supplied for a PaymentCurrencyAmount to be valid:
PaymentCurrencyAmount
currencycurrency is a string containing a currency identifier. The most common identifiers are three-letter alphabetic codes as defined by [ISO4217] (for example,
"USD" for US Dollars) however any string is considered valid.
value^-?[0-9]+(\.[0-9]+)?$.
The following example shows how to represent US$55.00.
{
"currency": "USD",
"value" : "55.00"
}dictionary PaymentDetails {
PaymentItem total;
sequence<PaymentItem> displayItems;
sequence<PaymentShippingOption> shippingOptions;
sequence<PaymentDetailsModifier> modifiers;
};
The PaymentDetails dictionary is passed to the constructor and provides information about the requested transaction. The PaymentRequestPaymentDetails dictionary is also used to update the payment request using .
updateWith
The following fields are part of the PaymentDetails dictionary:
totalPaymentItem contains the total amount of the payment request.
total MUST be a non-negative value. This means that the total.amount.value field MUST NOT begin with a U+002D HYPHEN-MINUS character.
displayItemsPaymentItem dictionaries contains line items for the payment request that the user agent MAY display. For example, it might include details of products or breakdown of tax and shipping. It is optional to provide this information.
The user agent MAY validate that the total amount is the sum of these items, but it is the responsibility of the calling code to ensure that.
shippingOptionsIf the sequence is empty, then this indicates that the merchant cannot ship to the current .shippingAddress
If an item in the sequence has the selected field set to true, then this is the shipping option that will be used by default and will be set to the shippingOptionid of this option without running the shipping option changed
algorithm. Authors SHOULD NOT set selected to true on more than one item. If more than one item in the sequence has selected set to true, then user agents MUST select the last one in the sequence.
The shippingOptions field is only used if the was constructed with PaymentRequestPaymentOptionsrequestShipping set to true.
If the sequence has an item with the selected field set to true, then authors SHOULD ensure that the total field includes the cost of the shipping option. This is because no event will be fired for this option unless the user selects an alternative option first.
shippingoptionchange
modifiersPaymentDetailsModifier dictionaries contains modifiers for particular payment method identifiers. For example, it allows you to adjust the total amount based on payment method.
dictionary PaymentDetailsModifier {
required sequence<DOMString> supportedMethods;
PaymentItem total;
sequence<PaymentItem> additionalDisplayItems;
};
The PaymentDetailsModifier dictionary provides details that modify the
based on payment method identifier. It contains the following fields:
PaymentDetails
supportedMethodssupportedMethods field contains a sequence of payment method identifiers. The remaining fields in the PaymentDetailsModifier apply only if the user selects a payment method included in this sequence.
totalPaymentItem value overrides the total field in the
PaymentDetails dictionary for the payment method identifiers in the supportedMethods field.
additionalDisplayItemsPaymentItem dictionaries provides additional display items that are appended to the displayItems field in the PaymentDetails dictionary for the payment method identifiers in the supportedMethods field. This field is commonly used to add a discount or surcharge line item indicating the reason for the different total amount for the selected payment method that the user agent MAY display.
The user agent MAY validate that the total amount is the sum of the displayItems and the additionalDisplayItems, but it is the responsibility of the calling code to ensure that.
dictionary PaymentOptions {
boolean requestPayerEmail = false;
boolean requestPayerPhone = false;
boolean requestShipping = false;
};
The PaymentOptions dictionary is passed to the constructor and provides information about the options desired for the payment request.
PaymentRequest
The following fields MAY be passed to the constructor:
PaymentRequest
requestPayerEmailtrue to allow a merchant to email a receipt.
requestPayerPhonetrue to allow a merchant to phone a customer with a billing enquiry.
requestShippingtrue when physical goods need to be shipped by the merchant to the user. This would be set to false for an online-only electronic purchase transaction.
dictionary PaymentItem {
required DOMString label;
required PaymentCurrencyAmount amount;
};
A sequence of one or more PaymentItem dictionaries is included in the dictionary to indicate the what the payment request is for and the value asked for.
PaymentDetails
The following fields MUST be included in a PaymentItem for it to be valid:
labelamountPaymentCurrencyAmount containing the monetary amount for the item.
PaymentItem with amounts in more than once currency.
interface PaymentAddress {
readonly attribute DOMString country;
readonly attribute FrozenArray<DOMString> addressLine;
readonly attribute DOMString region;
readonly attribute DOMString city;
readonly attribute DOMString dependentLocality;
readonly attribute DOMString postalCode;
readonly attribute DOMString sortingCode;
readonly attribute DOMString languageCode;
readonly attribute DOMString organization;
readonly attribute DOMString recipient;
readonly attribute DOMString careOf;
readonly attribute DOMString phone;
};
countryaddressLineregioncitydependentLocalitypostalCodesortingCodelanguageCodeorganizationrecipientcareOfphone
If the requestShipping flag was set to true in the PaymentOptions passed to the PaymentRequest constructor, then the user agent will populate the
shippingAddress field of the and ultimately the
PaymentRequest object with the user's selected shipping address after the user has accepted the payment.
PaymentResponse
dictionary PaymentShippingOption {
required DOMString id;
required DOMString label;
required PaymentCurrencyAmount amount;
boolean selected = false;
};
The PaymentShippingOption dictionary has fields describing a shipping option. A web page can provide the user with one or more shipping options by calling the updateWith method in response to a change event.
The following fields MUST be included in a PaymentItem for it to be valid:
idPaymentShippingOption. It MUST be unique for a given PaymentRequest.labelamountPaymentCurrencyAmount containing the monetary amount for the item.
selectedtrue to indicate that this is the default selected PaymentShippingOption in a sequence. User agents SHOULD display this option by default in the user interface.enumPaymentComplete{ "success", "fail", "" }; interfacePaymentResponse{ readonly attribute DOMString methodName; readonly attribute object details; readonly attributePaymentAddress? shippingAddress; readonly attribute DOMString? shippingOption; readonly attribute DOMString? payerEmail; readonly attribute DOMString? payerPhone; Promise<void> complete(optionalPaymentCompleteresult = ""); };
A PaymentResponse is returned when a user has selected a payment method and approved a payment request. It contains the following fields:
methodNamedetailsshippingAddressrequestShipping flag was set to true in the PaymentOptions passed to the PaymentRequest constructor, then shippingAddress will be the full and final shipping address chosen by the user.
shippingOptionrequestShipping flag was set to true in the PaymentOptions passed to the PaymentRequest constructor, then shippingOption will be the id attribute of the selected shipping option.
payerEmailrequestPayerEmail flag was set to true in the PaymentOptions passed to the PaymentRequest constructor, then payerEmail will be the email address chosen by the user.
payerPhonerequestPayerPhone flag was set to true in the PaymentOptions passed to the PaymentRequest constructor, then payerPhone will be the phone number chosen by the user.
The complete method must be called after the user has accepted the payment request and the [[acceptPromise]] has been resolved. Calling the complete method tells the user agent that the user interaction is over (and should cause any remaining user interface to be closed).
The complete method takes a string argument from the PaymentComplete enum (result). These values are used to influence the user experience provided by the user agent when the user interface is dismissed. The value of result has the following meaning:
"success""fail"""result.The method MUST act as follows:complete
InvalidStateError.
result to influence the user experience. User agents SHOULD treat unrecognized result values as the value "".undefined.Instances of are created with the internal slots in the following table:PaymentResponse
| Internal Slot | Description (non-normative) |
|---|---|
| [[completeCalled]] |
true if the method has been called and false otherwise.
|
This section is non-normative.
| Event name | Interface | Dispatched when... |
|---|---|---|
shippingaddresschange |
PaymentRequestUpdateEvent |
The user provides a new shipping address. |
shippingoptionchange |
PaymentRequestUpdateEvent |
The user chooses a new shipping option. |
[Constructor(DOMString type, optionalPaymentRequestUpdateEventIniteventInitDict)] interface PaymentRequestUpdateEvent :Event{ void updateWith(Promise<PaymentDetails> d); }; dictionary PaymentRequestUpdateEventInit : EventInit { };
The enables the web page to update the details of the payment request in response to a user interaction.PaymentRequestUpdateEvent
If the web page wishes to update the payment request then it should call and provide a promise that will resolve with a updateWith dictionary containing changed values that the user agent SHOULD present to the user.PaymentDetails
The PaymentRequestUpdateEvent constructor MUST set the internal slot [[waitForUpdate]] to false.
The updateWith method MUST act as follows:
PaymentRequest object that is the target of the event.
InvalidStateError.InvalidStateError.
InvalidStateError.
InvalidStateError.
d to indicate that the payment request is valid again.
The user agent SHOULD disable any part of the user interface that could cause another update event to be fired. Only one update may be processed at a time.
d settles.d is rejected, then:
AbortError.d is rejected then this is a fatal error for the payment request. This would potentially leave the payment request in an inconsistent state since the web page hasn't successfully handled the change event. Consequently, if d is rejected then the payment request is aborted.
User agents MAY show an error message to the user when this occurs.
d is resolved with details and details is a
PaymentDetails dictionary, then:
details contains a total value and the first character of
total.amount.value is NOT U+002D HYPHEN-MINUS, then copy
total value to the total field of target@[[details]] (total MUST be a non-negative amount).
details contains a displayItems value, then copy this value to the displayItems field of target@[[details]].
details contains a modifiers value, then copy this value to the modifiers field of target@[[details]].
details contains a shippingOptions sequence, then:
shippingOptions sequence from details to the
shippingOptions field of target@[[details]].
details contains a shippingOptions sequence and if any ShippingOption in the sequence has the selected field set to true, then set
newOption to the id of the last ShippingOption in the sequence with selected set to true.
shippingOption on target to
newOption.
The spec needs to clearly state how it will handle internationalization issues (such as selection order for language via explicit preferences, Accept-Language headers, etc.)
When the internal slot [[state]] of a object is set to
interactive, the user agent will trigger the following algorithms based on user interaction.PaymentRequest
The shipping address changed algorithm runs when the user provides a new shipping address. It MUST run the following steps:
PaymentRequest object that the user is interacting with.shippingaddresschange.shippingAddress attribute on request to the shipping address provided by the user.
The shipping option changed algorithm runs when the user chooses a new shipping option. It MUST run the following steps:
PaymentRequest object that the user is interacting with.shippingoptionchange.shippingOption attribute on request to the
id string of the PaymentShippingOption provided by the user.
The PaymentRequest updated algorithm is run by other algorithms above to fire an event to indicate that a user has made a change to a called request with an event name of name.PaymentRequest
It MUST run the following steps:
PaymentRequestUpdateEvent.The user accepts the payment request algorithm runs when the user accepts the payment request and confirms that they want to pay. It MUST run the following steps:
PaymentRequest object that the user is interacting with.
requestShipping value of request@[[options]] is true, then if the shippingAddress attribute of request is null or if the shippingOption attribute of request is null, then terminate this algorithm and take no further action. This should never occur.
PaymentResponse.
methodName attribute value of response to the payment method identifier for the payment method that the user selected to accept the payment.
details attribute value of response to a JSON-serializable object containing the payment method specific message used by the merchant to process the transaction. The format of this response will be defined by a Payment Transaction
Message Specification.
requestShipping value of request@[[options]] is true, then copy the shippingAddress attribute of
request to the shippingAddress attribute of response.
requestShipping value of request@[[options]] is true, then copy the shippingOption attribute of
request to the shippingOption attribute of response.
requestPayerEmail value of request@[[options]] is true, then set the payerEmail attribute of
response to the payer's email address selected by the user.
requestPayerPhone value of request@[[options]] is true, then set the payerPhone attribute of
response to the payer's phone number selected by the user.
This section is non-normative.
This section is a placeholder to record security considerations as we gather them through working group discussion.
The API does not directly support encryption of data fields. Individual payment methods may choose to include support for encrypted data but it is not mandatory that all payment methods support this.
PaymentRequest
This section is non-normative.
This section is a placeholder to record privacy considerations as we gather them through working group discussion.
The user agent should never share information about the user to the web page (such as the shipping address) without user consent.