diff --git a/modules/ppcp-axo/services.php b/modules/ppcp-axo/services.php index 0e11e2742..21daccdd1 100644 --- a/modules/ppcp-axo/services.php +++ b/modules/ppcp-axo/services.php @@ -41,7 +41,18 @@ return array( 'axo.gateway' => static function ( ContainerInterface $container ): AxoGateway { return new AxoGateway( - $container->get( 'wcgateway.settings' ) + $container->get( 'wcgateway.settings' ), + $container->get( 'wcgateway.url' ), + $container->get( 'axo.card_icons' ) + ); + }, + + 'axo.card_icons' => static function ( ContainerInterface $container ): array { + return array( + array('title' => 'Visa', 'file' => 'visa-dark.svg'), + array('title' => 'MasterCard', 'file' => 'mastercard-dark.svg'), + array('title' => 'American Express', 'file' => 'amex.svg'), + array('title' => 'Discover', 'file' => 'discover.svg'), ); }, diff --git a/modules/ppcp-axo/src/Assets/AxoManager.php b/modules/ppcp-axo/src/Assets/AxoManager.php index af4c8fd14..26e920461 100644 --- a/modules/ppcp-axo/src/Assets/AxoManager.php +++ b/modules/ppcp-axo/src/Assets/AxoManager.php @@ -163,4 +163,37 @@ class AxoManager { ); } + /** + * Returns the action name that PayPal AXO button will use for rendering on the checkout page. + * + * @return string + */ + public function checkout_button_renderer_hook(): string { + /** + * The filter returning the action name that PayPal AXO button will use for rendering on the checkout page. + */ + return (string) apply_filters( 'woocommerce_paypal_payments_checkout_axo_renderer_hook', 'woocommerce_review_order_after_submit' ); + } + + /** + * Renders the HTML for the AXO submit button. + */ + public function render_checkout_button() { + $id = 'ppcp-axo-submit-button-container'; + + /** + * The WC filter returning the WC order button text. + * phpcs:disable WordPress.WP.I18n.TextDomainMismatch + */ + $label = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ); + + printf( + '
', + esc_attr( $id ), + esc_html( $label ) + ); + } + } diff --git a/modules/ppcp-axo/src/AxoModule.php b/modules/ppcp-axo/src/AxoModule.php index a960d474d..3656d8b98 100644 --- a/modules/ppcp-axo/src/AxoModule.php +++ b/modules/ppcp-axo/src/AxoModule.php @@ -61,14 +61,13 @@ class AxoModule implements ModuleInterface { add_action( 'init', static function () use ( $c ) { + $manager = $c->get( 'axo.manager' ); + assert( $manager instanceof AxoManager ); // Enqueue frontend scripts. add_action( 'wp_enqueue_scripts', - static function () use ( $c ) { - $manager = $c->get( 'axo.manager' ); - assert( $manager instanceof AxoManager ); - + static function () use ( $c, $manager ) { $smart_button = $c->get( 'button.smart-button' ); assert( $smart_button instanceof SmartButtonInterface ); @@ -78,52 +77,18 @@ class AxoModule implements ModuleInterface { } ); + // Render submit button. + add_action( + $manager->checkout_button_renderer_hook(), + static function () use ( $c, $manager ) { + $manager->render_checkout_button(); + } + ); + }, 1 ); - add_action( - $this->checkout_button_renderer_hook(), - array( - $this, - 'axo_button_renderer', - ), - 11 - ); - - } - - /** - * Returns the action name that PayPal AXO button will use for rendering on the checkout page. - * - * @return string - */ - private function checkout_button_renderer_hook(): string { - /** - * The filter returning the action name that PayPal AXO button will use for rendering on the checkout page. - */ - return (string) apply_filters( 'woocommerce_paypal_payments_checkout_axo_renderer_hook', 'woocommerce_review_order_after_submit' ); - } - - /** - * Renders the HTML for the AXO submit button. - */ - public function axo_button_renderer() { - $id = 'ppcp-axo-submit-button-container'; - - /** - * The WC filter returning the WC order button text. - * phpcs:disable WordPress.WP.I18n.TextDomainMismatch - */ - $label = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ); - - printf( - ' ', - esc_attr( $id ), - esc_html( $label ) - ); } /** diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index d7cadcbd2..53d438103 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -26,18 +26,36 @@ class AxoGateway extends WC_Payment_Gateway { */ protected $ppcp_settings; + /** + * The WcGateway module URL. + * + * @var string + */ + protected $wcgateway_module_url; + + /** + * The card icons. + * + * @var array + */ + protected $card_icons; + /** * AXOGateway constructor. * * @param ContainerInterface $ppcp_settings The settings. */ public function __construct( - ContainerInterface $ppcp_settings + ContainerInterface $ppcp_settings, + string $wcgateway_module_url, + array $card_icons ) { - $this->ppcp_settings = $ppcp_settings; - $this->id = self::ID; + $this->ppcp_settings = $ppcp_settings; + $this->wcgateway_module_url = $wcgateway_module_url; + $this->card_icons = $card_icons; + $this->method_title = __( 'Fastlane Debit & Credit Cards', 'woocommerce-paypal-payments' ); $this->method_description = __( 'Fastlane Debit & Credit Cards', 'woocommerce-paypal-payments' ); @@ -108,41 +126,24 @@ class AxoGateway extends WC_Payment_Gateway { return $result; } -// public function is_available() -// { -// return $this->is_enabled(); // parent::is_available(); -// } -// -// /** -// * Returns if the gateway is enabled. -// * -// * @return bool -// */ -// private function is_enabled(): bool { -// return true; -// //return $this->ppcp_settings->has( 'axo_enabled' ) && $this->ppcp_settings->get( 'axo_enabled' ); // TODO -// } - /** * Returns the icons of the gateway. * * @return string */ public function get_icon() { + $icon = parent::get_icon(); + + if ( empty( $this->card_icons ) ) { + return $icon; + } + $images = array(); - - $cards = array( - array('title' => 'Visa', 'file' => 'visa-dark.svg'), - array('title' => 'MasterCard', 'file' => 'mastercard-dark.svg'), - array('title' => 'American Express', 'file' => 'amex.svg'), - array('title' => 'Discover', 'file' => 'discover.svg'), - ); - - foreach ($cards as $card) { + foreach ($this->card_icons as $card) { $images[] = '