Skip to content

Commit

Permalink
Add client data to the compatibility service
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoumpierre committed Nov 12, 2024
1 parent b647d8d commit 7271454
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
34 changes: 31 additions & 3 deletions includes/class-compatibility-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use WC_Payments;
use WC_Payments_API_Client;
use WCPay\Exceptions\API_Exception;
use WC_Payments_Session_Service;

defined( 'ABSPATH' ) || exit; // block direct access.

Expand All @@ -26,13 +26,25 @@ class Compatibility_Service {
*/
private $payments_api_client;

/**
* Session service.
*
* @var WC_Payments_Session_Service instance for working with session information
*/
private $session_service;

/**
* Constructor for Compatibility_Service.
*
* @param WC_Payments_API_Client $payments_api_client WooCommerce Payments API client.
* @param WC_Payments_API_Client $payments_api_client WooCommerce Payments API client.
* @param WC_Payments_Session_Service $session_service Session service.
*/
public function __construct( WC_Payments_API_Client $payments_api_client ) {
public function __construct(
WC_Payments_API_Client $payments_api_client,
WC_Payments_Session_Service $session_service
) {
$this->payments_api_client = $payments_api_client;
$this->session_service = $session_service;
}

/**
Expand Down Expand Up @@ -77,6 +89,19 @@ public function add_compatibility_onboarding_data( $args ): array {
return $args;
}

/**
* Gets the browser info.
*
* @return array
*/
public function get_browser_info() {
return [
'user_agent' => isset( $_SERVER['HTTP_USER_AGENT'] ) ? wc_clean( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '',
'accept_language' => isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ? wc_clean( wp_unslash( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) : '',
'content_language' => empty( get_user_locale() ) ? 'en-US' : str_replace( '_', '-', get_user_locale() ),
];
}

/**
* Gets the compatibility data.
*
Expand All @@ -100,6 +125,9 @@ private function get_compatibility_data(): array {
'blog_theme' => get_stylesheet(),
'active_plugins' => $active_plugins,
'post_types_count' => $post_types_count,
'sift_session_id' => $this->session_service->get_sift_session_id(),
'ip_address' => \WC_Geolocation::get_ip_address(),
'browser' => $this->get_browser_info(),
];
}

Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ public static function init() {
include_once WCPAY_ABSPATH . 'includes/class-woopay-tracker.php';

self::$order_service = new WC_Payments_Order_Service( self::$api_client );
self::$compatibility_service = new Compatibility_Service( self::$api_client );
self::$action_scheduler_service = new WC_Payments_Action_Scheduler_Service( self::$api_client, self::$order_service, self::$compatibility_service );
self::$session_service = new WC_Payments_Session_Service( self::$api_client );
self::$compatibility_service = new Compatibility_Service( self::$api_client, self::$session_service );
self::$action_scheduler_service = new WC_Payments_Action_Scheduler_Service( self::$api_client, self::$order_service, self::$compatibility_service );
self::$redirect_service = new WC_Payments_Redirect_Service( self::$api_client );
self::$onboarding_service = new WC_Payments_Onboarding_Service( self::$api_client, self::$database_cache, self::$session_service );
self::$account = new WC_Payments_Account( self::$api_client, self::$database_cache, self::$action_scheduler_service, self::$onboarding_service, self::$redirect_service );
Expand Down

0 comments on commit 7271454

Please sign in to comment.