PHP Class WC_Payment_Tokens

An API for storing and managing tokens for gateways and customers.
Since: 2.6.0
Author: WooThemes
Show file Open project: woocommerce/woocommerce Class Usage Examples

Public Methods

Method Description
delete ( WC_Payment_Token $token_id ) Remove a payment token from the database by ID.
get ( integer $token_id, $token_result = null ) : WC_Payment_Token | null Get a token object by ID.
get_customer_default_token ( integer $customer_id ) : WC_Payment_Token | null Returns a customers default token or NULL if there is no default token.
get_customer_tokens ( integer $customer_id, string $gateway_id = '' ) : array Returns an array of payment token objects associated with the passed customer ID.
get_order_tokens ( integer $order_id ) : array Returns an array of payment token objects associated with the passed order ID.
get_token_type_by_id ( integer $token_id ) : string Returns what type (credit card, echeck, etc) of token a token is by ID.
get_tokens ( array $args ) : array Gets valid tokens from the database based on user defined criteria.
set_users_default ( integer $user_id, integer $token_id ) Loops through all of a users payment tokens and sets is_default to false for all but a specific token.

Method Details

delete() public static method

Remove a payment token from the database by ID.
Since: 2.6.0
public static delete ( WC_Payment_Token $token_id )
$token_id WC_Payment_Token Token ID

get() public static method

Get a token object by ID.
Since: 2.6.0
public static get ( integer $token_id, $token_result = null ) : WC_Payment_Token | null
$token_id integer Token ID
return WC_Payment_Token | null Returns a valid payment token or null if no token can be found

get_customer_default_token() public static method

Returns a customers default token or NULL if there is no default token.
Since: 2.6.0
public static get_customer_default_token ( integer $customer_id ) : WC_Payment_Token | null
$customer_id integer
return WC_Payment_Token | null

get_customer_tokens() public static method

Returns an array of payment token objects associated with the passed customer ID.
Since: 2.6.0
public static get_customer_tokens ( integer $customer_id, string $gateway_id = '' ) : array
$customer_id integer Customer ID
$gateway_id string Optional Gateway ID for getting tokens for a specific gateway
return array Array of token objects

get_order_tokens() public static method

Returns an array of payment token objects associated with the passed order ID.
Since: 2.6.0
public static get_order_tokens ( integer $order_id ) : array
$order_id integer Order ID
return array Array of token objects

get_token_type_by_id() public static method

Returns what type (credit card, echeck, etc) of token a token is by ID.
Since: 2.6.0
public static get_token_type_by_id ( integer $token_id ) : string
$token_id integer Token ID
return string Type

get_tokens() public static method

Gets valid tokens from the database based on user defined criteria.
Since: 2.6.0
public static get_tokens ( array $args ) : array
$args array
return array

set_users_default() public static method

Loops through all of a users payment tokens and sets is_default to false for all but a specific token.
Since: 2.6.0
public static set_users_default ( integer $user_id, integer $token_id )
$user_id integer User to set a default for
$token_id integer The ID of the token that should be default