[w3c/browser-payment-api] Should the API support field validation? (#225)

It would be nice if the web page could indicate a problem with specific fields provided by the user:

Examples:

* Invalid credit card number
* Web page does not ship to a particular postal code
* Web page requires both a first and last name to fulfill the order

I am particularly interested in checks that CAN NOT be done by the user agent on it's own. For instance the user agent could check that the state and zip code match, but it could not know which states the web page supports shipping to.

My understanding is that currently the only way to indicate invalid fields is to:

* Web page calls `paymentResponse.complete('fail')`
* Web page displays the error with it's own UX
* User is required to start the payment process over from the beginning

That seems like a big headache for a user who just has to tweak one field.

Instead, I am proposing that the web page could indicate errors of various types. One idea of how this could work is with a new `validationErrors()` method on the `PaymentResponse` object:

```
paymentResponse.validationErrors([
  { field: 'shippingAddress.postalCode', message: 'Example web site does not support shipping to postal code 99999.' },
  { field: 'shippingAddress.recipient', message: 'Please provide both a first name and a last name.' },
])
```

The user agent, upon receiving these validation errors, could display a list of invalid fields along with the message for each field. The user would correct each field and then continue.


---
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/browser-payment-api/issues/225

Received on Monday, 8 August 2016 22:58:21 UTC