♻️ Apply new icon logic to ACDC gateway

This commit is contained in:
Philipp Stracker 2024-09-13 18:57:27 +02:00
parent cbd3fe24e4
commit 1c4d17f0ea
No known key found for this signature in database
2 changed files with 25 additions and 60 deletions

View file

@ -132,10 +132,13 @@ return array(
$payments_endpoint = $container->get( 'api.endpoint.payments' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
$vaulted_credit_card_handler = $container->get( 'vaulting.credit-card-handler' );
$icons = $container->get( 'wcgateway.credit-card-icons' );
return new CreditCardGateway(
$settings_renderer,
$order_processor,
$settings,
$icons,
$module_url,
$session_handler,
$refund_processor,

View file

@ -59,6 +59,13 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
*/
protected $order_processor;
/**
* The card icons.
*
* @var array
*/
protected $card_icons;
/**
* The settings.
*
@ -184,6 +191,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 array $card_icons The card icons.
* @param string $module_url The URL to the module.
* @param SessionHandler $session_handler The Session Handler.
* @param RefundProcessor $refund_processor The refund processor.
@ -204,6 +212,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
SettingsRenderer $settings_renderer,
OrderProcessor $order_processor,
ContainerInterface $config,
array $card_icons,
string $module_url,
SessionHandler $session_handler,
RefundProcessor $refund_processor,
@ -264,6 +273,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
$this->config->get( 'dcc_gateway_title' ) : $this->method_title;
$this->description = $this->config->has( 'dcc_gateway_description' ) ?
$this->config->get( 'dcc_gateway_description' ) : $this->method_description;
$this->card_icons = $card_icons;
$this->init_form_fields();
$this->init_settings();
@ -339,74 +349,26 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
* @return string
*/
public function get_icon() {
$icon = parent::get_icon();
$icon = parent::get_icon();
$icons = $this->card_icons;
$icons = $this->config->has( 'card_icons' ) ? (array) $this->config->get( 'card_icons' ) : array();
if ( empty( $icons ) ) {
if ( ! $icons ) {
return $icon;
}
$title_options = $this->card_labels();
$images = array_map(
function ( string $type ) use ( $title_options ): string {
$striped_dark = str_replace( '-dark', '', $type );
return '<img
title="' . esc_attr( $title_options[ $striped_dark ] ) . '"
src="' . esc_url( $this->module_url ) . 'assets/images/' . esc_attr( $type ) . '.svg"
class="ppcp-card-icon"
> ';
},
$icons
);
$images = array();
foreach ( $icons as $card ) {
$images[] = '<img
class="ppcp-card-icon"
title="' . esc_attr( $card['title'] ) . '"
src="' . esc_url( $card['url'] ) . '"
> ';
}
return implode( '', $images );
}
/**
* Returns an array of credit card names.
*
* @return array
*/
private function card_labels(): 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'
),
);
}
/**
* Whether the gateway is available or not.
*