From b8291a11e586bb8969194896f11f8504297da1f1 Mon Sep 17 00:00:00 2001 From: Grant Date: Wed, 14 Feb 2024 16:22:42 +0900 Subject: [PATCH] fix another warning and refactor --- class-wc-gateway-komoju.php | 5 +-- docs/dev_setup.md | 2 +- .../class-wc-gateway-komoju-single-slug.php | 45 ++++++++++--------- index.php | 1 - 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/class-wc-gateway-komoju.php b/class-wc-gateway-komoju.php index 3d480c3..10dcf16 100755 --- a/class-wc-gateway-komoju.php +++ b/class-wc-gateway-komoju.php @@ -28,14 +28,13 @@ class WC_Gateway_Komoju extends WC_Payment_Gateway /** @var WC_Logger Logger instance */ public static $log; - // Fixing deprecated properties protected $debug; protected $invoice_prefix; protected $secretKey; protected $webhookSecretToken; protected $komoju_api; - protected $instructions; // Fixing deprecated property - protected $useOnHold; // Fixing deprecated property + protected $instructions; + protected $useOnHold; /** * Constructor for the gateway. diff --git a/docs/dev_setup.md b/docs/dev_setup.md index 8cc3405..9f7dcd9 100644 --- a/docs/dev_setup.md +++ b/docs/dev_setup.md @@ -12,7 +12,7 @@ This will download the docker images and WordPress plugins. Once the initial set **Note:** It _has_ to be `127.0.0.1`, not `localhost` -If you've made changes to your Docker configuration, you can do a fresh build: +If you've made changes to your files, you can rebuild using build. If you've made changes to your Docker configuration, you can do a fresh build with --no-cache option. ``` docker-compose build (--no-cache) diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index cea7b44..e946576 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -32,27 +32,30 @@ public function __construct($payment_method) $this->has_fields = $this->should_use_inline_fields($slug); $this->method_title = __('Komoju', 'komoju-woocommerce') . ' - ' . $this->default_title(); - // if ($slug == 'credit_card') { - // // Show dynamic icon with supported brands. - // $brands = isset($payment_method['subtypes']) ? $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"; - // } + if ($slug == 'credit_card') { + // Show dynamic icon with supported brands. + $brands = isset($payment_method['subtypes']) ? $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) { + // Get the sort order for $a and $b, providing a default value if the key doesn't exist + $sort_a = isset($sort_order[$a]) ? $sort_order[$a] : count($sort_order); + $sort_b = isset($sort_order[$b]) ? $sort_order[$b] : count($sort_order); + + return $sort_a - $sort_b; + }); + + $brands = implode(',', $brands); + $this->icon .= "?brands=$brands"; + } // TODO: It would be nice if KOMOJU told us in the payment method object whether or // not it supports refunds. For now, we'll just wing it. diff --git a/index.php b/index.php index 7fcf6c3..b118106 100755 --- a/index.php +++ b/index.php @@ -32,7 +32,6 @@ function woocommerce_add_komoju_gateway($methods) $methods[] = new WC_Gateway_Komoju_Single_Slug($payment_method); } } - return $methods; }