WC_Payment_Token_Data_Store
extends WC_Data_Store_WP
in package
implements
WC_Object_Data_Store_Interface, WC_Payment_Token_Data_Store_Interface
WC Payment Token Data Store: Custom Table.
Tags
Interfaces, Classes and Traits
- WC_Object_Data_Store_Interface
- WC Data Store Interface
- WC_Payment_Token_Data_Store_Interface
- WC Payment Token Data Store Interface
Table of Contents
- $extra_data_saved : bool
- If we have already saved our extra data, don't do automatic / default handling.
- $internal_meta_keys : array<string|int, mixed>
- Data stored in meta keys, but not considered "meta" for an object.
- $meta_type : string
- Meta type. Payment tokens are a new object type.
- $must_exist_meta_keys : array<string|int, mixed>
- Meta data which should exist in the DB, even if empty.
- $object_id_field_for_meta : string
- This only needs set if you are using a custom metadata type (for example payment tokens.
- add_meta() : int
- Add new piece of meta.
- create() : mixed
- Create a new payment token in the database.
- delete() : bool
- Remove a payment token from the database.
- delete_from_lookup_table() : mixed
- Delete lookup table data for an ID.
- delete_meta() : mixed
- Deletes meta based on meta ID.
- filter_raw_meta_data() : mixed|void
- Helper method to filter internal meta keys from all meta data rows for the object.
- get_internal_meta_keys() : array<string|int, mixed>
- Return list of internal meta keys.
- get_metadata() : array<string|int, mixed>
- Returns metadata for a specific payment token.
- get_token_by_id() : object
- Returns an stdObject of a token.
- get_token_type_by_id() : string
- Get a token's type by ID.
- get_tokens() : array<string|int, mixed>
- Returns an array of objects (stdObject) matching specific token criteria.
- get_users_default_token() : object
- Returns an stdObject of a token for a user's default token.
- parse_date_for_wp_query() : array<string|int, mixed>
- Map a valid date query var to WP_Query arguments.
- read() : mixed
- Read a token from the database.
- read_meta() : array<string|int, mixed>
- Returns an array of meta for an object.
- set_default_status() : void
- Update's a tokens default status in the database. Used for quickly looping through tokens and setting their statuses instead of creating a bunch of objects.
- update() : mixed
- Update a payment token.
- update_meta() : mixed
- Update meta.
- exclude_internal_meta_keys() : bool
- Callback to remove unwanted meta data.
- get_data_for_lookup_table() : array<string|int, mixed>
- Get data to save to a lookup table.
- get_db_info() : array<string|int, mixed>
- Table structure is slightly different between meta types, this function will return what we need to know.
- get_primary_key_for_lookup_table() : string
- Get primary key name for lookup table.
- get_props_to_update() : array<string|int, mixed>
- Gets a list of props and meta keys that need updated based on change state or if they are present in the database or not.
- get_search_stopwords() : array<string|int, mixed>
- Retrieve stopwords used when parsing search terms.
- get_term_ids() : array<string|int, mixed>
- Get and store terms from a taxonomy.
- get_valid_search_terms() : array<string|int, mixed>
- Check if the terms are suitable for searching.
- get_wp_query_args() : array<string|int, mixed>
- Get valid WP_Query args from a WC_Object_Query's query variables.
- prefix_key() : string
- Internal meta keys we don't want exposed as part of meta_data. This is in addition to all data props with _ prefix.
- read_extra_data() : mixed
- Read extra data associated with the token (like last4 digits of a card for expiry dates).
- save_extra_data() : array<string|int, mixed>
- Saves extra token data as meta.
- string_to_timestamp() : int|null
- Converts a WP post date string into a timestamp.
- update_lookup_table() : null
- Update a lookup table for an object.
- update_or_delete_post_meta() : bool
- Update meta data in, or delete it from, the database.
Properties
$extra_data_saved
If we have already saved our extra data, don't do automatic / default handling.
protected
bool
$extra_data_saved
= alse
$internal_meta_keys
Data stored in meta keys, but not considered "meta" for an object.
protected
array<string|int, mixed>
$internal_meta_keys
= array()
Tags
$meta_type
Meta type. Payment tokens are a new object type.
protected
string
$meta_type
= 'payment_token'
$must_exist_meta_keys
Meta data which should exist in the DB, even if empty.
protected
array<string|int, mixed>
$must_exist_meta_keys
= array()
Tags
$object_id_field_for_meta
This only needs set if you are using a custom metadata type (for example payment tokens.
protected
string
$object_id_field_for_meta
= ''
This should be the name of the field your table uses for associating meta with objects. For example, in payment_tokenmeta, this would be payment_token_id.
Methods
add_meta()
Add new piece of meta.
public
add_meta(WC_Data &$object, stdClass $meta) : int
Parameters
- $object : WC_Data
-
WC_Data object.
- $meta : stdClass
-
(containing ->key and ->value).
Tags
Return values
int — meta IDcreate()
Create a new payment token in the database.
public
create(WC_Payment_Token &$token) : mixed
Parameters
- $token : WC_Payment_Token
-
Payment token object.
Tags
Return values
mixed —delete()
Remove a payment token from the database.
public
delete(WC_Payment_Token &$token[, bool $force_delete = false ]) : bool
Parameters
- $token : WC_Payment_Token
-
Payment token object.
- $force_delete : bool = false
-
Unused param.
Tags
Return values
bool — resultdelete_from_lookup_table()
Delete lookup table data for an ID.
public
delete_from_lookup_table(int $id, string $table) : mixed
Parameters
- $id : int
-
ID of object to update.
- $table : string
-
Lookup table name.
Tags
Return values
mixed —delete_meta()
Deletes meta based on meta ID.
public
delete_meta(WC_Data &$object, stdClass $meta) : mixed
Parameters
- $object : WC_Data
-
WC_Data object.
- $meta : stdClass
-
(containing at least ->id).
Tags
Return values
mixed —filter_raw_meta_data()
Helper method to filter internal meta keys from all meta data rows for the object.
public
filter_raw_meta_data(WC_Data &$object, array<string|int, mixed> $raw_meta_data) : mixed|void
Parameters
- $object : WC_Data
-
WC_Data object.
- $raw_meta_data : array<string|int, mixed>
-
Array of std object of meta data to be filtered.
Tags
Return values
mixed|void —get_internal_meta_keys()
Return list of internal meta keys.
public
get_internal_meta_keys() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_metadata()
Returns metadata for a specific payment token.
public
get_metadata(int $token_id) : array<string|int, mixed>
Parameters
- $token_id : int
-
Token ID.
Tags
Return values
array<string|int, mixed> —get_token_by_id()
Returns an stdObject of a token.
public
get_token_by_id(int $token_id) : object
Should contain the fields token_id, gateway_id, token, user_id, type, is_default.
Parameters
- $token_id : int
-
Token ID.
Tags
Return values
object —get_token_type_by_id()
Get a token's type by ID.
public
get_token_type_by_id(int $token_id) : string
Parameters
- $token_id : int
-
Token ID.
Tags
Return values
string —get_tokens()
Returns an array of objects (stdObject) matching specific token criteria.
public
get_tokens(array<string|int, mixed> $args) : array<string|int, mixed>
Accepts token_id, user_id, gateway_id, and type. Each object should contain the fields token_id, gateway_id, token, user_id, type, is_default.
Parameters
- $args : array<string|int, mixed>
-
List of accepted args: token_id, gateway_id, user_id, type.
Tags
Return values
array<string|int, mixed> —get_users_default_token()
Returns an stdObject of a token for a user's default token.
public
get_users_default_token(int $user_id) : object
Should contain the fields token_id, gateway_id, token, user_id, type, is_default.
Parameters
- $user_id : int
-
User ID.
Tags
Return values
object —parse_date_for_wp_query()
Map a valid date query var to WP_Query arguments.
public
parse_date_for_wp_query(mixed $query_var, string $key[, array<string|int, mixed> $wp_query_args = array() ]) : array<string|int, mixed>
Valid date formats: YYYY-MM-DD or timestamp, possibly combined with an operator from $valid_operators. Also accepts a WC_DateTime object.
Parameters
- $query_var : mixed
-
A valid date format.
- $key : string
-
meta or db column key.
- $wp_query_args : array<string|int, mixed> = array()
-
WP_Query args.
Tags
Return values
array<string|int, mixed> — Modified $wp_query_argsread()
Read a token from the database.
public
read(WC_Payment_Token &$token) : mixed
Parameters
- $token : WC_Payment_Token
-
Payment token object.
Tags
Return values
mixed —read_meta()
Returns an array of meta for an object.
public
read_meta(WC_Data &$object) : array<string|int, mixed>
Parameters
- $object : WC_Data
-
WC_Data object.
Tags
Return values
array<string|int, mixed> —set_default_status()
Update's a tokens default status in the database. Used for quickly looping through tokens and setting their statuses instead of creating a bunch of objects.
public
set_default_status(int $token_id[, bool $status = true ]) : void
Parameters
- $token_id : int
-
Token ID.
- $status : bool = true
-
Whether given payment token is the default payment token or not.
Tags
Return values
void —update()
Update a payment token.
public
update(WC_Payment_Token &$token) : mixed
Parameters
- $token : WC_Payment_Token
-
Payment token object.
Tags
Return values
mixed —update_meta()
Update meta.
public
update_meta(WC_Data &$object, stdClass $meta) : mixed
Parameters
- $object : WC_Data
-
WC_Data object.
- $meta : stdClass
-
(containing ->id, ->key and ->value).
Tags
Return values
mixed —exclude_internal_meta_keys()
Callback to remove unwanted meta data.
protected
exclude_internal_meta_keys(object $meta) : bool
Parameters
- $meta : object
-
Meta object to check if it should be excluded or not.
Return values
bool —get_data_for_lookup_table()
Get data to save to a lookup table.
protected
get_data_for_lookup_table(int $id, string $table) : array<string|int, mixed>
Parameters
- $id : int
-
ID of object to update.
- $table : string
-
Lookup table name.
Tags
Return values
array<string|int, mixed> —get_db_info()
Table structure is slightly different between meta types, this function will return what we need to know.
protected
get_db_info() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — Array elements: table, object_id_field, meta_id_fieldget_primary_key_for_lookup_table()
Get primary key name for lookup table.
protected
get_primary_key_for_lookup_table(string $table) : string
Parameters
- $table : string
-
Lookup table name.
Tags
Return values
string —get_props_to_update()
Gets a list of props and meta keys that need updated based on change state or if they are present in the database or not.
protected
get_props_to_update(WC_Data $object, array<string|int, mixed> $meta_key_to_props[, string $meta_type = 'post' ]) : array<string|int, mixed>
Parameters
- $object : WC_Data
-
The WP_Data object (WC_Coupon for coupons, etc).
- $meta_key_to_props : array<string|int, mixed>
-
A mapping of meta keys => prop names.
- $meta_type : string = 'post'
-
The internal WP meta type (post, user, etc).
Return values
array<string|int, mixed> — A mapping of meta keys => prop names, filtered by ones that should be updated.get_search_stopwords()
Retrieve stopwords used when parsing search terms.
protected
get_search_stopwords() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — Stopwords.get_term_ids()
Get and store terms from a taxonomy.
protected
get_term_ids(WC_Data|int $object, string $taxonomy) : array<string|int, mixed>
Parameters
- $object : WC_Data|int
-
WC_Data object or object ID.
- $taxonomy : string
-
Taxonomy name e.g. product_cat.
Tags
Return values
array<string|int, mixed> — of termsget_valid_search_terms()
Check if the terms are suitable for searching.
protected
get_valid_search_terms(array<string|int, mixed> $terms) : array<string|int, mixed>
Uses an array of stopwords (terms) that are excluded from the separate term matching when searching for posts. The list of English stopwords is the approximate search engines list, and is translatable.
Parameters
- $terms : array<string|int, mixed>
-
Terms to check.
Tags
Return values
array<string|int, mixed> — Terms that are not stopwords.get_wp_query_args()
Get valid WP_Query args from a WC_Object_Query's query variables.
protected
get_wp_query_args(array<string|int, mixed> $query_vars) : array<string|int, mixed>
Parameters
- $query_vars : array<string|int, mixed>
-
query vars from a WC_Object_Query.
Tags
Return values
array<string|int, mixed> —prefix_key()
Internal meta keys we don't want exposed as part of meta_data. This is in addition to all data props with _ prefix.
protected
prefix_key(string $key) : string
Parameters
- $key : string
-
Prefix to be added to meta keys.
Tags
Return values
string —read_extra_data()
Read extra data associated with the token (like last4 digits of a card for expiry dates).
protected
read_extra_data(WC_Payment_Token &$token) : mixed
Parameters
- $token : WC_Payment_Token
-
Payment token object.
Tags
Return values
mixed —save_extra_data()
Saves extra token data as meta.
protected
save_extra_data(WC_Payment_Token &$token[, bool $force = false ]) : array<string|int, mixed>
Parameters
- $token : WC_Payment_Token
-
Payment token object.
- $force : bool = false
-
By default, only changed props are updated. When this param is true all props are updated.
Tags
Return values
array<string|int, mixed> — List of updated props.string_to_timestamp()
Converts a WP post date string into a timestamp.
protected
string_to_timestamp(string $time_string) : int|null
Parameters
- $time_string : string
-
The WP post date string.
Tags
Return values
int|null — The date string converted to a timestamp or null.update_lookup_table()
Update a lookup table for an object.
protected
update_lookup_table(int $id, string $table) : null
Parameters
- $id : int
-
ID of object to update.
- $table : string
-
Lookup table name.
Tags
Return values
null —update_or_delete_post_meta()
Update meta data in, or delete it from, the database.
protected
update_or_delete_post_meta(WC_Data $object, string $meta_key, mixed $meta_value) : bool
Avoids storing meta when it's either an empty string or empty array.
Other empty values such as numeric 0 and null should still be stored.
Data-stores can force meta to exist using must_exist_meta_keys
.
Note: WordPress get_metadata
function returns an empty string when meta data does not exist.
Parameters
- $object : WC_Data
-
The WP_Data object (WC_Coupon for coupons, etc).
- $meta_key : string
-
Meta key to update.
- $meta_value : mixed
-
Value to save.