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/gtest_prod_util.h" | |
13 #include "base/logging.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/scoped_vector.h" | |
16 #include "base/string16.h" | |
17 #include "chrome/browser/autofill/wallet/required_action.h" | |
18 #include "chrome/browser/autofill/wallet/wallet_address.h" | |
19 | |
20 class GURL; | |
21 | |
22 namespace base { | |
23 class DictionaryValue; | |
24 } | |
25 | |
26 namespace gfx { | |
27 class Image; | |
28 } | |
29 | |
30 namespace autofill { | |
31 namespace wallet { | |
32 | |
33 class WalletItemsTest; | |
34 | |
35 // WalletItems is a collection of cards and addresses that a user picks from to | |
36 // construct a full wallet. However, it also provides a transaction ID which | |
37 // must be used throughout all API calls being made using this data. | |
38 // Additionally, user actions may be required before a purchase can be completed | |
39 // using Online Wallet and those actions are present in the object as well. | |
40 class WalletItems { | |
41 public: | |
42 // Container for all information about a credit card except for it's card | |
43 // verfication number (CVN) and it's complete primary account number (PAN). | |
44 class MaskedInstrument { | |
45 public: | |
46 enum Type { | |
47 AMEX, | |
48 DISCOVER, | |
49 MAESTRO, | |
50 MASTER_CARD, | |
51 SOLO, | |
52 SWITCH, | |
53 UNKNOWN, // Catch all type. | |
54 VISA, | |
55 }; | |
56 enum Status { | |
57 BILLING_INCOMPLETE, | |
58 DECLINED, | |
59 DISABLED_FOR_THIS_MERCHANT, | |
60 EXPIRED, | |
61 INAPPLICABLE, // Catch all status. | |
62 PENDING, | |
63 UNSUPPORTED_COUNTRY, | |
64 VALID, | |
65 }; | |
66 | |
67 ~MaskedInstrument(); | |
68 | |
69 // Returns an empty scoped_ptr if input is invalid or a valid masked | |
70 // instrument. | |
71 static scoped_ptr<MaskedInstrument> | |
72 CreateMaskedInstrument(const base::DictionaryValue& dictionary); | |
73 | |
74 bool operator==(const MaskedInstrument& other) const; | |
75 bool operator!=(const MaskedInstrument& other) const; | |
76 | |
77 // Gets an image to display for this instrument. | |
78 const gfx::Image& CardIcon() const; | |
79 | |
80 const string16& descriptive_name() const { return descriptive_name_; } | |
81 const Type& type() const { return type_; } | |
82 const std::vector<string16>& supported_currencies() const { | |
83 return supported_currencies_; | |
84 } | |
85 const string16& last_four_digits() const { return last_four_digits_; } | |
86 int expiration_month() const { return expiration_month_; } | |
87 int expiration_year() const { return expiration_year_; } | |
88 const Address& address() const { return *address_; } | |
89 const Status& status() const { return status_; } | |
90 const std::string& object_id() const { return object_id_; } | |
91 | |
92 private: | |
93 friend class WalletItemsTest; | |
94 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateMaskedInstrument); | |
95 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems); | |
96 MaskedInstrument(const string16& descriptve_name, | |
97 const Type& type, | |
98 const std::vector<string16>& supported_currencies, | |
99 const string16& last_four_digits, | |
100 int expiration_month, | |
101 int expiration_year, | |
102 scoped_ptr<Address> address, | |
103 const Status& status, | |
104 const std::string& object_id); | |
105 | |
106 // A user-provided description of the instrument. For example, "Google Visa | |
107 // Card". | |
108 string16 descriptive_name_; | |
109 | |
110 // The payment network of the instrument. For example, Visa. | |
111 Type type_; | |
112 | |
113 // |supported_currencies_| are ISO 4217 currency codes, e.g. USD. | |
114 std::vector<string16> supported_currencies_; | |
115 | |
116 // The last four digits of the primary account number of the instrument. | |
117 string16 last_four_digits_; | |
118 | |
119 // |expiration month_| should be 1-12. | |
120 int expiration_month_; | |
121 | |
122 // |expiration_year_| should be a 4-digit year. | |
123 int expiration_year_; | |
124 | |
125 // The billing address for the instrument. | |
126 scoped_ptr<Address> address_; | |
127 | |
128 // The current status of the instrument. For example, expired or declined. | |
129 Status status_; | |
130 | |
131 // Externalized Online Wallet id for this instrument. | |
132 std::string object_id_; | |
133 | |
134 DISALLOW_COPY_AND_ASSIGN(MaskedInstrument); | |
135 }; | |
136 | |
137 // Class representing a legal document that the user must accept before they | |
138 // can use Online Wallet. | |
139 class LegalDocument { | |
140 public: | |
141 ~LegalDocument(); | |
142 | |
143 // Returns null if input is invalid or a valid legal document. Caller owns | |
144 // returned pointer. | |
145 static scoped_ptr<LegalDocument> | |
146 CreateLegalDocument(const base::DictionaryValue& dictionary); | |
147 | |
148 // Get the url where this legal document is hosted. | |
149 GURL GetUrl(); | |
150 | |
151 bool operator==(const LegalDocument& other) const; | |
152 bool operator!=(const LegalDocument& other) const; | |
153 | |
154 const std::string& document_id() const { return document_id_; } | |
155 const std::string& display_name() const { return display_name_; } | |
156 | |
157 private: | |
158 friend class WalletItemsTest; | |
159 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateLegalDocument); | |
160 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems); | |
161 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, LegalDocumentGetUrl); | |
162 LegalDocument(const std::string& document_id, | |
163 const std::string& display_name); | |
164 | |
165 // Externalized Online Wallet id for the document. | |
166 std::string document_id_; | |
167 | |
168 // User displayable name for the document. | |
169 std::string display_name_; | |
170 DISALLOW_COPY_AND_ASSIGN(LegalDocument); | |
171 }; | |
172 | |
173 ~WalletItems(); | |
174 | |
175 // Returns null on invalid input, an empty wallet items with required | |
176 // actions if any are present, and a populated wallet items otherwise. Caller | |
177 // owns returned pointer. | |
178 static scoped_ptr<WalletItems> | |
179 CreateWalletItems(const base::DictionaryValue& dictionary); | |
180 | |
181 bool operator==(const WalletItems& other) const; | |
182 bool operator!=(const WalletItems& other) const; | |
183 | |
184 void AddInstrument(scoped_ptr<MaskedInstrument> instrument) { | |
185 DCHECK(instrument.get()); | |
186 instruments_.push_back(instrument.release()); | |
187 } | |
188 void AddAddress(scoped_ptr<Address> address) { | |
189 DCHECK(address.get()); | |
190 addresses_.push_back(address.release()); | |
191 } | |
192 void AddLegalDocument(scoped_ptr<LegalDocument> legal_document) { | |
193 DCHECK(legal_document.get()); | |
194 legal_documents_.push_back(legal_document.release()); | |
195 } | |
196 | |
197 // Whether or not |action| is in |required_actions_|. | |
198 bool HasRequiredAction(RequiredAction action) const; | |
199 | |
200 const std::vector<RequiredAction>& required_actions() const { | |
201 return required_actions_; | |
202 } | |
203 const std::string& google_transaction_id() const { | |
204 return google_transaction_id_; | |
205 } | |
206 const std::vector<MaskedInstrument*>& instruments() const { | |
207 return instruments_.get(); | |
208 } | |
209 const std::string& default_instrument_id() const { | |
210 return default_instrument_id_; | |
211 } | |
212 const std::vector<Address*>& addresses() const { return addresses_.get(); } | |
213 const std::string& default_address_id() const { return default_address_id_; } | |
214 const std::string& obfuscated_gaia_id() const { return obfuscated_gaia_id_; } | |
215 const std::vector<LegalDocument*>& legal_documents() const { | |
216 return legal_documents_.get(); | |
217 } | |
218 | |
219 private: | |
220 friend class WalletItemsTest; | |
221 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems); | |
222 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, | |
223 CreateWalletItemsWithRequiredActions); | |
224 | |
225 WalletItems(const std::vector<RequiredAction>& required_actions, | |
226 const std::string& google_transaction_id, | |
227 const std::string& default_instrument_id, | |
228 const std::string& default_address_id, | |
229 const std::string& obfuscated_gaia_id); | |
230 | |
231 // Actions that must be completed by the user before a FullWallet can be | |
232 // issued to them by the Online Wallet service. | |
233 std::vector<RequiredAction> required_actions_; | |
234 | |
235 // The id for this transaction issued by Google. | |
236 std::string google_transaction_id_; | |
237 | |
238 // The id of the user's default instrument. | |
239 std::string default_instrument_id_; | |
240 | |
241 // The id of the user's default address. | |
242 std::string default_address_id_; | |
243 | |
244 // The externalized Gaia id of the user. | |
245 std::string obfuscated_gaia_id_; | |
246 | |
247 // The user's backing instruments. | |
248 ScopedVector<MaskedInstrument> instruments_; | |
249 | |
250 // The user's shipping addresses. | |
251 ScopedVector<Address> addresses_; | |
252 | |
253 // Legal documents the user must accept before using Online Wallet. | |
254 ScopedVector<LegalDocument> legal_documents_; | |
255 | |
256 DISALLOW_COPY_AND_ASSIGN(WalletItems); | |
257 }; | |
258 | |
259 } // namespace wallet | |
260 } // namespace autofill | |
261 | |
262 #endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ITEMS_H_ | |
OLD | NEW |