1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_AUTOFILL_BROWSER_WALLET_FORM_FIELD_ERROR_H_
6 #define COMPONENTS_AUTOFILL_BROWSER_WALLET_FORM_FIELD_ERROR_H_
8 #include "base/strings/string16.h"
9 #include "components/autofill/core/browser/field_types.h"
12 class DictionaryValue
;
18 // Class for representing a single Wallet server side validation error.
19 class FormFieldError
{
21 // The validation error returned from the server.
26 // Bad street address.
30 // Wallet sends this when ZIP is invalid for the given city.
32 // Catch-all for many errors. E.g., no address given, no address ID,
33 // invalid card number. Wallet should only send us this error for invalid
36 // Wallet sends this when ZIP is invalid for the given state.
38 REQUIRED_FIELD_NOT_SET
,
39 // TODO(ahutter): Add INVALID_COUNTRY when user can select country in the
43 // The section of the "form" where the error occurred.
48 // Currently Sugar uses the billing address as user's legal address. So any
49 // error in billing address will be accompanied by an error in legal
50 // address. The client side should map LEGAL_ADDRESS to the billing address.
51 // This will ensure compatibility in case Sugar starts having a separate
52 // legal address form.
56 FormFieldError(ErrorType error_type
, Location location
);
59 ErrorType
error_type() const { return error_type_
; }
60 Location
location() const { return location_
; }
62 // Gets the appropriate field type for |location| and |error_type|.
63 ServerFieldType
GetAutofillType() const;
65 // Gets a user facing error message appropriate for |location| and
67 base::string16
GetErrorMessage() const;
69 // Creates an instance of FormFieldError from the input dictionary.
70 static FormFieldError
CreateFormFieldError(
71 const base::DictionaryValue
& dictionary
);
73 bool operator==(const FormFieldError
& other
) const;
76 // The type of error as defined by the Wallet server.
77 ErrorType error_type_
;
79 // The location of the error as defined by the Wallet server.
82 // This class is intentionally copyable and assignable.
86 } // namespace autofill
88 #endif // COMPONENTS_AUTOFILL_BROWSER_WALLET_FORM_FIELD_ERROR_H_