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

@adamroach proposed:
> const methodData = [{
    supportedMethods: ["basic-card"],
    filters: {
    supportedNetworks: ['visa', 'mastercard'],
    supportedTypes: ['credit']
  },
  data: {
    // Any payment-method-specific fields go here.
  }
}];

I like this approach to filtering, but would prefer to avoid breaking changes to the PaymentMethodData structure. So, let's not add `filters`, but define an algorithm for the browser to filter payment apps based on subset of `data`. In particular, let's consider all lists of strings to be filters. First, a payment app should tell the browser how it should be matched by filters:
```javascript
hypothetical.api.register(
    "basic-card",
    "MyBank's Debit Card",
    data: {
        supportedNetworks: "visa",
        supportedTypes: "debit"
    });
```
Second, the merchant website requests a payment:
```javascript
new PaymentRequest([{
        supportedMethods: ["basic-card"],
        data: {
            supportedNetworks: ["visa", "amex"],
            supportedTypes: ["debit", "prepaid"],
        }
    }], details);
```
Third, the browser runs the matching algorithm for `PaymentRequest.show()`. This matching algorithm returns the list of payment methods that the user should be able to select:
* Let `matchingMethods` be an empty list.
* For each `PaymentMethodData`:
  * Let `requestMethodNames` be `PaymentMethodData.supportedMethods`, e.g., `["basic-card]`.
  * Let `filterKeys` be the keys of `PaymentMethodData.data` that have a type of "array of strings", e.g., `["supportedNetworks", "supportedTypes"]`.
  * For each registered payment method:
    * Let `matchingFiltersNumber` be `0`.
    * Let `method` be the current payment method, e.g., `"basic-card", "MyBank's Debit Card", data: {...}`.
    * Let `methodName` be the payment method identifier, e.g., `"basic-card"`.
     * If `methodName` is in `requestMethodNames`:
       * Let `dataKeys` be the names of the keys of `method.data`, e.g., `["supportedNetworks", "supportedTypes"]`.
       * For each `key` in `dataKeys`:
         * If `key` is in `filterKeys`:
           * Let `methodValue` be the value of `method.data[key]`, e.g., `"visa"`.
           * Let `requestFilter` be the value of `PaymentMethodData.data[key]`, e.g., `["visa", "amex"]`.
           * If `methodValue` is in `requestFilter`:
             * Increment `matchingFiltersNumber` by 1.
    * If `matchingFiltersNumber` is equal to `len(dataKeys)`, i.e., all filters match:
      * Add `method` to `matchingMethods`.
* Return `matchingMethods`.

-- 
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-276423629

Received on Tuesday, 31 January 2017 17:00:50 UTC