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

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

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
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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_ 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_ 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_
7 7
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "components/autofill/core/browser/field_types.h" 10 #include "components/autofill/core/browser/field_types.h"
11 11
12 namespace base { 12 namespace base {
13 class Time; 13 class Time;
14 } // namespace base 14 } // namespace base
15 15
16 namespace autofill { 16 namespace autofill {
17 17
18 class CreditCard;
19
18 // Constants for the length of a CVC. 20 // Constants for the length of a CVC.
19 static const size_t GENERAL_CVC_LENGTH = 3; 21 static const size_t GENERAL_CVC_LENGTH = 3;
20 static const size_t AMEX_CVC_LENGTH = 4; 22 static const size_t AMEX_CVC_LENGTH = 4;
21 23
24 // Used to express the completion status of a credit card.
25 typedef uint32_t CreditCardCompletionStatus;
26 static const CreditCardCompletionStatus CREDIT_CARD_COMPLETE = 0;
27 static const CreditCardCompletionStatus CREDIT_CARD_EXPIRED = 1 << 0;
28 static const CreditCardCompletionStatus CREDIT_CARD_NO_CARDHOLDER = 1 << 1;
29 static const CreditCardCompletionStatus CREDIT_CARD_NO_NUMBER = 1 << 2;
30
22 // Returns true if |year| and |month| describe a date later than |now|. 31 // Returns true if |year| and |month| describe a date later than |now|.
23 // |year| must have 4 digits. 32 // |year| must have 4 digits.
24 bool IsValidCreditCardExpirationDate(int year, 33 bool IsValidCreditCardExpirationDate(int year,
25 int month, 34 int month,
26 const base::Time& now); 35 const base::Time& now);
27 36
28 // Returns true if |text| looks like a valid credit card number. 37 // Returns true if |text| looks like a valid credit card number.
29 // Uses the Luhn formula to validate the number. 38 // Uses the Luhn formula to validate the number.
30 bool IsValidCreditCardNumber(const base::string16& text); 39 bool IsValidCreditCardNumber(const base::string16& text);
31 40
32 // Returns true if |code| looks like a valid credit card security code 41 // Returns true if |code| looks like a valid credit card security code
33 // for the given credit card type. 42 // for the given credit card type.
34 bool IsValidCreditCardSecurityCode(const base::string16& code, 43 bool IsValidCreditCardSecurityCode(const base::string16& code,
35 const base::StringPiece card_type); 44 const base::StringPiece card_type);
36 45
37 // Returns true if |text| is a supported card type and a valid credit card 46 // Returns true if |text| is a supported card type and a valid credit card
38 // number. |error_message| can't be null and will be filled with the appropriate 47 // number. |error_message| can't be null and will be filled with the appropriate
39 // error message. 48 // error message.
40 bool IsValidCreditCardNumberForBasicCardNetworks( 49 bool IsValidCreditCardNumberForBasicCardNetworks(
41 const base::string16& text, 50 const base::string16& text,
42 const std::set<std::string>& supported_basic_card_networks, 51 const std::set<std::string>& supported_basic_card_networks,
43 base::string16* error_message); 52 base::string16* error_message);
44 53
54 // Returns the credit card's completion status. If equal to
55 // CREDIT_CARD_COMPLETE, then the card is ready to be used for Payment Request.
56 // TODO(crbug.com/709776): Check for billing address association.
57 CreditCardCompletionStatus GetCompletionStatusForCard(
58 const CreditCard& credit_card,
59 const std::string& app_locale);
60
61 // Return the message to be displayed to the user, indicating what's missing
62 // to make the credit card complete for payment. If more than one thing is
63 // missing, the message will be a generic "more information required".
64 base::string16 GetCompletionMessageForCard(CreditCardCompletionStatus status);
65
45 // Returns true if |text| looks like a valid e-mail address. 66 // Returns true if |text| looks like a valid e-mail address.
46 bool IsValidEmailAddress(const base::string16& text); 67 bool IsValidEmailAddress(const base::string16& text);
47 68
48 // Returns true if |text| is a valid US state name or abbreviation. It is case 69 // Returns true if |text| is a valid US state name or abbreviation. It is case
49 // insensitive. Valid for US states only. 70 // insensitive. Valid for US states only.
50 bool IsValidState(const base::string16& text); 71 bool IsValidState(const base::string16& text);
51 72
52 // Returns whether the number contained in |text| is valid for the specified 73 // Returns whether the number contained in |text| is valid for the specified
53 // |country_code|. Callers should cache the result as the parsing is expensive. 74 // |country_code|. Callers should cache the result as the parsing is expensive.
54 bool IsValidPhoneNumber(const base::string16& text, 75 bool IsValidPhoneNumber(const base::string16& text,
(...skipping 15 matching lines...) Expand all
70 // Returns the expected CVC length based on the |card_type|. 91 // Returns the expected CVC length based on the |card_type|.
71 size_t GetCvcLengthForCardType(const base::StringPiece card_type); 92 size_t GetCvcLengthForCardType(const base::StringPiece card_type);
72 93
73 // Returns true if |value| appears to be a UPI Virtual Payment Address. 94 // Returns true if |value| appears to be a UPI Virtual Payment Address.
74 // https://upipayments.co.in/virtual-payment-address-vpa/ 95 // https://upipayments.co.in/virtual-payment-address-vpa/
75 bool IsUPIVirtualPaymentAddress(const base::string16& value); 96 bool IsUPIVirtualPaymentAddress(const base::string16& value);
76 97
77 } // namespace autofill 98 } // namespace autofill
78 99
79 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_ 100 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/payment_method_view_controller.cc ('k') | components/autofill/core/browser/validation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698