mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
♻️ Favor DCC config class over settings access
This commit is contained in:
parent
0677364eb2
commit
bcd62f674d
6 changed files with 34 additions and 32 deletions
|
@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
||||
|
||||
return array(
|
||||
|
||||
|
@ -135,10 +136,10 @@ return array(
|
|||
},
|
||||
|
||||
'axo.smart-button-location-notice' => static function ( ContainerInterface $container ) : string {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
$dcc_configuration = $container->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
|
||||
if ( $settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' ) ) {
|
||||
if ( $dcc_configuration->use_fastlane() ) {
|
||||
$fastlane_settings_url = admin_url(
|
||||
sprintf(
|
||||
'admin.php?page=wc-settings&tab=checkout§ion=%1$s&ppcp-tab=%2$s#field-axo_heading',
|
||||
|
|
|
@ -29,6 +29,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
|
||||
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
|
||||
use WC_Payment_Gateways;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
||||
|
||||
/**
|
||||
* Class AxoModule
|
||||
|
@ -87,13 +88,10 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
return $methods;
|
||||
}
|
||||
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
|
||||
$is_paypal_enabled = $settings->has( 'enabled' ) && $settings->get( 'enabled' ) ?? false;
|
||||
$is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ) ?? false;
|
||||
|
||||
if ( ! $is_paypal_enabled || ! $is_dcc_enabled ) {
|
||||
if ( ! $dcc_configuration->is_enabled() ) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
|
@ -156,11 +154,11 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
$listener = $c->get( 'wcgateway.settings.listener' );
|
||||
assert( $listener instanceof SettingsListener );
|
||||
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
|
||||
$listener->filter_settings(
|
||||
$settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' ),
|
||||
$dcc_configuration->use_fastlane(),
|
||||
'smart_button_locations',
|
||||
function( array $existing_setting_value ) {
|
||||
$axo_forced_locations = array( 'cart-block', 'cart' );
|
||||
|
@ -237,12 +235,10 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
echo '<script async src="https://www.paypalobjects.com/insights/v1/paypal-insights.sandbox.min.js"></script>';
|
||||
|
||||
// Add meta tag to allow feature-detection of the site's AXO payment state.
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
|
||||
$this->add_feature_detection_tag(
|
||||
$settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' )
|
||||
);
|
||||
$this->add_feature_detection_tag( $dcc_configuration->use_fastlane() );
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -364,16 +360,12 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
* @return bool
|
||||
*/
|
||||
private function should_render_fastlane( ContainerInterface $c ): bool {
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
$is_axo_enabled = $settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' ) ?? false;
|
||||
$is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ) ?? false;
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
|
||||
return ! is_user_logged_in()
|
||||
&& CartCheckoutDetector::has_classic_checkout()
|
||||
&& $is_axo_enabled
|
||||
&& $is_dcc_enabled
|
||||
&& $dcc_configuration->use_fastlane()
|
||||
&& ! $this->is_excluded_endpoint();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
|||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
||||
|
||||
/**
|
||||
* Class CardFieldsModule
|
||||
|
@ -45,9 +46,9 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
|
|||
return true;
|
||||
}
|
||||
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
if ( ! $settings->has( 'dcc_enabled' ) || ! $settings->get( 'dcc_enabled' ) ) {
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
if ( ! $dcc_configuration->is_enabled() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -384,9 +384,10 @@ return array(
|
|||
assert( $settings instanceof Settings );
|
||||
|
||||
$axo_available = $container->has( 'axo.available' ) && $container->get( 'axo.available' );
|
||||
$axo_enabled = $settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' );
|
||||
$dcc_configuration = $container->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
|
||||
if ( $axo_available && $axo_enabled ) {
|
||||
if ( $axo_available && $dcc_configuration->use_fastlane() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,7 @@ class DCCGatewayConfiguration {
|
|||
* Requires PayPal features to be enabled.
|
||||
*
|
||||
* @return bool
|
||||
* @todo Some classes still directly access `$settings->get('dcc_enabled')`
|
||||
*/
|
||||
public function is_enabled() : bool {
|
||||
return $this->is_enabled;
|
||||
|
|
|
@ -57,6 +57,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
|||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Registrar\TaskRegistrarInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
||||
|
||||
/**
|
||||
* Class WcGatewayModule
|
||||
|
@ -181,6 +182,9 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
|
|||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
|
||||
$assets = new SettingsPageAssets(
|
||||
$c->get( 'wcgateway.url' ),
|
||||
$c->get( 'ppcp.asset-version' ),
|
||||
|
@ -193,7 +197,7 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
|
|||
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
|
||||
$c->get( 'wcgateway.settings.funding-sources' ),
|
||||
$c->get( 'wcgateway.is-ppcp-settings-page' ),
|
||||
$settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ),
|
||||
$dcc_configuration->is_enabled(),
|
||||
$c->get( 'api.endpoint.billing-agreements' ),
|
||||
$c->get( 'wcgateway.is-ppcp-settings-payment-methods-page' )
|
||||
);
|
||||
|
@ -554,10 +558,12 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
|
|||
return $methods;
|
||||
}
|
||||
|
||||
$is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ) ?? false;
|
||||
$dcc_configuration = $container->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
|
||||
$standard_card_button = get_option( 'woocommerce_ppcp-card-button-gateway_settings' );
|
||||
|
||||
if ( $is_dcc_enabled && isset( $standard_card_button['enabled'] ) ) {
|
||||
if ( $dcc_configuration->is_enabled() && isset( $standard_card_button['enabled'] ) ) {
|
||||
$standard_card_button['enabled'] = 'no';
|
||||
update_option( 'woocommerce_ppcp-card-button-gateway_settings', $standard_card_button );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue