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

Unified Diff: components/autofill/core/browser/validation.cc

Issue 2813203004: [Payments] Show what's missing for incomplete payment methods. (Closed)
Patch Set: Initial 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/core/browser/validation.h ('k') | components/payments/content/payment_request_state.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(
« no previous file with comments | « components/autofill/core/browser/validation.h ('k') | components/payments/content/payment_request_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698