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 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> GetTestFullWalletWithRequiredActions(
     87       const std::vector<RequiredAction>& action);
     88   friend scoped_ptr<FullWallet> GetTestFullWalletInstrumentOnly();
     89   FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWallet);
     90   FRIEND_TEST_ALL_PREFIXES(FullWalletTest, CreateFullWalletWithRequiredActions);
     91   FRIEND_TEST_ALL_PREFIXES(FullWalletTest, RestLengthCorrectDecryptionTest);
     92   FRIEND_TEST_ALL_PREFIXES(FullWalletTest, RestLengthUnderDecryptionTest);
     93   FRIEND_TEST_ALL_PREFIXES(FullWalletTest, GetCreditCardInfo);
     94 
     95   FullWallet(int expiration_month,
     96              int expiration_year,
     97              const std::string& iin,
     98              const std::string& encrypted_rest,
     99              scoped_ptr<Address> billing_address,
    100              scoped_ptr<Address> shipping_address,
    101              const std::vector<RequiredAction>& required_actions);
    102 
    103   // Decrypts both |pan_| and |cvn_|.
    104   void DecryptCardInfo();
    105 
    106   // Decrypts and returns the primary account number (PAN) using the generated
    107   // one time pad, |one_time_pad_|.
    108   const std::string& GetPan();
    109 
    110   // Decrypts and returns the card verification number (CVN) using the generated
    111   // one time pad, |one_time_pad_|.
    112   const std::string& GetCvn();
    113 
    114   // The expiration month of the proxy card. It should be 1-12.
    115   int expiration_month_;
    116 
    117   // The expiration year of the proxy card. It should be a 4-digit year.
    118   int expiration_year_;
    119 
    120   // Primary account number (PAN). Its format is \d{16}.
    121   std::string pan_;
    122 
    123   // Card verification number (CVN). Its format is \d{3}.
    124   std::string cvn_;
    125 
    126   // Issuer identification number (IIN). Its format is \d{6}.
    127   std::string iin_;
    128 
    129   // Encrypted concatentation of CVN and PAN without IIN
    130   std::string encrypted_rest_;
    131 
    132   // The billing address of the backing instrument.
    133   scoped_ptr<Address> billing_address_;
    134 
    135   // The shipping address for the transaction.
    136   scoped_ptr<Address> shipping_address_;
    137 
    138   // Actions that must be completed by the user before a FullWallet can be
    139   // issued to them by the Online Wallet service.
    140   std::vector<RequiredAction> required_actions_;
    141 
    142   // The one time pad used for FullWallet encryption.
    143   std::vector<uint8> one_time_pad_;
    144 
    145   DISALLOW_COPY_AND_ASSIGN(FullWallet);
    146 };
    147 
    148 }  // namespace wallet
    149 }  // namespace autofill
    150 
    151 #endif  // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_FULL_WALLET_H_
    152