From c68b40d68d02fab418987a84682187f384b1ba3e Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Thu, 2 Nov 2023 13:15:31 +0100 Subject: [PATCH 1/2] Add transaction ID to the authorized order --- src/MerchantCapture/MerchantCaptureModule.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/MerchantCapture/MerchantCaptureModule.php b/src/MerchantCapture/MerchantCaptureModule.php index 4d028857..0be33962 100644 --- a/src/MerchantCapture/MerchantCaptureModule.php +++ b/src/MerchantCapture/MerchantCaptureModule.php @@ -126,19 +126,23 @@ public function services(): array public function run(ContainerInterface $container): bool { $pluginId = $container->get('shared.plugin_id'); - add_action($pluginId . '_after_webhook_action', static function (Payment $payment, WC_Order $order) use ($container) { + add_action( + /** + * @throws \WC_Data_Exception + */ $pluginId . '_after_webhook_action', static function (Payment $payment, WC_Order $order) use ($container) { if ($payment->isAuthorized()) { if (!$payment->getAmountCaptured() == 0.0) { return; } $order->set_status(SharedDataDictionary::STATUS_ON_HOLD); $order->update_meta_data(self::ORDER_PAYMENT_STATUS_META_KEY, ManualCaptureStatus::STATUS_AUTHORIZED); + $order->set_transaction_id($payment->id); $order->save(); } elseif ($payment->isPaid() && ($container->get('merchant.manual_capture.is_waiting'))($order)) { $order->update_meta_data(self::ORDER_PAYMENT_STATUS_META_KEY, ManualCaptureStatus::STATUS_CAPTURED); $order->save(); } - }, 10, 2); + }, 10, 2); add_action('woocommerce_order_refunded', static function (int $orderId) use ($container) { $order = wc_get_order($orderId); From b323b6745227f41538c8aed179eee35de2c5b1c7 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Thu, 2 Nov 2023 13:24:33 +0100 Subject: [PATCH 2/2] Code style --- src/MerchantCapture/MerchantCaptureModule.php | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/MerchantCapture/MerchantCaptureModule.php b/src/MerchantCapture/MerchantCaptureModule.php index 0be33962..f5630556 100644 --- a/src/MerchantCapture/MerchantCaptureModule.php +++ b/src/MerchantCapture/MerchantCaptureModule.php @@ -129,20 +129,24 @@ public function run(ContainerInterface $container): bool add_action( /** * @throws \WC_Data_Exception - */ $pluginId . '_after_webhook_action', static function (Payment $payment, WC_Order $order) use ($container) { - if ($payment->isAuthorized()) { - if (!$payment->getAmountCaptured() == 0.0) { - return; + */ $pluginId . '_after_webhook_action', + static function (Payment $payment, WC_Order $order) use ($container) { + if ($payment->isAuthorized()) { + if (!$payment->getAmountCaptured() == 0.0) { + return; + } + $order->set_status(SharedDataDictionary::STATUS_ON_HOLD); + $order->update_meta_data(self::ORDER_PAYMENT_STATUS_META_KEY, ManualCaptureStatus::STATUS_AUTHORIZED); + $order->set_transaction_id($payment->id); + $order->save(); + } elseif ($payment->isPaid() && ($container->get('merchant.manual_capture.is_waiting'))($order)) { + $order->update_meta_data(self::ORDER_PAYMENT_STATUS_META_KEY, ManualCaptureStatus::STATUS_CAPTURED); + $order->save(); } - $order->set_status(SharedDataDictionary::STATUS_ON_HOLD); - $order->update_meta_data(self::ORDER_PAYMENT_STATUS_META_KEY, ManualCaptureStatus::STATUS_AUTHORIZED); - $order->set_transaction_id($payment->id); - $order->save(); - } elseif ($payment->isPaid() && ($container->get('merchant.manual_capture.is_waiting'))($order)) { - $order->update_meta_data(self::ORDER_PAYMENT_STATUS_META_KEY, ManualCaptureStatus::STATUS_CAPTURED); - $order->save(); - } - }, 10, 2); + }, + 10, + 2 + ); add_action('woocommerce_order_refunded', static function (int $orderId) use ($container) { $order = wc_get_order($orderId);