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

Side by Side Diff: components/autofill/core/browser/credit_card.cc

Issue 2906763005: Add support for Brazil Elo card in autofill. (Closed)
Patch Set: Fix test Created 3 years, 6 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
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/core/browser/credit_card.h" 5 #include "components/autofill/core/browser/credit_card.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 return false; 72 return false;
73 } 73 }
74 74
75 base::string16 NetworkForFill(const std::string& network) { 75 base::string16 NetworkForFill(const std::string& network) {
76 if (network == kAmericanExpressCard) 76 if (network == kAmericanExpressCard)
77 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX); 77 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX);
78 if (network == kDinersCard) 78 if (network == kDinersCard)
79 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS); 79 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS);
80 if (network == kDiscoverCard) 80 if (network == kDiscoverCard)
81 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER); 81 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER);
82 if (network == kEloCard)
83 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_ELO);
82 if (network == kJCBCard) 84 if (network == kJCBCard)
83 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB); 85 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB);
84 if (network == kMasterCard) 86 if (network == kMasterCard)
85 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD); 87 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD);
86 if (network == kMirCard) 88 if (network == kMirCard)
87 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MIR); 89 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MIR);
88 if (network == kUnionPay) 90 if (network == kUnionPay)
89 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_UNION_PAY); 91 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_UNION_PAY);
90 if (network == kVisaCard) 92 if (network == kVisaCard)
91 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); 93 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 141 }
140 142
141 // static 143 // static
142 int CreditCard::IconResourceId(const std::string& network) { 144 int CreditCard::IconResourceId(const std::string& network) {
143 if (network == kAmericanExpressCard) 145 if (network == kAmericanExpressCard)
144 return IDR_AUTOFILL_CC_AMEX; 146 return IDR_AUTOFILL_CC_AMEX;
145 if (network == kDinersCard) 147 if (network == kDinersCard)
146 return IDR_AUTOFILL_CC_DINERS; 148 return IDR_AUTOFILL_CC_DINERS;
147 if (network == kDiscoverCard) 149 if (network == kDiscoverCard)
148 return IDR_AUTOFILL_CC_DISCOVER; 150 return IDR_AUTOFILL_CC_DISCOVER;
151 if (network == kEloCard)
152 return IDR_AUTOFILL_CC_ELO;
149 if (network == kJCBCard) 153 if (network == kJCBCard)
150 return IDR_AUTOFILL_CC_JCB; 154 return IDR_AUTOFILL_CC_JCB;
151 if (network == kMasterCard) 155 if (network == kMasterCard)
152 return IDR_AUTOFILL_CC_MASTERCARD; 156 return IDR_AUTOFILL_CC_MASTERCARD;
153 if (network == kMirCard) 157 if (network == kMirCard)
154 return IDR_AUTOFILL_CC_MIR; 158 return IDR_AUTOFILL_CC_MIR;
155 if (network == kUnionPay) 159 if (network == kUnionPay)
156 return IDR_AUTOFILL_CC_UNIONPAY; 160 return IDR_AUTOFILL_CC_UNIONPAY;
157 if (network == kVisaCard) 161 if (network == kVisaCard)
158 return IDR_AUTOFILL_CC_VISA; 162 return IDR_AUTOFILL_CC_VISA;
159 163
160 // If you hit this DCHECK, the above list of cases needs to be updated to 164 // If you hit this DCHECK, the above list of cases needs to be updated to
161 // include a new card. 165 // include a new card.
162 DCHECK_EQ(kGenericCard, network); 166 DCHECK_EQ(kGenericCard, network);
163 return IDR_AUTOFILL_CC_GENERIC; 167 return IDR_AUTOFILL_CC_GENERIC;
164 } 168 }
165 169
166 // static 170 // static
167 const char* CreditCard::GetCardNetwork(const base::string16& number) { 171 const char* CreditCard::GetCardNetwork(const base::string16& number) {
168 // Credit card number specifications taken from: 172 // Credit card number specifications taken from:
169 // http://en.wikipedia.org/wiki/Credit_card_numbers, 173 // https://en.wikipedia.org/wiki/Payment_card_number,
170 // http://en.wikipedia.org/wiki/List_of_Issuer_Identification_Numbers,
171 // http://www.discovernetwork.com/merchants/images/Merchant_Marketing_PDF.pdf,
172 // http://www.regular-expressions.info/creditcard.html, 174 // http://www.regular-expressions.info/creditcard.html,
173 // http://developer.ean.com/general_info/Valid_Credit_Card_Types, 175 // https://developer.ean.com/general-info/valid-card-types,
174 // http://www.bincodes.com/, 176 // http://www.bincodes.com/, and
175 // http://www.fraudpractice.com/FL-binCC.html, and 177 // http://www.fraudpractice.com/FL-binCC.html.
176 // http://www.beachnet.com/~hstiles/cardtype.html 178 // (Last updated: May 29, 2017)
177 // 179 //
178 // The last site is currently unavailable, but a cached version remains at 180 // Card Type Prefix(es) Length
179 // http://web.archive.org/web/20120923111349/http://www.beachnet.com/~hstiles/ cardtype.html 181 // --------------------------------------------------------------------------
180 // 182 // Visa 4 13,16,19
181 // Card Type Prefix(es) Length 183 // American Express 34,37 15
182 // --------------------------------------------------------------- 184 // Diners Club 300-305,309,36,38-39 14
183 // Visa 4 13,16 185 // Discover Card 6011,644-649,65 16
184 // American Express 34,37 15 186 // Elo 431274,451416,5067,5090,627780,636297 16
185 // Diners Club 300-305,3095,36,38-39 14 187 // JCB 3528-3589 16
186 // Discover Card 6011,644-649,65 16 188 // Mastercard 2221-2720, 51-55 16
187 // JCB 3528-3589 16 189 // MIR 2200-2204 16
188 // Mastercard 51-55 16 190 // UnionPay 62 16-19
189 // UnionPay 62 16-19
190 191
191 // Check for prefixes of length 1. 192 // Check for prefixes of length 1.
192 if (number.empty()) 193 if (number.empty())
193 return kGenericCard; 194 return kGenericCard;
194 195
195 if (number[0] == '4') 196 if (number[0] == '4')
196 return kVisaCard; 197 return kVisaCard;
197 198
198 // Check for prefixes of length 2. 199 // Check for prefixes of length 2.
199 if (number.size() < 2) 200 if (number.size() < 2)
200 return kGenericCard; 201 return kGenericCard;
201 202
202 int first_two_digits = 0; 203 int first_two_digits = 0;
203 if (!base::StringToInt(number.substr(0, 2), &first_two_digits)) 204 if (!base::StringToInt(number.substr(0, 2), &first_two_digits))
204 return kGenericCard; 205 return kGenericCard;
205 206
206 if (first_two_digits == 22)
207 return kMirCard;
208
209 if (first_two_digits == 34 || first_two_digits == 37) 207 if (first_two_digits == 34 || first_two_digits == 37)
210 return kAmericanExpressCard; 208 return kAmericanExpressCard;
211 209
212 if (first_two_digits == 36 || 210 if (first_two_digits == 36 ||
213 first_two_digits == 38 || 211 first_two_digits == 38 ||
214 first_two_digits == 39) 212 first_two_digits == 39)
215 return kDinersCard; 213 return kDinersCard;
216 214
217 if (first_two_digits >= 51 && first_two_digits <= 55) 215 if (first_two_digits >= 51 && first_two_digits <= 55)
218 return kMasterCard; 216 return kMasterCard;
219 217
220 if (first_two_digits == 62) 218 if (first_two_digits == 62)
221 return kUnionPay; 219 return kUnionPay;
222 220
223 if (first_two_digits == 65) 221 if (first_two_digits == 65)
224 return kDiscoverCard; 222 return kDiscoverCard;
225 223
226 // Check for prefixes of length 3. 224 // Check for prefixes of length 3.
227 if (number.size() < 3) 225 if (number.size() < 3)
228 return kGenericCard; 226 return kGenericCard;
229 227
230 int first_three_digits = 0; 228 int first_three_digits = 0;
231 if (!base::StringToInt(number.substr(0, 3), &first_three_digits)) 229 if (!base::StringToInt(number.substr(0, 3), &first_three_digits))
232 return kGenericCard; 230 return kGenericCard;
233 231
234 if (first_three_digits >= 300 && first_three_digits <= 305) 232 if ((first_three_digits >= 300 && first_three_digits <= 305) ||
233 first_three_digits == 309)
235 return kDinersCard; 234 return kDinersCard;
236 235
237 if (first_three_digits >= 644 && first_three_digits <= 649) 236 if (first_three_digits >= 644 && first_three_digits <= 649)
238 return kDiscoverCard; 237 return kDiscoverCard;
239 238
240 // Check for prefixes of length 4. 239 // Check for prefixes of length 4.
241 if (number.size() < 4) 240 if (number.size() < 4)
242 return kGenericCard; 241 return kGenericCard;
243 242
244 int first_four_digits = 0; 243 int first_four_digits = 0;
245 if (!base::StringToInt(number.substr(0, 4), &first_four_digits)) 244 if (!base::StringToInt(number.substr(0, 4), &first_four_digits))
246 return kGenericCard; 245 return kGenericCard;
247 246
248 if (first_four_digits == 3095) 247 if (first_four_digits >= 2200 && first_four_digits <= 2204)
249 return kDinersCard; 248 return kMirCard;
249
250 if (first_four_digits >= 2221 && first_four_digits <= 2720)
251 return kMasterCard;
250 252
251 if (first_four_digits >= 3528 && first_four_digits <= 3589) 253 if (first_four_digits >= 3528 && first_four_digits <= 3589)
252 return kJCBCard; 254 return kJCBCard;
253 255
256 if (first_four_digits == 5067 || first_four_digits == 5090)
257 return kEloCard;
258
254 if (first_four_digits == 6011) 259 if (first_four_digits == 6011)
255 return kDiscoverCard; 260 return kDiscoverCard;
256 261
262 // Check for prefixes of length 6.
263 if (number.size() < 6)
264 return kGenericCard;
265
266 int first_six_digits = 0;
267 if (!base::StringToInt(number.substr(0, 6), &first_six_digits))
268 return kGenericCard;
269
270 if (first_six_digits == 431274 ||
271 first_six_digits == 451416 ||
272 first_six_digits == 627780 ||
273 first_six_digits == 636297)
274 return kEloCard;
275
257 return kGenericCard; 276 return kGenericCard;
258 } 277 }
259 278
260 void CreditCard::SetNetworkForMaskedCard(base::StringPiece network) { 279 void CreditCard::SetNetworkForMaskedCard(base::StringPiece network) {
261 DCHECK_EQ(MASKED_SERVER_CARD, record_type()); 280 DCHECK_EQ(MASKED_SERVER_CARD, record_type());
262 network_ = network.as_string(); 281 network_ = network.as_string();
263 } 282 }
264 283
265 void CreditCard::SetServerStatus(ServerStatus status) { 284 void CreditCard::SetServerStatus(ServerStatus status) {
266 DCHECK_NE(LOCAL_CARD, record_type()); 285 DCHECK_NE(LOCAL_CARD, record_type());
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 << " " 942 << " "
924 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_TYPE)) 943 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_TYPE))
925 << " " 944 << " "
926 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_NUMBER)) 945 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_NUMBER))
927 << " " 946 << " "
928 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_EXP_MONTH)) 947 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_EXP_MONTH))
929 << " " << base::UTF16ToUTF8( 948 << " " << base::UTF16ToUTF8(
930 credit_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 949 credit_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
931 } 950 }
932 951
933 // These values must match the values in WebKitPlatformSupportImpl in
934 // webkit/glue. We send these strings to WebKit, which then asks
935 // WebKitPlatformSupportImpl to load the image data.
936 const char kAmericanExpressCard[] = "americanExpressCC"; 952 const char kAmericanExpressCard[] = "americanExpressCC";
937 const char kDinersCard[] = "dinersCC"; 953 const char kDinersCard[] = "dinersCC";
938 const char kDiscoverCard[] = "discoverCC"; 954 const char kDiscoverCard[] = "discoverCC";
955 const char kEloCard[] = "eloCC";
939 const char kGenericCard[] = "genericCC"; 956 const char kGenericCard[] = "genericCC";
940 const char kJCBCard[] = "jcbCC"; 957 const char kJCBCard[] = "jcbCC";
941 const char kMasterCard[] = "masterCardCC"; 958 const char kMasterCard[] = "masterCardCC";
942 const char kMirCard[] = "mirCC"; 959 const char kMirCard[] = "mirCC";
943 const char kUnionPay[] = "unionPayCC"; 960 const char kUnionPay[] = "unionPayCC";
944 const char kVisaCard[] = "visaCC"; 961 const char kVisaCard[] = "visaCC";
945 962
946 } // namespace autofill 963 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698