From 4ca93c93bb3455c6256034f576fcb71f180388ed Mon Sep 17 00:00:00 2001
From: Marcos Caceres PaymentRequest
interface
- The shippingAddress, shippingOption,
- and shippingType attributes
- are populated during processing if the requestShipping
flag is set.
+ The shippingAddress,
+ shippingOption,
+ and shippingType attributes
+ are populated during processing if the requestShipping flag is set.
- The [SecureContext]
extended attribute means that the PaymentRequest
+ The [SecureContext]
extended attribute means that the PaymentRequest
is only exposed within a secure context and won't be accessible elsewhere.
The following example shows how to construct a PaymentRequest
and begin the
+
The following example shows how to construct a PaymentRequest and begin the user interaction:
-- 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); - }); -+
+ 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 PaymentRequest
is constructed using the supplied methodData
+ The PaymentRequest is constructed using the supplied methodData
list including any payment method specific data
, the payment details
,
and the payment options
.
The methodData
sequence contains PaymentMethodData
dictionaries
+
The methodData
sequence contains PaymentMethodData dictionaries
containing the payment method identifiers for the payment methods that the web site accepts
and any associated payment method specific data.
+[ { supportedMethods: ["visa","bitcoin"] @@ -222,7 +223,7 @@PaymentRequest constructor
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: [ { @@ -245,7 +246,7 @@PaymentRequest constructor
The
-options
object contains information about what options the web page wishes to use from the payment request system.+{ requestShipping: true } @@ -253,73 +254,73 @@PaymentRequest constructor
- The PaymentRequest
constructor MUST act as follows:
+ The PaymentRequest constructor MUST act as follows:
methodData
sequence is zero, then throw
- a TypeError
.
+ a TypeError.
PaymentMethodData
dictionary, if the length of the
- supportedMethods
sequence is zero, then throw a TypeError
.
+ For each PaymentMethodData dictionary, if the length of the
+ supportedMethods
sequence is zero, then throw a TypeError.
SecurityError
.
+ a SecurityError.
details
does not contain a value for total
, then throw a
- TypeError
.
+ TypeError.
details.total.amount.value
is not a valid decimal monetary value, then throw a
- TypeError
.
+ TypeError.
details.total.amount.value
is U+002D HYPHEN-MINUS, then throw a
- TypeError
. total
MUST be a non-negative amount.
+ TypeError. total
MUST be a non-negative amount.
details.displayItems
sequence contains any PaymentItem
+ If the details.displayItems
sequence contains any PaymentItem
objects with an amount
that is not a valid decimal monetary value, then throw a
- TypeError
.
+ TypeError.
details.shippingOptions
sequence contains any PaymentShippingOption
+ If the details.shippingOptions
sequence contains any PaymentShippingOption
objects with an amount
that is not a valid decimal monetary value, then throw a
- TypeError
.
+ TypeError.
details
contains a value for error
, then throw a
- TypeError
.
+ TypeError.
PaymentMethodData
in methodData
, if the data
field
- is supplied but is not a JSON-serializable object, then throw a TypeError
.
+ For each 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 is not a valid decimal monetary value, then throw a TypeError
.
+ For each PaymentDetailsModifier in details.modifiers
, if the total
field
+ is supplied and is not a valid decimal monetary value, then throw a TypeError.
PaymentDetailsModifier
in details.modifiers
, if the total
field
+ For each 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.
+ TypeError. total
MUST be a non-negative amount.
PaymentDetailsModifier
in details.modifiers
, if the
- additionalDisplayItems
sequence contains any PaymentItem
+ For each PaymentDetailsModifier in details.modifiers
, if the
+ additionalDisplayItems
sequence contains any PaymentItem
objects with an amount
that is not a valid decimal monetary value, then throw a
- TypeError
.
+ TypeError.
PaymentRequest
.methodData
into request@[[\methodData]].
- The methodData
supplied to the PaymentRequest
constructor
+ The methodData
supplied to the PaymentRequest 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.
@@ -329,19 +330,19 @@
options
into request@[[\options]].shippingAddress
attribute on request to null.
+ Set the value of the shippingAddress attribute on request to null.
shippingOption
attribute on request to null.
+ Set the value of the shippingOption attribute on request to null.
shippingType
attribute on request to null.
+ Set the value of the shippingType attribute on request to null.
options.requestShipping
is set to true
, then set the value of the
- shippingType
attribute on request to options.shippingType
.
- If options.shippingType
is not a valid PaymentShippingType
value
- then set the shippingType
attribute on request to "shipping"
.
+ shippingType attribute on request to options.shippingType
.
+ If options.shippingType
is not a valid PaymentShippingType value
+ then set the shippingType attribute on request to "shipping"
.
details.shippingOptions
sequence contains multiple
- PaymentShippingOption
objects that have the same id
,
- then set the shippingOptions
field of request@[[\details]]
+ PaymentShippingOption objects that have the same id
,
+ then set the shippingOptions field of request@[[\details]]
to an empty sequence.
shippingOptions
sequence and
- if any PaymentShippingOption
in the sequence
+ if any PaymentShippingOption in the sequence
has the selected
field set to true
, then set
- shippingOption
to the id
of the last ShippingOption
+ shippingOption to the id
of the last PaymentShippingOption
in the sequence with selected
set to true
.
show()
method
- The show
method is called when the page wants to begin user interaction for the
+ The show method is called when the page wants to begin user interaction for the
payment request. The show
method returns 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 show
method MUST act as follows:
+ The show method MUST act as follows:
PaymentRequest
object on which the method is called.
+ Let request be the PaymentRequest object on which the method is called.
InvalidStateError
.supportedMethods
sequences from each
- PaymentMethodData
in the request@[[\methodData]] sequence.
+ PaymentMethodData in the request@[[\methodData]] sequence.
NotSupportedError
.
+ NotSupportedError.
abort()
method
- The abort
method may be called if the web page wishes to tell the
+ 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 show
method
+ might be shown. abort
can only be called after the show 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
@@ -433,20 +434,20 @@
The abort
method MUST act as follows:
The abort method MUST act as follows:
PaymentRequest
object on which the method is called.
+ Let request be the PaymentRequest object on which the method is called.
InvalidStateError
.InvalidStateError
and abort this algorithm.AbortError
.undefined
.shippingAddress
attribute
- shippingAddress
is populated when the user provides a shipping
+ 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
+ onshippingaddresschange is an EventHandler
for an
Event
named shippingaddresschange
.
shippingOption
attribute
- shippingOption
is populated when the user chooses a shipping
+ 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
+ onshippingoptionchange is an EventHandler
for an
Event
named shippingoptionchange
.
Instances of PaymentRequest
are created with the internal slots in
+
Instances of PaymentRequest are created with the internal slots in the following table:
Internal Slot | Description (non-normative) | |
---|---|---|
[[\details]] |
- The current PaymentDetails for the payment request initially
- supplied to the constructor and then updated with calls to updateWith .
+ The current PaymentDetails for the payment request initially
+ supplied to the constructor and then updated with calls to updateWith.
|
|
[[\options]] | -The PaymentOptions supplied to the constructor. |
+ The PaymentOptions supplied to the constructor. |
[[\state]] | @@ -512,14 +513,14 @@||
[[\updating]] |
- true is there is a pending updateWith call to update
+ true is there is a pending updateWith call to update
the payment request and false otherwise.
|
|
[[\acceptPromise]] |
- The pending Promise created during show that will be
+ The pending Promise created during show that will be
resolved if the user accepts the payment request.
|
Internal Slot | Description (non-normative) |
---|---|
[[\completeCalled]] |
- true if the complete method has been called and false
+ true if the complete method has been called and false
otherwise.
|
-[Constructor(DOMString type, optional PaymentRequestUpdateEventInit eventInitDict),SecureContext] -interface PaymentRequestUpdateEvent : Event { - void updateWith(Promise<PaymentDetails> d); -}; - -dictionary PaymentRequestUpdateEventInit : EventInit { -}; --
The The PaymentRequestUpdateEvent enables the web page to update
the details of the payment request in response to a user interaction. If the web page wishes to update the payment request then it should call If the web page wishes to update the payment request then it should call updateWith
+ and provide a promise that will resolve with a PaymentDetails
dictionary containing changed values that the user agent SHOULD present to the user. The PaymentRequestUpdateEvent constructor MUST set the internal slot [[\waitForUpdate]]
to false. The The updateWith method MUST act as follows: When the internal slot [[\state]] of a When the internal slot [[\state]] of a PaymentRequest object is set to
interactive, the user agent will trigger the following algorithms based
on user interaction.PaymentRequestUpdateEvent
enables the web page to update
+
+ PaymentRequestUpdateEvent
interface
+ [Constructor(DOMString type, optional PaymentRequestUpdateEventInit eventInitDict),SecureContext]
+ interface PaymentRequestUpdateEvent : Event {
+ void updateWith(Promise<PaymentDetails> d);
+ };
+
+ dictionary PaymentRequestUpdateEventInit : EventInit {
+ };
+
+ updateWith
- and provide a promise that will resolve with a PaymentDetails
+ updateWith()
- updateWith
method MUST act as follows:
+ updateWith()
method
PaymentRequest
object that is the target of
+ Let target be the PaymentRequest object that is the target of
the event.
InvalidStateError
.InvalidStateError
.
+ If [[\waitForUpdate]] is true, then throw an InvalidStateError.
InvalidStateError
.
+ InvalidStateError.
InvalidStateError
.
+ an InvalidStateError.
updateWith()
AbortError
.updateWith()
d
is resolved with details
and details
is a
- PaymentDetails
dictionary, then:
+ PaymentDetails dictionary, then:
details
contains a total
value and total.amount.value
@@ -1213,7 +1214,7 @@ updateWith()
details
contains a displayItems
value and every
- PaymentItem
in the displayItems
has an
+ PaymentItem in the displayItems
has an
amount.value
containing a valid decimal monetary value,
then copy details.displayItems
to the displayItems
field of target@[[\details]].
@@ -1222,11 +1223,11 @@ updateWith()
If details
contains a modifiers
value, then:
@@ -1283,7 +1284,7 @@ details.modifiers
.PaymentDetailsModifier
in modifiers, if the
+ total
field is supplied and is not a valid decimal monetary value,
then set modifiers to an empty sequence.PaymentDetailsModifier
in modifiers, if the
- additionalDisplayItems
sequence contains any PaymentItem
+ additionalDisplayItems
sequence contains any PaymentItem
objects with an amount
that is not a valid decimal monetary value,
then set modifiers to an empty sequence.modifiers
field of target@[[\details]].updateWith()
details.shippingOptions
.PaymentShippingOption
objects that have the same id
,
+ PaymentShippingOption objects that have the same id
,
then set shippingOptions to the empty sequence.PaymentShippingOption
+ If the shippingOptions sequence contains a PaymentShippingOption
that has an amount.value
that is not a valid decimal monetary value,
then set shippingOptions to the empty sequence.updateWith()
shippingOptions
sequence
- and if any ShippingOption
in the sequence
+ and if any PaymentShippingOption in the sequence
has the selected
field set to true
, then set
- newOption to the id
of the last ShippingOption
+ newOption to the id
of the last PaymentShippingOption
in the sequence with selected
set to true
.
shippingOption
on target to
+ Set the value of shippingOption on target to
newOption.
updateWith()
Algorithms
- PaymentRequest
object is set to
+ Shipping address changed algorithm
address. It MUST run the following steps:
PaymentRequest
object that the user is
+ shippingaddresschange
.shippingAddress
attribute on request to the
+ Set the shippingAddress attribute on request to the
shipping address provided by the user.
PaymentRequest
object that the user is
+ shippingoptionchange
.shippingOption
attribute on request to the
- id
string of the PaymentShippingOption
provided by the user.
+ Set the 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 PaymentRequest
+ an event to indicate that a user has made a change to a PaymentRequest
called request with an event name of name.
It MUST run the following steps:
PaymentRequestUpdateEvent
.PaymentRequest
object that the user is
+ Let request be the PaymentRequest object that the user is
interacting with.
PaymentResponse
.
+ Let response be a new PaymentResponse.
methodName
attribute value of response to the payment method identifier
@@ -1397,21 +1398,21 @@ requestShipping
value of request@[[\options]]
is true
, then copy the shippingAddress
attribute of
- request to the shippingAddress
attribute of response.
+ 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.
+ request to the shippingOption attribute of response.
requestPayerName
value of request@[[\options]]
- is true
, then set the payerName
attribute of
+ is true
, then set the payerName attribute of
response to the payer's name provided by the user.
requestPayerEmail
value of request@[[\options]]
- is true
, then set the payerEmail
attribute of
+ is true
, then set the payerEmail attribute of
response to the payer's email address selected by the user.
- The PaymentRequest
API does not directly support encryption of data fields.
+ The PaymentRequest 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.
Event
type and the terms fire an event, dispatch flag,
+ The 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 |
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 |