Merge pull request #19942 from woocommerce/tweak/gdpr-customer-tokens
Introduce GDPR export/erase for customer tokens
This commit is contained in:
commit
d4e8ae093d
|
@ -310,4 +310,52 @@ class WC_Privacy_Erasers {
|
|||
*/
|
||||
do_action( 'woocommerce_privacy_remove_order_personal_data', $order );
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and erases customer tokens by email address.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @param string $email_address The user email address.
|
||||
* @param int $page Page.
|
||||
* @return array An array of personal data in name value pairs
|
||||
*/
|
||||
public static function customer_tokens_eraser( $email_address, $page ) {
|
||||
$response = array(
|
||||
'items_removed' => false,
|
||||
'items_retained' => false,
|
||||
'messages' => array(),
|
||||
'done' => true,
|
||||
);
|
||||
|
||||
$user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
|
||||
|
||||
if ( ! $user instanceof WP_User ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$tokens = WC_Payment_Tokens::get_tokens( array(
|
||||
'user_id' => $user->ID,
|
||||
) );
|
||||
|
||||
if ( empty( $tokens ) ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
foreach ( $tokens as $token ) {
|
||||
WC_Payment_Tokens::delete( $token->get_id() );
|
||||
|
||||
/* Translators: %s Prop name. */
|
||||
$response['messages'][] = sprintf( __( 'Removed payment token "%d"', 'woocommerce' ), $token->get_id() );
|
||||
$response['items_removed'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow extensions to remove data for tokens and adjust the response.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @param array $response Array resonse data. Must include messages, num_items_removed, num_items_retained, done.
|
||||
* @param array $tokens Array of tokens.
|
||||
*/
|
||||
return apply_filters( 'woocommerce_privacy_erase_personal_data_tokens', $response, $tokens );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -350,4 +350,49 @@ class WC_Privacy_Exporters {
|
|||
|
||||
return $personal_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and exports customer tokens by email address.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @param string $email_address The user email address.
|
||||
* @param int $page Page.
|
||||
* @return array An array of personal data in name value pairs
|
||||
*/
|
||||
public static function customer_tokens_exporter( $email_address, $page ) {
|
||||
$user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
|
||||
$data_to_export = array();
|
||||
|
||||
if ( ! $user instanceof WP_User ) {
|
||||
return array(
|
||||
'data' => $data_to_export,
|
||||
'done' => true,
|
||||
);
|
||||
}
|
||||
|
||||
$tokens = WC_Payment_Tokens::get_tokens( array(
|
||||
'user_id' => $user->ID,
|
||||
'limit' => 10,
|
||||
'page' => $page,
|
||||
) );
|
||||
|
||||
if ( 0 < count( $tokens ) ) {
|
||||
foreach ( $tokens as $token ) {
|
||||
$data_to_export[] = array(
|
||||
'group_id' => 'woocommerce_tokens',
|
||||
'group_label' => __( 'Payment Tokens', 'woocommerce' ),
|
||||
'item_id' => 'token-' . $token->get_id(),
|
||||
'data' => $token->get_display_name(),
|
||||
);
|
||||
}
|
||||
$done = 10 > count( $tokens );
|
||||
} else {
|
||||
$done = true;
|
||||
}
|
||||
|
||||
return array(
|
||||
'data' => $data_to_export,
|
||||
'done' => true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,11 +38,13 @@ class WC_Privacy extends WC_Abstract_Privacy {
|
|||
$this->add_exporter( 'woocommerce-customer-data', __( 'Customer Data', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'customer_data_exporter' ) );
|
||||
$this->add_exporter( 'woocommerce-customer-orders', __( 'Customer Orders', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'order_data_exporter' ) );
|
||||
$this->add_exporter( 'woocommerce-customer-downloads', __( 'Customer Downloads', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'download_data_exporter' ) );
|
||||
$this->add_exporter( 'woocommerce-customer-tokens', __( 'Customer Tokens', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'customer_tokens_exporter' ) );
|
||||
|
||||
// This hook registers WooCommerce data erasers.
|
||||
$this->add_eraser( 'woocommerce-customer-data', __( 'Customer Data', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'customer_data_eraser' ) );
|
||||
$this->add_eraser( 'woocommerce-customer-orders', __( 'Customer Orders', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'order_data_eraser' ) );
|
||||
$this->add_eraser( 'woocommerce-customer-downloads', __( 'Customer Downloads', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'download_data_eraser' ) );
|
||||
$this->add_eraser( 'woocommerce-customer-tokens', __( 'Customer Tokens', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'customer_tokens_eraser' ) );
|
||||
|
||||
// Cleanup orders daily - this is a callback on a daily cron event.
|
||||
add_action( 'woocommerce_cleanup_personal_data', array( $this, 'queue_cleanup_personal_data' ) );
|
||||
|
|
|
@ -262,6 +262,12 @@ class WC_Payment_Token_Data_Store extends WC_Data_Store_WP implements WC_Payment
|
|||
$gateway_ids = $gateways->get_payment_gateway_ids();
|
||||
}
|
||||
|
||||
$page = isset( $args['page'] ) ? absint( $args['page'] ) : 1;
|
||||
$posts_per_page = isset( $args['limit'] ) ? absint( $args['limit'] ) : get_option( 'posts_per_page' );
|
||||
|
||||
$pgstrt = absint( ( $page - 1 ) * $posts_per_page ) . ', ';
|
||||
$limits = 'LIMIT ' . $pgstrt . $posts_per_page;
|
||||
|
||||
$gateway_ids[] = '';
|
||||
$where[] = "gateway_id IN ('" . implode( "','", array_map( 'esc_sql', $gateway_ids ) ) . "')";
|
||||
|
||||
|
@ -270,7 +276,7 @@ class WC_Payment_Token_Data_Store extends WC_Data_Store_WP implements WC_Payment
|
|||
}
|
||||
|
||||
// phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
||||
$token_results = $wpdb->get_results( $sql . ' WHERE ' . implode( ' AND ', $where ) );
|
||||
$token_results = $wpdb->get_results( $sql . ' WHERE ' . implode( ' AND ', $where ) . ' ' . $limits );
|
||||
|
||||
return $token_results;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,12 @@ class WC_Payment_Token_ECheck extends WC_Payment_Token {
|
|||
* @return string
|
||||
*/
|
||||
public function get_display_name( $deprecated = '' ) {
|
||||
return __( 'eCheck', 'woocommerce' );
|
||||
$display = sprintf(
|
||||
/* translators: 1: credit card type 2: last 4 digits 3: expiry month 4: expiry year */
|
||||
__( 'eCheck ending in %1$s', 'woocommerce' ),
|
||||
$this->get_last4()
|
||||
);
|
||||
return $display;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue