Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Internal/FraudPro...
File: PaymentMethodEventTracker.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* PaymentMethodEventTracker class file.
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
declare( strict_types=1 );
[5] Fix | Delete
[6] Fix | Delete
namespace Automattic\WooCommerce\Internal\FraudProtection;
[7] Fix | Delete
[8] Fix | Delete
defined( 'ABSPATH' ) || exit;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Tracks payment method events for fraud protection analysis.
[12] Fix | Delete
*
[13] Fix | Delete
* This class provides methods to track events for adding payment methods in My Account page
[14] Fix | Delete
* for fraud protection. Event-specific data is passed to the SessionDataCollector which
[15] Fix | Delete
* handles session data storage internally.
[16] Fix | Delete
*
[17] Fix | Delete
* @since 10.5.0
[18] Fix | Delete
* @internal This class is part of the internal API and is subject to change without notice.
[19] Fix | Delete
*/
[20] Fix | Delete
class PaymentMethodEventTracker {
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Session data collector instance.
[24] Fix | Delete
*
[25] Fix | Delete
* @var SessionDataCollector
[26] Fix | Delete
*/
[27] Fix | Delete
private SessionDataCollector $session_data_collector;
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Initialize with dependencies.
[31] Fix | Delete
*
[32] Fix | Delete
* @internal
[33] Fix | Delete
*
[34] Fix | Delete
* @param SessionDataCollector $session_data_collector The session data collector instance.
[35] Fix | Delete
*/
[36] Fix | Delete
final public function init( SessionDataCollector $session_data_collector ): void {
[37] Fix | Delete
$this->session_data_collector = $session_data_collector;
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Track add payment method page loaded event.
[42] Fix | Delete
*
[43] Fix | Delete
* Collects session data when the add payment method page is initially loaded.
[44] Fix | Delete
* This captures the initial session state before any user interactions.
[45] Fix | Delete
*
[46] Fix | Delete
* @internal
[47] Fix | Delete
* @return void
[48] Fix | Delete
*/
[49] Fix | Delete
public function track_add_payment_method_page_loaded(): void {
[50] Fix | Delete
$this->session_data_collector->collect( 'add_payment_method_page_loaded', array() );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Track payment method added event.
[55] Fix | Delete
*
[56] Fix | Delete
* Collects session data when a payment method is added.
[57] Fix | Delete
*
[58] Fix | Delete
* @internal
[59] Fix | Delete
*
[60] Fix | Delete
* @param int $token_id The newly created token ID.
[61] Fix | Delete
* @param \WC_Payment_Token $token The payment token object.
[62] Fix | Delete
*/
[63] Fix | Delete
public function track_payment_method_added( $token_id, $token ): void {
[64] Fix | Delete
$event_data = $this->build_payment_method_event_data( 'added', $token );
[65] Fix | Delete
[66] Fix | Delete
$this->session_data_collector->collect( 'payment_method_added', $event_data );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Build payment method event-specific data.
[71] Fix | Delete
*
[72] Fix | Delete
* Extracts relevant information from the payment token object including
[73] Fix | Delete
* token type, gateway ID, user ID, and card details for card tokens.
[74] Fix | Delete
* This data will be merged with session data during collection.
[75] Fix | Delete
*
[76] Fix | Delete
* @param string $action Action type (added, updated, set_default, deleted, add_failed).
[77] Fix | Delete
* @param \WC_Payment_Token $token The payment token object.
[78] Fix | Delete
* @return array Payment method event data.
[79] Fix | Delete
*/
[80] Fix | Delete
private function build_payment_method_event_data( string $action, \WC_Payment_Token $token ): array {
[81] Fix | Delete
$event_data = array(
[82] Fix | Delete
'action' => $action,
[83] Fix | Delete
'token_id' => $token->get_id(),
[84] Fix | Delete
'token_type' => $token->get_type(),
[85] Fix | Delete
'gateway_id' => $token->get_gateway_id(),
[86] Fix | Delete
'user_id' => $token->get_user_id(),
[87] Fix | Delete
'is_default' => $token->is_default(),
[88] Fix | Delete
);
[89] Fix | Delete
[90] Fix | Delete
// Add card-specific details if this is a credit card token.
[91] Fix | Delete
if ( $token instanceof \WC_Payment_Token_CC ) {
[92] Fix | Delete
$event_data['card_type'] = $token->get_card_type();
[93] Fix | Delete
$event_data['card_last4'] = $token->get_last4();
[94] Fix | Delete
$event_data['expiry_month'] = $token->get_expiry_month();
[95] Fix | Delete
$event_data['expiry_year'] = $token->get_expiry_year();
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
return $event_data;
[99] Fix | Delete
}
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function