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

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

Issue 2906763005: Add support for Brazil Elo card in autofill. (Closed)
Patch Set: 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,
Jared Saul 2017/05/26 19:51:10 These two are removed entirely, but I wonder if th
jiahuiguo 2017/05/29 20:08:05 Ha, this is a good point! But I wonder since they
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/,
175 // http://www.fraudpractice.com/FL-binCC.html, and 177 // http://www.fraudpractice.com/FL-binCC.html, and
176 // http://www.beachnet.com/~hstiles/cardtype.html 178 // http://www.beachnet.com/~hstiles/cardtype.html
177 // 179 //
178 // The last site is currently unavailable, but a cached version remains at 180 // The last site is currently unavailable, but a cached version remains at
179 // http://web.archive.org/web/20120923111349/http://www.beachnet.com/~hstiles/ cardtype.html 181 // http://web.archive.org/web/20120923111349/http://www.beachnet.com/~hstiles/ cardtype.html
180 // 182 //
181 // Card Type Prefix(es) Length 183 // Card Type Prefix(es) Length
182 // --------------------------------------------------------------- 184 // --------------------------------------------------------------------------
183 // Visa 4 13,16 185 // Visa 4 13,16,19
184 // American Express 34,37 15 186 // American Express 34,37 15
185 // Diners Club 300-305,3095,36,38-39 14 187 // Diners Club 300-305,309,36,38-39 14
186 // Discover Card 6011,644-649,65 16 188 // Discover Card 6011,644-649,65 16
187 // JCB 3528-3589 16 189 // Elo 431274,451416,5067,5090,627780,636297 16
188 // Mastercard 51-55 16 190 // JCB 3528-3589 16
189 // UnionPay 62 16-19 191 // Maestro 50,56-58,6 12-19
Jared Saul 2017/05/26 19:51:10 Maestro is not represented in the rules below, and
Mathieu 2017/05/29 15:54:31 Should Maestro be supported one day? I'm not too f
jiahuiguo 2017/05/29 20:08:06 Payments platform now support this card type, we h
192 // Mastercard 2221-2720, 51-55 16
193 // MIR 2200-2204 16
194 // UnionPay 62 16-19
190 195
191 // Check for prefixes of length 1. 196 // Check for prefixes of length 1.
192 if (number.empty()) 197 if (number.empty())
193 return kGenericCard; 198 return kGenericCard;
194 199
195 if (number[0] == '4') 200 if (number[0] == '4')
196 return kVisaCard; 201 return kVisaCard;
197 202
198 // Check for prefixes of length 2. 203 // Check for prefixes of length 2.
199 if (number.size() < 2) 204 if (number.size() < 2)
200 return kGenericCard; 205 return kGenericCard;
201 206
202 int first_two_digits = 0; 207 int first_two_digits = 0;
203 if (!base::StringToInt(number.substr(0, 2), &first_two_digits)) 208 if (!base::StringToInt(number.substr(0, 2), &first_two_digits))
204 return kGenericCard; 209 return kGenericCard;
205 210
206 if (first_two_digits == 22)
207 return kMirCard;
208
209 if (first_two_digits == 34 || first_two_digits == 37) 211 if (first_two_digits == 34 || first_two_digits == 37)
210 return kAmericanExpressCard; 212 return kAmericanExpressCard;
211 213
212 if (first_two_digits == 36 || 214 if (first_two_digits == 36 ||
213 first_two_digits == 38 || 215 first_two_digits == 38 ||
214 first_two_digits == 39) 216 first_two_digits == 39)
215 return kDinersCard; 217 return kDinersCard;
216 218
217 if (first_two_digits >= 51 && first_two_digits <= 55) 219 if (first_two_digits >= 51 && first_two_digits <= 55)
218 return kMasterCard; 220 return kMasterCard;
219 221
220 if (first_two_digits == 62) 222 if (first_two_digits == 62)
221 return kUnionPay; 223 return kUnionPay;
222 224
223 if (first_two_digits == 65) 225 if (first_two_digits == 65)
224 return kDiscoverCard; 226 return kDiscoverCard;
225 227
226 // Check for prefixes of length 3. 228 // Check for prefixes of length 3.
227 if (number.size() < 3) 229 if (number.size() < 3)
228 return kGenericCard; 230 return kGenericCard;
229 231
230 int first_three_digits = 0; 232 int first_three_digits = 0;
231 if (!base::StringToInt(number.substr(0, 3), &first_three_digits)) 233 if (!base::StringToInt(number.substr(0, 3), &first_three_digits))
232 return kGenericCard; 234 return kGenericCard;
233 235
234 if (first_three_digits >= 300 && first_three_digits <= 305) 236 if ((first_three_digits >= 300 && first_three_digits <= 305) ||
237 first_three_digits == 309)
235 return kDinersCard; 238 return kDinersCard;
236 239
237 if (first_three_digits >= 644 && first_three_digits <= 649) 240 if (first_three_digits >= 644 && first_three_digits <= 649)
238 return kDiscoverCard; 241 return kDiscoverCard;
239 242
240 // Check for prefixes of length 4. 243 // Check for prefixes of length 4.
241 if (number.size() < 4) 244 if (number.size() < 4)
242 return kGenericCard; 245 return kGenericCard;
243 246
244 int first_four_digits = 0; 247 int first_four_digits = 0;
245 if (!base::StringToInt(number.substr(0, 4), &first_four_digits)) 248 if (!base::StringToInt(number.substr(0, 4), &first_four_digits))
246 return kGenericCard; 249 return kGenericCard;
247 250
248 if (first_four_digits == 3095) 251 if (first_four_digits >= 2200 && first_four_digits <= 2204)
249 return kDinersCard; 252 return kMirCard;
253
254 if (first_four_digits >= 2221 && first_four_digits <= 2720)
255 return kMasterCard;
250 256
251 if (first_four_digits >= 3528 && first_four_digits <= 3589) 257 if (first_four_digits >= 3528 && first_four_digits <= 3589)
252 return kJCBCard; 258 return kJCBCard;
253 259
260 if (first_four_digits == 5067 || first_four_digits == 5090)
261 return kEloCard;
262
254 if (first_four_digits == 6011) 263 if (first_four_digits == 6011)
255 return kDiscoverCard; 264 return kDiscoverCard;
256 265
266 // Check for prefixes of length 6.
267 if (number.size() < 6)
268 return kGenericCard;
269
270 int first_six_digits = 0;
271 if (!base::StringToInt(number.substr(0, 6), &first_six_digits))
272 return kGenericCard;
273
274 if (first_six_digits == 431274 ||
275 first_six_digits == 451416 ||
276 first_six_digits == 636297 ||
277 first_six_digits == 627780)
Jared Saul 2017/05/26 19:51:10 Reverse line order: 627780 < 636297
jiahuiguo 2017/05/29 20:08:06 Nice catch! Thanks.
278 return kEloCard;
279
257 return kGenericCard; 280 return kGenericCard;
258 } 281 }
259 282
260 void CreditCard::SetNetworkForMaskedCard(base::StringPiece network) { 283 void CreditCard::SetNetworkForMaskedCard(base::StringPiece network) {
261 DCHECK_EQ(MASKED_SERVER_CARD, record_type()); 284 DCHECK_EQ(MASKED_SERVER_CARD, record_type());
262 network_ = network.as_string(); 285 network_ = network.as_string();
263 } 286 }
264 287
265 void CreditCard::SetServerStatus(ServerStatus status) { 288 void CreditCard::SetServerStatus(ServerStatus status) {
266 DCHECK_NE(LOCAL_CARD, record_type()); 289 DCHECK_NE(LOCAL_CARD, record_type());
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 << " " 943 << " "
921 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_NUMBER)) 944 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_NUMBER))
922 << " " 945 << " "
923 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_EXP_MONTH)) 946 << base::UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_EXP_MONTH))
924 << " " << base::UTF16ToUTF8( 947 << " " << base::UTF16ToUTF8(
925 credit_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 948 credit_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
926 } 949 }
927 950
928 // These values must match the values in WebKitPlatformSupportImpl in 951 // These values must match the values in WebKitPlatformSupportImpl in
929 // webkit/glue. We send these strings to WebKit, which then asks 952 // webkit/glue. We send these strings to WebKit, which then asks
930 // WebKitPlatformSupportImpl to load the image data. 953 // WebKitPlatformSupportImpl to load the image data.
Mathieu 2017/05/26 13:48:32 that seems... out of date. Can we remove this comm
jiahuiguo 2017/05/26 19:44:10 Yeah, I search the WebKitPlatformSupportImpl in cs
931 const char kAmericanExpressCard[] = "americanExpressCC"; 954 const char kAmericanExpressCard[] = "americanExpressCC";
932 const char kDinersCard[] = "dinersCC"; 955 const char kDinersCard[] = "dinersCC";
933 const char kDiscoverCard[] = "discoverCC"; 956 const char kDiscoverCard[] = "discoverCC";
957 const char kEloCard[] = "eloCC";
934 const char kGenericCard[] = "genericCC"; 958 const char kGenericCard[] = "genericCC";
935 const char kJCBCard[] = "jcbCC"; 959 const char kJCBCard[] = "jcbCC";
936 const char kMasterCard[] = "masterCardCC"; 960 const char kMasterCard[] = "masterCardCC";
937 const char kMirCard[] = "mirCC"; 961 const char kMirCard[] = "mirCC";
938 const char kUnionPay[] = "unionPayCC"; 962 const char kUnionPay[] = "unionPayCC";
939 const char kVisaCard[] = "visaCC"; 963 const char kVisaCard[] = "visaCC";
940 964
941 } // namespace autofill 965 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698