Skip to content

Commit

Permalink
Merge pull request #2620 from woocommerce/PCP-3680-simplify-fastlane-…
Browse files Browse the repository at this point in the history
…settings

Fastlane: Remove Gateway Title, and move Cardholder Name to Advanced Card Processing (3680)
  • Loading branch information
InpsydeNiklas committed Sep 19, 2024
2 parents 39531cf + a5a1294 commit 75960fc
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 40 deletions.
1 change: 1 addition & 0 deletions modules/ppcp-axo-block/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
$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' )
);
Expand Down
13 changes: 12 additions & 1 deletion modules/ppcp-axo-block/src/AxoBlockPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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
Expand Down Expand Up @@ -57,6 +58,13 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
*/
protected $settings;

/**
* The DCC gateway settings.
*
* @var DCCGatewayConfiguration
*/
protected DCCGatewayConfiguration $dcc_configuration;

/**
* The environment object.
*
Expand All @@ -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.
*/
Expand All @@ -89,6 +98,7 @@ public function __construct(
WC_Payment_Gateway $gateway,
$smart_button,
Settings $settings,
DCCGatewayConfiguration $dcc_configuration,
Environment $environment,
string $wcgateway_module_url
) {
Expand All @@ -98,6 +108,7 @@ public function __construct(
$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;

Expand Down Expand Up @@ -215,7 +226,7 @@ private function script_data() : array {
'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' ),
Expand Down
34 changes: 0 additions & 34 deletions modules/ppcp-axo/extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@
$display_manager
->rule()
->condition_element( 'axo_enabled', '1' )
->action_visible( 'axo_gateway_title' )
->action_visible( 'axo_main_notice' )
->action_visible( 'axo_privacy' )
->action_visible( 'axo_name_on_card' )
->action_visible( 'axo_style_heading' )
->action_class( 'axo_enabled', 'active' )
->to_array(),
Expand Down Expand Up @@ -133,25 +131,6 @@
'requirements' => array( 'dcc', 'axo' ),
'gateway' => array( 'dcc', 'axo' ),
),
'axo_gateway_title' => array(
'title' => __( 'Gateway Title', 'woocommerce-paypal-payments' ),
'type' => 'text',
'classes' => array( 'ppcp-field-indent' ),
'desc_tip' => true,
'description' => __(
'This controls the title of the Fastlane gateway the user sees on checkout.',
'woocommerce-paypal-payments'
),
'default' => __(
'Debit & Credit Cards',
'woocommerce-paypal-payments'
),
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array( 'axo' ),
'gateway' => array( 'dcc', 'axo' ),
),
'axo_privacy' => array(
'title' => __( 'Privacy', 'woocommerce-paypal-payments' ),
'type' => 'select',
Expand All @@ -168,19 +147,6 @@
'gateway' => array( 'dcc', 'axo' ),
'requirements' => array( 'axo' ),
),
'axo_name_on_card' => array(
'title' => __( 'Cardholder Name', 'woocommerce-paypal-payments' ),
'type' => 'select',
'default' => 'yes',
'options' => PropertiesDictionary::cardholder_name_options(),
'classes' => array( 'ppcp-field-indent' ),
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'description' => __( 'This setting will control whether or not the cardholder name is displayed in the card field\'s UI.', 'woocommerce-paypal-payments' ),
'screens' => array( State::STATE_ONBOARDED ),
'gateway' => array( 'dcc', 'axo' ),
'requirements' => array( 'axo' ),
),
'axo_style_heading' => array(
'heading' => __( 'Advanced Style Settings (optional)', 'woocommerce-paypal-payments' ),
'heading_html' => sprintf(
Expand Down
1 change: 1 addition & 0 deletions modules/ppcp-axo/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
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' ),
Expand Down
15 changes: 12 additions & 3 deletions modules/ppcp-axo/src/Gateway/AxoGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.
Expand All @@ -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.
*
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -156,6 +166,7 @@ public function __construct(

$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;
Expand All @@ -167,9 +178,7 @@ public function __construct(
$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' );

Expand Down
28 changes: 28 additions & 0 deletions modules/ppcp-wc-gateway/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
use WooCommerce\PayPalCommerce\Axo\Helper\PropertiesDictionary;
use WooCommerce\PayPalCommerce\Applepay\ApplePayGateway;
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;

return array(
'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway {
Expand Down Expand Up @@ -123,6 +125,7 @@
$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' );
Expand All @@ -138,6 +141,7 @@
$settings_renderer,
$order_processor,
$settings,
$dcc_configuration,
$icons,
$module_url,
$session_handler,
Expand Down Expand Up @@ -620,6 +624,9 @@ static function ( ContainerInterface $container ): string {
$subscription_helper = $container->get( 'wc-subscriptions.helper' );
assert( $subscription_helper instanceof SubscriptionHelper );

$dcc_configuration = $container->get( 'wcgateway.configuration.dcc' );
assert( $dcc_configuration instanceof DCCGatewayConfiguration );

$fields = array(
'checkout_settings_heading' => array(
'heading' => __( 'Standard Payments Settings', 'woocommerce-paypal-payments' ),
Expand Down Expand Up @@ -975,6 +982,20 @@ static function ( ContainerInterface $container ): string {
),
'gateway' => 'dcc',
),
'dcc_name_on_card' => array(
'title' => __( 'Cardholder Name', 'woocommerce-paypal-payments' ),
'type' => 'select',
'default' => $dcc_configuration->show_name_on_card(),
'options' => PropertiesDictionary::cardholder_name_options(),
'classes' => array(),
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'desc_tip' => true,
'description' => __( 'This setting will control whether or not the cardholder name is displayed in the card field\'s UI.', 'woocommerce-paypal-payments' ),
'screens' => array( State::STATE_ONBOARDED ),
'gateway' => array( 'dcc', 'axo' ),
'requirements' => array( 'axo' ),
),
'3d_secure_heading' => array(
'heading' => __( '3D Secure', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
Expand Down Expand Up @@ -1278,6 +1299,13 @@ static function ( ContainerInterface $container ): string {
return new TransactionUrlProvider( $sandbox_url_base, $live_url_base );
},

'wcgateway.configuration.dcc' => static function ( ContainerInterface $container ) : DCCGatewayConfiguration {
$settings = $container->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );

return new DCCGatewayConfiguration( $settings );
},

'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : DCCProductStatus {

$settings = $container->get( 'wcgateway.settings' );
Expand Down
14 changes: 12 additions & 2 deletions modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
Expand All @@ -212,6 +221,7 @@ public function __construct(
SettingsRenderer $settings_renderer,
OrderProcessor $order_processor,
ContainerInterface $config,
DCCGatewayConfiguration $dcc_configuration,
array $card_icons,
string $module_url,
SessionHandler $session_handler,
Expand All @@ -233,6 +243,7 @@ public function __construct(
$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;
Expand Down Expand Up @@ -269,8 +280,7 @@ public function __construct(
'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;
Expand Down
79 changes: 79 additions & 0 deletions modules/ppcp-wc-gateway/src/Helper/DCCGatewayConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* Encapsulates all configuration details for "Credit & Debit Card" gateway.
*
* @package WooCommerce\PayPalCommerce\WcGateway\Helper
*/

declare( strict_types = 1 );

namespace WooCommerce\PayPalCommerce\WcGateway\Helper;

use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\Axo\Helper\PropertiesDictionary;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;

/**
* A simple DTO that provides convenient access to the DCC/AXO gateway settings.
*
* This class should not implement business logic, but only provide a convenient
* way to access gateway settings by wrapping the Settings instance.
*/
class DCCGatewayConfiguration {
/**
* Gateway title.
*
* @var string
*/
private string $gateway_title;

/**
* Whether to display the cardholder's name on the payment form.
*
* @var string
*/
private string $show_name_on_card;

/**
* Initializes the gateway details based on the provided Settings instance.
*
* @throws NotFoundException If an expected gateway setting is not found.
*
* @param Settings $settings Plugin settings instance.
*/
public function __construct( Settings $settings ) {
$this->gateway_title = $settings->has( 'dcc_gateway_title' ) ?
$settings->get( 'dcc_gateway_title' ) : '';

$show_on_card = '';
if ( $settings->has( 'dcc_name_on_card' ) ) {
$show_on_card = $settings->get( 'dcc_name_on_card' );
} elseif ( $settings->has( 'axo_name_on_card' ) ) {
// Legacy. The AXO gateway setting was replaced by the DCC setting.
$show_on_card = $settings->get( 'axo_name_on_card' );
}
$valid_options = array_keys( PropertiesDictionary::cardholder_name_options() );

$this->show_name_on_card = in_array( $show_on_card, $valid_options, true )
? $show_on_card
: $valid_options[0];
}

/**
* User facing title of the gateway.
*
* @return string Display title of the gateway.
*/
public function gateway_title() : string {
return $this->gateway_title ?: __( 'Advanced Card Processing', 'woocommerce-paypal-payments' );
}

/**
* Whether to show a field for the cardholder's name in the payment form.
*
* @return string [yes|no]
*/
public function show_name_on_card() : string {
return $this->show_name_on_card;
}
}
Loading

0 comments on commit 75960fc

Please sign in to comment.