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

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

Issue 2813203004: [Payments] Show what's missing for incomplete payment methods. (Closed)
Patch Set: addressed comments, now two functions Created 3 years, 8 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
« no previous file with comments | « components/autofill/core/browser/validation.h ('k') | components/payments/core/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/validation.h" 5 #include "components/autofill/core/browser/validation.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 118 }
119 119
120 if (IsValidCreditCardNumber(text)) 120 if (IsValidCreditCardNumber(text))
121 return true; 121 return true;
122 122
123 *error_message = l10n_util::GetStringUTF16( 123 *error_message = l10n_util::GetStringUTF16(
124 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); 124 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE);
125 return false; 125 return false;
126 } 126 }
127 127
128 CreditCardCompletionStatus GetCompletionStatusForCard(
129 const CreditCard& card,
130 const std::string& app_locale) {
131 CreditCardCompletionStatus status = CREDIT_CARD_COMPLETE;
132 if (card.IsExpired(autofill::AutofillClock::Now()))
133 status |= CREDIT_CARD_EXPIRED;
134
135 if (card.number().empty())
136 status |= CREDIT_CARD_NO_NUMBER;
137
138 if (card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
139 app_locale)
140 .empty()) {
141 status |= CREDIT_CARD_NO_CARDHOLDER;
142 }
143
144 return status;
145 }
146
147 base::string16 GetCompletionMessageForCard(CreditCardCompletionStatus status) {
148 switch (status) {
149 case CREDIT_CARD_COMPLETE:
150 return base::string16();
151 case CREDIT_CARD_EXPIRED:
152 return l10n_util::GetStringUTF16(
153 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED);
154 case CREDIT_CARD_NO_CARDHOLDER:
155 return l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_ON_CARD_REQUIRED);
156 case CREDIT_CARD_NO_NUMBER:
157 return l10n_util::GetStringUTF16(
158 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE);
159 default:
160 // Multiple things are missing
161 return l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED);
162 }
163 }
164
128 bool IsValidEmailAddress(const base::string16& text) { 165 bool IsValidEmailAddress(const base::string16& text) {
129 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) 166 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state)
130 const base::string16 kEmailPattern = base::ASCIIToUTF16( 167 const base::string16 kEmailPattern = base::ASCIIToUTF16(
131 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" 168 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@"
132 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); 169 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$");
133 return MatchesPattern(text, kEmailPattern); 170 return MatchesPattern(text, kEmailPattern);
134 } 171 }
135 172
136 bool IsValidState(const base::string16& text) { 173 bool IsValidState(const base::string16& text) {
137 return !state_names::GetAbbreviationForName(text).empty() || 174 return !state_names::GetAbbreviationForName(text).empty() ||
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 return AMEX_CVC_LENGTH; 357 return AMEX_CVC_LENGTH;
321 358
322 return GENERAL_CVC_LENGTH; 359 return GENERAL_CVC_LENGTH;
323 } 360 }
324 361
325 bool IsUPIVirtualPaymentAddress(const base::string16& value) { 362 bool IsUPIVirtualPaymentAddress(const base::string16& value) {
326 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); 363 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe));
327 } 364 }
328 365
329 } // namespace autofill 366 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/validation.h ('k') | components/payments/core/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698