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 void set_object_id(const std::string& object_id) { object_id_ = object_id; } 71 72 private: 73 void Init(); 74 75 // |primary_account_number_| is expected to be \d{12-19}. 76 base::string16 primary_account_number_; 77 78 // |card_verification_number_| is expected to be \d{3-4}. 79 base::string16 card_verification_number_; 80 81 // |expiration month_| should be 1-12. 82 int expiration_month_; 83 84 // |expiration_year_| should be a 4-digit year. 85 int expiration_year_; 86 87 // The payment network of the instrument, e.g. Visa. 88 FormOfPayment form_of_payment_; 89 90 // The billing address of the instrument. 91 scoped_ptr<Address> address_; 92 93 // The last four digits of |primary_account_number_|. 94 base::string16 last_four_digits_; 95 96 // Externalized Online Wallet id for this instrument. 97 std::string object_id_; 98 99 DISALLOW_ASSIGN(Instrument); 100 }; 101 102 } // namespace wallet 103 } // namespace autofill 104 105 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_INSTRUMENT_H_ 106