Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: chrome/browser/autofill/wallet/wallet_items.h

Issue 12434004: Move remaining Autofill code to //components/autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 EXPIRED,
60 INAPPLICABLE, // Catch all status.
61 PENDING,
62 UNSUPPORTED_COUNTRY,
63 VALID,
64 };
65
66 ~MaskedInstrument();
67
68 // Returns an empty scoped_ptr if input is invalid or a valid masked
69 // instrument.
70 static scoped_ptr<MaskedInstrument>
71 CreateMaskedInstrument(const base::DictionaryValue& dictionary);
72
73 bool operator==(const MaskedInstrument& other) const;
74 bool operator!=(const MaskedInstrument& other) const;
75
76 // Gets an image to display for this instrument.
77 const gfx::Image& CardIcon() const;
78
79 const string16& descriptive_name() const { return descriptive_name_; }
80 const Type& type() const { return type_; }
81 const std::vector<string16>& supported_currencies() const {
82 return supported_currencies_;
83 }
84 const string16& last_four_digits() const { return last_four_digits_; }
85 int expiration_month() const { return expiration_month_; }
86 int expiration_year() const { return expiration_year_; }
87 const Address& address() const { return *address_; }
88 const Status& status() const { return status_; }
89 const std::string& object_id() const { return object_id_; }
90
91 private:
92 friend class WalletItemsTest;
93 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateMaskedInstrument);
94 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems);
95 MaskedInstrument(const string16& descriptve_name,
96 const Type& type,
97 const std::vector<string16>& supported_currencies,
98 const string16& last_four_digits,
99 int expiration_month,
100 int expiration_year,
101 scoped_ptr<Address> address,
102 const Status& status,
103 const std::string& object_id);
104
105 // A user-provided description of the instrument. For example, "Google Visa
106 // Card".
107 string16 descriptive_name_;
108
109 // The payment network of the instrument. For example, Visa.
110 Type type_;
111
112 // |supported_currencies_| are ISO 4217 currency codes, e.g. USD.
113 std::vector<string16> supported_currencies_;
114
115 // The last four digits of the primary account number of the instrument.
116 string16 last_four_digits_;
117
118 // |expiration month_| should be 1-12.
119 int expiration_month_;
120
121 // |expiration_year_| should be a 4-digit year.
122 int expiration_year_;
123
124 // The billing address for the instrument.
125 scoped_ptr<Address> address_;
126
127 // The current status of the instrument. For example, expired or declined.
128 Status status_;
129
130 // Externalized Online Wallet id for this instrument.
131 std::string object_id_;
132
133 DISALLOW_COPY_AND_ASSIGN(MaskedInstrument);
134 };
135
136 // Class representing a legal document that the user must accept before they
137 // can use Online Wallet.
138 class LegalDocument {
139 public:
140 ~LegalDocument();
141
142 // Returns null if input is invalid or a valid legal document. Caller owns
143 // returned pointer.
144 static scoped_ptr<LegalDocument>
145 CreateLegalDocument(const base::DictionaryValue& dictionary);
146
147 // Get the url where this legal document is hosted.
148 GURL GetUrl();
149
150 bool operator==(const LegalDocument& other) const;
151 bool operator!=(const LegalDocument& other) const;
152
153 const std::string& document_id() const { return document_id_; }
154 const std::string& display_name() const { return display_name_; }
155
156 private:
157 friend class WalletItemsTest;
158 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateLegalDocument);
159 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems);
160 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, LegalDocumentGetUrl);
161 LegalDocument(const std::string& document_id,
162 const std::string& display_name);
163
164 // Externalized Online Wallet id for the document.
165 std::string document_id_;
166
167 // User displayable name for the document.
168 std::string display_name_;
169 DISALLOW_COPY_AND_ASSIGN(LegalDocument);
170 };
171
172 ~WalletItems();
173
174 // Returns null on invalid input, an empty wallet items with required
175 // actions if any are present, and a populated wallet items otherwise. Caller
176 // owns returned pointer.
177 static scoped_ptr<WalletItems>
178 CreateWalletItems(const base::DictionaryValue& dictionary);
179
180 bool operator==(const WalletItems& other) const;
181 bool operator!=(const WalletItems& other) const;
182
183 void AddInstrument(scoped_ptr<MaskedInstrument> instrument) {
184 DCHECK(instrument.get());
185 instruments_.push_back(instrument.release());
186 }
187 void AddAddress(scoped_ptr<Address> address) {
188 DCHECK(address.get());
189 addresses_.push_back(address.release());
190 }
191 void AddLegalDocument(scoped_ptr<LegalDocument> legal_document) {
192 DCHECK(legal_document.get());
193 legal_documents_.push_back(legal_document.release());
194 }
195
196 // Whether or not |action| is in |required_actions_|.
197 bool HasRequiredAction(RequiredAction action) const;
198
199 const std::vector<RequiredAction>& required_actions() const {
200 return required_actions_;
201 }
202 const std::string& google_transaction_id() const {
203 return google_transaction_id_;
204 }
205 const std::vector<MaskedInstrument*>& instruments() const {
206 return instruments_.get();
207 }
208 const std::string& default_instrument_id() const {
209 return default_instrument_id_;
210 }
211 const std::vector<Address*>& addresses() const { return addresses_.get(); }
212 const std::string& default_address_id() const { return default_address_id_; }
213 const std::string& obfuscated_gaia_id() const { return obfuscated_gaia_id_; }
214 const std::vector<LegalDocument*>& legal_documents() const {
215 return legal_documents_.get();
216 }
217
218 private:
219 friend class WalletItemsTest;
220 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems);
221 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest,
222 CreateWalletItemsWithRequiredActions);
223
224 WalletItems(const std::vector<RequiredAction>& required_actions,
225 const std::string& google_transaction_id,
226 const std::string& default_instrument_id,
227 const std::string& default_address_id,
228 const std::string& obfuscated_gaia_id);
229
230 // Actions that must be completed by the user before a FullWallet can be
231 // issued to them by the Online Wallet service.
232 std::vector<RequiredAction> required_actions_;
233
234 // The id for this transaction issued by Google.
235 std::string google_transaction_id_;
236
237 // The id of the user's default instrument.
238 std::string default_instrument_id_;
239
240 // The id of the user's default address.
241 std::string default_address_id_;
242
243 // The externalized Gaia id of the user.
244 std::string obfuscated_gaia_id_;
245
246 // The user's backing instruments.
247 ScopedVector<MaskedInstrument> instruments_;
248
249 // The user's shipping addresses.
250 ScopedVector<Address> addresses_;
251
252 // Legal documents the user must accept before using Online Wallet.
253 ScopedVector<LegalDocument> legal_documents_;
254
255 DISALLOW_COPY_AND_ASSIGN(WalletItems);
256 };
257
258 } // namespace wallet
259 } // namespace autofill
260
261 #endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ITEMS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698