From 0adc8ae4bafeaa953447b0a1a29cc48b1f3f6718 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Wed, 18 Sep 2024 15:35:46 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Switch=20gateways=20to=20u?= =?UTF-8?q?se=20new=20configuration=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ppcp-axo-block/services.php | 1 + .../ppcp-axo-block/src/AxoBlockPaymentMethod.php | 13 ++++++++++++- modules/ppcp-axo/services.php | 1 + modules/ppcp-axo/src/Gateway/AxoGateway.php | 15 ++++++++++++--- modules/ppcp-wc-gateway/services.php | 3 +++ .../src/Gateway/CreditCardGateway.php | 14 ++++++++++++-- 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-axo-block/services.php b/modules/ppcp-axo-block/services.php index 2b706a865..270b69260 100644 --- a/modules/ppcp-axo-block/services.php +++ b/modules/ppcp-axo-block/services.php @@ -35,6 +35,7 @@ return array( $container->get( 'axo.gateway' ), fn() : SmartButtonInterface => $container->get( 'button.smart-button' ), $container->get( 'wcgateway.settings' ), + $container->get( 'wcgateway.configuration.dcc' ), $container->get( 'onboarding.environment' ), $container->get( 'wcgateway.url' ) ); diff --git a/modules/ppcp-axo-block/src/AxoBlockPaymentMethod.php b/modules/ppcp-axo-block/src/AxoBlockPaymentMethod.php index 5f9ec31d0..a0c35f145 100644 --- a/modules/ppcp-axo-block/src/AxoBlockPaymentMethod.php +++ b/modules/ppcp-axo-block/src/AxoBlockPaymentMethod.php @@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface; use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; +use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration; /** * Class AxoBlockPaymentMethod @@ -57,6 +58,13 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType { */ protected $settings; + /** + * The DCC gateway settings. + * + * @var DCCGatewayConfiguration + */ + protected DCCGatewayConfiguration $dcc_configuration; + /** * The environment object. * @@ -80,6 +88,7 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType { * @param SmartButtonInterface|callable $smart_button The smart button script loading * handler. * @param Settings $settings The settings. + * @param DCCGatewayConfiguration $dcc_configuration The DCC gateway settings. * @param Environment $environment The environment object. * @param string $wcgateway_module_url The WcGateway module URL. */ @@ -89,6 +98,7 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType { WC_Payment_Gateway $gateway, $smart_button, Settings $settings, + DCCGatewayConfiguration $dcc_configuration, Environment $environment, string $wcgateway_module_url ) { @@ -98,6 +108,7 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType { $this->gateway = $gateway; $this->smart_button = $smart_button; $this->settings = $settings; + $this->dcc_configuration = $dcc_configuration; $this->environment = $environment; $this->wcgateway_module_url = $wcgateway_module_url; @@ -215,7 +226,7 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType { 'focusBorderColor' => $this->settings->has( 'axo_style_input_focus_border_color' ) ? $this->settings->get( 'axo_style_input_focus_border_color' ) : '', ), ), - 'name_on_card' => $this->settings->has( 'axo_name_on_card' ) ? $this->settings->get( 'axo_name_on_card' ) : '', + 'name_on_card' => $this->dcc_configuration->show_name_on_card(), 'woocommerce' => array( 'states' => array( 'US' => WC()->countries->get_states( 'US' ), diff --git a/modules/ppcp-axo/services.php b/modules/ppcp-axo/services.php index 33ff6df8e..692562d81 100644 --- a/modules/ppcp-axo/services.php +++ b/modules/ppcp-axo/services.php @@ -74,6 +74,7 @@ return array( return new AxoGateway( $container->get( 'wcgateway.settings.render' ), $container->get( 'wcgateway.settings' ), + $container->get( 'wcgateway.configuration.dcc' ), $container->get( 'wcgateway.url' ), $container->get( 'session.handler' ), $container->get( 'wcgateway.order-processor' ), diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index 3161b9a8b..eb202d6cb 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -29,6 +29,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer; use WooCommerce\PayPalCommerce\WcGateway\Gateway\ProcessPaymentTrait; use WooCommerce\PayPalCommerce\WcGateway\Exception\GatewayGenericException; use WooCommerce\PayPalCommerce\Session\SessionHandler; +use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration; /** * Class AXOGateway. @@ -52,6 +53,13 @@ class AxoGateway extends WC_Payment_Gateway { */ protected $ppcp_settings; + /** + * Gateway configuration object, providing relevant settings. + * + * @var DCCGatewayConfiguration + */ + protected DCCGatewayConfiguration $dcc_configuration; + /** * The WcGateway module URL. * @@ -127,6 +135,7 @@ class AxoGateway extends WC_Payment_Gateway { * * @param SettingsRenderer $settings_renderer The settings renderer. * @param ContainerInterface $ppcp_settings The settings. + * @param DCCGatewayConfiguration $dcc_configuration The DCC Gateway configuration. * @param string $wcgateway_module_url The WcGateway module URL. * @param SessionHandler $session_handler The Session Handler. * @param OrderProcessor $order_processor The Order processor. @@ -141,6 +150,7 @@ class AxoGateway extends WC_Payment_Gateway { public function __construct( SettingsRenderer $settings_renderer, ContainerInterface $ppcp_settings, + DCCGatewayConfiguration $dcc_configuration, string $wcgateway_module_url, SessionHandler $session_handler, OrderProcessor $order_processor, @@ -156,6 +166,7 @@ class AxoGateway extends WC_Payment_Gateway { $this->settings_renderer = $settings_renderer; $this->ppcp_settings = $ppcp_settings; + $this->dcc_configuration = $dcc_configuration; $this->wcgateway_module_url = $wcgateway_module_url; $this->session_handler = $session_handler; $this->order_processor = $order_processor; @@ -167,9 +178,7 @@ class AxoGateway extends WC_Payment_Gateway { $is_axo_enabled = $this->ppcp_settings->has( 'axo_enabled' ) && $this->ppcp_settings->get( 'axo_enabled' ); $this->update_option( 'enabled', $is_axo_enabled ? 'yes' : 'no' ); - $this->title = $this->ppcp_settings->has( 'axo_gateway_title' ) - ? $this->ppcp_settings->get( 'axo_gateway_title' ) - : $this->get_option( 'title', $this->method_title ); + $this->title = $this->dcc_configuration->gateway_title( $this->get_option( 'title', $this->method_title ) ); $this->description = __( 'Enter your email address above to continue.', 'woocommerce-paypal-payments' ); diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index efe1beb3b..8bee02788 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -79,6 +79,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener; use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer; use WooCommerce\PayPalCommerce\Applepay\ApplePayGateway; +use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration; return array( 'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway { @@ -123,6 +124,7 @@ return array( $order_processor = $container->get( 'wcgateway.order-processor' ); $settings_renderer = $container->get( 'wcgateway.settings.render' ); $settings = $container->get( 'wcgateway.settings' ); + $dcc_configuration = $container->get( 'wcgateway.configuration.dcc' ); $module_url = $container->get( 'wcgateway.url' ); $session_handler = $container->get( 'session.handler' ); $refund_processor = $container->get( 'wcgateway.processor.refunds' ); @@ -138,6 +140,7 @@ return array( $settings_renderer, $order_processor, $settings, + $dcc_configuration, $icons, $module_url, $session_handler, diff --git a/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php b/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php index 4842df17b..ff70f3c12 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php @@ -35,6 +35,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer; use WooCommerce\PayPalCommerce\WcSubscriptions\FreeTrialHandlerTrait; use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper; +use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration; /** * Class CreditCardGateway @@ -73,6 +74,13 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC { */ protected $config; + /** + * The DCC Gateway Configuration. + * + * @var DCCGatewayConfiguration + */ + protected DCCGatewayConfiguration $dcc_configuration; + /** * The vaulted credit card handler. * @@ -191,6 +199,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC { * @param SettingsRenderer $settings_renderer The Settings Renderer. * @param OrderProcessor $order_processor The Order processor. * @param ContainerInterface $config The settings. + * @param DCCGatewayConfiguration $dcc_configuration The DCC Gateway Configuration. * @param array $card_icons The card icons. * @param string $module_url The URL to the module. * @param SessionHandler $session_handler The Session Handler. @@ -212,6 +221,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC { SettingsRenderer $settings_renderer, OrderProcessor $order_processor, ContainerInterface $config, + DCCGatewayConfiguration $dcc_configuration, array $card_icons, string $module_url, SessionHandler $session_handler, @@ -233,6 +243,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC { $this->settings_renderer = $settings_renderer; $this->order_processor = $order_processor; $this->config = $config; + $this->dcc_configuration = $dcc_configuration; $this->module_url = $module_url; $this->session_handler = $session_handler; $this->refund_processor = $refund_processor; @@ -269,8 +280,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC { 'Accept debit and credit cards, and local payment methods with PayPal’s latest solution.', 'woocommerce-paypal-payments' ); - $this->title = $this->config->has( 'dcc_gateway_title' ) ? - $this->config->get( 'dcc_gateway_title' ) : $this->method_title; + $this->title = $this->dcc_configuration->gateway_title(); $this->description = $this->config->has( 'dcc_gateway_description' ) ? $this->config->get( 'dcc_gateway_description' ) : $this->method_description; $this->card_icons = $card_icons;