Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: components/autofill/content/browser/wallet/instrument.cc

Issue 17970003: New encryption/escrow endpoints for Wallet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebasing again... Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/content/browser/wallet/instrument.h" 5 #include "components/autofill/content/browser/wallet/instrument.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 int expiration_month, 73 int expiration_month,
74 int expiration_year, 74 int expiration_year,
75 FormOfPayment form_of_payment, 75 FormOfPayment form_of_payment,
76 scoped_ptr<Address> address) 76 scoped_ptr<Address> address)
77 : primary_account_number_(primary_account_number), 77 : primary_account_number_(primary_account_number),
78 card_verification_number_(card_verification_number), 78 card_verification_number_(card_verification_number),
79 expiration_month_(expiration_month), 79 expiration_month_(expiration_month),
80 expiration_year_(expiration_year), 80 expiration_year_(expiration_year),
81 form_of_payment_(form_of_payment), 81 form_of_payment_(form_of_payment),
82 address_(address.Pass()) { 82 address_(address.Pass()) {
83 DCHECK(address_);
84 Init(); 83 Init();
85 } 84 }
86 85
87 Instrument::Instrument(const Instrument& instrument) 86 Instrument::Instrument(const Instrument& instrument)
88 : primary_account_number_(instrument.primary_account_number()), 87 : primary_account_number_(instrument.primary_account_number()),
89 card_verification_number_(instrument.card_verification_number()), 88 card_verification_number_(instrument.card_verification_number()),
90 expiration_month_(instrument.expiration_month()), 89 expiration_month_(instrument.expiration_month()),
91 expiration_year_(instrument.expiration_year()), 90 expiration_year_(instrument.expiration_year()),
92 form_of_payment_(instrument.form_of_payment()), 91 form_of_payment_(instrument.form_of_payment()),
93 address_(new Address(instrument.address())) { 92 address_(instrument.address() ?
93 new Address(*instrument.address()) : NULL) {
94 Init(); 94 Init();
95 } 95 }
96 96
97 Instrument::~Instrument() {} 97 Instrument::~Instrument() {}
98 98
99 scoped_ptr<base::DictionaryValue> Instrument::ToDictionary() const { 99 scoped_ptr<base::DictionaryValue> Instrument::ToDictionary() const {
100 // |primary_account_number_| and |card_verification_number_| can never be 100 // |primary_account_number_| and |card_verification_number_| can never be
101 // sent the server in way that would require putting them into a dictionary. 101 // sent the server in way that would require putting them into a dictionary.
102 // Never add them to this function. 102 // Never add them to this function.
103 103
104 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 104 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
105 dict->SetString("type", "CREDIT_CARD"); 105 dict->SetString("type", "CREDIT_CARD");
106 dict->SetInteger("credit_card.exp_month", expiration_month_); 106 dict->SetInteger("credit_card.exp_month", expiration_month_);
107 dict->SetInteger("credit_card.exp_year", expiration_year_); 107 dict->SetInteger("credit_card.exp_year", expiration_year_);
108 dict->SetString("credit_card.fop_type", 108 dict->SetString("credit_card.fop_type",
109 FormOfPaymentToString(form_of_payment_)); 109 FormOfPaymentToString(form_of_payment_));
110 dict->SetString("credit_card.last_4_digits", last_four_digits_); 110 dict->SetString("credit_card.last_4_digits", last_four_digits_);
111 dict->Set("credit_card.address", 111 dict->Set("credit_card.address",
112 address_.get()->ToDictionaryWithoutID().release()); 112 address_.get()->ToDictionaryWithoutID().release());
113 113
114 return dict.Pass(); 114 return dict.Pass();
115 } 115 }
116 116
117 bool Instrument::IsValid() const {
118 if (!IsStringASCII(primary_account_number_))
119 return false;
120 bool primary_account_number_valid =
121 autofill::IsValidCreditCardNumber(primary_account_number_);
122 bool card_verification_number_valid = card_verification_number_.size() == 3 ||
123 card_verification_number_.size() == 4;
124 bool exp_month_valid = expiration_month_ >= 1 && expiration_month_ <= 12;
125 bool exp_year_valid = expiration_year_ >= 2013 && expiration_year_ <= 2100;
126
127 return primary_account_number_valid &&
128 card_verification_number_valid &&
129 exp_month_valid &&
130 exp_year_valid;
131 }
132
133 void Instrument::Init() { 117 void Instrument::Init() {
134 if (primary_account_number_.size() >= 4) { 118 if (primary_account_number_.size() >= 4) {
135 last_four_digits_ = 119 last_four_digits_ =
136 primary_account_number_.substr(primary_account_number_.size() - 4); 120 primary_account_number_.substr(primary_account_number_.size() - 4);
137 } 121 }
138 } 122 }
139 123
140 } // namespace wallet 124 } // namespace wallet
141 } // namespace autofill 125 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698