Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should the API support field validation? #225

Closed
andrewagain opened this issue Aug 8, 2016 · 3 comments
Closed

Should the API support field validation? #225

andrewagain opened this issue Aug 8, 2016 · 3 comments

Comments

@andrewagain
Copy link

andrewagain commented Aug 8, 2016

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

Examples:

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

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/region and postal code match, but it could not know which states/regions the web page supports shipping to.

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

  1. Web page calls paymentResponse.complete('fail')
  2. Web page displays the error with it's own UX
  3. 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.

@rsolomakhin
Copy link
Collaborator

We can also add validation errors to PaymentDetails, so that merchant can notify the browser during shippingaddresschange event.

payment.addEventListener('shippingaddresschange', function(evt) {
  evt.updateWith(new Promise(function(resolve) {
    if (payment.shippingAddress.postalCode === '99999') {
      details.validationErrors = [{field: 'postalCode', message: 'Example site does not support shipping to postal code 9999'}];
    } else {
      delete details.validationErrors;
    }
    resolve(details);
  }));
});

@adrianba
Copy link
Contributor

This is an interesting proposal but one that adds a fair amount of complexity. PR #257 added the ability to provide a free form error message describing the validation error as part of the updateWith call. I propose that the error message is sufficient for v1 and propose that we postpone this issue until we have more implementation experience.

@marcoscaceres
Copy link
Member

closing this one as duplicate of #647

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants