Re: [w3c/payment-request] Add way to update `total` and `displayItems` after `.show()` but before user interaction (#645)

That would work, although I think “loading screen” is a bit specific. The promise management for the user here is also a bit tricky — if the merchant is trying to update greedily, they will need to store a reference to the promise corresponding to their last update. How about something like this:

```js
    let pr = new PaymentRequest(/* ... */);
    const updatePromise = fetchDisplayItemsAndTotal();
    
    if (pr.update) {
      pr.update(updatePromise); // this is a new API.
    }
    
    // later on...
    pr.show().then(handlePayment).catch(handleError); // this shows the payment sheet in a loading  state if one of the update promises hasn't resolved yet.
```

This is a nice developer experience because it detaches updates from the `show()` API, which has pretty clear semantics. The update API could have its own error messages.

The merchant can also call update as much as they’d like as the interface changes (as they do today), and the user agent can handle races between `update` resolution (likely preserving the last update only).

Another alternative is to mirror the other events that PaymentRequest emits and emit a `initialize` (exact naming TBD) event that the user can call `ev.updateWith(updatePromise)` on. This has the same promise management issue that the proposed API has, but is a more familiar API for the merchant.

-- 
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-request/issues/645#issuecomment-342561545

Received on Tuesday, 7 November 2017 17:37:39 UTC