[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 | |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 5 | #ifndef COMPONENTS_AUTOFILL_BROWSER_WALLET_FULL_WALLET_H_ |
| 6 | #define COMPONENTS_AUTOFILL_BROWSER_WALLET_FULL_WALLET_H_ |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 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" |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 14 | #include "components/autofill/browser/wallet/required_action.h" |
| 15 | #include "components/autofill/browser/wallet/wallet_address.h" |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 16 | |
| 17 | namespace base { |
| 18 | class DictionaryValue; |
| 19 | } |
| 20 | |
[email protected] | 34517564 | 2013-02-20 19:25:52 | [diff] [blame] | 21 | namespace autofill { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 22 | namespace wallet { |
| 23 | |
| 24 | class FullWalletTest; |
| 25 | |
| 26 | // FullWallet contains all the information a merchant requires from a user for |
[email protected] | 7a97aa8 | 2013-01-07 21:34:53 | [diff] [blame] | 27 | // that user to make a purchase. This includes: |
| 28 | // - billing information |
| 29 | // - shipping information |
| 30 | // - a proxy card for the backing card selected from a user's wallet items |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 31 | class FullWallet { |
| 32 | public: |
| 33 | ~FullWallet(); |
| 34 | |
| 35 | // Returns an empty scoped_ptr if the input invalid, an empty wallet with |
| 36 | // required actions if there are any, or a valid wallet. |
| 37 | static scoped_ptr<FullWallet> |
| 38 | CreateFullWallet(const base::DictionaryValue& dictionary); |
| 39 | |
[email protected] | 1a43a90d | 2013-03-15 09:13:27 | [diff] [blame] | 40 | // Returns corresponding data for |type|. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 41 | base::string16 GetInfo(AutofillFieldType type); |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 42 | |
[email protected] | ab6601f | 2013-03-02 19:11:58 | [diff] [blame] | 43 | // Whether or not |action| is in |required_actions_|. |
| 44 | bool HasRequiredAction(RequiredAction action) const; |
| 45 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 46 | bool operator==(const FullWallet& other) const; |
| 47 | bool operator!=(const FullWallet& other) const; |
| 48 | |
| 49 | // If there are required actions |billing_address_| might contain NULL. |
| 50 | const Address* billing_address() const { return billing_address_.get(); } |
| 51 | |
| 52 | // If there are required actions or shipping address is not required |
| 53 | // |shipping_address_| might contain NULL. |
| 54 | const Address* shipping_address() const { return shipping_address_.get(); } |
| 55 | |
[email protected] | 7a97aa8 | 2013-01-07 21:34:53 | [diff] [blame] | 56 | const std::vector<RequiredAction>& required_actions() const { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 57 | return required_actions_; |
| 58 | } |
| 59 | int expiration_month() const { return expiration_month_; } |
| 60 | int expiration_year() const { return expiration_year_; } |
| 61 | |
[email protected] | 34517564 | 2013-02-20 19:25:52 | [diff] [blame] | 62 | void set_one_time_pad(const std::vector<uint8>& one_time_pad) { |
| 63 | one_time_pad_ = one_time_pad; |
| 64 | } |
| 65 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 66 | private: |
| 67 | friend class FullWalletTest; |
| 68 | FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWallet); |
| 69 | FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWalletWithRequiredActions); |
[email protected] | c56a4aa5 | 2013-04-03 05:04:21 | [diff] [blame] | 70 | FRIEND_TEST_ALL_PREFIXES(FullWalletTest, EvenRestDecryptionTest); |
| 71 | FRIEND_TEST_ALL_PREFIXES(FullWalletTest, OddRestDecryptionTest); |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 72 | FullWallet(int expiration_month, |
| 73 | int expiration_year, |
| 74 | const std::string& iin, |
| 75 | const std::string& encrypted_rest, |
| 76 | scoped_ptr<Address> billing_address, |
| 77 | scoped_ptr<Address> shipping_address, |
[email protected] | 7a97aa8 | 2013-01-07 21:34:53 | [diff] [blame] | 78 | const std::vector<RequiredAction>& required_actions); |
[email protected] | 1a43a90d | 2013-03-15 09:13:27 | [diff] [blame] | 79 | |
| 80 | // Decrypts both |pan_| and |cvn_|. |
[email protected] | 34517564 | 2013-02-20 19:25:52 | [diff] [blame] | 81 | void DecryptCardInfo(); |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 82 | |
[email protected] | 1a43a90d | 2013-03-15 09:13:27 | [diff] [blame] | 83 | // Decrypts and returns the primary account number (PAN) using the generated |
| 84 | // one time pad, |one_time_pad_|. |
| 85 | const std::string& GetPan(); |
| 86 | |
| 87 | // Decrypts and returns the card verification number (CVN) using the generated |
| 88 | // one time pad, |one_time_pad_|. |
| 89 | const std::string& GetCvn(); |
| 90 | |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 91 | // The expiration month of the proxy card. It should be 1-12. |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 92 | int expiration_month_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 93 | |
| 94 | // The expiration year of the proxy card. It should be a 4-digit year. |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 95 | int expiration_year_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 96 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 97 | // Primary account number (PAN). Its format is \d{16}. |
| 98 | std::string pan_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 99 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 100 | // Card verification number (CVN). Its format is \d{3}. |
| 101 | std::string cvn_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 102 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 103 | // Issuer identification number (IIN). Its format is \d{6}. |
| 104 | std::string iin_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 105 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 106 | // Encrypted concatentation of CVN and PAN without IIN |
| 107 | std::string encrypted_rest_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 108 | |
| 109 | // The billing address of the backing instrument. |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 110 | scoped_ptr<Address> billing_address_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 111 | |
| 112 | // The shipping address for the transaction. |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 113 | scoped_ptr<Address> shipping_address_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 114 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 115 | // Actions that must be completed by the user before a FullWallet can be |
| 116 | // issued to them by the Online Wallet service. |
[email protected] | 7a97aa8 | 2013-01-07 21:34:53 | [diff] [blame] | 117 | std::vector<RequiredAction> required_actions_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 118 | |
[email protected] | 34517564 | 2013-02-20 19:25:52 | [diff] [blame] | 119 | // The one time pad used for FullWallet encryption. |
| 120 | std::vector<uint8> one_time_pad_; |
| 121 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 122 | DISALLOW_COPY_AND_ASSIGN(FullWallet); |
| 123 | }; |
| 124 | |
| 125 | } // namespace wallet |
[email protected] | 34517564 | 2013-02-20 19:25:52 | [diff] [blame] | 126 | } // namespace autofill |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 127 | |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 128 | #endif // COMPONENTS_AUTOFILL_BROWSER_WALLET_FULL_WALLET_H_ |