From 6fbd4f38906b453f61b8e3dac55abb7f11fbfaac Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 29 Apr 2024 14:38:43 +0200 Subject: [PATCH] Add Fastlane settings to the AXO payment gateway settings screen --- modules/ppcp-axo/extensions.php | 46 +++++++++---------- modules/ppcp-axo/services.php | 1 + modules/ppcp-axo/src/Gateway/AxoGateway.php | 25 +++++++++- modules/ppcp-wc-gateway/services.php | 1 + .../src/Settings/PageMatcherTrait.php | 2 + 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index 93e36e31c..644fe3239 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -57,9 +57,9 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array( - 'dcc', + array('dcc', 'axo'), ), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_enabled' => array( 'title' => __( 'Fastlane', 'woocommerce-paypal-payments' ), @@ -75,7 +75,7 @@ return array( . '

', 'default' => 'yes', 'screens' => array( State::STATE_ONBOARDED ), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), 'requirements' => array(), 'custom_attributes' => array( 'data-ppcp-display' => wp_json_encode( @@ -129,7 +129,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_privacy' => array( 'title' => __( 'Privacy', 'woocommerce-paypal-payments' ), @@ -145,7 +145,7 @@ return array( 'default' => 'yes', 'options' => PropertiesDictionary::privacy_options(), 'screens' => array( State::STATE_ONBOARDED ), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), 'requirements' => array(), ), 'axo_style_heading' => array( @@ -179,9 +179,9 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array( - 'dcc', + array('dcc', 'axo'), ), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_root_heading' => array( @@ -193,8 +193,8 @@ return array( ), 'classes' => array( 'ppcp-field-indent' ), 'screens' => array( State::STATE_ONBOARDED ), - 'requirements' => array( 'dcc' ), - 'gateway' => 'dcc', + 'requirements' => array( array('dcc', 'axo') ), + 'gateway' => array('dcc', 'axo'), ), 'axo_style_root_bg_color' => array( 'title' => __( 'Background Color', 'woocommerce-paypal-payments' ), @@ -204,7 +204,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_root_error_color' => array( 'title' => __( 'Error Color', 'woocommerce-paypal-payments' ), @@ -214,7 +214,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_root_font_family' => array( 'title' => __( 'Font Family', 'woocommerce-paypal-payments' ), @@ -224,7 +224,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_root_font_size_base' => array( 'title' => __( 'Font Size Base', 'woocommerce-paypal-payments' ), @@ -234,7 +234,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_root_padding' => array( 'title' => __( 'Padding', 'woocommerce-paypal-payments' ), @@ -244,7 +244,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_root_primary_color' => array( 'title' => __( 'Primary Color', 'woocommerce-paypal-payments' ), @@ -254,7 +254,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_input_heading' => array( 'heading' => __( 'Input Settings', 'woocommerce-paypal-payments' ), @@ -265,8 +265,8 @@ return array( ), 'classes' => array( 'ppcp-field-indent' ), 'screens' => array( State::STATE_ONBOARDED ), - 'requirements' => array( 'dcc' ), - 'gateway' => 'dcc', + 'requirements' => array( array('dcc', 'axo') ), + 'gateway' => array('dcc', 'axo'), ), 'axo_style_input_bg_color' => array( 'title' => __( 'Background Color', 'woocommerce-paypal-payments' ), @@ -276,7 +276,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_input_border_radius' => array( 'title' => __( 'Border Radius', 'woocommerce-paypal-payments' ), @@ -286,7 +286,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_input_border_color' => array( 'title' => __( 'Border Color', 'woocommerce-paypal-payments' ), @@ -296,7 +296,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_input_border_width' => array( 'title' => __( 'Border Width', 'woocommerce-paypal-payments' ), @@ -306,7 +306,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_input_text_color_base' => array( 'title' => __( 'Text Color Base', 'woocommerce-paypal-payments' ), @@ -316,7 +316,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), 'axo_style_input_focus_border_color' => array( 'title' => __( 'Focus Border Color', 'woocommerce-paypal-payments' ), @@ -326,7 +326,7 @@ return array( State::STATE_ONBOARDED, ), 'requirements' => array(), - 'gateway' => 'dcc', + 'gateway' => array('dcc', 'axo'), ), ) diff --git a/modules/ppcp-axo/services.php b/modules/ppcp-axo/services.php index 2a35321c1..8b65508ae 100644 --- a/modules/ppcp-axo/services.php +++ b/modules/ppcp-axo/services.php @@ -63,6 +63,7 @@ return array( 'axo.gateway' => static function ( ContainerInterface $container ): AxoGateway { return new AxoGateway( + $container->get( 'wcgateway.settings.render' ), $container->get( 'wcgateway.settings' ), $container->get( 'wcgateway.url' ), $container->get( 'wcgateway.order-processor' ), diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index 356c35d79..63603a6b4 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -21,18 +21,27 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory; use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; +use WooCommerce\PayPalCommerce\WcGateway\Gateway\GatewaySettingsRendererTrait; use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider; use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait; use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor; +use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer; /** * Class AXOGateway. */ class AxoGateway extends WC_Payment_Gateway { - use OrderMetaTrait; + use OrderMetaTrait, GatewaySettingsRendererTrait; const ID = 'ppcp-axo-gateway'; + /** + * The Settings Renderer. + * + * @var SettingsRenderer + */ + protected $settings_renderer; + /** * The settings. * @@ -106,6 +115,7 @@ class AxoGateway extends WC_Payment_Gateway { /** * AXOGateway constructor. * + * @param SettingsRenderer $settings_renderer The settings renderer. * @param ContainerInterface $ppcp_settings The settings. * @param string $wcgateway_module_url The WcGateway module URL. * @param OrderProcessor $order_processor The Order processor. @@ -118,6 +128,7 @@ class AxoGateway extends WC_Payment_Gateway { * @param LoggerInterface $logger The logger. */ public function __construct( + SettingsRenderer $settings_renderer, ContainerInterface $ppcp_settings, string $wcgateway_module_url, OrderProcessor $order_processor, @@ -131,6 +142,7 @@ class AxoGateway extends WC_Payment_Gateway { ) { $this->id = self::ID; + $this->settings_renderer = $settings_renderer; $this->ppcp_settings = $ppcp_settings; $this->wcgateway_module_url = $wcgateway_module_url; $this->order_processor = $order_processor; @@ -181,6 +193,9 @@ class AxoGateway extends WC_Payment_Gateway { 'desc_tip' => true, 'description' => __( 'Enable/Disable AXO payment gateway.', 'woocommerce-paypal-payments' ), ), + 'ppcp' => array( + 'type' => 'ppcp', + ), ); } @@ -321,4 +336,12 @@ class AxoGateway extends WC_Payment_Gateway { return parent::get_title(); } + /** + * Returns the settings renderer. + * + * @return SettingsRenderer + */ + protected function settings_renderer(): SettingsRenderer { + return $this->settings_renderer; + } } diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 145401c61..65101e8b8 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -195,6 +195,7 @@ return array( CardButtonGateway::ID, OXXOGateway::ID, Settings::PAY_LATER_TAB_ID, + AxoGateway::ID, ), true ); diff --git a/modules/ppcp-wc-gateway/src/Settings/PageMatcherTrait.php b/modules/ppcp-wc-gateway/src/Settings/PageMatcherTrait.php index 6aac3cc16..1a6345a29 100644 --- a/modules/ppcp-wc-gateway/src/Settings/PageMatcherTrait.php +++ b/modules/ppcp-wc-gateway/src/Settings/PageMatcherTrait.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\WcGateway\Settings; +use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; @@ -37,6 +38,7 @@ trait PageMatcherTrait { Settings::PAY_LATER_TAB_ID => Settings::PAY_LATER_TAB_ID, CreditCardGateway::ID => 'dcc', // TODO: consider using just the gateway ID for PayPal and DCC too. CardButtonGateway::ID => CardButtonGateway::ID, + AxoGateway::ID => 'axo', ); return array_key_exists( $current_page_id, $gateway_page_id_map ) && in_array( $gateway_page_id_map[ $current_page_id ], $allowed_gateways, true );