chromium/components/autofill/core/browser/data_model/credit_card.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/core/browser/data_model/credit_card.h"

#include <math.h>
#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <ostream>
#include <string_view>

#include "base/check_op.h"
#include "base/i18n/rtl.h"
#include "base/i18n/time_formatting.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/data_model/data_model_utils.h"
#include "components/autofill/core/browser/data_model/payments_metadata.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/payments/constants.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_regexes.h"
#include "components/autofill/core/common/credit_card_network_identifiers.h"
#include "components/autofill/core/common/credit_card_number_validation.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/grit/components_scaled_resources.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"

namespace autofill {

namespace {

constexpr char16_t kCreditCardObfuscationSymbol =;

constexpr char16_t kWhiteSpaceSeparator =;

constexpr int kMaxNicknameLength =;

constexpr std::array<int, 3> k15DigitAmexNumberSegmentations =;
constexpr std::array<int, 4> k16DigitNumberSegmentations =;

// Suffix for GUID of a virtual card to differentiate it from it's corresponding
// masked server card..
constexpr char kVirtualCardIdentifierSuffix[] =;

std::u16string NetworkForFill(const std::string& network) {}

// Returns the last four digits of the credit card |number| (fewer if there are
// not enough characters in |number|).
std::u16string GetLastFourDigits(const std::u16string& number) {}

// Returns a new string based on the input `number` by adding a white space
// between `segments`. The provided `segments` denotes the length of each
// segment, and we don't need to add whitespace to the last segmentation. For
// example, if you would like to format 15-digit card number into "XXXX XXXXXX
// XXXXX", you need to provide [4, 6, 5] as the `segments`.
std::u16string AddWhiteSpaceSeparatorForNumber(const std::u16string& number,
                                               base::span<const int> segments) {}

Suggestion::Icon ConvertCardNetworkIntoIcon(std::string_view network) {}

}  // namespace

// static
CreditCard CreditCard::CreateVirtualCard(const CreditCard& card) {}

// static
std::unique_ptr<CreditCard> CreditCard::CreateVirtualCardWithGuidSuffix(
    const CreditCard& card) {}

// static
std::u16string CreditCard::GetObfuscatedStringForCardDigits(
    int obfuscation_length,
    const std::u16string& digits) {}

CreditCard::CreditCard(const std::string& guid, const std::string& origin)
    :{}

// TODO(crbug.com/40146355): Calling the CreditCard's default constructor
// initializes the `guid_`. This shouldn't happen for server cards, since they
// are not identified by guids. However, some of the server card logic relies
// by them for historical reasons.
CreditCard::CreditCard(RecordType type, const std::string& server_id)
    :{}

// TODO(crbug.com/40146355): See `server_id` constructor.
CreditCard::CreditCard(RecordType type, int64_t instrument_id) :{}

CreditCard::CreditCard()
    :{}

CreditCard::CreditCard(const CreditCard& credit_card) = default;
CreditCard::CreditCard(CreditCard&& credit_card) = default;
CreditCard& CreditCard::operator=(const CreditCard& credit_card) = default;
CreditCard& CreditCard::operator=(CreditCard&& credit_card) = default;

CreditCard::~CreditCard() = default;

// static
std::u16string CreditCard::NetworkForDisplay(const std::string& network) {}

// static
int CreditCard::IconResourceId(Suggestion::Icon icon) {}

// static
int CreditCard::IconResourceId(std::string_view icon_str) {}

// static
bool CreditCard::IsNicknameValid(const std::u16string& nickname) {}

// static
std::u16string CreditCard::GetMidlineEllipsisDots(size_t num_dots) {}

// static
std::u16string CreditCard::GetMidlineEllipsisPlainDots(size_t num_dots) {}

// static
bool CreditCard::IsLocalCard(const CreditCard* card) {}

void CreditCard::SetNetworkForMaskedCard(std::string_view network) {}

PaymentsMetadata CreditCard::GetMetadata() const {}

double CreditCard::GetRankingScore(base::Time current_time,
                                   bool use_frecency) const {}

bool CreditCard::HasGreaterRankingThan(const CreditCard& other,
                                       base::Time comparison_time,
                                       bool use_frecency) const {}

bool CreditCard::SetMetadata(const PaymentsMetadata& metadata) {}

bool CreditCard::IsDeletable() const {}

std::u16string CreditCard::GetRawInfo(FieldType type) const {}

void CreditCard::SetRawInfoWithVerificationStatus(FieldType type,
                                                  const std::u16string& value,
                                                  VerificationStatus status) {}

void CreditCard::GetMatchingTypes(const std::u16string& text,
                                  const std::string& app_locale,
                                  FieldTypeSet* matching_types) const {}

void CreditCard::SetInfoForMonthInputType(const std::u16string& value) {}

void CreditCard::SetExpirationMonth(int expiration_month) {}

void CreditCard::SetExpirationYear(int expiration_year) {}

void CreditCard::SetNickname(const std::u16string& nickname) {}

bool CreditCard::UpdateFromImportedCard(const CreditCard& imported_card,
                                        const std::string& app_locale) {}

int CreditCard::Compare(const CreditCard& credit_card) const {}

bool CreditCard::IsLocalOrServerDuplicateOf(const CreditCard& other) const {}

bool CreditCard::MatchingCardDetails(const CreditCard& other) const {}

bool CreditCard::HasSameNumberAs(const CreditCard& other) const {}

bool CreditCard::HasSameExpirationDateAs(const CreditCard& other) const {}

bool CreditCard::operator==(const CreditCard& credit_card) const {}

bool CreditCard::IsVerified() const {}

bool CreditCard::IsEmpty(const std::string& app_locale) const {}

bool CreditCard::IsValid() const {}

bool CreditCard::HasValidCardNumber() const {}

bool CreditCard::HasValidExpirationYear() const {}

bool CreditCard::HasValidExpirationDate() const {}

bool CreditCard::SetExpirationMonthFromString(const std::u16string& text,
                                              const std::string& app_locale) {}

bool CreditCard::SetExpirationYearFromString(const std::u16string& text) {}

void CreditCard::SetExpirationDateFromString(const std::u16string& text) {}

std::pair<std::u16string, std::u16string> CreditCard::LabelPieces() const {}

std::u16string CreditCard::Label() const {}

std::u16string CreditCard::LastFourDigits() const {}

std::u16string CreditCard::FullDigitsForDisplay() const {}

std::u16string CreditCard::NetworkForDisplay() const {}

std::u16string CreditCard::ObfuscatedNumberWithVisibleLastFourDigits(
    int obfuscation_length) const {}

std::u16string
CreditCard::ObfuscatedNumberWithVisibleLastFourDigitsForSplitFields() const {}

Suggestion::Icon CreditCard::CardIconForAutofillSuggestion() const {}

std::u16string CreditCard::NetworkAndLastFourDigits(
    int obfuscation_length) const {}

std::u16string CreditCard::CardNameAndLastFourDigits(
    std::u16string customized_nickname,
    int obfuscation_length) const {}

std::u16string CreditCard::CardNameForAutofillDisplay(
    const std::u16string& customized_nickname) const {}

#if BUILDFLAG(IS_ANDROID)
std::u16string CreditCard::CardIdentifierStringForManualFilling() const {
  std::u16string obfuscated_number =
      ObfuscatedNumberWithVisibleLastFourDigits();
  if (record_type_ == RecordType::kVirtualCard) {
    return l10n_util::GetStringUTF16(
               IDS_AUTOFILL_VIRTUAL_CARD_SUGGESTION_OPTION_VALUE) +
           u" " + obfuscated_number;
  }
  return obfuscated_number;
}
#endif  // BUILDFLAG(IS_ANDROID)

std::u16string CreditCard::CardIdentifierStringAndDescriptiveExpiration(
    const std::string& app_locale,
    std::u16string customized_nickname) const {}

std::u16string CreditCard::DescriptiveExpiration(
    const std::string& app_locale) const {}

std::u16string CreditCard::AbbreviatedExpirationDateForDisplay(
    bool with_prefix) const {}

std::u16string CreditCard::ExpirationDateForDisplay() const {}

std::u16string CreditCard::Expiration2DigitMonthAsString() const {}

std::u16string CreditCard::Expiration2DigitYearAsString() const {}

std::u16string CreditCard::Expiration4DigitYearAsString() const {}

bool CreditCard::HasNameOnCard() const {}

bool CreditCard::HasNonEmptyValidNickname() const {}

std::u16string CreditCard::NicknameAndLastFourDigitsForTesting() const {}

bool CreditCard::HasRichCardArtImageFromMetadata() const {}

void CreditCard::GetSupportedTypes(FieldTypeSet* supported_types) const {}

std::u16string CreditCard::GetInfoImpl(const AutofillType& type,
                                       const std::string& app_locale) const {}

bool CreditCard::SetInfoWithVerificationStatusImpl(
    const AutofillType& type,
    const std::u16string& value,
    const std::string& app_locale,
    VerificationStatus status) {}

std::u16string CreditCard::NetworkForFill() const {}

std::u16string CreditCard::NicknameAndLastFourDigits(
    std::u16string customized_nickname,
    int obfuscation_length) const {}

void CreditCard::SetNumber(const std::u16string& number) {}

void CreditCard::RecordAndLogUse() {}

bool CreditCard::IsExpired(base::Time current_time) const {}

bool CreditCard::masked() const {}

bool CreditCard::ShouldUpdateExpiration() const {}

bool CreditCard::IsCompleteValidCard() const {}

// So we can compare CreditCards with EXPECT_EQ().
std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) {}

void CreditCard::SetNameOnCardFromSeparateParts() {}

}  // namespace autofill