Re: [w3c/payment-handler] Normative what happens when users closing the window opened by PaymentRequestEvent.openWindow (#299)

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:
    ````javascript
    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:
    ````javascript
    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 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/payment-handler/issues/299#issuecomment-420372783

Received on Tuesday, 11 September 2018 18:26:05 UTC