Skip to content

Commit ee56f25

Browse files
Define PaymentResponse.prototype.retry() method (#720)
Sets foundation for the method, which is then expanded upon by other pull requests.
1 parent 0d2ab3a commit ee56f25

File tree

1 file changed

+177
-36
lines changed

1 file changed

+177
-36
lines changed

index.html

Lines changed: 177 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,8 @@ <h2>
666666
<var>paymentMethod</var>.<a data-lt=
667667
"PaymentMethodData.supportedMethods">supportedMethods</a>.
668668
If it returns false, then throw a <a>RangeError</a>
669-
exception and terminate this algorithm. Optionally, inform
670-
the developer that the payment method identifier is
671-
invalid.
669+
exception. Optionally, inform the developer that the
670+
payment method identifier is invalid.
672671
</li>
673672
<li>If the <a data-lt="PaymentMethodData.data">data</a>
674673
member of <var>paymentMethod</var> is missing, let
@@ -842,6 +841,8 @@ <h2>
842841
<li>Set <var>request</var>.<a>[[\serializedMethodData]]</a> to <var>
843842
serializedMethodData</var>.
844843
</li>
844+
<li>Set <var>request</var>.<a>[[\response]]</a> to null.
845+
</li>
845846
<li>Set the value of <var>request</var>'s <a data-lt=
846847
"PaymentRequest.shippingOption">shippingOption</a> attribute to <var>
847848
selectedShippingOption</var>.
@@ -900,9 +901,9 @@ <h2>
900901
<ol class="algorithm">
901902
<li data-tests=
902903
"payment-request-show-method-manual.https.html, show-method-postmessage-manual.https.html">
903-
If the method was not <a>triggered by user activation</a>, return a
904-
promise rejected with a "<a>SecurityError</a>" <a>DOMException</a>
905-
and terminate this algorithm.
904+
If the method was not <a>triggered by user activation</a>, return <a>
905+
a promise rejected with</a> with a "<a>SecurityError</a>"
906+
<a>DOMException</a>.
906907
</li>
907908
<li>Let <var>request</var> be the <a>context object</a>.
908909
</li>
@@ -1120,10 +1121,14 @@ <h2>
11201121
<ol class="algorithm">
11211122
<li>Let <var>request</var> be the <a>context object</a>.
11221123
</li>
1124+
<li>If <var>request</var>.<a>[[\response]]</a> is not null, and <var>
1125+
request</var>.<a>[[\response]]</a>.<a>[[\retryPromise]]</a> is not
1126+
null, return <a>a promise rejected with</a> an
1127+
"<a>InvalidStateError</a>" <a>DOMException</a>.
1128+
</li>
11231129
<li>If the value of <var>request</var>.<a>[[\state]]</a> is not
1124-
"<a>interactive</a>" then return a promise rejected with a
1125-
"<a>InvalidStateError</a>" <a>DOMException</a> and terminate this
1126-
algorithm.
1130+
"<a>interactive</a>" then return <a>a promise rejected with</a> an
1131+
"<a>InvalidStateError</a>" <a>DOMException</a>.
11271132
</li>
11281133
<li>Let <var>promise</var> be <a>a new promise</a>.
11291134
</li>
@@ -1180,8 +1185,9 @@ <h2>
11801185
then return <a>a promise rejected with</a> an
11811186
"<a>InvalidStateError</a>" <a>DOMException</a>.
11821187
</li>
1183-
<li>Optionally, at the <a>user agent</a>'s discretion, return a
1184-
promise rejected with a "<a>NotAllowedError</a>" <a>DOMException</a>.
1188+
<li>Optionally, at the <a>user agent</a>'s discretion, return <a>a
1189+
promise rejected with</a> a "<a>NotAllowedError</a>"
1190+
<a>DOMException</a>.
11851191
<p class="note" data-link-for="PaymentRequest">
11861192
This allows user agents to apply heuristics to detect and prevent
11871193
abuse of the <a>canMakePayment()</a> method for fingerprinting
@@ -1443,6 +1449,15 @@ <h2>
14431449
accepts the payment request.
14441450
</td>
14451451
</tr>
1452+
<tr>
1453+
<td>
1454+
<dfn>[[\response]]</dfn>
1455+
</td>
1456+
<td>
1457+
Null, or the <a>PaymentResponse</a> instantiated by this
1458+
<a>PaymentRequest</a>.
1459+
</td>
1460+
</tr>
14461461
</table>
14471462
</section>
14481463
</section>
@@ -3150,12 +3165,83 @@ <h2>
31503165
readonly attribute DOMString? payerPhone;
31513166

31523167
Promise&lt;void&gt; complete(optional PaymentComplete result = "unknown");
3168+
Promise&lt;void&gt; retry();
31533169
};
31543170
</pre>
31553171
<p class="note">
31563172
A <a>PaymentResponse</a> is returned when a user has selected a payment
31573173
method and approved a payment request.
31583174
</p>
3175+
<section>
3176+
<h2>
3177+
<dfn>retry()</dfn> method
3178+
</h2>
3179+
<p data-tests="payment-response/retry-method-manual.https.html">
3180+
The <a>retry()</a> method MUST act as follows:
3181+
</p>
3182+
<ol class="algorithm">
3183+
<li>Let <var>response</var> be the <a>context object</a>.
3184+
</li>
3185+
<li>Let <var>request</var> be
3186+
<var>response</var>.<a>[[\request]]</a>.
3187+
</li>
3188+
<li>Let <var>document</var> be <var>request</var>'s <a data-cite=
3189+
"!HTML#concept-relevant-global">relevant global object</a>'s
3190+
<a data-cite="!HTML#concept-document-window">associated Document</a>.
3191+
</li>
3192+
<li data-tests=
3193+
"payment-response/rejects_if_not_active-manual.https.html">If
3194+
<var>document</var> is not <a data-cite="!HTML#fully-active">fully
3195+
active</a>, then return <a>a promise rejected with</a> an
3196+
"<a>AbortError</a>" <a>DOMException</a>.
3197+
</li>
3198+
<li>If <var>response</var>.<a>[[\complete]]</a> is true, return <a>a
3199+
promise rejected with</a> an "<a>InvalidStateError</a>"
3200+
<a>DOMException</a>.
3201+
</li>
3202+
<li>If <var>response</var>.<a>[[\retryPromise]]</a> is not null,
3203+
return <a>a promise rejected with</a> an "<a>InvalidStateError</a>"
3204+
<a>DOMException</a>.
3205+
</li>
3206+
<li>Set <var>request</var>.<a>[[\state]]</a> to "<a>interactive</a>".
3207+
</li>
3208+
<li>Let <var>retryPromise</var> be <a>a new promise</a>.
3209+
</li>
3210+
<li>Set <var>response</var>.<a>[[\retryPromise]]</a> to
3211+
<var>retryPromise</var>.
3212+
</li>
3213+
<li>In the payments UI, indicate to the end-user that something is
3214+
wrong with the user-provided data of the payment response.
3215+
</li>
3216+
<li data-tests=
3217+
"payment-request/payment-response/rejects_if_not_active-manual.https.html">
3218+
If <var>document</var> stops being <a data-cite="!HTML#fully-active">
3219+
fully active</a> while the user interface is being shown, or no
3220+
longer is by the time this step is reached, then:
3221+
<ol>
3222+
<li>Close down the user interface.
3223+
</li>
3224+
<li>Set the <a>user agent</a>'s <a>payment request is showing</a>
3225+
boolean to false.
3226+
</li>
3227+
<li>Reject <var>retryPromise</var> with an "<a>AbortError</a>"
3228+
<a>DOMException</a>.
3229+
</li>
3230+
</ol>
3231+
</li>
3232+
<li>Finally, when <var>retryPromise</var> settles, set
3233+
<var>response</var>.<a>[[\retryPromise]]</a> to null.
3234+
</li>
3235+
<li>Return <var>retryPromise</var>.
3236+
<p class="note">
3237+
The <var>retryPromise</var> will later be resolved or rejected by
3238+
either the <a>user accepts the payment request algorithm</a> or
3239+
the <a>user aborts the payment request algorithm</a>, which are
3240+
triggered through interaction with the user interface.
3241+
</p>
3242+
</li>
3243+
</ol>
3244+
</section>
31593245
<section>
31603246
<h2>
31613247
<dfn>toJSON()</dfn> method
@@ -3321,19 +3407,27 @@ <h2>
33213407
</li>
33223408
<li>Let <var>promise</var> be <a>a new promise</a>.
33233409
</li>
3324-
<li>If <var>response</var>.<a>[[\completeCalled]]</a> is true, reject
3410+
<li>If <var>response</var>.<a>[[\complete]]</a> is true, reject <var>
3411+
promise</var> with an "<a>InvalidStateError</a>"
3412+
<a>DOMException</a>.
3413+
</li>
3414+
<li data-tests=
3415+
"payment-request/payment-response/retry-method-manual.https.html">If
3416+
<var>response</var>.<a>[[\retryPromise]]</a> is not null, reject
33253417
<var>promise</var> with an "<a>InvalidStateError</a>"
33263418
<a>DOMException</a>.
33273419
</li>
3328-
<li>Otherwise, set <var>response</var>.<a>[[\completeCalled]]</a> to
3329-
true.
3420+
<li>Otherwise, set <var>response</var>.<a>[[\complete]]</a> to true.
33303421
</li>
33313422
<li>Return <var>promise</var> and perform the remaining steps <a>in
33323423
parallel</a>.
33333424
</li>
33343425
<li>Close down any remaining user interface. The <a>user agent</a>
33353426
MAY use the value <var>result</var> to influence the user experience.
33363427
</li>
3428+
<li>Set the <a>user agent</a>'s <a>payment request is showing</a>
3429+
boolean to false.
3430+
</li>
33373431
<li>Resolve <var>promise</var> with undefined.
33383432
</li>
33393433
</ol>
@@ -3357,11 +3451,30 @@ <h2>
33573451
</tr>
33583452
<tr>
33593453
<td>
3360-
<dfn>[[\completeCalled]]</dfn>
3454+
<dfn>[[\complete]]</dfn>
33613455
</td>
33623456
<td>
3363-
true if the <a data-lt="PaymentResponse.complete">complete</a>
3364-
method has been called and false otherwise.
3457+
Is true if that the request for payment has completed, or false
3458+
otherwise.
3459+
</td>
3460+
</tr>
3461+
<tr>
3462+
<td>
3463+
<dfn>[[\request]]</dfn>
3464+
</td>
3465+
<td>
3466+
The <a>PaymentRequest</a> instance that instantiated this
3467+
<a>PaymentResponse</a>.
3468+
</td>
3469+
</tr>
3470+
<tr>
3471+
<td>
3472+
<dfn>[[\retryPromise]]</dfn>
3473+
</td>
3474+
<td>
3475+
Null, or a <a>Promise</a> that resolves when a <a>user accepts
3476+
the payment request</a> or rejects if the <a>user aborts the
3477+
payment request</a>.
33653478
</td>
33663479
</tr>
33673480
</table>
@@ -3878,21 +3991,40 @@ <h2>
38783991
further action. The <a>user agent</a> SHOULD ensure that this never
38793992
occurs.
38803993
</li>
3881-
<li>Let <var>response</var> be a new <a>PaymentResponse</a>.
3994+
<li>Let <var>isRetry</var> be true if
3995+
<var>request</var>.<a>[[\response]]</a> is not null, false otherwise.
38823996
</li>
3883-
<li>Set the <a data-lt="PaymentResponse.requestId">requestId</a>
3884-
attribute value of <var>response</var> to the value of
3885-
<var>request</var>.<a>[[\details]]</a>.<a data-lt=
3886-
"PaymentDetailsInit.id">id</a>.
3997+
<li>Let <var>response</var> be
3998+
<var>request</var>.<a>[[\response]]</a> if <var>isRetry</var> is
3999+
true, or a new <a>PaymentResponse</a> otherwise.
38874000
</li>
3888-
<li>Set the <a data-lt="PaymentResponse.methodName">methodName</a>
3889-
attribute value of <var>response</var> to the <a>payment method
3890-
identifier</a> for the <a>payment method</a> that the user selected
3891-
to accept the payment.
4001+
<li>If <var>isRetry</var> if false, initialize the newly created
4002+
<var>response</var>:
4003+
<ol>
4004+
<li>Set <var>response</var>.<a>[[\request]]</a> to
4005+
<var>request</var>.
4006+
</li>
4007+
<li>Set <var>response</var>.<a>[[\retryPromise]]</a> to null.
4008+
</li>
4009+
<li>Set <var>response</var>.<a>[[\complete]]</a> to false.
4010+
</li>
4011+
<li>Set the <a data-lt="PaymentResponse.requestId">requestId</a>
4012+
attribute value of <var>response</var> to the value of
4013+
<var>request</var>.<a>[[\details]]</a>.<a data-lt=
4014+
"PaymentDetailsInit.id">id</a>.
4015+
</li>
4016+
<li>Set <var>request</var>.<a>[[\response]]</a> to
4017+
<var>response</var>.
4018+
</li>
4019+
</ol>
38924020
</li>
38934021
<li>Let <var>handler</var> be the <a>payment handler</a> selected by
38944022
the user.
38954023
</li>
4024+
<li>Set the <a data-lt="PaymentResponse.methodName">methodName</a>
4025+
attribute value of <var>response</var> to the <a>payment method
4026+
identifier</a> of <var>handler</var>.
4027+
</li>
38964028
<li>Set the <a data-lt="PaymentResponse.details">details</a>
38974029
attribute value of <var>response</var> to an object resulting from
38984030
running the <var>handler</var>'s <a>steps to respond to a payment
@@ -3951,17 +4083,13 @@ <h2>
39514083
"PaymentResponse.payerPhone">payerPhone</a> value, the user agent
39524084
SHOULD format the phone number to adhere to [[!E.164]].
39534085
</li>
3954-
<li>Set <var>response</var>.<a>[[\completeCalled]]</a> to false.
4086+
<li>If <var>isRetry</var> is true, resolve
4087+
<var>response</var>.<a>[[\retryPromise]]</a> with undefined.
4088+
Otherwise, resolve <var>request</var>.<a>[[\acceptPromise]]</a> with
4089+
<var>response</var>.
39554090
</li>
39564091
<li>Set <var>request</var>.<a>[[\state]]</a> to "<a>closed</a>".
39574092
</li>
3958-
<li>Set the <a>user agent</a>'s <a>payment request is showing</a>
3959-
boolean to false.
3960-
</li>
3961-
<li>Resolve the pending promise
3962-
<var>request</var>.<a>[[\acceptPromise]]</a> with
3963-
<var>response</var>.
3964-
</li>
39654093
</ol>
39664094
</section>
39674095
<section>
@@ -3993,8 +4121,21 @@ <h2>
39934121
<li>Set the <a>user agent</a>'s <a>payment request is showing</a>
39944122
boolean to false.
39954123
</li>
3996-
<li>Reject the promise <var>request</var>.<a>[[\acceptPromise]]</a>
3997-
with an "<a>AbortError</a>" <a>DOMException</a>.
4124+
<li>Let <var>error</var> be an "<a>AbortError</a>"
4125+
<a>DOMException</a>.
4126+
</li>
4127+
<li>Let <var>response</var> be
4128+
<var>request</var>.<a>[[\response]]</a>.
4129+
</li>
4130+
<li>If <var>response</var> not null:
4131+
<ol>
4132+
<li>Reject <var>response</var>.<a>[[\retryPromise]]</a> with
4133+
<var>error</var>
4134+
</li>
4135+
</ol>
4136+
</li>
4137+
<li>Otherwise, reject <var>request</var>.<a>[[\acceptPromise]]</a>
4138+
with <var>error</var>.
39984139
</li>
39994140
</ol>
40004141
</section>

0 commit comments

Comments
 (0)