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

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

Issue 11293078: Integrating Online Wallet into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing HexStringToInt Created 8 years 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 "chrome/browser/autofill/wallet/wallet_address.h"
17
18 namespace base {
19 class DictionaryValue;
20 }
21
22 namespace wallet {
23
24 class WalletItemsTest;
25
26 // WalletItems primarily serves as a container for the user's instruments and
27 // address, however, it also provides a transaction id which must be used
28 // throughout all API calls being made using this data. Additionally, user
29 // actions may be required before a purchase can be completed using Online
30 // Wallet and those actions are present in the object as well.
31 class WalletItems {
32 public:
33 // Container for all information about a credit card except for it's card
34 // verfication number (CVN) and it's complete primary account number (PAN).
35 class MaskedInstrument {
36 public:
37 enum Type {
38 AMEX,
39 DISCOVER,
40 MAESTRO,
41 MASTER_CARD,
42 SOLO,
43 SWITCH,
44 UNKNOWN, // Catch all type.
45 VISA,
46 };
47 enum Status {
48 BILLING_INCOMPLETE,
49 DECLINED,
50 EXPIRED,
51 INAPPLICABLE, // Catch all status.
52 PENDING,
53 UNSUPPORTED_COUNTRY,
54 VALID,
55 };
56
57 ~MaskedInstrument();
58
59 // Returns an empty scoped_ptr if input is invalid or a valid masked
60 // instrument.
61 static scoped_ptr<MaskedInstrument>
62 CreateMaskedInstrument(const base::DictionaryValue& dictionary);
63
64 bool operator==(const MaskedInstrument& other) const;
65 bool operator!=(const MaskedInstrument& other) const;
66
67 const std::string& descriptive_name() const { return descriptive_name_; }
68 const Type& type() const { return type_; }
69 const std::vector<std::string>& supported_currencies() const {
70 return supported_currencies_;
71 }
72 const std::string& last_four_digits() const { return last_four_digits_; }
73 int expiration_month() const { return expiration_month_; }
74 int expiration_year() const { return expiration_year_; }
75 const std::string& brand() const { return brand_; }
76 const Address& address() const { return *address_; }
77 const Status& status() const { return status_; }
78 const std::string& object_id() const { return object_id_; }
79
80 private:
81 friend class WalletItemsTest;
82 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateMaskedInstrument);
83 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems);
84 MaskedInstrument(const std::string& descriptve_name,
85 const Type& type,
86 const std::vector<std::string>& supported_currencies,
87 const std::string& last_four_digits,
88 int expiration_month,
89 int expiration_year,
90 const std::string& brand,
91 scoped_ptr<Address> address,
92 const Status& status,
93 const std::string& object_id);
94 std::string descriptive_name_;
95 Type type_;
96 std::vector<std::string> supported_currencies_;
97 std::string last_four_digits_;
98 int expiration_month_;
99 int expiration_year_;
100 std::string brand_;
101 scoped_ptr<Address> address_;
102 Status status_;
103 std::string object_id_;
104 DISALLOW_COPY_AND_ASSIGN(MaskedInstrument);
105 };
106
107 // Class representing a legal document that the user must accept before they
108 // can use Online Wallet.
109 class LegalDocument {
110 public:
111 ~LegalDocument();
112
113 // Returns null if input is invalid or a valid legal document. Caller owns
114 // returned pointer.
115 static scoped_ptr<LegalDocument>
116 CreateLegalDocument(const base::DictionaryValue& dictionary);
117
118 bool operator==(const LegalDocument& other) const;
119 bool operator!=(const LegalDocument& other) const;
120
121 const std::string& document_id() const { return document_id_; }
122 const std::string& display_name() const { return display_name_; }
123 const std::string& document_body() const { return document_body_; }
124
125 private:
126 friend class WalletItemsTest;
127 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateLegalDocument);
128 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems);
129 LegalDocument(const std::string& document_id,
130 const std::string& display_name,
131 const std::string& document_body);
132 std::string document_id_;
133 std::string display_name_;
134 std::string document_body_;
135 DISALLOW_COPY_AND_ASSIGN(LegalDocument);
136 };
137
138 ~WalletItems();
139
140 // Returns null on invalid input, an empty wallet items with required
141 // actions if any are present, and a populated wallet items otherwise. Caller
142 // owns returned pointer.
143 static scoped_ptr<WalletItems>
144 CreateWalletItems(const base::DictionaryValue& dictionary);
145
146 bool operator==(const WalletItems& other) const;
147 bool operator!=(const WalletItems& other) const;
148
149 void AddInstrument(scoped_ptr<MaskedInstrument> instrument) {
150 DCHECK(instrument.get());
151 instruments_.push_back(instrument.release());
152 }
153 void AddAddress(scoped_ptr<Address> address) {
154 DCHECK(address.get());
155 addresses_.push_back(address.release());
156 }
157 void AddLegalDocument(scoped_ptr<LegalDocument> legal_document) {
158 DCHECK(legal_document.get());
159 legal_documents_.push_back(legal_document.release());
160 }
161 const std::vector<std::string>& required_actions() const {
162 return required_actions_;
163 }
164 const std::string& google_transaction_id() const {
165 return google_transaction_id_;
166 }
167 const std::vector<MaskedInstrument*>& instruments() const {
168 return instruments_.get();
169 }
170 const std::string& default_instrument_id() const {
171 return default_instrument_id_;
172 }
173 const std::vector<Address*>& addresses() const { return addresses_.get(); }
174 const std::string& default_address_id() const {
175 return default_address_id_;
176 }
177 const std::vector<LegalDocument*>& legal_documents() const {
178 return legal_documents_.get();
179 }
180
181 private:
182 friend class WalletItemsTest;
183 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems);
184 FRIEND_TEST_ALL_PREFIXES(WalletItemsTest,
185 CreateWalletItemsWithRequiredActions);
186 WalletItems(const std::vector<std::string>& required_actions,
187 const std::string& google_transaction_id,
188 const std::string& default_instrument_id,
189 const std::string& default_address_id);
190 // Actions that must be completed by the user before a FullWallet can be
191 // issued to them by the Online Wallet service.
192 // TODO(ahutter): |required_actions_| should be members of an enum not
193 // strings. See http://crbug.com/165195.
194 std::vector<std::string> required_actions_;
195 std::string google_transaction_id_;
196 std::string default_instrument_id_;
197 std::string default_address_id_;
198 ScopedVector<MaskedInstrument> instruments_;
199 ScopedVector<Address> addresses_;
200 ScopedVector<LegalDocument> legal_documents_;
201 DISALLOW_COPY_AND_ASSIGN(WalletItems);
202 };
203
204 } // namespace wallet
205
206 #endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ITEMS_H_
207
OLDNEW
« no previous file with comments | « chrome/browser/autofill/wallet/wallet_client_unittest.cc ('k') | chrome/browser/autofill/wallet/wallet_items.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698