Re: [w3c/payment-handler] Ability to set default instrument for given handler (#173)

Given the decision to remove "wallets" the spec has become somewhat cleaner wrt this scenario. I wanted to try and summarize where we are (I think).

The remaining challenge is a payment app (origin) that has multiple service workers where the instruments are registered to different SWs.

If a user explicitly selects an instrument then it is clear which SW's request handler will be invoked however if the browser simply presents the origin of the payment app and the user selects this it is unclear what the behavior should be.

Option 1: Invoke on all SW's and handle first response that is provided
This seems technically feasible but is a crappy developer experience.

Option 2: Always invoke the default instrument (and pick a default if the handler hasn't set one)
This seems best but raises the questions we have above. Does the handler behave differently based on what the user was shown?

## Proposal

Keep the API simple and intuitive for developers:

1. Add a `setDefault(PaymentInstrument)` method to `PaymentInstruments`
2. Add a `displayedInstruments` property to the `PaymentRequestEvent` that lists the instrumentIds of the instruments shown to the user.

This will provide extra value to the payment handler as it can know explicitly what options the user was given and what they selected.

If the user was presented only with the origin of the payment app (no default presented to the user) this list must be empty. The browser must still select a default and invoke the appropriate SW's event handler and populate the `selectedIntrument` property. (This seems an unlikely scenrio given @zkoch 's comments. I'd expect the browser to always pick a default and display that to the user)

If the user is presented with one option (a default defined by the handler OR selected by the browser) then only that key should be passed in the `displayedInstruments` list.

```
interface PaymentInstruments {
    Promise<boolean>             delete(DOMString instrumentKey);
    Promise<PaymentInstrument>   get(DOMString instrumentKey);
    Promise<sequence<DOMString>> keys();
    Promise<boolean>             has(DOMString instrumentKey);
    Promise<void>                set(DOMString instrumentKey, PaymentInstrument details);
    Promise<void>                setDefault(DOMString instrumentKey);
    Promise<void>                clear();
};

[Constructor(DOMString type, PaymentRequestEventInit eventInitDict),
 Exposed=ServiceWorker]
interface PaymentRequestEvent : ExtendableEvent {
    readonly attribute USVString                           topLevelOrigin;
    readonly attribute USVString                           paymentRequestOrigin;
    readonly attribute DOMString                           paymentRequestId;
    readonly attribute FrozenArray<PaymentMethodData>      methodData;
    readonly attribute object                              total;
    readonly attribute FrozenArray<PaymentDetailsModifier> modifiers;
    readonly attribute DOMString                           selectedInstrument;
    readonly attribute sequence<DOMString>                 displayedInstruments;
    Promise<WindowClient> openWindow(USVString url);
    void                  respondWith(Promise<PaymentHandlerResponse> handlerResponse);
};
```

-- 
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/173#issuecomment-316978011

Received on Friday, 21 July 2017 11:32:43 UTC