1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_PAYMENTS_CORE_AUTOFILL_CARD_VALIDATION_H_
6 #define COMPONENTS_PAYMENTS_CORE_AUTOFILL_CARD_VALIDATION_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/strings/string16.h"
12 
13 namespace autofill {
14 
15 class CreditCard;
16 class AutofillProfile;
17 
18 }  // namespace autofill
19 
20 namespace payments {
21 
22 // Used to express the completion status of a credit card. Bit field values are
23 // identical to CompletionStatus fields in AutofillPaymentInstrument.java.
24 // Please modify AutofillPaymentInstrument.java after changing these bits since
25 // missing fields on both Android and Desktop are recorded in the same UMA
26 // metric: PaymentRequest.MissingPaymentFields.
27 typedef uint32_t CreditCardCompletionStatus;
28 static const CreditCardCompletionStatus CREDIT_CARD_COMPLETE = 0;
29 static const CreditCardCompletionStatus CREDIT_CARD_EXPIRED = 1 << 0;
30 static const CreditCardCompletionStatus CREDIT_CARD_NO_CARDHOLDER = 1 << 1;
31 static const CreditCardCompletionStatus CREDIT_CARD_NO_NUMBER = 1 << 2;
32 static const CreditCardCompletionStatus CREDIT_CARD_NO_BILLING_ADDRESS = 1 << 3;
33 static const CreditCardCompletionStatus CREDIT_CARD_TYPE_MISMATCH = 1 << 4;
34 
35 // Returns the credit card's completion status. If equal to
36 // CREDIT_CARD_COMPLETE, then the card is ready to be used for Payment Request.
37 CreditCardCompletionStatus GetCompletionStatusForCard(
38     const autofill::CreditCard& credit_card,
39     const std::string& app_locale,
40     const std::vector<autofill::AutofillProfile*> billing_addresses);
41 
42 // Returns the credit card's completeness score. The score is used for sorting
43 // available cards before showing them to the user in payment sheet. Different
44 // fields are weighted according to the effort needed to complete them. The
45 // weights are set so that the number of missing fields matters most (i.e. cards
46 // with any three missing fields are scored lower than cards with any two
47 // missing fields which are in turn scored lower than cards with only one
48 // missing field). When number of missing fields are equal the order of
49 // importance is 1-missing card number 2-missing address 3-missing card holder's
50 // name 4-invalid expiry date. A complete card gets the highest score which is
51 // 37 and each score represents a unique set of missing/invalid fields (i.e. Two
52 // cards will tie if and only if they both have identical missing/invalid
53 // fields).
54 uint32_t GetCompletenessScore(
55     const autofill::CreditCard& credit_card,
56     const std::string& app_locale,
57     const std::vector<autofill::AutofillProfile*> billing_addresses);
58 
59 // Return the message to be displayed to the user, indicating what's missing
60 // to make the credit card complete for payment. If more than one thing is
61 // missing, the message will be a generic "more information required".
62 base::string16 GetCompletionMessageForCard(CreditCardCompletionStatus status);
63 
64 // Returns the title string for a card edit dialog. The title string will
65 // mention what needs to be added/fixed to make the card valid if it is not
66 // valid. Otherwise, it will be "Edit card".
67 base::string16 GetEditDialogTitleForCard(CreditCardCompletionStatus status);
68 
69 }  // namespace payments
70 
71 #endif  // COMPONENTS_PAYMENTS_CORE_AUTOFILL_CARD_VALIDATION_H_
72