From d7d3749f6cd0c8621cda46f2cdf5a9c31f63ade5 Mon Sep 17 00:00:00 2001 From: Nigel Baillie Date: Mon, 31 Oct 2022 18:43:14 +0900 Subject: [PATCH 1/3] request dynamic credit card icon from komoju --- assets/cards.svg | 250 ------------------ .../class-wc-gateway-komoju-single-slug.php | 8 +- 2 files changed, 5 insertions(+), 253 deletions(-) delete mode 100644 assets/cards.svg diff --git a/assets/cards.svg b/assets/cards.svg deleted file mode 100644 index 36b856b..0000000 --- a/assets/cards.svg +++ /dev/null @@ -1,250 +0,0 @@ - - - - diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index 3f78cc4..29f18ed 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -22,10 +22,12 @@ public function __construct($payment_method) $this->method_title = __('Komoju', 'komoju-woocommerce') . ' - ' . $this->default_title(); if ($this->get_option('showIcon') == 'yes') { + $this->icon = "https://komoju.com/payment_methods/$slug.svg"; + if ($slug == 'credit_card') { - $this->icon = plugins_url('komoju-woocommerce/assets/cards.svg'); - } else { - $this->icon = "https://komoju.com/payment_methods/$slug.svg"; + // Show dynamic icon with supported brands. + $brands = implode(',', $payment_method['subtypes']); + $this->icon .= "?brands=$brands"; } } From ce557a56c6f9d781b2735959a46c8e86a0d975e9 Mon Sep 17 00:00:00 2001 From: Nigel Baillie Date: Tue, 1 Nov 2022 10:27:11 +0900 Subject: [PATCH 2/3] Sort brands --- .../class-wc-gateway-komoju-single-slug.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index 29f18ed..19b3756 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -26,7 +26,23 @@ public function __construct($payment_method) if ($slug == 'credit_card') { // Show dynamic icon with supported brands. - $brands = implode(',', $payment_method['subtypes']); + $brands = $payment_method['subtypes']; + + $sort_order = [ + 'visa' => 0, + 'master' => 1, + 'jcb' => 2, + 'american_express' => 3, + 'diners_club' => 4, + 'discover' => 5 + ]; + + // Sort by the order defined above. + usort($brands, function ($a, $b) use ($sort_order) { + return $sort_order[$a] - $sort_order[$b]; + }); + + $brands = implode(',', $brands); $this->icon .= "?brands=$brands"; } } From 6185c0bcb2cedbf57f5085a0e261c240a9945b4a Mon Sep 17 00:00:00 2001 From: Nigel Baillie Date: Tue, 1 Nov 2022 11:03:19 +0900 Subject: [PATCH 3/3] lint fix --- includes/class-wc-gateway-komoju-single-slug.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index 19b3756..141787d 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -29,12 +29,12 @@ public function __construct($payment_method) $brands = $payment_method['subtypes']; $sort_order = [ - 'visa' => 0, - 'master' => 1, - 'jcb' => 2, + 'visa' => 0, + 'master' => 1, + 'jcb' => 2, 'american_express' => 3, - 'diners_club' => 4, - 'discover' => 5 + 'diners_club' => 4, + 'discover' => 5, ]; // Sort by the order defined above.