Add diagnostics_writer.cc to the list of files allowed to printf.
[chromium-blink-merge.git] / components / autofill / content / browser / wallet / wallet_items.h
blobe6121a2d3505a0771b999e089b46655e79e4796c
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_CONTENT_BROWSER_WALLET_WALLET_ITEMS_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_ITEMS_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h"
17 #include "base/strings/string16.h"
18 #include "components/autofill/content/browser/wallet/required_action.h"
19 #include "components/autofill/content/browser/wallet/wallet_address.h"
20 #include "url/gurl.h"
22 namespace base {
23 class DictionaryValue;
26 namespace gfx {
27 class Image;
30 namespace autofill {
32 class AutofillType;
34 FORWARD_DECLARE_TEST(WalletInstrumentWrapperTest, GetInfoCreditCardExpMonth);
35 FORWARD_DECLARE_TEST(WalletInstrumentWrapperTest,
36 GetDisplayTextEmptyWhenExpired);
38 namespace wallet {
40 class GaiaAccount;
41 class WalletItemsTest;
43 enum AmexPermission {
44 AMEX_ALLOWED,
45 AMEX_DISALLOWED,
48 // WalletItems is a collection of cards and addresses that a user picks from to
49 // construct a full wallet. However, it also provides a transaction ID which
50 // must be used throughout all API calls being made using this data.
51 // Additionally, user actions may be required before a purchase can be completed
52 // using Online Wallet and those actions are present in the object as well.
53 class WalletItems {
54 public:
55 // Container for all information about a credit card except for it's card
56 // verfication number (CVN) and it's complete primary account number (PAN).
57 class MaskedInstrument {
58 public:
59 enum Type {
60 AMEX,
61 DISCOVER,
62 MAESTRO,
63 MASTER_CARD,
64 SOLO,
65 SWITCH,
66 UNKNOWN, // Catch all type.
67 VISA,
69 enum Status {
70 AMEX_NOT_SUPPORTED,
71 BILLING_INCOMPLETE,
72 DECLINED,
73 DISABLED_FOR_THIS_MERCHANT, // Deprecated.
74 EXPIRED,
75 INAPPLICABLE, // Catch all status.
76 PENDING,
77 UNSUPPORTED_COUNTRY,
78 VALID,
81 ~MaskedInstrument();
83 // Returns an empty scoped_ptr if input is invalid or a valid masked
84 // instrument.
85 static scoped_ptr<MaskedInstrument>
86 CreateMaskedInstrument(const base::DictionaryValue& dictionary);
88 bool operator==(const MaskedInstrument& other) const;
89 bool operator!=(const MaskedInstrument& other) const;
91 // Gets an image to display for this instrument.
92 const gfx::Image& CardIcon() const;
94 // Returns a pair of strings that summarizes this CC,
95 // suitable for display to the user.
96 base::string16 DisplayName() const;
97 base::string16 DisplayNameDetail() const;
99 // Gets info that corresponds with |type|.
100 base::string16 GetInfo(const AutofillType& type,
101 const std::string& app_locale) const;
103 // Returns the display type of the and last four digits (e.g. Visa - 4444).
104 base::string16 TypeAndLastFourDigits() const;
106 const base::string16& descriptive_name() const { return descriptive_name_; }
107 const Type& type() const { return type_; }
108 const base::string16& last_four_digits() const { return last_four_digits_; }
109 int expiration_month() const { return expiration_month_; }
110 int expiration_year() const { return expiration_year_; }
111 const Address& address() const { return *address_; }
112 const Status& status() const { return status_; }
113 const std::string& object_id() const { return object_id_; }
115 private:
116 friend class WalletItemsTest;
117 friend scoped_ptr<MaskedInstrument> GetTestMaskedInstrumentWithDetails(
118 const std::string& id,
119 scoped_ptr<Address> address,
120 Type type,
121 Status status);
122 FRIEND_TEST_ALL_PREFIXES(::autofill::WalletInstrumentWrapperTest,
123 GetInfoCreditCardExpMonth);
124 FRIEND_TEST_ALL_PREFIXES(::autofill::WalletInstrumentWrapperTest,
125 GetDisplayTextEmptyWhenExpired);
126 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateMaskedInstrument);
127 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems);
129 MaskedInstrument(const base::string16& descriptive_name,
130 const Type& type,
131 const base::string16& last_four_digits,
132 int expiration_month,
133 int expiration_year,
134 scoped_ptr<Address> address,
135 const Status& status,
136 const std::string& object_id);
138 // A user-provided description of the instrument. For example, "Google Visa
139 // Card".
140 base::string16 descriptive_name_;
142 // The payment network of the instrument. For example, Visa.
143 Type type_;
145 // The last four digits of the primary account number of the instrument.
146 base::string16 last_four_digits_;
148 // |expiration month_| should be 1-12.
149 int expiration_month_;
151 // |expiration_year_| should be a 4-digit year.
152 int expiration_year_;
154 // The billing address for the instrument.
155 scoped_ptr<Address> address_;
157 // The current status of the instrument. For example, expired or declined.
158 Status status_;
160 // Externalized Online Wallet id for this instrument.
161 std::string object_id_;
163 DISALLOW_COPY_AND_ASSIGN(MaskedInstrument);
166 // Class representing a legal document that the user must accept before they
167 // can use Online Wallet.
168 class LegalDocument {
169 public:
170 ~LegalDocument();
172 // Returns null if input is invalid or a valid legal document.
173 static scoped_ptr<LegalDocument>
174 CreateLegalDocument(const base::DictionaryValue& dictionary);
176 // Returns a document for the privacy policy (acceptance of which is not
177 // tracked by the server).
178 static scoped_ptr<LegalDocument> CreatePrivacyPolicyDocument();
180 bool operator==(const LegalDocument& other) const;
181 bool operator!=(const LegalDocument& other) const;
183 const std::string& id() { return id_; }
184 const GURL& url() const { return url_; }
185 const base::string16& display_name() const { return display_name_; }
187 private:
188 friend class WalletItemsTest;
189 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateLegalDocument);
190 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems);
191 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, LegalDocumentUrl);
192 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, LegalDocumentEmptyId);
193 LegalDocument(const std::string& id,
194 const base::string16& display_name);
195 LegalDocument(const GURL& url,
196 const base::string16& display_name);
198 // Externalized Online Wallet id for the document, or an empty string for
199 // documents not tracked by the server (such as the privacy policy).
200 std::string id_;
201 // The human-visitable URL that displays the document.
202 GURL url_;
203 // User displayable name for the document.
204 base::string16 display_name_;
205 DISALLOW_COPY_AND_ASSIGN(LegalDocument);
208 ~WalletItems();
210 // Returns null on invalid input, an empty wallet items with required
211 // actions if any are present, and a populated wallet items otherwise. Caller
212 // owns returned pointer.
213 static scoped_ptr<WalletItems>
214 CreateWalletItems(const base::DictionaryValue& dictionary);
216 bool operator==(const WalletItems& other) const;
217 bool operator!=(const WalletItems& other) const;
219 void AddAccount(scoped_ptr<GaiaAccount> account);
220 void AddInstrument(scoped_ptr<MaskedInstrument> instrument) {
221 DCHECK(instrument);
222 instruments_.push_back(instrument.release());
224 void AddAddress(scoped_ptr<Address> address) {
225 DCHECK(address);
226 addresses_.push_back(address.release());
228 void AddLegalDocument(scoped_ptr<LegalDocument> legal_document) {
229 DCHECK(legal_document);
230 legal_documents_.push_back(legal_document.release());
232 void AddAllowedShippingCountry(const std::string& country_code) {
233 allowed_shipping_countries_.insert(country_code);
236 // Return the corresponding instrument for |id| or NULL if it doesn't exist.
237 const WalletItems::MaskedInstrument* GetInstrumentById(
238 const std::string& object_id) const;
240 // Whether or not |action| is in |required_actions_|.
241 bool HasRequiredAction(RequiredAction action) const;
243 // Checks whether |card_number| is supported by Wallet for this merchant and
244 // if not, fills in |message| with a user-visible explanation.
245 bool SupportsCard(const base::string16& card_number,
246 base::string16* message) const;
248 const std::vector<GaiaAccount*>& gaia_accounts() const {
249 return gaia_accounts_.get();
251 const std::vector<RequiredAction>& required_actions() const {
252 return required_actions_;
254 const std::string& google_transaction_id() const {
255 return google_transaction_id_;
257 const std::vector<MaskedInstrument*>& instruments() const {
258 return instruments_.get();
260 const std::string& default_instrument_id() const {
261 return default_instrument_id_;
263 const std::vector<Address*>& addresses() const { return addresses_.get(); }
264 const std::string& default_address_id() const { return default_address_id_; }
265 // Returns the GAIA id of the active account, or an empty string if no account
266 // is active.
267 std::string ObfuscatedGaiaId() const;
268 size_t active_account_index() const { return active_account_index_; }
269 const std::vector<LegalDocument*>& legal_documents() const {
270 return legal_documents_.get();
272 const std::set<std::string>& allowed_shipping_countries() const {
273 return allowed_shipping_countries_;
276 private:
277 friend class WalletItemsTest;
278 friend scoped_ptr<WalletItems> GetTestWalletItemsWithDetails(
279 const std::vector<RequiredAction>& required_actions,
280 const std::string& default_instrument_id,
281 const std::string& default_address_id,
282 AmexPermission amex_permission);
283 friend scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds(
284 RequiredAction action);
285 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems);
286 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest,
287 CreateWalletItemsWithRequiredActions);
289 WalletItems(const std::vector<RequiredAction>& required_actions,
290 const std::string& google_transaction_id,
291 const std::string& default_instrument_id,
292 const std::string& default_address_id,
293 AmexPermission amex_permission);
295 // Actions that must be completed by the user before a FullWallet can be
296 // issued to them by the Online Wallet service.
297 std::vector<RequiredAction> required_actions_;
299 // The id for this transaction issued by Google.
300 std::string google_transaction_id_;
302 // The id of the user's default instrument.
303 std::string default_instrument_id_;
305 // The id of the user's default address.
306 std::string default_address_id_;
308 // The index into |gaia_accounts_| of the account for which this object
309 // holds data.
310 size_t active_account_index_;
312 // The complete set of logged in GAIA accounts.
313 ScopedVector<GaiaAccount> gaia_accounts_;
315 // The user's backing instruments.
316 ScopedVector<MaskedInstrument> instruments_;
318 // The user's shipping addresses.
319 ScopedVector<Address> addresses_;
321 // Legal documents the user must accept before using Online Wallet.
322 ScopedVector<LegalDocument> legal_documents_;
324 // Country codes for allowed Wallet shipping destinations.
325 std::set<std::string> allowed_shipping_countries_;
327 // Whether Google Wallet allows American Express card for this merchant.
328 AmexPermission amex_permission_;
330 DISALLOW_COPY_AND_ASSIGN(WalletItems);
333 } // namespace wallet
334 } // namespace autofill
336 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_ITEMS_H_