From 645e64ccc92583c274993ecdf2f8c97c53e5b702 Mon Sep 17 00:00:00 2001 From: Jae Date: Thu, 12 Dec 2024 14:52:14 +0900 Subject: [PATCH 1/6] Skip creating checkout session when cart is empty --- includes/class-wc-gateway-komoju-block.php | 4 ++++ index.php | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-gateway-komoju-block.php b/includes/class-wc-gateway-komoju-block.php index 572755e..23c2b77 100644 --- a/includes/class-wc-gateway-komoju-block.php +++ b/includes/class-wc-gateway-komoju-block.php @@ -45,6 +45,10 @@ public function get_payment_method_script_handles() public function get_payment_method_data() { + if (!is_null(WC()->cart) && WC()->cart->is_empty()) { + return; + } + // We lazily fetch one session to be shared by all payment methods with dynamic fields. static $checkout_session; if (is_null($checkout_session)) { diff --git a/index.php b/index.php index ca7f291..fe65288 100755 --- a/index.php +++ b/index.php @@ -1,4 +1,6 @@ payment_gateways()->payment_gateways(); if ($gateways) { From 346b986f90fba54f4d7546eff37eba5fa3b47575 Mon Sep 17 00:00:00 2001 From: Jae Date: Thu, 12 Dec 2024 15:08:16 +0900 Subject: [PATCH 2/6] Fix lint --- index.php | 1 + uninstall.php | 1 + 2 files changed, 2 insertions(+) diff --git a/index.php b/index.php index fe65288..a5b54e6 100755 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ Date: Fri, 13 Dec 2024 13:45:41 +0900 Subject: [PATCH 3/6] Add isAdmin check & fix if statement --- includes/class-wc-gateway-komoju-block.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-gateway-komoju-block.php b/includes/class-wc-gateway-komoju-block.php index 23c2b77..7e61541 100644 --- a/includes/class-wc-gateway-komoju-block.php +++ b/includes/class-wc-gateway-komoju-block.php @@ -45,7 +45,7 @@ public function get_payment_method_script_handles() public function get_payment_method_data() { - if (!is_null(WC()->cart) && WC()->cart->is_empty()) { + if (!is_admin() && (is_null(WC()->cart) || WC()->cart->is_empty())) { return; } From e2aa0dd1c555d3c7db662e99f401944058ce17b1 Mon Sep 17 00:00:00 2001 From: Jae Date: Fri, 13 Dec 2024 15:18:29 +0900 Subject: [PATCH 4/6] Prevent total null error --- includes/class-wc-gateway-komoju-single-slug.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index 0950919..52f9196 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -131,8 +131,14 @@ public function create_session_for_fields() { $komoju_api = $this->komoju_api; $currency = get_woocommerce_currency(); + $orderTotal = 0; + + if (WC()->cart) { + $orderTotal = $this->get_order_total(); + } + $session_params = [ - 'amount' => self::to_cents($this->get_order_total(), $currency), + 'amount' => self::to_cents($orderTotal, $currency), 'currency' => $currency, 'default_locale' => self::get_locale_or_fallback(), 'metadata' => [ @@ -140,7 +146,7 @@ public function create_session_for_fields() ], ]; - if ($this->get_order_total() == 0) { + if ($orderTotal == 0) { return null; } From 3b57017d28846ffc757cd5aff46a45632821e674 Mon Sep 17 00:00:00 2001 From: Jae Date: Tue, 17 Dec 2024 16:12:08 +0900 Subject: [PATCH 5/6] Fix lint --- includes/class-wc-gateway-komoju-single-slug.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index 52f9196..ab13a02 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -131,14 +131,14 @@ public function create_session_for_fields() { $komoju_api = $this->komoju_api; $currency = get_woocommerce_currency(); - $orderTotal = 0; + $order_total = 0; if (WC()->cart) { - $orderTotal = $this->get_order_total(); + $order_total = $this->get_order_total(); } $session_params = [ - 'amount' => self::to_cents($orderTotal, $currency), + 'amount' => self::to_cents($order_total, $currency), 'currency' => $currency, 'default_locale' => self::get_locale_or_fallback(), 'metadata' => [ @@ -146,7 +146,7 @@ public function create_session_for_fields() ], ]; - if ($orderTotal == 0) { + if ($order_total == 0) { return null; } From 7ed4a5257884bf7f8b3e888a039c12252b57f30c Mon Sep 17 00:00:00 2001 From: Jae Date: Tue, 17 Dec 2024 16:23:16 +0900 Subject: [PATCH 6/6] Fix lint --- includes/class-wc-gateway-komoju-single-slug.php | 2 +- index.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index ab13a02..dbd79ce 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -131,7 +131,7 @@ public function create_session_for_fields() { $komoju_api = $this->komoju_api; $currency = get_woocommerce_currency(); - $order_total = 0; + $order_total = 0; if (WC()->cart) { $order_total = $this->get_order_total(); diff --git a/index.php b/index.php index a5b54e6..01c00f5 100755 --- a/index.php +++ b/index.php @@ -143,6 +143,7 @@ function (PaymentMethodRegistry $payment_method_registry) { } } } - }); + } + ); } }