3 <link rel=
"help" href=
"https://w3c.github.io/payment-request/#dom-paymentresponse-retry">
5 PaymentResponse.prototype.retry() method
7 <script src=
"/resources/testharness.js"></script>
8 <script src=
"/resources/testharnessreport.js"></script>
9 <script src=
"helpers.js"></script>
13 "retry" in PaymentResponse
.prototype,
14 "retry must be in prototype"
17 PaymentResponse
.prototype.retry
instanceof Function
,
18 "retry must be a function"
20 }, "PaymentResponse.prototype must have a retry() function (smoke test).");
22 function checkCompletedCantRetry(button
) {
23 button
.disabled
= true;
24 promise_test(async t
=> {
25 const { response
} = await
getPaymentRequestResponse();
26 // sets response.[[complete]] to true.
27 await response
.complete("success");
28 return promise_rejects(
32 "response.[[complete]] is true, so rejects with InvalidStateError."
34 }, button
.textContent
.trim());
37 function repeatedCallsToRetry(button
) {
38 button
.disabled
= true;
39 promise_test(async t
=> {
40 const { response
} = await
getPaymentRequestResponse();
41 const retryPromise
= response
.retry();
42 await
promise_rejects(
46 "Calling retry() again rejects with an InvalidStateError"
49 await response
.complete("success");
50 }, button
.textContent
.trim());
53 function callCompleteWhileRetrying(button
) {
54 button
.disabled
= true;
55 promise_test(async t
=> {
56 const { response
} = await
getPaymentRequestResponse();
57 const retryPromise
= response
.retry();
58 const completePromise1
= response
.complete("success");
59 const completePromise2
= response
.complete("fail");
63 "complete() must return unique promises"
65 await
promise_rejects(
69 "Calling complete() while retrying rejects with an InvalidStateError"
71 await
promise_rejects(
75 "Calling complete() while retrying rejects with an InvalidStateError"
80 "complete() must return unique promises"
83 await response
.complete("success");
84 }, button
.textContent
.trim());
87 function callingRequestAbortMustNotAbort(button
) {
88 button
.disabled
= true;
89 promise_test(async t
=> {
90 const { response
, request
} = await
getPaymentRequestResponse();
91 const retryPromise
= response
.retry();
92 await
promise_rejects(
96 "Calling request.abort() while retrying rejects with an InvalidStateError"
99 await response
.complete("success");
100 }, button
.textContent
.trim());
103 function canRetryMultipleTimes(button
) {
104 button
.disabled
= true;
105 promise_test(async t
=> {
106 const { response
} = await
getPaymentRequestResponse();
108 await response
.retry(),
110 "Expected undefined as the resolve value"
113 await response
.retry(),
115 "Expected undefined as the resolve value"
117 await response
.complete("success");
118 await
promise_rejects(
122 "Calling retry() after complete() rejects with a InvalidStateError"
124 }, button
.textContent
.trim());
127 function userCanAbortARetry(button
) {
128 button
.disabled
= true;
129 promise_test(async t
=> {
130 const { response
} = await
getPaymentRequestResponse();
131 await
promise_rejects(
135 "The user aborting a retry rejects with a AbortError"
137 await
promise_rejects(
141 "After the user aborts, response [[complete]] is true so retry() must reject with InvalidStateError"
143 await
promise_rejects(
146 response
.complete("success"),
147 "After the user aborts, response [[complete]] is true, so complete() rejects with a InvalidStateError"
149 }, button
.textContent
.trim());
152 function userIsShownErrorsFields(button
) {
153 button
.disabled
= true;
154 promise_test(async t
=> {
155 const { response
, request
} = await
getPaymentRequestResponse({ requestShipping
: true });
156 const retryPromise
= response
.retry({
157 shippingAddress
: { city
: "Invalid city", addressLine
: "Invalid address line" },
160 await response
.complete("success");
161 }, button
.textContent
.trim());
164 function abortTheUpdate(button
) {
165 button
.disabled
= true;
166 promise_test(async t
=> {
167 const { response
, request
} = await
getPaymentRequestResponse({
168 requestShipping
: true,
170 const shipOptionChangePromise
= new Promise(resolve
=> {
171 request
.onshippingoptionchange
= event
=> {
172 // causes "abort the update" to run
173 event
.updateWith({ total
: "error!" });
177 const retryPromise
= response
.retry();
178 await shipOptionChangePromise
;
179 await
promise_rejects(
183 "retry() aborts with a TypeError, because totals' value is invalid"
185 await
promise_rejects(
188 response
.complete("success"),
189 "After the user aborts, response [[complete]] is true, so complete() rejects with a InvalidStateError"
191 }, button
.textContent
.trim());
194 function callingRetryReturnsUniquePromise(button
){
195 button
.disabled
= true;
196 promise_test(async t
=> {
197 const { response
} = await
getPaymentRequestResponse();
198 const retryPromise
= response
.retry();
199 const promises
= new Set([
204 assert_equals(promises
.size
, 3, "Must have three unique objects");
206 await response
.complete();
207 }, button
.textContent
.trim());
213 Manual Tests for PaymentResponse.retry() - Please run in order!
216 Click on each button in sequence from top to bottom without refreshing the page.
217 Each button will bring up the Payment Request UI window.
220 When presented with the payment sheet, use any credit card select to
"Pay" multiple times.
224 <button onclick=
"checkCompletedCantRetry(this);">
225 A completed payment request cannot be retried.
229 <button onclick=
"repeatedCallsToRetry(this);">
230 Calling retry() more than once yield a rejected promise, but the
231 retryPromise resolves independently.
235 <button onclick=
"callCompleteWhileRetrying(this);">
236 Calling complete() while a retry() is in progress results in an InvalidStateError.
240 <button onclick=
"callingRequestAbortMustNotAbort(this);">
241 Trying to abort() via PaymentRequest is not possible.
245 <button onclick=
"canRetryMultipleTimes(this);">
246 It's possible to retry() multiple times and eventually complete().
247 After complete(), however, retry() rejects with an InvalidStateError.
252 When shown the payment sheet, hit pay once, then abort retrying the payment.
254 <button onclick=
"userCanAbortARetry(this);">
255 The user aborting retrying a payment causes the retryPromise to reject with AbortError.
256 Aborting a payment is causes it complete.
261 When shown the payment sheet, hit pay once. Check payment sheet for error fields.
262 Then hit escape or otherwise abort the payment.
264 <button onclick=
"userIsShownErrorsFields(this);">
265 When retrying, the user is shown error fields to fix.
270 When shown the payment sheet, hit pay once.
271 Then, change the shipping option.
274 <button onclick=
"abortTheUpdate(this);">
275 When
"abort the update" occurs because of an update error,
276 the `retryPromise` is rejected and response.[[complete]] becomes true.
281 When shown the payment sheet, hit pay once. Then retry once.
283 <button onclick=
"callingRetryReturnsUniquePromise(this);">
284 Calling retry() multiple times is always a new object.
288 <button onclick=
"done();">
294 If you find a buggy test, please
<a href=
"https://github.com/web-platform-tests/wpt/issues">file a bug
</a>
295 and tag one of the
<a href=
"https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">owners
</a>.