Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ITEMS_H_ | |
| 6 #define CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ITEMS_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/scoped_vector.h" | |
| 15 #include "chrome/browser/autofill/wallet/wallet_address.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class DictionaryValue; | |
| 19 } | |
| 20 | |
| 21 namespace wallet { | |
| 22 | |
| 23 // WalletItems primarily serves as a container for the user's instruments and | |
| 24 // address, however, it also provides a transaction id which must be used | |
| 25 // throughout all API calls being made using this data. Additionally, user | |
| 26 // actions may be required before a purchase can be completing using Online | |
|
Albert Bodenhamer
2012/12/05 19:22:29
typo: completed, not completing
ahutter
2012/12/05 23:37:23
Done.
| |
| 27 // Wallet and those actions are present in the object as well. | |
| 28 class WalletItems { | |
| 29 public: | |
| 30 // Container for all information about a credit card except for it's card | |
| 31 // verfication number (CVN) and it's complete primary account number (PAN). | |
| 32 class MaskedInstrument { | |
| 33 public: | |
| 34 enum Type { | |
| 35 UNKNOWN, | |
| 36 VISA, | |
| 37 MASTER_CARD, | |
| 38 AMEX, | |
| 39 DISCOVER, | |
| 40 SOLO, | |
| 41 MAESTRO, | |
| 42 SWITCH, | |
|
Dan Beam
2012/12/05 19:34:59
nit: is there a rationale to the order of these en
ahutter
2012/12/05 23:37:23
Nope. Now alphabetized.
| |
| 43 }; | |
| 44 enum Status { | |
| 45 PENDING, | |
| 46 VALID, | |
| 47 DECLINED, | |
| 48 UNSUPPORTED_COUNTRY, | |
| 49 EXPIRED, | |
| 50 BILLING_INCOMPLETE, | |
| 51 // correspond to any other inapplicable reasons that do not listed above | |
|
Dan Beam
2012/12/05 19:34:59
nit: fix this comment
ahutter
2012/12/05 23:37:23
Done.
| |
| 52 INAPPLICABLE, | |
| 53 }; | |
| 54 MaskedInstrument(const std::string& descriptve_name, | |
| 55 Type type, | |
|
Dan Beam
2012/12/05 19:34:59
nit: why are |type| and |status| not const-ref?
ahutter
2012/12/05 23:37:23
Done.
| |
| 56 std::vector<std::string> supported_currencies, | |
| 57 const std::string& last_four_digits, | |
| 58 int expiration_month, | |
| 59 int expiration_year, | |
| 60 const std::string& brand, | |
| 61 Address* address, | |
| 62 Status status, | |
| 63 const std::string& object_id); | |
| 64 ~MaskedInstrument(); | |
| 65 | |
| 66 // Returns null if input is invalid or a valid masked instrument. Caller | |
| 67 // owns returned pointer. | |
| 68 static MaskedInstrument* CreateMaskedInstrument( | |
| 69 const base::DictionaryValue& dictionary); | |
| 70 | |
| 71 bool operator==(const MaskedInstrument& other) const; | |
| 72 bool operator!=(const MaskedInstrument& other) const; | |
| 73 | |
| 74 const std::string descriptive_name() const { return descriptive_name_; } | |
| 75 Type type() const { return type_; } | |
| 76 const std::vector<std::string> supported_currencies() const { | |
| 77 return supported_currencies_; | |
| 78 } | |
| 79 const std::string last_four_digits() const { return last_four_digits_; } | |
| 80 int expiration_month() const { return expiration_month_; } | |
| 81 int expiration_year() const { return expiration_year_; } | |
| 82 const std::string brand() const { return brand_; } | |
| 83 const Address* address() const { return address_.get(); } | |
| 84 Status status() const { return status_; } | |
| 85 const std::string object_id() const { return object_id_; } | |
| 86 | |
| 87 private: | |
| 88 static Type TypeFromString(const std::string& type_string); | |
| 89 static Status StatusFromString(const std::string& status_string); | |
| 90 std::string descriptive_name_; | |
| 91 Type type_; | |
| 92 std::vector<std::string> supported_currencies_; | |
| 93 std::string last_four_digits_; | |
| 94 int expiration_month_; | |
| 95 int expiration_year_; | |
| 96 std::string brand_; | |
| 97 scoped_ptr<Address> address_; | |
| 98 Status status_; | |
| 99 std::string object_id_; | |
| 100 DISALLOW_COPY_AND_ASSIGN(MaskedInstrument); | |
| 101 }; | |
| 102 | |
| 103 // Class representing a legal document that the user must accept before they | |
| 104 // can use Online Wallet. | |
| 105 class LegalDocument { | |
| 106 public: | |
| 107 LegalDocument(const std::string& document_id, | |
| 108 const std::string& display_name, | |
| 109 const std::string& document_body); | |
| 110 ~LegalDocument(); | |
| 111 | |
| 112 // Returns null if input is invalid or a valid legal document. Caller owns | |
| 113 // returned pointer. | |
| 114 static LegalDocument* CreateLegalDocument( | |
| 115 const base::DictionaryValue& dictionary); | |
| 116 | |
| 117 bool operator==(const LegalDocument& other) const; | |
| 118 bool operator!=(const LegalDocument& other) const; | |
| 119 | |
| 120 const std::string document_id() const { return document_id_; } | |
| 121 const std::string display_name() const { return display_name_; } | |
| 122 const std::string document_body() const { return document_body_; } | |
| 123 | |
| 124 private: | |
| 125 std::string document_id_; | |
| 126 std::string display_name_; | |
| 127 std::string document_body_; | |
| 128 DISALLOW_COPY_AND_ASSIGN(LegalDocument); | |
| 129 }; | |
| 130 | |
| 131 WalletItems(const std::vector<std::string>& required_actions, | |
| 132 const std::string& google_transaction_id, | |
| 133 const std::string& default_instrument_id, | |
| 134 const std::string& default_address_id); | |
| 135 ~WalletItems(); | |
| 136 | |
| 137 // Returns null on invalid input, an empty wallet items with required | |
| 138 // actions if any are present, and a populated wallet items otherwise. Caller | |
| 139 // owns returned pointer. | |
| 140 static WalletItems* CreateWalletItems( | |
| 141 const base::DictionaryValue& dictionary); | |
| 142 | |
| 143 bool operator==(const WalletItems& other) const; | |
| 144 bool operator!=(const WalletItems& other) const; | |
| 145 | |
| 146 void AddInstrument(MaskedInstrument* instrument) { | |
| 147 DCHECK(instrument); | |
| 148 instruments_.push_back(instrument); | |
| 149 } | |
| 150 void AddAddress(Address* address) { | |
| 151 DCHECK(address); | |
| 152 addresses_.push_back(address); | |
| 153 } | |
| 154 void AddLegalDocument(LegalDocument* legal_document) { | |
| 155 DCHECK(legal_document); | |
| 156 legal_documents_.push_back(legal_document); | |
| 157 } | |
| 158 const std::vector<std::string> required_actions() const { | |
| 159 return required_actions_; | |
| 160 } | |
| 161 const std::string google_transaction_id() const { | |
| 162 return google_transaction_id_; | |
| 163 } | |
| 164 const std::vector<MaskedInstrument*> instruments() const { | |
| 165 return instruments_.get(); | |
| 166 } | |
| 167 const std::string default_instrument_id() const { | |
| 168 return default_instrument_id_; | |
| 169 } | |
| 170 const std::vector<Address*> addresses() const { return addresses_.get(); } | |
| 171 const std::string default_address_id() const { | |
| 172 return default_address_id_; | |
| 173 } | |
| 174 const std::vector<LegalDocument*> legal_documents() const { | |
| 175 return legal_documents_.get(); | |
| 176 } | |
| 177 | |
| 178 private: | |
| 179 std::vector<std::string> required_actions_; | |
| 180 std::string google_transaction_id_; | |
| 181 std::string default_instrument_id_; | |
| 182 std::string default_address_id_; | |
| 183 ScopedVector<MaskedInstrument> instruments_; | |
| 184 ScopedVector<Address> addresses_; | |
| 185 ScopedVector<LegalDocument> legal_documents_; | |
| 186 DISALLOW_COPY_AND_ASSIGN(WalletItems); | |
| 187 }; | |
| 188 | |
| 189 } // end namespace wallet | |
| 190 | |
| 191 #endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ITEMS_H_ | |
| OLD | NEW |