[w3c/payment-request] Duplicate shippingOptions lead to inconsistent `updateWith()` - should throw! (#594)

If given: 

```JS
const methods = [{ supportedMethods: ["basic-card"] }];
const details = {
  total: {
    label: "Total due",
    amount: { currency: "USD", value: "1.0" },
  },
};
const options = {
  requestShipping: true,
};

const request = new PaymentRequest(methods, detailsNoShippingOptions, options);
// See below
const response = await request.show();
```

And we do: 

```JS
response.onshippingaddresschange =  ev =>{
  const shippingOptions = [
    {
      id: "duplicate",
      label: "Option",
      amount: { currency: "USD", value: "5.00" },
      selected: true,
    },
    {
      id: "duplicate",
      label: "Option",
      amount: { currency: "USD", value: "5.00" },
    },
    {
      id: "not a duplicate",
      label: "Option",
      amount: { currency: "USD", value: "5.00" },
    },
 ];
 const newDetails = {...details, shippingOptions};
 ev.updateWith(newDetails);
}
```

The API says that because there are duplicates, all the shippingOptions become invalid and essentially this becomes an error in the payment sheet. 

However, the above is developer error, not a user error!  This leads to somewhat frustrating user experience where the user is told the merchant can't ship to that address (when in fact, the merchant can!):

![screenshot 2017-08-25 15 18 56](https://user-images.githubusercontent.com/870154/29700547-dafa19fa-89a8-11e7-99bd-b958b23cc765.png)
 
I think we should throw on duplicate IDs instead, because the developer screwed up.  

-- 
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/594

Received on Friday, 25 August 2017 05:23:01 UTC