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. 4 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_FULL_WALLET_H_ 6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_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 "base/strings/string16.h" 15 #include "components/autofill/content/browser/wallet/required_action.h" 16 #include "components/autofill/content/browser/wallet/wallet_address.h" 17 18 namespace base { 19 class DictionaryValue; 20 } 21 22 namespace autofill { 23 24 class AutofillType; 25 26 namespace wallet { 27 28 class FullWalletTest; 29 30 // FullWallet contains all the information a merchant requires from a user for 31 // that user to make a purchase. This includes: 32 // - billing information 33 // - shipping information 34 // - a proxy card for the backing card selected from a user's wallet items 35 class FullWallet { 36 public: 37 ~FullWallet(); 38 39 // Returns an empty scoped_ptr if the input invalid, an empty wallet with 40 // required actions if there are any, or a valid wallet. 41 static scoped_ptr<FullWallet> 42 CreateFullWallet(const base::DictionaryValue& dictionary); 43 44 // Returns a wallet built from the provided clear-text data. 45 // Data is not validated; |pan|, |cvn| and |billing_address| must be set. 46 static scoped_ptr<FullWallet> 47 CreateFullWalletFromClearText(int expiration_month, 48 int expiration_year, 49 const std::string& pan, 50 const std::string& cvn, 51 scoped_ptr<Address> billing_address, 52 scoped_ptr<Address> shipping_address); 53 54 // Returns corresponding data for |type|. 55 base::string16 GetInfo(const AutofillType& type); 56 57 // Whether or not |action| is in |required_actions_|. 58 bool HasRequiredAction(RequiredAction action) const; 59 60 // The type of the card that this FullWallet contains and the last four digits 61 // like this "Visa - 4111". 62 base::string16 TypeAndLastFourDigits(); 63 64 bool operator==(const FullWallet& other) const; 65 bool operator!=(const FullWallet& other) const; 66 67 // If there are required actions |billing_address_| might contain NULL. 68 const Address* billing_address() const { return billing_address_.get(); } 69 70 // If there are required actions or shipping address is not required 71 // |shipping_address_| might contain NULL. 72 const Address* shipping_address() const { return shipping_address_.get(); } 73 74 const std::vector<RequiredAction>& required_actions() const { 75 return required_actions_; 76 } 77 int expiration_month() const { return expiration_month_; } 78 int expiration_year() const { return expiration_year_; } 79 80 void set_one_time_pad(const std::vector<uint8>& one_time_pad) { 81 one_time_pad_ = one_time_pad; 82 } 83 84 private: 85 friend class FullWalletTest; 86 friend scoped_ptr<FullWallet> GetTestFullWallet(); 87 friend scoped_ptr<FullWallet> GetTestFullWalletInstrumentOnly(); 88 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWallet); 89 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWalletWithRequiredActions); 90 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, RestLengthCorrectDecryptionTest); 91 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, RestLengthUnderDecryptionTest); 92 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, GetCreditCardInfo); 93 94 FullWallet(int expiration_month, 95 int expiration_year, 96 const std::string& iin, 97 const std::string& encrypted_rest, 98 scoped_ptr<Address> billing_address, 99 scoped_ptr<Address> shipping_address, 100 const std::vector<RequiredAction>& required_actions); 101 102 // Decrypts both |pan_| and |cvn_|. 103 void DecryptCardInfo(); 104 105 // Decrypts and returns the primary account number (PAN) using the generated 106 // one time pad, |one_time_pad_|. 107 const std::string& GetPan(); 108 109 // Decrypts and returns the card verification number (CVN) using the generated 110 // one time pad, |one_time_pad_|. 111 const std::string& GetCvn(); 112 113 // The expiration month of the proxy card. It should be 1-12. 114 int expiration_month_; 115 116 // The expiration year of the proxy card. It should be a 4-digit year. 117 int expiration_year_; 118 119 // Primary account number (PAN). Its format is \d{16}. 120 std::string pan_; 121 122 // Card verification number (CVN). Its format is \d{3}. 123 std::string cvn_; 124 125 // Issuer identification number (IIN). Its format is \d{6}. 126 std::string iin_; 127 128 // Encrypted concatentation of CVN and PAN without IIN 129 std::string encrypted_rest_; 130 131 // The billing address of the backing instrument. 132 scoped_ptr<Address> billing_address_; 133 134 // The shipping address for the transaction. 135 scoped_ptr<Address> shipping_address_; 136 137 // Actions that must be completed by the user before a FullWallet can be 138 // issued to them by the Online Wallet service. 139 std::vector<RequiredAction> required_actions_; 140 141 // The one time pad used for FullWallet encryption. 142 std::vector<uint8> one_time_pad_; 143 144 DISALLOW_COPY_AND_ASSIGN(FullWallet); 145 }; 146 147 } // namespace wallet 148 } // namespace autofill 149 150 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_FULL_WALLET_H_ 151