From 5ef15e0442a538c0361abb59694393ab5ba09e03 Mon Sep 17 00:00:00 2001 From: Grant Date: Wed, 14 Feb 2024 14:05:23 +0900 Subject: [PATCH 1/4] update version and get rid of deprecation warnings --- Dockerfile | 2 +- class-wc-gateway-komoju.php | 9 +++ docker-compose.yml | 2 +- docs/dev_setup.md | 14 ++++- .../class-wc-gateway-komoju-single-slug.php | 56 ++++++++++--------- .../komoju-php/lib/komoju/KomojuApi.php | 4 ++ 6 files changed, 59 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index 88bf1cc..395c4ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM wordpress:6.1.1 +FROM wordpress:6.4.2 ARG woocommerce_version diff --git a/class-wc-gateway-komoju.php b/class-wc-gateway-komoju.php index 8241ff2..3d480c3 100755 --- a/class-wc-gateway-komoju.php +++ b/class-wc-gateway-komoju.php @@ -28,6 +28,15 @@ 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 + /** * Constructor for the gateway. */ diff --git a/docker-compose.yml b/docker-compose.yml index d4f8080..2790464 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,7 +21,7 @@ services: context: . dockerfile: Dockerfile args: - woocommerce_version: 6.3.1 + woocommerce_version: 8.5.1 ports: - "8000:80" restart: always diff --git a/docs/dev_setup.md b/docs/dev_setup.md index c50204f..8cc3405 100644 --- a/docs/dev_setup.md +++ b/docs/dev_setup.md @@ -12,12 +12,24 @@ 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: + +``` +docker-compose build (--no-cache) +``` + +If you want to completely start fresh, including removing any data stored in Docker volumes (such as your MySQL database data), you can use the -v option: + +``` +docker-compose down -v +``` + ## Configuring Ngrok Because the Komoju plugin uses webhooks to receive notifications once the payment is complete the wordpress instance will need to be accessible to the internet. This can be done with [ngrok](https://ngrok.com/): ``` -ngrok http -host-header=rewrite http://127.0.0.1:8000 +ngrok http --host-header=rewrite http://127.0.0.1:8000 ``` **Note:** Accessing the website using the ngrok endpoint doesn't work particularly well, so you're better off using 127.0.0.1 to go through the checkout flow and just use ngrok for the webhook integration. diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index 7988bf7..cea7b44 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -12,6 +12,16 @@ */ class WC_Gateway_Komoju_Single_Slug extends WC_Gateway_Komoju { + protected $publishableKey; + protected $payment_method; + protected $debug; + protected $invoice_prefix; + protected $secretKey; + protected $webhookSecretToken; + protected $komoju_api; + protected $instructions; + protected $useOnHold; + public function __construct($payment_method) { $slug = $payment_method['type_slug']; @@ -22,31 +32,27 @@ public function __construct($payment_method) $this->has_fields = $this->should_use_inline_fields($slug); $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') { - // Show dynamic icon with supported brands. - $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"; - } - } + // 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"; + // } // 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/komoju-php/komoju-php/lib/komoju/KomojuApi.php b/komoju-php/komoju-php/lib/komoju/KomojuApi.php index b76f9ee..d0877be 100644 --- a/komoju-php/komoju-php/lib/komoju/KomojuApi.php +++ b/komoju-php/komoju-php/lib/komoju/KomojuApi.php @@ -2,6 +2,10 @@ class KomojuApi { + private $endpoint; + private $via; + private $secretKey; + public static function defaultEndpoint() { return 'https://komoju.com'; From b8291a11e586bb8969194896f11f8504297da1f1 Mon Sep 17 00:00:00 2001 From: Grant Date: Wed, 14 Feb 2024 16:22:42 +0900 Subject: [PATCH 2/4] 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; } From 107cf879435dbccfa5dc52107ccac85a8e4c496d Mon Sep 17 00:00:00 2001 From: Grant Date: Thu, 15 Feb 2024 16:24:53 +0900 Subject: [PATCH 3/4] update dev setup readme --- docs/dev_setup.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/dev_setup.md b/docs/dev_setup.md index 9f7dcd9..e5f036e 100644 --- a/docs/dev_setup.md +++ b/docs/dev_setup.md @@ -2,20 +2,20 @@ This document provides a detailed setup guide for the development environment, including instructions for WordPress and WooCommerce. This was written on WordPress version 6.1.1 and WooCommerce 6.3.1. -To begin, start the docker containers: +To begin, start the docker containers, using the --build option to watch for changes: ``` -$ docker-compose up +docker-compose up --build ``` This will download the docker images and WordPress plugins. Once the initial setup is done (docker is no longer constantly writing text to screen), you can navigate to `127.0.0.1:8000` to setup WordPress. **Note:** It _has_ to be `127.0.0.1`, not `localhost` -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. +If you've made changes to your files, you can manually 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) +docker-compose build --no-cache ``` If you want to completely start fresh, including removing any data stored in Docker volumes (such as your MySQL database data), you can use the -v option: From 66597df5457b535c3f397db677e36240e069de85 Mon Sep 17 00:00:00 2001 From: Grant Date: Thu, 15 Feb 2024 16:29:10 +0900 Subject: [PATCH 4/4] refactor --- includes/class-wc-gateway-komoju-single-slug.php | 4 ++++ index.php | 1 + 2 files changed, 5 insertions(+) diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index e946576..d4d76a5 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -32,6 +32,10 @@ public function __construct($payment_method) $this->has_fields = $this->should_use_inline_fields($slug); $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') { // Show dynamic icon with supported brands. $brands = isset($payment_method['subtypes']) ? $payment_method['subtypes'] : []; diff --git a/index.php b/index.php index b118106..7fcf6c3 100755 --- a/index.php +++ b/index.php @@ -32,6 +32,7 @@ function woocommerce_add_komoju_gateway($methods) $methods[] = new WC_Gateway_Komoju_Single_Slug($payment_method); } } + return $methods; }