mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
♻️ Move logging and next-steps into new function
This commit is contained in:
parent
c8b46dfcb7
commit
f7eeef3821
1 changed files with 23 additions and 3 deletions
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue