blob: 0a592dbab19120c9e7136ff7ba054fb34926320b [file] [log] [blame]
[email protected]ce63d6b2012-12-20 02:46:281// 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]e4b2fa32013-03-09 22:56:565#ifndef COMPONENTS_AUTOFILL_BROWSER_WALLET_FULL_WALLET_H_
6#define COMPONENTS_AUTOFILL_BROWSER_WALLET_FULL_WALLET_H_
[email protected]ce63d6b2012-12-20 02:46:287
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]e4b2fa32013-03-09 22:56:5614#include "components/autofill/browser/wallet/required_action.h"
15#include "components/autofill/browser/wallet/wallet_address.h"
[email protected]ce63d6b2012-12-20 02:46:2816
17namespace base {
18class DictionaryValue;
19}
20
[email protected]345175642013-02-20 19:25:5221namespace autofill {
[email protected]ce63d6b2012-12-20 02:46:2822namespace wallet {
23
24class FullWalletTest;
25
26// FullWallet contains all the information a merchant requires from a user for
[email protected]7a97aa82013-01-07 21:34:5327// 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]ce63d6b2012-12-20 02:46:2831class 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]1a43a90d2013-03-15 09:13:2740 // Returns corresponding data for |type|.
[email protected]d5ca8fb2013-04-11 17:54:3141 base::string16 GetInfo(AutofillFieldType type);
[email protected]ce63d6b2012-12-20 02:46:2842
[email protected]ab6601f2013-03-02 19:11:5843 // Whether or not |action| is in |required_actions_|.
44 bool HasRequiredAction(RequiredAction action) const;
45
[email protected]ce63d6b2012-12-20 02:46:2846 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]7a97aa82013-01-07 21:34:5356 const std::vector<RequiredAction>& required_actions() const {
[email protected]ce63d6b2012-12-20 02:46:2857 return required_actions_;
58 }
59 int expiration_month() const { return expiration_month_; }
60 int expiration_year() const { return expiration_year_; }
61
[email protected]345175642013-02-20 19:25:5262 void set_one_time_pad(const std::vector<uint8>& one_time_pad) {
63 one_time_pad_ = one_time_pad;
64 }
65
[email protected]ce63d6b2012-12-20 02:46:2866 private:
67 friend class FullWalletTest;
68 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWallet);
69 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWalletWithRequiredActions);
[email protected]c56a4aa52013-04-03 05:04:2170 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, EvenRestDecryptionTest);
71 FRIEND_TEST_ALL_PREFIXES(FullWalletTest, OddRestDecryptionTest);
[email protected]ce63d6b2012-12-20 02:46:2872 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]7a97aa82013-01-07 21:34:5378 const std::vector<RequiredAction>& required_actions);
[email protected]1a43a90d2013-03-15 09:13:2779
80 // Decrypts both |pan_| and |cvn_|.
[email protected]345175642013-02-20 19:25:5281 void DecryptCardInfo();
[email protected]f8a02362013-02-15 20:28:5582
[email protected]1a43a90d2013-03-15 09:13:2783 // 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]f8a02362013-02-15 20:28:5591 // The expiration month of the proxy card. It should be 1-12.
[email protected]ce63d6b2012-12-20 02:46:2892 int expiration_month_;
[email protected]f8a02362013-02-15 20:28:5593
94 // The expiration year of the proxy card. It should be a 4-digit year.
[email protected]ce63d6b2012-12-20 02:46:2895 int expiration_year_;
[email protected]f8a02362013-02-15 20:28:5596
[email protected]ce63d6b2012-12-20 02:46:2897 // Primary account number (PAN). Its format is \d{16}.
98 std::string pan_;
[email protected]f8a02362013-02-15 20:28:5599
[email protected]ce63d6b2012-12-20 02:46:28100 // Card verification number (CVN). Its format is \d{3}.
101 std::string cvn_;
[email protected]f8a02362013-02-15 20:28:55102
[email protected]ce63d6b2012-12-20 02:46:28103 // Issuer identification number (IIN). Its format is \d{6}.
104 std::string iin_;
[email protected]f8a02362013-02-15 20:28:55105
[email protected]ce63d6b2012-12-20 02:46:28106 // Encrypted concatentation of CVN and PAN without IIN
107 std::string encrypted_rest_;
[email protected]f8a02362013-02-15 20:28:55108
109 // The billing address of the backing instrument.
[email protected]ce63d6b2012-12-20 02:46:28110 scoped_ptr<Address> billing_address_;
[email protected]f8a02362013-02-15 20:28:55111
112 // The shipping address for the transaction.
[email protected]ce63d6b2012-12-20 02:46:28113 scoped_ptr<Address> shipping_address_;
[email protected]f8a02362013-02-15 20:28:55114
[email protected]ce63d6b2012-12-20 02:46:28115 // Actions that must be completed by the user before a FullWallet can be
116 // issued to them by the Online Wallet service.
[email protected]7a97aa82013-01-07 21:34:53117 std::vector<RequiredAction> required_actions_;
[email protected]f8a02362013-02-15 20:28:55118
[email protected]345175642013-02-20 19:25:52119 // The one time pad used for FullWallet encryption.
120 std::vector<uint8> one_time_pad_;
121
[email protected]ce63d6b2012-12-20 02:46:28122 DISALLOW_COPY_AND_ASSIGN(FullWallet);
123};
124
125} // namespace wallet
[email protected]345175642013-02-20 19:25:52126} // namespace autofill
[email protected]ce63d6b2012-12-20 02:46:28127
[email protected]e4b2fa32013-03-09 22:56:56128#endif // COMPONENTS_AUTOFILL_BROWSER_WALLET_FULL_WALLET_H_