[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame^] | 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_FULL_WALLET_H_ |
| 6 | #define CHROME_BROWSER_AUTOFILL_WALLET_FULL_WALLET_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/basictypes.h" |
| 12 | #include "base/gtest_prod_util.h" |
| 13 | #include "base/memory/scoped_ptr.h" |
| 14 | #include "chrome/browser/autofill/wallet/wallet_address.h" |
| 15 | |
| 16 | namespace base { |
| 17 | class DictionaryValue; |
| 18 | } |
| 19 | |
| 20 | namespace wallet { |
| 21 | |
| 22 | class FullWalletTest; |
| 23 | |
| 24 | // FullWallet contains all the information a merchant requires from a user for |
| 25 | // that user to make a purchase. |
| 26 | class FullWallet { |
| 27 | public: |
| 28 | ~FullWallet(); |
| 29 | |
| 30 | // Returns an empty scoped_ptr if the input invalid, an empty wallet with |
| 31 | // required actions if there are any, or a valid wallet. |
| 32 | static scoped_ptr<FullWallet> |
| 33 | CreateFullWallet(const base::DictionaryValue& dictionary); |
| 34 | |
| 35 | // Decrypts and returns primary account number (PAN) using generated one time |
| 36 | // pad, |otp|. |
| 37 | const std::string& GetPan(void* otp, size_t length); |
| 38 | |
| 39 | // Decrypts and returns card verification number (CVN) using generated one |
| 40 | // time pad, |otp|. |
| 41 | const std::string& GetCvn(void* otp, size_t length); |
| 42 | |
| 43 | bool operator==(const FullWallet& other) const; |
| 44 | bool operator!=(const FullWallet& other) const; |
| 45 | |
| 46 | // If there are required actions |billing_address_| might contain NULL. |
| 47 | const Address* billing_address() const { return billing_address_.get(); } |
| 48 | |
| 49 | // If there are required actions or shipping address is not required |
| 50 | // |shipping_address_| might contain NULL. |
| 51 | const Address* shipping_address() const { return shipping_address_.get(); } |
| 52 | |
| 53 | const std::vector<std::string>& required_actions() const { |
| 54 | return required_actions_; |
| 55 | } |
| 56 | int expiration_month() const { return expiration_month_; } |
| 57 | int expiration_year() const { return expiration_year_; } |
| 58 | |
| 59 | private: |
| 60 | friend class FullWalletTest; |
| 61 | FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWallet); |
| 62 | FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWalletWithRequiredActions); |
| 63 | FullWallet(int expiration_month, |
| 64 | int expiration_year, |
| 65 | const std::string& iin, |
| 66 | const std::string& encrypted_rest, |
| 67 | scoped_ptr<Address> billing_address, |
| 68 | scoped_ptr<Address> shipping_address, |
| 69 | const std::vector<std::string>& required_actions); |
| 70 | void DecryptCardInfo(uint8* otp, size_t length); |
| 71 | int expiration_month_; |
| 72 | int expiration_year_; |
| 73 | // Primary account number (PAN). Its format is \d{16}. |
| 74 | std::string pan_; |
| 75 | // Card verification number (CVN). Its format is \d{3}. |
| 76 | std::string cvn_; |
| 77 | // Issuer identification number (IIN). Its format is \d{6}. |
| 78 | std::string iin_; |
| 79 | // Encrypted concatentation of CVN and PAN without IIN |
| 80 | std::string encrypted_rest_; |
| 81 | scoped_ptr<Address> billing_address_; |
| 82 | scoped_ptr<Address> shipping_address_; |
| 83 | // Actions that must be completed by the user before a FullWallet can be |
| 84 | // issued to them by the Online Wallet service. |
| 85 | // TODO(ahutter): |required_actions_| should be members of an enum not |
| 86 | // strings. See http://crbug.com/165195. |
| 87 | std::vector<std::string> required_actions_; |
| 88 | DISALLOW_COPY_AND_ASSIGN(FullWallet); |
| 89 | }; |
| 90 | |
| 91 | } // namespace wallet |
| 92 | |
| 93 | #endif // CHROME_BROWSER_AUTOFILL_WALLET_FULL_WALLET_H_ |
| 94 | |