Add diagnostics_writer.cc to the list of files allowed to printf.
[chromium-blink-merge.git] / components / autofill / content / browser / wallet / full_wallet.h
blob9a8607bac08337f3ac7a7c65b0e68226949711b9
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.
5 #ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_FULL_WALLET_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_FULL_WALLET_H_
8 #include <string>
9 #include <vector>
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"
18 namespace base {
19 class DictionaryValue;
22 namespace autofill {
24 class AutofillType;
26 namespace wallet {
28 class FullWalletTest;
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();
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);
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);
54 // Returns corresponding data for |type|.
55 base::string16 GetInfo(const std::string& app_locale,
56 const AutofillType& type);
58 // Whether or not |action| is in |required_actions_|.
59 bool HasRequiredAction(RequiredAction action) const;
61 // The type of the card that this FullWallet contains and the last four digits
62 // like this "Visa - 4111".
63 base::string16 TypeAndLastFourDigits();
65 // Decrypts and returns the primary account number (PAN) using the generated
66 // one time pad, |one_time_pad_|.
67 const std::string& GetPan();
69 bool operator==(const FullWallet& other) const;
70 bool operator!=(const FullWallet& other) const;
72 // If there are required actions |billing_address_| might contain NULL.
73 const Address* billing_address() const { return billing_address_.get(); }
75 // If there are required actions or shipping address is not required
76 // |shipping_address_| might contain NULL.
77 const Address* shipping_address() const { return shipping_address_.get(); }
79 const std::vector<RequiredAction>& required_actions() const {
80 return required_actions_;
82 int expiration_month() const { return expiration_month_; }
83 int expiration_year() const { return expiration_year_; }
85 void set_one_time_pad(const std::vector<uint8>& one_time_pad) {
86 one_time_pad_ = one_time_pad;
89 private:
90 friend class FullWalletTest;
91 friend scoped_ptr<FullWallet> GetTestFullWalletWithRequiredActions(
92 const std::vector<RequiredAction>& action);
93 friend scoped_ptr<FullWallet> GetTestFullWalletInstrumentOnly();
94 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWallet);
95 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWalletWithRequiredActions);
96 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, RestLengthCorrectDecryptionTest);
97 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, RestLengthUnderDecryptionTest);
98 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, GetCreditCardInfo);
100 FullWallet(int expiration_month,
101 int expiration_year,
102 const std::string& iin,
103 const std::string& encrypted_rest,
104 scoped_ptr<Address> billing_address,
105 scoped_ptr<Address> shipping_address,
106 const std::vector<RequiredAction>& required_actions);
108 // Decrypts both |pan_| and |cvn_|.
109 void DecryptCardInfo();
111 // Decrypts and returns the card verification number (CVN) using the generated
112 // one time pad, |one_time_pad_|.
113 const std::string& GetCvn();
115 // The expiration month of the proxy card. It should be 1-12.
116 int expiration_month_;
118 // The expiration year of the proxy card. It should be a 4-digit year.
119 int expiration_year_;
121 // Primary account number (PAN). Its format is \d{16}.
122 std::string pan_;
124 // Card verification number (CVN). Its format is \d{3}.
125 std::string cvn_;
127 // Issuer identification number (IIN). Its format is \d{6}.
128 std::string iin_;
130 // Encrypted concatentation of CVN and PAN without IIN
131 std::string encrypted_rest_;
133 // The billing address of the backing instrument.
134 scoped_ptr<Address> billing_address_;
136 // The shipping address for the transaction.
137 scoped_ptr<Address> shipping_address_;
139 // Actions that must be completed by the user before a FullWallet can be
140 // issued to them by the Online Wallet service.
141 std::vector<RequiredAction> required_actions_;
143 // The one time pad used for FullWallet encryption.
144 std::vector<uint8> one_time_pad_;
146 DISALLOW_COPY_AND_ASSIGN(FullWallet);
149 } // namespace wallet
150 } // namespace autofill
152 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_FULL_WALLET_H_