diff --git a/modules/ppcp-axo/services.php b/modules/ppcp-axo/services.php index 44cd181c1..4c62cab69 100644 --- a/modules/ppcp-axo/services.php +++ b/modules/ppcp-axo/services.php @@ -76,7 +76,7 @@ return array( $container->get( 'wcgateway.settings' ), $container->get( 'wcgateway.url' ), $container->get( 'wcgateway.order-processor' ), - $container->get( 'axo.card_icons' ), + $container->get( 'wcgateway.credit-card-icons' ), $container->get( 'api.endpoint.order' ), $container->get( 'api.factory.purchase-unit' ), $container->get( 'api.factory.shipping-preference' ), @@ -86,27 +86,6 @@ return array( ); }, - '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', - ), - ); - }, - /** * The matrix which countries and currency combinations can be used for AXO. */ diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index fd1644b41..8c5292f73 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -119,7 +119,7 @@ class AxoGateway extends WC_Payment_Gateway { * @param ContainerInterface $ppcp_settings The settings. * @param string $wcgateway_module_url The WcGateway module URL. * @param OrderProcessor $order_processor The Order processor. - * @param array $card_icons The card icons. + * @param array $card_icons The card icons. * @param OrderEndpoint $order_endpoint The order endpoint. * @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory. * @param ShippingPreferenceFactory $shipping_preference_factory The shipping preference factory. @@ -285,9 +285,8 @@ class AxoGateway extends WC_Payment_Gateway { * @return string */ public function get_icon() { - $icon = parent::get_icon(); - $icons = $this->card_icons; - $icons_src = esc_url( $this->wcgateway_module_url ) . 'assets/images/'; + $icon = parent::get_icon(); + $icons = $this->card_icons; if ( ! $icons ) { return $icon; @@ -298,8 +297,8 @@ class AxoGateway extends WC_Payment_Gateway { foreach ( $icons as $card ) { $images[] = ' '; } diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index a23de8457..4d8f6bd4f 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -153,6 +153,68 @@ return array( $logger ); }, + 'wcgateway.credit-card-labels' => static function ( ContainerInterface $container ) : array { + return array( + 'visa' => _x( + 'Visa', + 'Name of credit card', + 'woocommerce-paypal-payments' + ), + 'mastercard' => _x( + 'Mastercard', + 'Name of credit card', + 'woocommerce-paypal-payments' + ), + 'amex' => _x( + 'American Express', + 'Name of credit card', + 'woocommerce-paypal-payments' + ), + 'discover' => _x( + 'Discover', + 'Name of credit card', + 'woocommerce-paypal-payments' + ), + 'jcb' => _x( + 'JCB', + 'Name of credit card', + 'woocommerce-paypal-payments' + ), + 'elo' => _x( + 'Elo', + 'Name of credit card', + 'woocommerce-paypal-payments' + ), + 'hiper' => _x( + 'Hiper', + 'Name of credit card', + 'woocommerce-paypal-payments' + ), + ); + }, + 'wcgateway.credit-card-icons' => static function ( ContainerInterface $container ) : array { + $settings = $container->get( 'wcgateway.settings' ); + assert( $settings instanceof Settings ); + + $icons = $settings->has( 'card_icons' ) ? (array) $settings->get( 'card_icons' ) : array(); + $labels = $container->get( 'wcgateway.credit-card-labels' ); + + $module_url = $container->get( 'wcgateway.url' ); + $url_root = esc_url( $module_url ) . 'assets/images/'; + + $icons_with_label = array(); + foreach ( $icons as $icon ) { + $type = str_replace( '-dark', '', $icon ); + + $icons_with_label[] = array( + 'type' => $type, + 'title' => ucwords( $labels[ $type ] ?? $type ), + 'url' => "$url_root/$icon.svg", + ); + } + + return $icons_with_label; + }, 'wcgateway.card-button-gateway' => static function ( ContainerInterface $container ): CardButtonGateway { return new CardButtonGateway( $container->get( 'wcgateway.settings.render' ),