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 completed using Online |
| 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 AMEX, |
| 36 DISCOVER, |
| 37 MAESTRO, |
| 38 MASTER_CARD, |
| 39 SOLO, |
| 40 SWITCH, |
| 41 UNKNOWN, // Catch all type. |
| 42 VISA, |
| 43 }; |
| 44 enum Status { |
| 45 BILLING_INCOMPLETE, |
| 46 DECLINED, |
| 47 EXPIRED, |
| 48 INAPPLICABLE, // Catch all status. |
| 49 PENDING, |
| 50 UNSUPPORTED_COUNTRY, |
| 51 VALID, |
| 52 }; |
| 53 |
| 54 // This constructor is only public for unit testing. |
| 55 MaskedInstrument(const std::string& descriptve_name, |
| 56 const Type& type, |
| 57 std::vector<std::string> supported_currencies, |
| 58 const std::string& last_four_digits, |
| 59 int expiration_month, |
| 60 int expiration_year, |
| 61 const std::string& brand, |
| 62 Address* address, |
| 63 const Status& status, |
| 64 const std::string& object_id); |
| 65 |
| 66 ~MaskedInstrument(); |
| 67 |
| 68 // Returns null if input is invalid or a valid masked instrument. Caller |
| 69 // owns returned pointer. |
| 70 static MaskedInstrument* CreateMaskedInstrument( |
| 71 const base::DictionaryValue& dictionary); |
| 72 |
| 73 bool operator==(const MaskedInstrument& other) const; |
| 74 bool operator!=(const MaskedInstrument& other) const; |
| 75 |
| 76 const std::string descriptive_name() const { return descriptive_name_; } |
| 77 Type type() const { return type_; } |
| 78 const std::vector<std::string> supported_currencies() const { |
| 79 return supported_currencies_; |
| 80 } |
| 81 const std::string last_four_digits() const { return last_four_digits_; } |
| 82 int expiration_month() const { return expiration_month_; } |
| 83 int expiration_year() const { return expiration_year_; } |
| 84 const std::string brand() const { return brand_; } |
| 85 const Address* address() const { return address_.get(); } |
| 86 Status status() const { return status_; } |
| 87 const std::string object_id() const { return object_id_; } |
| 88 |
| 89 private: |
| 90 static Type TypeFromString(const std::string& type_string); |
| 91 static Status StatusFromString(const std::string& status_string); |
| 92 std::string descriptive_name_; |
| 93 Type type_; |
| 94 std::vector<std::string> supported_currencies_; |
| 95 std::string last_four_digits_; |
| 96 int expiration_month_; |
| 97 int expiration_year_; |
| 98 std::string brand_; |
| 99 scoped_ptr<Address> address_; |
| 100 Status status_; |
| 101 std::string object_id_; |
| 102 DISALLOW_COPY_AND_ASSIGN(MaskedInstrument); |
| 103 }; |
| 104 |
| 105 // Class representing a legal document that the user must accept before they |
| 106 // can use Online Wallet. |
| 107 class LegalDocument { |
| 108 public: |
| 109 // This constructor is only public for unit testing. |
| 110 LegalDocument(const std::string& document_id, |
| 111 const std::string& display_name, |
| 112 const std::string& document_body); |
| 113 |
| 114 ~LegalDocument(); |
| 115 |
| 116 // Returns null if input is invalid or a valid legal document. Caller owns |
| 117 // returned pointer. |
| 118 static LegalDocument* CreateLegalDocument( |
| 119 const base::DictionaryValue& dictionary); |
| 120 |
| 121 bool operator==(const LegalDocument& other) const; |
| 122 bool operator!=(const LegalDocument& other) const; |
| 123 |
| 124 const std::string document_id() const { return document_id_; } |
| 125 const std::string display_name() const { return display_name_; } |
| 126 const std::string document_body() const { return document_body_; } |
| 127 |
| 128 private: |
| 129 std::string document_id_; |
| 130 std::string display_name_; |
| 131 std::string document_body_; |
| 132 DISALLOW_COPY_AND_ASSIGN(LegalDocument); |
| 133 }; |
| 134 |
| 135 // This constructor is only public for unit testing. |
| 136 WalletItems(const std::vector<std::string>& required_actions, |
| 137 const std::string& google_transaction_id, |
| 138 const std::string& default_instrument_id, |
| 139 const std::string& default_address_id); |
| 140 |
| 141 ~WalletItems(); |
| 142 |
| 143 // Returns null on invalid input, an empty wallet items with required |
| 144 // actions if any are present, and a populated wallet items otherwise. Caller |
| 145 // owns returned pointer. |
| 146 static WalletItems* CreateWalletItems( |
| 147 const base::DictionaryValue& dictionary); |
| 148 |
| 149 bool operator==(const WalletItems& other) const; |
| 150 bool operator!=(const WalletItems& other) const; |
| 151 |
| 152 void AddInstrument(MaskedInstrument* instrument) { |
| 153 DCHECK(instrument); |
| 154 instruments_.push_back(instrument); |
| 155 } |
| 156 void AddAddress(Address* address) { |
| 157 DCHECK(address); |
| 158 addresses_.push_back(address); |
| 159 } |
| 160 void AddLegalDocument(LegalDocument* legal_document) { |
| 161 DCHECK(legal_document); |
| 162 legal_documents_.push_back(legal_document); |
| 163 } |
| 164 const std::vector<std::string> required_actions() const { |
| 165 return required_actions_; |
| 166 } |
| 167 const std::string google_transaction_id() const { |
| 168 return google_transaction_id_; |
| 169 } |
| 170 const std::vector<MaskedInstrument*> instruments() const { |
| 171 return instruments_.get(); |
| 172 } |
| 173 const std::string default_instrument_id() const { |
| 174 return default_instrument_id_; |
| 175 } |
| 176 const std::vector<Address*> addresses() const { return addresses_.get(); } |
| 177 const std::string default_address_id() const { |
| 178 return default_address_id_; |
| 179 } |
| 180 const std::vector<LegalDocument*> legal_documents() const { |
| 181 return legal_documents_.get(); |
| 182 } |
| 183 |
| 184 private: |
| 185 std::vector<std::string> required_actions_; |
| 186 std::string google_transaction_id_; |
| 187 std::string default_instrument_id_; |
| 188 std::string default_address_id_; |
| 189 ScopedVector<MaskedInstrument> instruments_; |
| 190 ScopedVector<Address> addresses_; |
| 191 ScopedVector<LegalDocument> legal_documents_; |
| 192 DISALLOW_COPY_AND_ASSIGN(WalletItems); |
| 193 }; |
| 194 |
| 195 } // end namespace wallet |
| 196 |
| 197 #endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ITEMS_H_ |
OLD | NEW |