Commit cb7523c569 for woocommerce
commit cb7523c569ff32a5e909d075dad9fe8997025b05
Author: Leonardo Lopes de Albuquerque <leonardo.albuquerque@automattic.com>
Date: Thu Jan 15 17:11:44 2026 -0300
[Fraud Protection] Removed FraudProtectionTracker (#62825)
Removed FraudProtectionTracker as the code was moved to FraudProtectionDispatcher
diff --git a/plugins/woocommerce/src/Internal/FraudProtection/FraudProtectionTracker.php b/plugins/woocommerce/src/Internal/FraudProtection/FraudProtectionTracker.php
deleted file mode 100644
index ed93dcd3e9..0000000000
--- a/plugins/woocommerce/src/Internal/FraudProtection/FraudProtectionTracker.php
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-/**
- * FraudProtectionTracker class file.
- */
-
-declare( strict_types=1 );
-
-namespace Automattic\WooCommerce\Internal\FraudProtection;
-
-defined( 'ABSPATH' ) || exit;
-
-/**
- * Centralized fraud protection event tracker.
- *
- * This class provides a unified interface for tracking fraud protection events.
- * It logs events for the fraud protection service using already-collected data.
- *
- * @since 10.5.0
- * @internal This class is part of the internal API and is subject to change without notice.
- */
-class FraudProtectionTracker {
-
- /**
- * Track fraud protection event with already-collected data.
- *
- * This method accepts fully-collected event data (including session context)
- * and logs it for the fraud protection service.
- *
- * The method implements graceful degradation - any errors during tracking
- * will be logged but will not break the functionality.
- *
- * @param string $event_type Event type identifier (e.g., 'cart_item_added').
- * @param array $collected_data Fully-collected event data including session context.
- * @return void
- */
- public function track_event( string $event_type, array $collected_data ): void {
- try {
- // phpcs:ignore Generic.Commenting.Todo.TaskFound
- // TODO: Once EventTracker/API client is implemented (WOOSUBS-1249), call it here:
- // $event_tracker = wc_get_container()->get( EventTracker::class );
- // $event_tracker->track( $event_type, $collected_data );
- //
- // For now, log the event for debugging and verification.
- FraudProtectionController::log(
- 'info',
- sprintf(
- 'Fraud protection event tracked: %s | Session ID: %s',
- $event_type,
- $collected_data['session']['session_id'] ?? 'N/A'
- ),
- array(
- 'event_type' => $event_type,
- 'collected_data' => $collected_data,
- )
- );
- } catch ( \Exception $e ) {
- // Gracefully handle errors - fraud protection should never break functionality.
- FraudProtectionController::log(
- 'error',
- sprintf(
- 'Failed to track fraud protection event: %s | Error: %s',
- $event_type,
- $e->getMessage()
- ),
- array(
- 'event_type' => $event_type,
- 'exception' => $e,
- )
- );
- }
- }
-}
diff --git a/plugins/woocommerce/tests/php/src/Internal/FraudProtection/FraudProtectionTrackerTest.php b/plugins/woocommerce/tests/php/src/Internal/FraudProtection/FraudProtectionTrackerTest.php
deleted file mode 100644
index 9c8394d2cb..0000000000
--- a/plugins/woocommerce/tests/php/src/Internal/FraudProtection/FraudProtectionTrackerTest.php
+++ /dev/null
@@ -1,125 +0,0 @@
-<?php
-/**
- * FraudProtectionTrackerTest class file.
- */
-
-declare( strict_types = 1 );
-
-namespace Automattic\WooCommerce\Tests\Internal\FraudProtection;
-
-use Automattic\WooCommerce\Internal\FraudProtection\FraudProtectionTracker;
-use Automattic\WooCommerce\RestApi\UnitTests\LoggerSpyTrait;
-
-/**
- * Tests for FraudProtectionTracker.
- *
- * @covers \Automattic\WooCommerce\Internal\FraudProtection\FraudProtectionTracker
- */
-class FraudProtectionTrackerTest extends \WC_Unit_Test_Case {
-
- use LoggerSpyTrait;
-
- /**
- * The system under test.
- *
- * @var FraudProtectionTracker
- */
- private $sut;
-
- /**
- * Runs before each test.
- */
- public function setUp(): void {
- parent::setUp();
-
- // Create system under test.
- $this->sut = new FraudProtectionTracker();
- }
-
- /**
- * Test track_event logs collected data successfully.
- */
- public function test_track_event_logs_collected_data_successfully(): void {
- $event_type = 'test_event';
- $collected_data = array(
- 'session' => array( 'session_id' => 'test-session-123' ),
- 'action' => 'test_action',
- 'product_id' => 123,
- );
-
- // Call track_event.
- $this->sut->track_event( $event_type, $collected_data );
-
- // Verify the log was captured.
- $this->assertCount( 1, $this->captured_logs );
- $this->assertEquals( 'info', $this->captured_logs[0]['level'] );
- $this->assertStringContainsString( 'test_event', $this->captured_logs[0]['message'] );
- $this->assertStringContainsString( 'test-session-123', $this->captured_logs[0]['message'] );
- $this->assertEquals( 'test_event', $this->captured_logs[0]['context']['event_type'] );
- $this->assertEquals( $collected_data, $this->captured_logs[0]['context']['collected_data'] );
- }
-
- /**
- * Test track_event handles data without session gracefully.
- */
- public function test_track_event_handles_data_without_session_gracefully(): void {
- $event_type = 'test_event';
- $collected_data = array( 'invalid' => 'data_without_session' );
-
- // Call track_event with data without session - should handle gracefully and log with N/A.
- $this->sut->track_event( $event_type, $collected_data );
-
- // Verify the log was captured with N/A for session ID.
- $this->assertCount( 1, $this->captured_logs );
- $this->assertEquals( 'info', $this->captured_logs[0]['level'] );
- $this->assertStringContainsString( 'test_event', $this->captured_logs[0]['message'] );
- $this->assertStringContainsString( 'N/A', $this->captured_logs[0]['message'] );
- $this->assertEquals( 'test_event', $this->captured_logs[0]['context']['event_type'] );
- $this->assertEquals( $collected_data, $this->captured_logs[0]['context']['collected_data'] );
- }
-
- /**
- * Test track_event accepts various data structures.
- */
- public function test_track_event_accepts_various_data_structures(): void {
- $event_type = 'cart_item_added';
- $collected_data = array(
- 'session' => array( 'session_id' => 'test' ),
- 'action' => 'item_added',
- 'product_id' => 456,
- 'quantity' => 2,
- );
-
- // Call track_event.
- $this->sut->track_event( $event_type, $collected_data );
-
- // Verify the log was captured with all data.
- $this->assertCount( 1, $this->captured_logs );
- $this->assertEquals( 'info', $this->captured_logs[0]['level'] );
- $this->assertStringContainsString( 'cart_item_added', $this->captured_logs[0]['message'] );
- $this->assertEquals( 'cart_item_added', $this->captured_logs[0]['context']['event_type'] );
- $this->assertEquals( $collected_data, $this->captured_logs[0]['context']['collected_data'] );
- $this->assertEquals( 'item_added', $this->captured_logs[0]['context']['collected_data']['action'] );
- $this->assertEquals( 456, $this->captured_logs[0]['context']['collected_data']['product_id'] );
- $this->assertEquals( 2, $this->captured_logs[0]['context']['collected_data']['quantity'] );
- }
-
- /**
- * Test track_event works with empty collected data.
- */
- public function test_track_event_works_with_empty_collected_data(): void {
- $event_type = 'test_event';
- $collected_data = array();
-
- // Call track_event with empty data.
- $this->sut->track_event( $event_type, $collected_data );
-
- // Verify the log was captured even with empty data.
- $this->assertCount( 1, $this->captured_logs );
- $this->assertEquals( 'info', $this->captured_logs[0]['level'] );
- $this->assertStringContainsString( 'test_event', $this->captured_logs[0]['message'] );
- $this->assertStringContainsString( 'N/A', $this->captured_logs[0]['message'] );
- $this->assertEquals( 'test_event', $this->captured_logs[0]['context']['event_type'] );
- $this->assertEquals( $collected_data, $this->captured_logs[0]['context']['collected_data'] );
- }
-}