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. 4 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_WALLET_FORM_FIELD_ERROR_H_ 6 #define COMPONENTS_AUTOFILL_BROWSER_WALLET_FORM_FIELD_ERROR_H_ 7 8 #include "base/strings/string16.h" 9 #include "components/autofill/core/browser/field_types.h" 10 11 namespace base { 12 class DictionaryValue; 13 } 14 15 namespace autofill { 16 namespace wallet { 17 18 // Class for representing a single Wallet server side validation error. 19 class FormFieldError { 20 public: 21 // The validation error returned from the server. 22 enum ErrorType { 23 UNKNOWN_ERROR, 24 INVALID_PHONE_NUMBER, 25 INVALID_POSTAL_CODE, 26 // Bad street address. 27 INVALID_ADDRESS, 28 // Bad CVC. 29 INVALID_CARD_DETAILS, 30 // Wallet sends this when ZIP is invalid for the given city. 31 INVALID_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 34 // card number. 35 INVALID_INSTRUMENT, 36 // Wallet sends this when ZIP is invalid for the given state. 37 INVALID_STATE, 38 REQUIRED_FIELD_NOT_SET, 39 // TODO(ahutter): Add INVALID_COUNTRY when user can select country in the 40 // chooser. 41 }; 42 43 // The section of the "form" where the error occurred. 44 enum Location { 45 UNKNOWN_LOCATION, 46 PAYMENT_INSTRUMENT, 47 SHIPPING_ADDRESS, 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. 53 LEGAL_ADDRESS, 54 }; 55 56 FormFieldError(ErrorType error_type, Location location); 57 ~FormFieldError(); 58 59 ErrorType error_type() const { return error_type_; } 60 Location location() const { return location_; } 61 62 // Gets the appropriate field type for |location| and |error_type|. 63 ServerFieldType GetAutofillType() const; 64 65 // Gets a user facing error message appropriate for |location| and 66 // |error_type|. 67 base::string16 GetErrorMessage() const; 68 69 // Creates an instance of FormFieldError from the input dictionary. 70 static FormFieldError CreateFormFieldError( 71 const base::DictionaryValue& dictionary); 72 73 bool operator==(const FormFieldError& other) const; 74 75 private: 76 // The type of error as defined by the Wallet server. 77 ErrorType error_type_; 78 79 // The location of the error as defined by the Wallet server. 80 Location location_; 81 82 // This class is intentionally copyable and assignable. 83 }; 84 85 } // namespace wallet 86 } // namespace autofill 87 88 #endif // COMPONENTS_AUTOFILL_BROWSER_WALLET_FORM_FIELD_ERROR_H_ 89