Re: [w3c/webpayments-payment-apps-api] Revisiting payment app filtering (#96)

So, as a thumbnail sketch of how we can do this in a configuration way (instead of an executable way), I propose concretely that we:

(a) Move those attributes that can be used to distinguish among payment apps into a "filter" property:
```javascript
const methodData = [{
  supportedMethods: ["basic-card"],
  filters: {
    supportedNetworks: ['visa', 'mastercard'],
    supportedTypes: ['credit']
  },
  data: {
    // Any payment-method-specific fields go here.
  }
}];
```

On the payment app side, payment options include capabilities that are matched against these filters: 
```javascript
paymentMethodOptions.set("option-id-1", {
  supportedMethods: ["basic-card"],
  capabilities: {
    supportedNetworks: ['visa'],
    supportedTypes: ['credit']
  },
  // ... Other information about the payment option, such as "Visa ending in 1111"
});
```

Then, to determine matching (pseudocode):
```
set matchingOptions to an empty set

for requestMethod in paymentRequestMethodData:
  for app in paymentApps:
    for option in app.options:
      set optionMatch to true
      for filterName in keys(requestMethod.filters):
        if option.capabilities does not have key filterName, set optionMatch to false
        else if the union of requestMethod.filters[filterName] and option.capabilites[filtername]
          is empty, set optionMatch to false
      if optionMatch is true, add option to matchingOptions
```

Notably, this means that if the payment request asks for a filter (e.g., "country: 'gb'"), but the payment app does not include a matching capability (e.g., has not included "country" in their list of capabilities), then that payment app will not match the request. I believe the country example I give highlights why this is the correct way to handle things. The implication here is that payment apps will want to register will all of the capabilities associated with their payment method.

-- 
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/webpayments-payment-apps-api/issues/96#issuecomment-276416457

Received on Tuesday, 31 January 2017 16:39:09 UTC