Chromium Code Reviews| Index: components/autofill/core/browser/validation.cc |
| diff --git a/components/autofill/core/browser/validation.cc b/components/autofill/core/browser/validation.cc |
| index e7237f7b3b73d3fab1ad1a963a3cb245a0e0df3f..854c9d4c1d2983553f56e9b514e266eb804a70b3 100644 |
| --- a/components/autofill/core/browser/validation.cc |
| +++ b/components/autofill/core/browser/validation.cc |
| @@ -125,6 +125,54 @@ bool IsValidCreditCardNumberForBasicCardNetworks( |
| return false; |
| } |
| +bool CreditCardHasNumberAndName(const CreditCard& card, |
| + const std::string& app_locale) { |
| + return !card.number().empty() && |
| + !card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), |
| + app_locale) |
| + .empty(); |
| +} |
| + |
| +bool IsCompleteForPaymentRequest(const CreditCard& card, |
|
anthonyvd
2017/04/13 19:50:55
I think this could return a bitfield enum instead
Mathieu
2017/04/13 20:00:15
This is intentional because we want this file to b
anthonyvd
2017/04/13 20:48:27
Totally understand the need to have a common funct
Mathieu
2017/04/18 17:26:01
Cool, it's better now, PTAL
|
| + const std::string& app_locale, |
| + base::string16* missing_info) { |
| + base::string16 message; |
| + if (card.IsExpired(autofill::AutofillClock::Now())) { |
| + message = l10n_util::GetStringUTF16( |
| + IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED); |
| + } |
| + if (card.number().empty()) { |
| + if (!message.empty()) { |
| + if (missing_info) { |
| + *missing_info = |
| + l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED); |
| + } |
| + return false; |
| + } |
| + message = l10n_util::GetStringUTF16( |
| + IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); |
| + } |
| + if (card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), |
| + app_locale) |
| + .empty()) { |
| + if (!message.empty()) { |
| + if (missing_info) { |
| + *missing_info = |
| + l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED); |
| + } |
| + return false; |
| + } |
| + message = l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_ON_CARD_REQUIRED); |
| + } |
| + |
| + if (!message.empty()) { |
| + if (missing_info) |
| + *missing_info = std::move(message); |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| bool IsValidEmailAddress(const base::string16& text) { |
| // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) |
| const base::string16 kEmailPattern = base::ASCIIToUTF16( |