OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/credit_card.h" | 5 #include "components/autofill/browser/credit_card.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <ostream> | 9 #include <ostream> |
10 #include <string> | 10 #include <string> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 if (type == kAmericanExpressCard) | 143 if (type == kAmericanExpressCard) |
144 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX); | 144 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX); |
145 if (type == kDinersCard) | 145 if (type == kDinersCard) |
146 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS); | 146 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS); |
147 if (type == kDiscoverCard) | 147 if (type == kDiscoverCard) |
148 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER); | 148 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER); |
149 if (type == kJCBCard) | 149 if (type == kJCBCard) |
150 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB); | 150 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB); |
151 if (type == kMasterCard) | 151 if (type == kMasterCard) |
152 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD); | 152 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD); |
153 if (type == kSoloCard) | |
154 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_SOLO); | |
155 if (type == kVisaCard) | 153 if (type == kVisaCard) |
156 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); | 154 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); |
157 | 155 |
158 // If you hit this DCHECK, the above list of cases needs to be updated to | 156 // If you hit this DCHECK, the above list of cases needs to be updated to |
159 // include a new card. | 157 // include a new card. |
160 DCHECK_EQ(kGenericCard, type); | 158 DCHECK_EQ(kGenericCard, type); |
161 return base::string16(); | 159 return base::string16(); |
162 } | 160 } |
163 | 161 |
164 // static | 162 // static |
165 std::string CreditCard::GetCreditCardType(const base::string16& number) { | 163 std::string CreditCard::GetCreditCardType(const base::string16& number) { |
166 // Don't check for a specific type if this is not a credit card number. | 164 // Don't check for a specific type if this is not a credit card number. |
167 if (!autofill::IsValidCreditCardNumber(number)) | 165 if (!autofill::IsValidCreditCardNumber(number)) |
168 return kGenericCard; | 166 return kGenericCard; |
benquan
2013/06/08 07:27:57
There are tons of card types, I think kGenericCard
Ilya Sherman
2013/06/18 03:37:38
Done.
| |
169 | 167 |
170 // Credit card number specifications taken from: | 168 // Credit card number specifications taken from: |
171 // http://en.wikipedia.org/wiki/Credit_card_numbers and | 169 // http://en.wikipedia.org/wiki/Credit_card_numbers, |
170 // http://www.discovernetwork.com/merchants/images/Merchant_Marketing_PDF.pdf, | |
171 // http://www.regular-expressions.info/creditcard.html, and | |
172 // http://www.beachnet.com/~hstiles/cardtype.html | 172 // http://www.beachnet.com/~hstiles/cardtype.html |
benquan
2013/06/08 07:27:57
this link is dead, remove it?
Ilya Sherman
2013/06/18 03:37:38
I've kept the link, because it seems to be where t
| |
173 // | |
173 // Card Type Prefix(es) Length | 174 // Card Type Prefix(es) Length |
174 // --------------------------------------------------------------- | 175 // --------------------------------------------------------------- |
175 // Visa 4 13,16 | 176 // Visa 4 13,16 |
176 // American Express 34,37 15 | 177 // American Express 34,37 15 |
177 // Diners Club 300-305,2014,2149,36, 14,15 | 178 // Diners Club 300-305,3095,36,38-39 14 |
178 // Discover Card 6011,65 16 | 179 // Discover Card 6011,65 16 |
179 // JCB 3 16 | 180 // JCB 3528-3589 16 |
180 // JCB 2131,1800 15 | |
181 // MasterCard 51-55 16 | 181 // MasterCard 51-55 16 |
182 // Solo (debit card) 6334,6767 16,18,19 | |
183 | 182 |
184 // We need at least 4 digits to work with. | 183 // We need at least 4 digits to work with. |
185 if (number.length() < 4) | 184 if (number.length() < 4) |
186 return kGenericCard; | 185 return kGenericCard; |
187 | 186 |
188 int first_four_digits = 0; | 187 int first_four_digits = 0; |
189 if (!base::StringToInt(number.substr(0, 4), &first_four_digits)) | 188 if (!base::StringToInt(number.substr(0, 4), &first_four_digits)) |
190 return kGenericCard; | 189 return kGenericCard; |
191 | 190 |
192 int first_three_digits = first_four_digits / 10; | 191 int first_three_digits = first_four_digits / 10; |
193 int first_two_digits = first_three_digits / 10; | 192 int first_two_digits = first_three_digits / 10; |
194 int first_digit = first_two_digits / 10; | 193 int first_digit = first_two_digits / 10; |
195 | 194 |
196 switch (number.length()) { | 195 switch (number.length()) { |
197 case 13: | 196 case 13: |
198 if (first_digit == 4) | 197 if (first_digit == 4) |
199 return kVisaCard; | 198 return kVisaCard; |
200 | 199 |
201 break; | 200 break; |
201 | |
202 case 14: | 202 case 14: |
203 if (first_three_digits >= 300 && first_three_digits <= 305) | 203 if (first_three_digits >= 300 && first_three_digits <= 305) |
204 return kDinersCard; | 204 return kDinersCard; |
205 | 205 |
206 if (first_digit == 36) | 206 if (first_two_digits == 36) |
207 return kDinersCard; | |
208 | |
209 if (first_two_digits >= 38 && first_two_digits <= 39) | |
210 return kDinersCard; | |
211 | |
212 if (first_four_digits == 3095) | |
207 return kDinersCard; | 213 return kDinersCard; |
208 | 214 |
209 break; | 215 break; |
216 | |
210 case 15: | 217 case 15: |
211 if (first_two_digits == 34 || first_two_digits == 37) | 218 if (first_two_digits == 34 || first_two_digits == 37) |
212 return kAmericanExpressCard; | 219 return kAmericanExpressCard; |
213 | 220 |
214 if (first_four_digits == 2131 || first_four_digits == 1800) | 221 break; |
215 return kJCBCard; | |
216 | 222 |
217 if (first_four_digits == 2014 || first_four_digits == 2149) | |
218 return kDinersCard; | |
219 | |
220 break; | |
221 case 16: | 223 case 16: |
222 if (first_four_digits == 6011 || first_two_digits == 65) | 224 if (first_four_digits == 6011 || first_two_digits == 65) |
223 return kDiscoverCard; | 225 return kDiscoverCard; |
224 | 226 |
225 if (first_four_digits == 6334 || first_four_digits == 6767) | 227 if (first_three_digits >= 644 && first_three_digits <= 649) |
226 return kSoloCard; | 228 return kDiscoverCard; |
227 | 229 |
228 if (first_two_digits >= 51 && first_two_digits <= 55) | 230 if (first_two_digits >= 51 && first_two_digits <= 55) |
229 return kMasterCard; | 231 return kMasterCard; |
230 | 232 |
231 if (first_digit == 3) | 233 if (first_four_digits >= 3528 && first_four_digits <= 3589) |
232 return kJCBCard; | 234 return kJCBCard; |
233 | 235 |
234 if (first_digit == 4) | 236 if (first_digit == 4) |
235 return kVisaCard; | 237 return kVisaCard; |
236 | 238 |
237 break; | 239 break; |
238 case 18: | |
239 case 19: | |
240 if (first_four_digits == 6334 || first_four_digits == 6767) | |
241 return kSoloCard; | |
242 | |
243 break; | |
244 } | 240 } |
245 | 241 |
246 return kGenericCard; | 242 return kGenericCard; |
benquan
2013/06/08 07:27:57
Card type should be determined by BIN (the first 6
Ilya Sherman
2013/06/18 03:37:38
Done.
| |
247 } | 243 } |
248 | 244 |
249 base::string16 CreditCard::GetRawInfo(AutofillFieldType type) const { | 245 base::string16 CreditCard::GetRawInfo(AutofillFieldType type) const { |
250 switch (type) { | 246 switch (type) { |
251 case CREDIT_CARD_NAME: | 247 case CREDIT_CARD_NAME: |
252 return name_on_card_; | 248 return name_on_card_; |
253 | 249 |
254 case CREDIT_CARD_EXP_MONTH: | 250 case CREDIT_CARD_EXP_MONTH: |
255 return ExpirationMonthAsString(); | 251 return ExpirationMonthAsString(); |
256 | 252 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 const char* const kAmericanExpressCard = "americanExpressCC"; | 678 const char* const kAmericanExpressCard = "americanExpressCC"; |
683 const char* const kDinersCard = "dinersCC"; | 679 const char* const kDinersCard = "dinersCC"; |
684 const char* const kDiscoverCard = "discoverCC"; | 680 const char* const kDiscoverCard = "discoverCC"; |
685 const char* const kGenericCard = "genericCC"; | 681 const char* const kGenericCard = "genericCC"; |
686 const char* const kJCBCard = "jcbCC"; | 682 const char* const kJCBCard = "jcbCC"; |
687 const char* const kMasterCard = "masterCardCC"; | 683 const char* const kMasterCard = "masterCardCC"; |
688 const char* const kSoloCard = "soloCC"; | 684 const char* const kSoloCard = "soloCC"; |
689 const char* const kVisaCard = "visaCC"; | 685 const char* const kVisaCard = "visaCC"; |
690 | 686 |
691 } // namespace autofill | 687 } // namespace autofill |
OLD | NEW |