Home | History | Annotate | Download | only in wallet
      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 std::string& app_locale,
     56                          const AutofillType& type);
     57 
     58   // Whether or not |action| is in |required_actions_|.
     59   bool HasRequiredAction(RequiredAction action) const;
     60 
     61   // The type of the card that this FullWallet contains and the last four digits
     62   // like this "Visa - 4111".
     63   base::string16 TypeAndLastFourDigits();
     64 
     65   // Decrypts and returns the primary account number (PAN) using the generated
     66   // one time pad, |one_time_pad_|.
     67   const std::string& GetPan();
     68 
     69   bool operator==(const FullWallet& other) const;
     70   bool operator!=(const FullWallet& other) const;
     71 
     72   // If there are required actions |billing_address_| might contain NULL.
     73   const Address* billing_address() const { return billing_address_.get(); }
     74 
     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(); }
     78 
     79   const std::vector<RequiredAction>& required_actions() const {
     80     return required_actions_;
     81   }
     82   int expiration_month() const { return expiration_month_; }
     83   int expiration_year() const { return expiration_year_; }
     84 
     85   void set_one_time_pad(const std::vector<uint8>& one_time_pad) {
     86     one_time_pad_ = one_time_pad;
     87   }
     88 
     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);
     99 
    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);
    107 
    108   // Decrypts both |pan_| and |cvn_|.
    109   void DecryptCardInfo();
    110 
    111   // Decrypts and returns the card verification number (CVN) using the generated
    112   // one time pad, |one_time_pad_|.
    113   const std::string& GetCvn();
    114 
    115   // The expiration month of the proxy card. It should be 1-12.
    116   int expiration_month_;
    117 
    118   // The expiration year of the proxy card. It should be a 4-digit year.
    119   int expiration_year_;
    120 
    121   // Primary account number (PAN). Its format is \d{16}.
    122   std::string pan_;
    123 
    124   // Card verification number (CVN). Its format is \d{3}.
    125   std::string cvn_;
    126 
    127   // Issuer identification number (IIN). Its format is \d{6}.
    128   std::string iin_;
    129 
    130   // Encrypted concatentation of CVN and PAN without IIN
    131   std::string encrypted_rest_;
    132 
    133   // The billing address of the backing instrument.
    134   scoped_ptr<Address> billing_address_;
    135 
    136   // The shipping address for the transaction.
    137   scoped_ptr<Address> shipping_address_;
    138 
    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_;
    142 
    143   // The one time pad used for FullWallet encryption.
    144   std::vector<uint8> one_time_pad_;
    145 
    146   DISALLOW_COPY_AND_ASSIGN(FullWallet);
    147 };
    148 
    149 }  // namespace wallet
    150 }  // namespace autofill
    151 
    152 #endif  // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_FULL_WALLET_H_
    153