Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normative what happens when users closing the window opened by PaymentRequestEvent.openWindow #299

Open
gogerald opened this issue Apr 24, 2018 · 4 comments · May be fixed by #325
Open

Comments

@gogerald
Copy link
Contributor

Right now, it is not easy for PH to detect the window is closing/closed (note that 'beforeunload' event can be triggered by page navigation and refresh). And UA may provide different ways to let users close the window to abort payment request in the middle. So I would like to suggest we let UA handles closing opened window so as to abort payment request and send 'AbortPaymentEvent' to the service worker without waiting for result.

Ideas?

@gogerald
Copy link
Contributor Author

@marcoscaceres @romandev

@adrianhopebailie
Copy link
Contributor

Does it make sense for us to have a paymentRequestAborted event or similar that is raised:

  1. If the user cancels the payment from the payment sheet, or
  2. If the merchant website aborts the payment request
  3. If the window that was opened through openWindow is closed by the user

@rsolomakhin
Copy link
Collaborator

I would prefer to add AbrotPaymentEvent for merchant-initiated abort and a "window closed promise" for user-initiated abort. A promise has the nice property that it's impossible to miss it by starting to listen for it too late. Correct me if I'm wrong here.

  • AbortPaymentEvent
    • Sent by the merchant website via PaymentRequest.abort().
    • Payment Handler can choose to respondWIth(true) or respondWith(false) to indicate whether it's acceptable to interrupt it in the current state.
    • Example:
      self.addEventListener('abortpayment', evt => {
        // Easy-going payment handler.
        evt.respondWith(true);
      });
  • "Window closed promise"
    • Sent by the user agent when the user closes the payment handler window.
    • Payment Handler does not have a choice on how to respond: the user has already closed the payment handler window.
    • Example:
      self.addEventListener('paymentrequest', paymentRequestEvent => {
        paymentRequestEvent.respondWith(new Promise((resolve, reject) => {
          let userConfirmedPayment = false;
          paymentRequestEvent.openWindow("https://bobpay.xyz/").then(windowClient => {
      
            // Handle user closing the payment handler window.
            windowClient.windowClosed.then(() => {
              if (!userConfirmedPayment) {
                // User closed the window before confirming the payment.
                reject(err);
              }
            });
      
          }).catch(err => {
            // Was not able to open the window in the first place.
            reject(err);
          });
        }));
      });

This situation would be ideal, but I'm not sure whether this is how

@ianbjacobs
Copy link
Contributor

@rsolomakhin,

(Seems reasonable but I am not a promise expert.)

@romandev romandev linked a pull request Sep 24, 2018 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants