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_INSTRUMENT_H_
      6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_INSTRUMENT_H_
      7 
      8 #include <string>
      9 #include "base/basictypes.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/strings/string16.h"
     12 
     13 namespace base {
     14 class DictionaryValue;
     15 }
     16 
     17 namespace autofill {
     18 
     19 class AutofillProfile;
     20 class CreditCard;
     21 
     22 namespace wallet {
     23 
     24 class Address;
     25 
     26 // This class contains all the data necessary to save a new instrument to a
     27 // user's Google Wallet using WalletClient::SaveInstrument or
     28 // WalletClient::SaveInstrumentAndAddress.
     29 class Instrument {
     30  public:
     31   enum FormOfPayment {
     32     UNKNOWN,
     33     VISA,
     34     MASTER_CARD,
     35     AMEX,
     36     DISCOVER,
     37     JCB,
     38   };
     39 
     40   // Convert the info in |card| to an Instrument using |profile| for address.
     41   Instrument(const CreditCard& card,
     42              const base::string16& card_verification_number,
     43              const AutofillProfile& profile);
     44 
     45   Instrument(const base::string16& primary_account_number,
     46              const base::string16& card_verification_number,
     47              int expiration_month,
     48              int expiration_year,
     49              FormOfPayment form_of_payment,
     50              scoped_ptr<Address> address);
     51 
     52   Instrument(const Instrument& instrument);
     53 
     54   ~Instrument();
     55 
     56   scoped_ptr<base::DictionaryValue> ToDictionary() const;
     57 
     58   const base::string16& primary_account_number() const {
     59     return primary_account_number_;
     60   }
     61   const base::string16& card_verification_number() const {
     62     return card_verification_number_;
     63   }
     64   int expiration_month() const { return expiration_month_; }
     65   int expiration_year() const { return expiration_year_; }
     66   const Address* address() const { return address_.get(); }
     67   FormOfPayment form_of_payment() const { return form_of_payment_; }
     68   const base::string16& last_four_digits() const { return last_four_digits_; }
     69   const std::string& object_id() const { return object_id_; }
     70 
     71  private:
     72   void Init();
     73 
     74   // |primary_account_number_| is expected to be \d{12-19}.
     75   base::string16 primary_account_number_;
     76 
     77   // |card_verification_number_| is expected to be \d{3-4}.
     78   base::string16 card_verification_number_;
     79 
     80   // |expiration month_| should be 1-12.
     81   int expiration_month_;
     82 
     83   // |expiration_year_| should be a 4-digit year.
     84   int expiration_year_;
     85 
     86   // The payment network of the instrument, e.g. Visa.
     87   FormOfPayment form_of_payment_;
     88 
     89   // The billing address of the instrument.
     90   scoped_ptr<Address> address_;
     91 
     92   // The last four digits of |primary_account_number_|.
     93   base::string16 last_four_digits_;
     94 
     95   // Externalized Online Wallet id for this instrument.
     96   std::string object_id_;
     97 
     98   DISALLOW_ASSIGN(Instrument);
     99 };
    100 
    101 }  // namespace wallet
    102 }  // namespace autofill
    103 
    104 #endif  // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_INSTRUMENT_H_
    105