Skip to content

Commit 49114b4

Browse files
committed
Refactor error handling in ApiClient and remove unused OrderEventsTracker dependency from FraudProtectionController
This update modifies the error handling in the `ApiClient` class to return a `WP_Error` when the blog ID is not found, improving clarity. Additionally, the `OrderEventsTracker` dependency has been removed from the `FraudProtectionController`, streamlining the class and eliminating unnecessary code.
1 parent 0cff398 commit 49114b4

File tree

3 files changed

+4
-17
lines changed

3 files changed

+4
-17
lines changed

src/ApiClient.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,17 @@ private function make_request( string $method, string $path, string $session_id,
279279
}
280280

281281
if ( ! $this->get_blog_id() ) {
282-
FraudProtectionController::log(
283-
'error',
284-
'Jetpack blog ID not found. Is the site connected to WordPress.com? Failing open with "allow" decision.'
282+
return new \WP_Error(
283+
'blog_id_not_found',
284+
'Jetpack blog ID not found'
285285
);
286-
return self::DECISION_ALLOW;
287286
}
288287

289288
$body = \wp_json_encode(
290289
array_merge(
291290
$payload,
292291
array(
293-
'session_id' => $session_id,
292+
'session_id' => $session_id,
294293
)
295294
)
296295
);

src/FraudProtectionController.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ class FraudProtectionController /* implements RegisterHooksInterface */ {
9090
*/
9191
private SessionVerifier $session_verifier;
9292

93-
/**
94-
* Order events tracker instance.
95-
*
96-
* @var OrderEventsTracker
97-
*/
98-
private OrderEventsTracker $order_events_tracker;
99-
10093
/**
10194
* Session blocking handler instance.
10295
*
@@ -130,7 +123,6 @@ public function register(): void {
130123
* @param PaymentMethodEventTracker $payment_method_event_tracker The instance of PaymentMethodEventTracker to use.
131124
* @param SessionBlockingHandler $session_blocking_handler The instance of SessionBlockingHandler to use.
132125
* @param SessionVerifier $session_verifier The instance of SessionVerifier to use.
133-
* @param OrderEventsTracker $order_events_tracker The instance of OrderEventsTracker to use.
134126
* @param BlocksCheckoutProtector $blocks_checkout_protector The instance of BlocksCheckoutProtector to use.
135127
* @param ShortcodeCheckoutProtector $shortcode_checkout_protector The instance of ShortcodeCheckoutProtector to use.
136128
* @param AddPaymentMethodProtector $add_payment_method_protector The instance of AddPaymentMethodProtector to use.
@@ -145,7 +137,6 @@ final public function init(
145137
PaymentMethodEventTracker $payment_method_event_tracker,
146138
SessionBlockingHandler $session_blocking_handler,
147139
SessionVerifier $session_verifier,
148-
OrderEventsTracker $order_events_tracker,
149140
BlocksCheckoutProtector $blocks_checkout_protector,
150141
ShortcodeCheckoutProtector $shortcode_checkout_protector,
151142
AddPaymentMethodProtector $add_payment_method_protector,
@@ -159,7 +150,6 @@ final public function init(
159150
$this->payment_method_event_tracker = $payment_method_event_tracker;
160151
$this->session_blocking_handler = $session_blocking_handler;
161152
$this->session_verifier = $session_verifier;
162-
$this->order_events_tracker = $order_events_tracker;
163153
$this->blocks_checkout_protector = $blocks_checkout_protector;
164154
$this->shortcode_checkout_protector = $shortcode_checkout_protector;
165155
$this->add_payment_method_protector = $add_payment_method_protector;
@@ -181,7 +171,6 @@ public function on_init(): void {
181171
$this->blocked_session_notice->register();
182172
$this->blackbox_script_handler->register();
183173
$this->session_verifier->register();
184-
$this->order_events_tracker->register();
185174
$this->blocks_checkout_protector->register();
186175
$this->shortcode_checkout_protector->register();
187176
$this->add_payment_method_protector->register();

woocommerce-fraud-protection.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ function () {
123123
$payment_method_event_tracker,
124124
$session_blocking_handler,
125125
$session_verifier,
126-
$order_events_tracker,
127126
$blocks_checkout_protector,
128127
$shortcode_checkout_protector,
129128
$add_payment_method_protector,

0 commit comments

Comments
 (0)