From f7eeef382104952d5900b3a9fe95bc8584996d27 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Fri, 7 Mar 2025 13:09:42 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Move=20logging=20and=20nex?= =?UTF-8?q?t-steps=20into=20new=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Service/AuthenticationManager.php | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-settings/src/Service/AuthenticationManager.php b/modules/ppcp-settings/src/Service/AuthenticationManager.php index 0488077a2..67baaf9b3 100644 --- a/modules/ppcp-settings/src/Service/AuthenticationManager.php +++ b/modules/ppcp-settings/src/Service/AuthenticationManager.php @@ -449,20 +449,20 @@ class AuthenticationManager { $response = $this->rest_service->get_response( $endpoint ); if ( ! $response['success'] ) { - $this->logger->warning( 'Failed to load merchant details!', $response ); + $this->enrichment_failed( 'Server failed to provide data', $response ); return; } $details = $response['data']; } catch ( Throwable $exception ) { - $this->logger->warning( 'Could not determine merchant country: ' . $exception->getMessage() ); + $this->enrichment_failed( $exception->getMessage() ); return; } if ( ! isset( $details['country'] ) ) { - $this->logger->warning( 'Missing country in merchant details' ); + $this->enrichment_failed( 'Missing country in merchant details' ); return; } @@ -478,6 +478,26 @@ class AuthenticationManager { $this->common_settings->save(); } + /** + * When the `enrich_merchant_details()` call fails, this method might + * set up a cron task to retry the attempt after some time. + * + * @param string $reason Reason for the failure, will be logged. + * @param mixed $details Optional. Additional details to log. + * @return void + */ + private function enrichment_failed( string $reason, $details = null ) : void { + $this->logger->warning( + 'Failed to enrich merchant details: ' . $reason, + array( + 'reason' => $reason, + 'details' => $details, + ) + ); + + // TODO: Schedule a cron task to retry the enrichment, e.g. with wp_schedule_single_event(). + } + /** * Stores the provided details in the data model. *