Open marcoscaceres opened 6 years ago
Hacky workaround:
const response = await request.show();
// sheet is waiting for complete
const didPaySucceed = await fetch("/pay", {method: "POST", body: response.toJSON()});
//... bit's taking ages... so sheet shuts down or user hits "ESC"!
// finally, we get "didPaySucceed" result.
try {
// oh crap, invalid state error! The sheet was closed!
await request.complete("success");
} catch(err){
// site: we got this, show success or error.
displayCompleteResult(didPaySucceed);
}
A new event seems reasonable.
More examples and work arounds at: https://bugzilla.mozilla.org/show_bug.cgi?id=1447773#c13
But a simple event gets us to:
const payResponse = await request.show();
const response = await fetch("/process-payment/", { body: response.toJSON() })
response.ontimeout = ev => {
// can show a progress indicator or whatever...
showInPagePaymentProgress(response);
});
const result = await response;
await response.complete(result)
Could we allow complete()
to accept a Promise
.
The Promise
returned by complete()
could resolve/reject based on that Promise (and to the same value).
A developer with long running login that they must perform (even a chain of async calls) can wrap these behind a Promise and pass to complete()
. If complete()
is passed a promise it should never timeout.
From Gecko bug, spec says:
Problem is that the you have a race condition:
fetch("/make-payment", {body: response.toJSON()})
may take longer to resolve than the payment sheet being presented (e.g., 5 seconds in Browser X).fetch()
promise resolves successfully (the user has been charged!)..complete()
now just returns a rejected promise).We might need a new event to notify the merchant if the sheet has shut down on them. Otherwise, they will try to
.complete()
and response will just return a rejected promise.@domenic, @zkoch, @aestes, @adrianba, all, thoughts?