mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
♻️ Use DCCGatewayConfiguration service
This commit is contained in:
parent
60bdf6dea1
commit
0d69dff0f4
2 changed files with 17 additions and 29 deletions
|
@ -39,7 +39,10 @@ return array(
|
|||
},
|
||||
|
||||
'axo.helpers.compatibility-checker' => static function ( ContainerInterface $container ) : CompatibilityChecker {
|
||||
return new CompatibilityChecker( $container->get( 'axo.fastlane-incompatible-plugin-names' ) );
|
||||
return new CompatibilityChecker(
|
||||
$container->get( 'axo.fastlane-incompatible-plugin-names' ),
|
||||
$container->get( 'wcgateway.configuration.dcc' )
|
||||
);
|
||||
},
|
||||
|
||||
// If AXO is configured and onboarded.
|
||||
|
@ -221,9 +224,8 @@ return array(
|
|||
},
|
||||
|
||||
'axo.incompatible-plugins-notice.raw' => static function ( ContainerInterface $container ) : string {
|
||||
$settings_notice_generator = new CompatibilityChecker(
|
||||
$container->get( 'axo.fastlane-incompatible-plugin-names' )
|
||||
);
|
||||
$settings_notice_generator = $container->get( 'axo.helpers.compatibility-checker' );
|
||||
assert( $settings_notice_generator instanceof CompatibilityChecker );
|
||||
|
||||
return $settings_notice_generator->generate_incompatible_plugins_notice( true );
|
||||
},
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace WooCommerce\PayPalCommerce\Axo\Helper;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
||||
|
||||
/**
|
||||
* Class CompatibilityChecker
|
||||
|
@ -35,20 +36,23 @@ class CompatibilityChecker {
|
|||
protected array $checkout_compatibility;
|
||||
|
||||
/**
|
||||
* Stores whether DCC is enabled.
|
||||
* Provides details about the DCC configuration.
|
||||
*
|
||||
* @var bool|null
|
||||
* @var DCCGatewayConfiguration
|
||||
*/
|
||||
protected ?bool $is_dcc_enabled = null;
|
||||
private DCCGatewayConfiguration $dcc_configuration;
|
||||
|
||||
/**
|
||||
* CompatibilityChecker constructor.
|
||||
*
|
||||
* @param string[] $incompatible_plugin_names The list of Fastlane incompatible plugin names.
|
||||
* @param string[] $incompatible_plugin_names The list of Fastlane incompatible plugin names.
|
||||
* @param DCCGatewayConfiguration $dcc_configuration DCC gateway configuration.
|
||||
*/
|
||||
public function __construct( array $incompatible_plugin_names ) {
|
||||
public function __construct( array $incompatible_plugin_names, DCCGatewayConfiguration $dcc_configuration ) {
|
||||
$this->incompatible_plugin_names = $incompatible_plugin_names;
|
||||
$this->checkout_compatibility = array(
|
||||
$this->dcc_configuration = $dcc_configuration;
|
||||
|
||||
$this->checkout_compatibility = array(
|
||||
'has_elementor_checkout' => null,
|
||||
'has_classic_checkout' => null,
|
||||
'has_block_checkout' => null,
|
||||
|
@ -94,24 +98,6 @@ class CompatibilityChecker {
|
|||
return $this->checkout_compatibility['has_block_checkout'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if DCC is enabled.
|
||||
*
|
||||
* @param Settings $settings The plugin settings container.
|
||||
* @return bool Whether DCC is enabled.
|
||||
*/
|
||||
protected function is_dcc_enabled( Settings $settings ): bool {
|
||||
if ( $this->is_dcc_enabled === null ) {
|
||||
try {
|
||||
$this->is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' );
|
||||
} catch ( NotFoundException $ignored ) {
|
||||
$this->is_dcc_enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->is_dcc_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the full HTML of the notification.
|
||||
*
|
||||
|
@ -242,7 +228,7 @@ class CompatibilityChecker {
|
|||
* @return string
|
||||
*/
|
||||
public function generate_settings_conflict_notice( Settings $settings, bool $raw_message = false ) : string {
|
||||
if ( $this->is_dcc_enabled( $settings ) ) {
|
||||
if ( $this->dcc_configuration->is_enabled() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue