mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +08:00
Refactor AXO module
This commit is contained in:
parent
e71c34913f
commit
ffb2de496d
7 changed files with 258 additions and 60 deletions
|
@ -84,6 +84,23 @@ return array(
|
||||||
'requirements' => array(),
|
'requirements' => array(),
|
||||||
'gateway' => 'paypal',
|
'gateway' => 'paypal',
|
||||||
),
|
),
|
||||||
|
'axo_email_widget' => array(
|
||||||
|
'title' => __( 'Email Widget', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'select',
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __(
|
||||||
|
'This controls if the Hosted Email Widget should be used.',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
),
|
||||||
|
'classes' => array( 'ppcp-field-indent' ),
|
||||||
|
'class' => array(),
|
||||||
|
'input_class' => array( 'wc-enhanced-select' ),
|
||||||
|
'default' => 'pay',
|
||||||
|
'options' => PropertiesDictionary::email_widget_options(),
|
||||||
|
'screens' => array( State::STATE_ONBOARDED ),
|
||||||
|
'gateway' => 'paypal',
|
||||||
|
'requirements' => array(),
|
||||||
|
),
|
||||||
'axo_address_widget' => array(
|
'axo_address_widget' => array(
|
||||||
'title' => __( 'Address Widget', 'woocommerce-paypal-payments' ),
|
'title' => __( 'Address Widget', 'woocommerce-paypal-payments' ),
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
|
|
|
@ -9,6 +9,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\Axo;
|
namespace WooCommerce\PayPalCommerce\Axo;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\Axo\Assets\AxoManager;
|
||||||
|
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
@ -24,4 +26,23 @@ return array(
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'axo.manager' => static function ( ContainerInterface $container ): AxoManager {
|
||||||
|
return new AxoManager(
|
||||||
|
$container->get( 'axo.url' ),
|
||||||
|
$container->get( 'ppcp.asset-version' ),
|
||||||
|
$container->get( 'session.handler' ),
|
||||||
|
$container->get( 'wcgateway.settings' ),
|
||||||
|
$container->get( 'onboarding.environment' ),
|
||||||
|
$container->get( 'wcgateway.settings.status' ),
|
||||||
|
$container->get( 'api.shop.currency' ),
|
||||||
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
'axo.gateway' => static function ( ContainerInterface $container ): AxoGateway {
|
||||||
|
return new AxoGateway(
|
||||||
|
$container->get( 'wcgateway.settings' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
166
modules/ppcp-axo/src/Assets/AxoManager.php
Normal file
166
modules/ppcp-axo/src/Assets/AxoManager.php
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The AXO AxoManager
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\WcGateway\Assets
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\Axo\Assets;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||||
|
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AxoManager.
|
||||||
|
*
|
||||||
|
* @param string $module_url The URL to the module.
|
||||||
|
*/
|
||||||
|
class AxoManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL to the module.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $module_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The assets version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The settings.
|
||||||
|
*
|
||||||
|
* @var Settings
|
||||||
|
*/
|
||||||
|
private $settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The environment object.
|
||||||
|
*
|
||||||
|
* @var Environment
|
||||||
|
*/
|
||||||
|
private $environment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Settings status helper.
|
||||||
|
*
|
||||||
|
* @var SettingsStatus
|
||||||
|
*/
|
||||||
|
private $settings_status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 3-letter currency code of the shop.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $currency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The logger.
|
||||||
|
*
|
||||||
|
* @var LoggerInterface
|
||||||
|
*/
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Session handler.
|
||||||
|
*
|
||||||
|
* @var SessionHandler
|
||||||
|
*/
|
||||||
|
private $session_handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AxoManager constructor.
|
||||||
|
*
|
||||||
|
* @param string $module_url The URL to the module.
|
||||||
|
* @param string $version The assets version.
|
||||||
|
* @param SessionHandler $session_handler The Session handler.
|
||||||
|
* @param Settings $settings The Settings.
|
||||||
|
* @param Environment $environment The environment object.
|
||||||
|
* @param SettingsStatus $settings_status The Settings status helper.
|
||||||
|
* @param string $currency 3-letter currency code of the shop.
|
||||||
|
* @param LoggerInterface $logger The logger.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $module_url,
|
||||||
|
string $version,
|
||||||
|
SessionHandler $session_handler,
|
||||||
|
Settings $settings,
|
||||||
|
Environment $environment,
|
||||||
|
SettingsStatus $settings_status,
|
||||||
|
string $currency,
|
||||||
|
LoggerInterface $logger
|
||||||
|
) {
|
||||||
|
|
||||||
|
$this->module_url = $module_url;
|
||||||
|
$this->version = $version;
|
||||||
|
$this->session_handler = $session_handler;
|
||||||
|
$this->settings = $settings;
|
||||||
|
$this->environment = $environment;
|
||||||
|
$this->settings_status = $settings_status;
|
||||||
|
$this->currency = $currency;
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueues scripts/styles.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function enqueue() {
|
||||||
|
|
||||||
|
// Register styles.
|
||||||
|
wp_register_style(
|
||||||
|
'wc-ppcp-axo',
|
||||||
|
untrailingslashit( $this->module_url ) . '/assets/css/styles.css',
|
||||||
|
array(),
|
||||||
|
$this->version
|
||||||
|
);
|
||||||
|
wp_enqueue_style( 'wc-ppcp-axo' );
|
||||||
|
|
||||||
|
// Register scripts.
|
||||||
|
wp_register_script(
|
||||||
|
'wc-ppcp-axo',
|
||||||
|
untrailingslashit( $this->module_url ) . '/assets/js/boot.js',
|
||||||
|
array(),
|
||||||
|
$this->version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
wp_enqueue_script( 'wc-ppcp-axo' );
|
||||||
|
|
||||||
|
wp_localize_script(
|
||||||
|
'wc-ppcp-axo',
|
||||||
|
'wc_ppcp_axo',
|
||||||
|
$this->script_data()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration for AXO.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function script_data() {
|
||||||
|
$email_widget = $this->settings->has( 'axo_email_widget' ) ? $this->settings->get( 'axo_email_widget' ) : null;
|
||||||
|
$address_widget = $this->settings->has( 'axo_address_widget' ) ? $this->settings->get( 'axo_address_widget' ) : null;
|
||||||
|
$payment_widget = $this->settings->has( 'axo_payment_widget' ) ? $this->settings->get( 'axo_payment_widget' ) : null;
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'widgets' => array(
|
||||||
|
'email' => $email_widget ?: 'render',
|
||||||
|
'address' => $address_widget ?: 'render',
|
||||||
|
'payment' => $payment_widget ?: 'render',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,7 +9,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\Axo;
|
namespace WooCommerce\PayPalCommerce\Axo;
|
||||||
|
|
||||||
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
|
use WooCommerce\PayPalCommerce\Axo\Assets\AxoManager;
|
||||||
|
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||||
|
@ -37,11 +38,7 @@ class AxoModule implements ModuleInterface {
|
||||||
add_filter(
|
add_filter(
|
||||||
'woocommerce_payment_gateways',
|
'woocommerce_payment_gateways',
|
||||||
function ( $methods ) use ( $c ): array {
|
function ( $methods ) use ( $c ): array {
|
||||||
$settings = $c->get( 'wcgateway.settings' );
|
$methods[] = $c->get('axo.gateway');
|
||||||
|
|
||||||
$methods[] = new AxoGateway(
|
|
||||||
$settings
|
|
||||||
);
|
|
||||||
return $methods;
|
return $methods;
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
|
@ -69,36 +66,15 @@ class AxoModule implements ModuleInterface {
|
||||||
add_action(
|
add_action(
|
||||||
'wp_enqueue_scripts',
|
'wp_enqueue_scripts',
|
||||||
static function () use ( $c ) {
|
static function () use ( $c ) {
|
||||||
$module_url = $c->get( 'axo.url' );
|
$manager = $c->get( 'axo.manager' );
|
||||||
$version = '1';
|
assert( $manager instanceof AxoManager );
|
||||||
|
|
||||||
// Register styles.
|
$smart_button = $c->get( 'button.smart-button' );
|
||||||
wp_register_style(
|
assert( $smart_button instanceof SmartButtonInterface );
|
||||||
'wc-ppcp-axo',
|
|
||||||
untrailingslashit( $module_url ) . '/assets/css/styles.css',
|
|
||||||
array(),
|
|
||||||
$version
|
|
||||||
);
|
|
||||||
wp_enqueue_style( 'wc-ppcp-axo' );
|
|
||||||
|
|
||||||
// Register scripts.
|
|
||||||
wp_register_script(
|
|
||||||
'wc-ppcp-axo',
|
|
||||||
untrailingslashit( $module_url ) . '/assets/js/boot.js',
|
|
||||||
array(),
|
|
||||||
$version,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
wp_enqueue_script( 'wc-ppcp-axo' );
|
|
||||||
|
|
||||||
wp_localize_script(
|
|
||||||
'wc-ppcp-axo',
|
|
||||||
'wc_ppcp_axo',
|
|
||||||
array(
|
|
||||||
// TODO
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
if ( $smart_button->should_load_ppcp_script() ) {
|
||||||
|
$manager->enqueue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -24,24 +24,30 @@ class AxoGateway extends WC_Payment_Gateway {
|
||||||
*
|
*
|
||||||
* @var ContainerInterface
|
* @var ContainerInterface
|
||||||
*/
|
*/
|
||||||
protected $config;
|
protected $ppcp_settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AXOGateway constructor.
|
* AXOGateway constructor.
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $config The settings.
|
* @param ContainerInterface $ppcp_settings The settings.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ContainerInterface $config
|
ContainerInterface $ppcp_settings
|
||||||
) {
|
) {
|
||||||
$this->config = $config;
|
$this->ppcp_settings = $ppcp_settings;
|
||||||
|
|
||||||
$this->id = self::ID;
|
$this->id = self::ID;
|
||||||
|
|
||||||
$this->method_title = __( 'Fastlane Debit & Credit Cards', 'woocommerce-paypal-payments' );
|
$this->method_title = __( 'Fastlane Debit & Credit Cards', 'woocommerce-paypal-payments' );
|
||||||
$this->method_description = __( 'Fastlane Debit & Credit Cards', 'woocommerce-paypal-payments' );
|
$this->method_description = __( 'Fastlane Debit & Credit Cards', 'woocommerce-paypal-payments' );
|
||||||
|
|
||||||
$this->title = $this->get_option( 'title', $this->method_title );
|
$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->description = $this->get_option( 'description', __( '', 'woocommerce-paypal-payments' ) );
|
$this->description = $this->get_option( 'description', __( '', 'woocommerce-paypal-payments' ) );
|
||||||
|
|
||||||
$this->init_form_fields();
|
$this->init_form_fields();
|
||||||
|
@ -63,9 +69,6 @@ class AxoGateway extends WC_Payment_Gateway {
|
||||||
|
|
||||||
// $this->icon = esc_url( $this->module_url ) . 'assets/images/axo.svg'; // TODO
|
// $this->icon = esc_url( $this->module_url ) . 'assets/images/axo.svg'; // TODO
|
||||||
// $this->environment = $environment;
|
// $this->environment = $environment;
|
||||||
|
|
||||||
$is_axo_enabled = $this->config->has( 'axo_enabled' ) && $this->config->get( 'axo_enabled' );
|
|
||||||
$this->update_option( 'enabled', $is_axo_enabled ? 'yes' : 'no' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,7 +120,7 @@ class AxoGateway extends WC_Payment_Gateway {
|
||||||
// */
|
// */
|
||||||
// private function is_enabled(): bool {
|
// private function is_enabled(): bool {
|
||||||
// return true;
|
// return true;
|
||||||
// //return $this->config->has( 'axo_enabled' ) && $this->config->get( 'axo_enabled' ); // TODO
|
// //return $this->ppcp_settings->has( 'axo_enabled' ) && $this->ppcp_settings->get( 'axo_enabled' ); // TODO
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,6 +14,18 @@ namespace WooCommerce\PayPalCommerce\Axo\Helper;
|
||||||
*/
|
*/
|
||||||
class PropertiesDictionary {
|
class PropertiesDictionary {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the possible list of possible email widget options.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function email_widget_options(): array {
|
||||||
|
return array(
|
||||||
|
'render' => __( 'Render email input', 'woocommerce-paypal-payments' ),
|
||||||
|
'use_widget' => __( 'Use email widget', 'woocommerce-paypal-payments' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the possible list of possible address widget options.
|
* Returns the possible list of possible address widget options.
|
||||||
*
|
*
|
||||||
|
@ -21,8 +33,8 @@ class PropertiesDictionary {
|
||||||
*/
|
*/
|
||||||
public static function address_widget_options(): array {
|
public static function address_widget_options(): array {
|
||||||
return array(
|
return array(
|
||||||
'render' => __( 'Render address options.', 'woocommerce-paypal-payments' ),
|
'render' => __( 'Render address options list', 'woocommerce-paypal-payments' ),
|
||||||
'use_widget' => __( 'Use address widget.', 'woocommerce-paypal-payments' ),
|
'use_widget' => __( 'Use address widget', 'woocommerce-paypal-payments' ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +45,8 @@ class PropertiesDictionary {
|
||||||
*/
|
*/
|
||||||
public static function payment_widget_options(): array {
|
public static function payment_widget_options(): array {
|
||||||
return array(
|
return array(
|
||||||
'render' => __( 'Render payment options.', 'woocommerce-paypal-payments' ),
|
'render' => __( 'Render payment options list', 'woocommerce-paypal-payments' ),
|
||||||
'use_widget' => __( 'Use payment widget.', 'woocommerce-paypal-payments' ),
|
'use_widget' => __( 'Use payment widget', 'woocommerce-paypal-payments' ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,22 @@
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ppcp-field-indent {
|
.ppcp-settings-field {
|
||||||
|
border-left: 1px solid transparent;
|
||||||
|
border-right: 1px solid transparent;
|
||||||
|
|
||||||
|
&.ppcp-field-indent {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
border: 1px solid #c3c4c7;
|
||||||
|
|
||||||
th {
|
th {
|
||||||
padding-left: 20px;
|
padding-left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
& + .ppcp-field-indent {
|
||||||
|
border-top: 2px solid transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevents spacing after button group.
|
// Prevents spacing after button group.
|
||||||
|
@ -39,12 +51,3 @@
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ppcp-field-indent {
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
border: 1px solid #c3c4c7;
|
|
||||||
|
|
||||||
& + .ppcp-field-indent {
|
|
||||||
border-top: 2px solid transparent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue