From 2220f8d1d5f26bd58e290241c1d0d2be7af09442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Thu, 15 Feb 2024 10:29:03 +0100 Subject: [PATCH] fix two step --- src/Handlers/IPNHandler.php | 6 ++++++ src/Support/Request.php | 1 + src/TwoStepPayment.php | 15 ++++++++------- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Handlers/IPNHandler.php b/src/Handlers/IPNHandler.php index b85309a..8873ebf 100644 --- a/src/Handlers/IPNHandler.php +++ b/src/Handlers/IPNHandler.php @@ -52,6 +52,12 @@ protected function handleFinished() { $this->order->payment_complete(); + if ($this->order->get_meta('_cone_simplepay_two_step_payment_reserved') && ! $this->order->get_meta('_cone_simplepay_two_step_payment_finished')) { + $this->order->update_meta_data('_cone_simplepay_two_step_payment_finished', date('c')); + + $this->order->save(); + } + $virtual = true; foreach ($this->order->get_items(['line_item']) as $item) { diff --git a/src/Support/Request.php b/src/Support/Request.php index 6ee84c7..f2cadcb 100644 --- a/src/Support/Request.php +++ b/src/Support/Request.php @@ -117,6 +117,7 @@ public function send() if (is_wp_error($response)) { Log::info($response->get_error_message()); + throw new Exception($response->get_error_message()); } diff --git a/src/TwoStepPayment.php b/src/TwoStepPayment.php index a72b99b..c6364d6 100644 --- a/src/TwoStepPayment.php +++ b/src/TwoStepPayment.php @@ -25,7 +25,7 @@ class TwoStepPayment */ public static function boot() { - add_filter('woocommerce_order_actions', [static::class, 'register']); + add_filter('woocommerce_order_actions', [static::class, 'register'], 10, 2); add_action('woocommerce_order_action_'.static::ACTION, [static::class, 'handle']); } @@ -33,15 +33,12 @@ public static function boot() * Register the action. * * @param array $actions + * @param \WC_Order $order * @return array */ - public static function register($actions) + public static function register($actions, $order) { - global $theorder; - - if (! $theorder->is_paid() - && $theorder->get_meta('_cone_simplepay_two_step_payment_reserved') - && ! $theorder->get_meta('_cone_simplepay_two_step_payment_finished')) { + if ($order->get_meta('_cone_simplepay_two_step_payment_reserved') && ! $order->get_meta('_cone_simplepay_two_step_payment_finished')) { $actions[static::ACTION] = __('Finish the two step SimplePay payment', 'cone-simplepay'); } @@ -69,6 +66,10 @@ public static function handle(WC_Order $order) throw new Exception(__('Request is invalid', 'cone-simplepay')); } + if ($order->get_meta('_cone_simplepay_two_step_payment_reserved') && ! $order->get_meta('_cone_simplepay_two_step_payment_finished')) { + $order->update_meta_data('_cone_simplepay_two_step_payment_finished', date('c')); + } + $order->add_order_note( __('Two step SimplePay payment has been finished.', 'cone-simplepay') );