chromium/components/autofill/core/browser/webdata/payments/payments_autofill_table.h

// 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.

#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_PAYMENTS_PAYMENTS_AUTOFILL_TABLE_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_PAYMENTS_PAYMENTS_AUTOFILL_TABLE_H_

#include <stddef.h>

#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/gtest_prod_util.h"
#include "base/time/time.h"
#include "components/autofill/core/browser/data_model/credit_card_benefit.h"
#include "components/sync/base/data_type.h"
#include "components/sync/protocol/autofill_specifics.pb.h"
#include "components/webdata/common/web_database_table.h"

class WebDatabase;

namespace base {
class Time;
}

namespace autofill {

class AutofillOfferData;
class AutofillTableEncryptor;
class BankAccount;
class CreditCard;
struct CreditCardCloudTokenData;
class Iban;
struct PaymentsCustomerData;
struct PaymentsMetadata;
class VirtualCardUsageData;
// Helper struct to better group server cvc related variables for better
// passing last_updated_timestamp, which is needed for sync bridge. Limited
// scope in autofill table & sync bridge.
struct ServerCvc {};

// This class manages the various payments Autofill tables within the SQLite
// database passed to the constructor. It expects the following schemas:
//
// Note: The database stores time in seconds, UTC.
// -----------------------------------------------------------------------------
// credit_cards         This table contains credit card data added by the user
//                      with the Autofill dialog.  Most of the columns are
//                      standard entries in a credit card form.
//
//   guid               A guid string to uniquely identify the credit card.
//                      Added in version 31.
//   name_on_card       The cardholder's name, if available.
//   expiration_month   Expiration month: 1-12
//   expiration_year    Four-digit year: 2017
//   card_number_encrypted
//                      Stores encrypted credit card number.
//   use_count          The number of times this card has been used to fill
//                      a form. Added in version 61.
//   use_date           The date this card was last used to fill a form,
//                      in time_t. Added in version 61.
//   date_modified      The date on which this entry was last modified, in
//                      time_t. Added in version 30.
//   origin             The domain of origin for this profile.
//                      Added in version 50.
//   billing_address_id The guid string that identifies the local profile which
//                      is the billing address for this card. Can be null in the
//                      database, but always returned as an empty string in
//                      CreditCard. Added in version 66.
//   nickname           A nickname for the card, entered by the user. Added in
//                      version 87.
// -----------------------------------------------------------------------------
// masked_credit_cards
//                      This table contains "masked" credit card information
//                      about credit cards stored on the server. It consists
//                      of a short description and an ID, but not full payment
//                      information. Writing to this table is done by sync and
//                      on successful save of card to the server.
//
//   id                 String assigned by the server to identify this card.
//                      This is a legacy version of instrument_id and is opaque
//                      to the client.
//   status             Server's status of this card.
//                      TODO(brettw) define constants for this.
//   name_on_card       The cardholder's name, if available.
//   network            Issuer network of the card. For example, "VISA". Renamed
//                      from "type" in version 72.
//   last_four          Last four digits of the card number. For de-duping
//                      with locally stored cards and generating descriptions.
//   exp_month          Expiration month: 1-12
//   exp_year           Four-digit year: 2017
//   bank_name          Issuer bank name of the credit card.
//   nickname           The card's nickname, if it exists. Added in version 84.
//   card_issuer        Issuer for the card. An integer representing the
//                      CardIssuer.Issuer enum from the Chrome Sync response.
//                      For example, GOOGLE or ISSUER_UNKNOWN.
//   instrument_id      Credit card id assigned by the server to identify this
//                      card. This is opaque to the client, and |id| is the
//                      legacy version of this.
//   virtual_card_enrollment_state
//                      An enum indicating the virtual card enrollment state of
//                      this card. kUnspecified is the default value.
//                      kUnenrolled means this card has not been enrolled to
//                      have virtual cards. kEnrolled means the card has been
//                      enrolled and has related virtual credit cards.
//   card_art_url       URL to generate the card art image for this card.
//   product_description
//                      The product description for the card. Used to be shown
//                      in the UI when card is presented. Added in version 102.
//   card_issuer_id     The id of the card's issuer.
//   virtual_card_enrollment_type
//                      An enum indicating the type of virtual card enrollment
//                      of this card. kTypeUnspecified is the default value.
//                      kIssuer denotes that it is an issuer-level enrollment.
//                      kNetwork denotes that it is a network-level enrollment.
//   product_terms_url  Issuer terms of service to be displayed on the settings
//                      page.
// -----------------------------------------------------------------------------
// server_card_cloud_token_data
//                      Stores data related to Cloud Primary Account Number
//                      (CPAN) of server credit cards. Each card can have
//                      multiple entries.
//
//   id                 The server ID, which matches an ID from the
//                      masked_credit_cards table.
//   suffix             Last 4-5 digits of the Cloud Primary Account Number.
//   exp_month          Expiration month associated with the CPAN.
//   exp_year           Four-digit Expiration year associated with the CPAN.
//   card_art_url       URL of the card art to be displayed for CPAN.
//   instrument_token   Opaque identifier for the cloud token associated with
//                      the payment instrument.
// -----------------------------------------------------------------------------
// server_card_metadata
//                      Metadata (currently, usage data) about server credit
//                      cards. This will be synced.
//
//   id                 The server ID, which matches an ID from the
//                      masked_credit_cards table.
//   use_count          The number of times this card has been used to fill
//                      a form.
//   use_date           The date this card was last used to fill a form,
//                      in internal t.
//   billing_address_id The string that identifies the profile which is the
//                      billing address for this card. Can be null in the
//                      database, but always returned as an empty string in
//                      CreditCard. Added in version 71.
// -----------------------------------------------------------------------------
// local_ibans          This table contains International Bank Account
//                      Numbers (IBANs) added by the user. The columns are
//                      standard entries in an Iban form. Those are local IBANs
//                      and exist on Chrome client only.
//
//   guid               A guid string to uniquely identify the IBAN.
//   use_count          The number of times this IBAN has been used to fill
//                      a form.
//   use_date           The date this IBAN was last used to fill a form,
//                      in time_t.
//   value_encrypted    Actual value of the IBAN (the bank account number),
//                      encrypted.
//   nickname           A nickname for the IBAN, entered by the user.
// -----------------------------------------------------------------------------
// masked_ibans         This table contains "masked" International Bank Account
//                      Numbers (IBANs) added by the user. Those are server
//                      IBANs saved on GPay server and are available across all
//                      the Chrome devices.
//
//   instrument_id      String assigned by the server to identify this IBAN.
//                      This is opaque to the client.
//   prefix             Contains the prefix of the full IBAN value that is
//                      shown when in a masked format.
//   suffix             Contains the suffix of the full IBAN value that is
//                      shown when in a masked format.
//   nickname           A nickname for the IBAN, entered by the user.
// -----------------------------------------------------------------------------
// masked_ibans_metadata
//                      Metadata (currently, usage data) about server IBANS.
//                      This will be synced from Chrome sync.
//
//   instrument_id      The instrument ID, which matches an ID from the
//                      masked_ibans table.
//   use_count          The number of times this IBAN has been used to fill
//                      a form.
//   use_date           The date this IBAN was last used to fill a form,
//                      in time_t.
// -----------------------------------------------------------------------------
// payments_customer_data
//                      Contains Google Payments customer data.
//
//   customer_id        A string representing the Google Payments customer id.
// -----------------------------------------------------------------------------
// offer_data           The data for Autofill offers which will be presented in
//                      payments autofill flows.
//
//   offer_id           The unique server ID for this offer data.
//   offer_reward_amount
//                      The string including the reward details of the offer.
//                      Could be either percentage cashback (XXX%) or fixed
//                      amount cashback (XXX$).
//   expiry             The timestamp when the offer will go expired. Expired
//                      offers will not be shown in the frontend.
//   offer_details_url  The link leading to the offer details page on Gpay app.
//   promo_code         The promo code to be autofilled for a promo code offer.
//   value_prop_text    Server-driven UI string to explain the value of the
//                      offer.
//   see_details_text   Server-driven UI string to imply or link additional
//                      details.
//   usage_instructions_text
//                      Server-driven UI string to instruct the user on how they
//                      can redeem the offer.
// -----------------------------------------------------------------------------
// offer_eligible_instrument
//                      Contains the mapping of credit cards and card linked
//                      offers.
//
//   offer_id           Int 64 to identify the relevant offer. Matches the
//                      offer_id in the offer_data table.
//   instrument_id      The new form of instrument id of the card. Will not be
//                      used for now.
// -----------------------------------------------------------------------------
// offer_merchant_domain
//                      Contains the mapping of merchant domains and card linked
//                      offers.
//
//   offer_id           Int 64 to identify the relevant offer. Matches the
//                      offer_id in the offer_data table.
//   merchant_domain    List of full origins for merchant websites on which
//                      this offer would apply.
// -----------------------------------------------------------------------------
// virtual_card_usage_data
//                      Contains data related to retrieval attempts of a virtual
//                      card on a particular merchant domain
//
//   id                 Unique identifier for retrieval data. Generated
//                      originally in chrome sync server.
//   instrument_id      The instrument id of the actual card that the virtual
//                      card is related to.
//   merchant_domain    The merchant domain the usage data is linked to.
//   last_four          The last four digits of the virtual card number. This is
//                      tied to the usage data because the virtual card number
//                      may vary depending on merchants.
// -----------------------------------------------------------------------------
// local_stored_cvc     This table contains credit card CVC data stored locally
//                      in Chrome.
//
//   guid               A guid string to identify the corresponding locally
//                      stored credit card in the credit_cards table.
//   value_encrypted    Encrypted CVC value of the card. May be 3 digits or 4
//                      digits depending on the card issuer.
//   last_updated_timestamp
//                      The timestamp of the most recent update to the data
//                      entry.
// -----------------------------------------------------------------------------
// server_stored_cvc    This table contains credit card CVC data stored synced
//                      to Chrome Sync's Kansas server.
//
//   instrument_id      A server generated id to identify the corresponding
//                      credit cards stored in the masked_credit_cards table.
//   value_encrypted    Encrypted CVC value of the card. May be 3 digits or 4
//                      digits depending on the card issuer.
//   last_updated_timestamp
//                      The timestamp of the most recent update to the data
//                      entry.
// -----------------------------------------------------------------------------
// masked_bank_accounts_metadata
//                      Metadata (currently, usage data) about masked bank
//                      accounts. This will be synced. This is not part of the
//                      `masked_bank_accounts` table as that table is deleted
//                      and recreated on every sync where as this table is
//                      simply updated after a sync.
//
//   instrument_id      The server-generated id for the bank account.
//   use_count          The number of times this bank account has been used.
//   use_date           The date this bank account was last used.
// -----------------------------------------------------------------------------
// masked_bank_accounts This table contains the bank account data synced via
//                      Chrome Sync.
//
//   instrument_id      The identifier assigned by the GPay server to this bank
//                      account. This is intended to be a unique field.
//   bank_name          The name of the bank where the account is registered.
//   account_number_suffix
//                      The last four digits of the bank account, with which the
//                      user can identify the account.
//   account_type       The type of bank account. This is an integer mapping to
//                      one of the following types: {Checking, Savings, Current,
//                      Salary, Transacting}
//   nickname           The nickname set by the user for the payment instrument.
//   display_icon_url   The URL for the icon to be displayed when showing the
//                      payment instrument to the user.
// -----------------------------------------------------------------------------
// masked_credit_card_benefits
//                      This table contains the multi-valued benefits fields
//                      associated with a credit card, i.e., credit-card-linked
//                      benefits that help users save money on online purchases.
//
//   benefit_id         The unique ID for this benefit data. Generated
//                      originally in Chrome Sync server.
//   instrument_id      The instrument id string that identifies the credit card
//                      to which the benefit belongs to. Identical to
//                      `instrument_id` field in `masked_credit_cards`.
//   benefit_type       The type of benefit. Either category, merchant, or flat
//                      rate.
//   benefit_category   The category that the benefit applies to. Only set when
//                      `benefit_type` == category.
//   benefit_description
//                      A description of what the credit card benefit offers the
//                      user for purchases. Shown in the Autofill suggestion UI.
//   start_time         Timestamp when the benefit is active and should be
//                      displayed. Empty if no time range is specific for the
//                      benefit.
//   end_time           Timestamp When the benefit is no longer active and
//                      should no longer be displayed. This field is only set
//                      for benefits with an expiration date. Empty if the
//                      benefit will last indefinitely.
// -----------------------------------------------------------------------------
// benefit_merchant_domains
//                      Contains the mapping of non-personalized credit card
//                      merchant benefits to eligible merchant domains. A
//                      benefit may apply to multiple domains (and span
//                      multiple rows in this table).
//
//   benefit_id         Unique ID to identify the relevant benefit. Matches the
//                      `benefit_id` in the `masked_credit_card_benefits` table.
//   merchant_domain    Origin for merchant websites on which this benefit
//                      would apply.
// -----------------------------------------------------------------------------
// generic_payment_instruments
//                      Contains serialized versions of payment instruments such
//                      as eWallets.
//
//   instrument_id      The server-generated ID for the payment instrument.
//   serialized_value_encrypted
//                      A byte-encoded representation of the payment
//                      instrument's protobuf, encrypted.
// -----------------------------------------------------------------------------
class PaymentsAutofillTable : public WebDatabaseTable {};

}  // namespace autofill

#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_PAYMENTS_PAYMENTS_AUTOFILL_TABLE_H_