From d0e1e3eaf3fb4b5c355d4bf321fddd038f9a8bdb Mon Sep 17 00:00:00 2001 From: Dallin Layton Date: Mon, 6 May 2024 09:23:20 -0600 Subject: [PATCH 1/4] ASD-1193 adds default pending payment order status for express checkout --- Controller/Checkout/PlaceOrder.php | 3 +++ Model/CheckoutSessionManagement.php | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Controller/Checkout/PlaceOrder.php b/Controller/Checkout/PlaceOrder.php index f74b464b..a1d56a7f 100755 --- a/Controller/Checkout/PlaceOrder.php +++ b/Controller/Checkout/PlaceOrder.php @@ -90,6 +90,9 @@ public function execute() if (!$result['success']) { $this->messageManager->addErrorMessage($result['message']); } + + // for orders placed before payment authorization (Express checkout) + $this->amazonCheckoutSessionManagement->setOrderPendingPaymentReview($result['order_id'] ?? null); } catch (\Exception $e) { $this->exceptionLogger->logException($e); $this->messageManager->addErrorMessage($e->getMessage()); diff --git a/Model/CheckoutSessionManagement.php b/Model/CheckoutSessionManagement.php index 52b75782..daf4b17d 100755 --- a/Model/CheckoutSessionManagement.php +++ b/Model/CheckoutSessionManagement.php @@ -1344,4 +1344,25 @@ private function closeChargePermission($amazonSessionId, OrderInterface $order, ); } } + + /** + * Set order status to payment review + * + * @param $orderId + * @return void + */ + public function setOrderPendingPaymentReview($orderId) + { + try { + if(!$orderId) { + throw new \Exception('orderId missing'); + } + $order = $this->orderRepository->get($orderId); + // Update status to Pending Payment Review to support order placement before auth + $payment = $order->getPayment(); + $this->setPending($payment); + } catch (\Exception $e) { + $this->logger->error('Unable to set payment review order status. ' . $e->getMessage()); + } + } } From ea5fe080436ae4e5ddf4037874c149809c11c191 Mon Sep 17 00:00:00 2001 From: Dallin Layton Date: Tue, 7 May 2024 13:58:58 -0600 Subject: [PATCH 2/4] ASD-1193 sets processing order state anytime charge status is authorized or captured --- Model/CheckoutSessionManagement.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/CheckoutSessionManagement.php b/Model/CheckoutSessionManagement.php index daf4b17d..a1ab9df3 100755 --- a/Model/CheckoutSessionManagement.php +++ b/Model/CheckoutSessionManagement.php @@ -1273,17 +1273,17 @@ private function handlePayment($amazonSessionId, $amazonCheckoutResult, $order, $this->asyncManagement->queuePendingAuthorization($chargeId); break; case 'Authorized': + $this->setProcessing($payment); if ($this->amazonConfig->getAuthorizationMode() == AuthorizationMode::SYNC_THEN_ASYNC) { - $this->setProcessing($payment); $this->addCaptureComment($payment, $amazonCharge['chargePermissionId']); } break; case 'Captured': $payment->setIsTransactionClosed(true); $transaction->setIsClosed(true); + $this->setProcessing($payment); if ($this->amazonConfig->getAuthorizationMode() == AuthorizationMode::SYNC_THEN_ASYNC) { - $this->setProcessing($payment); // capture and invoice on the Magento side $this->asyncCharge->capture($order, $chargeId, $quote->getGrandTotal()); } From 20e40e88e0e5b2fd93d5899505322041399216e3 Mon Sep 17 00:00:00 2001 From: Dallin Layton Date: Tue, 14 May 2024 13:52:09 -0600 Subject: [PATCH 3/4] ASD-1193 phpcs fixes --- Model/CheckoutSessionManagement.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Model/CheckoutSessionManagement.php b/Model/CheckoutSessionManagement.php index a1ab9df3..37158a5c 100755 --- a/Model/CheckoutSessionManagement.php +++ b/Model/CheckoutSessionManagement.php @@ -1348,14 +1348,14 @@ private function closeChargePermission($amazonSessionId, OrderInterface $order, /** * Set order status to payment review * - * @param $orderId + * @param mixed $orderId * @return void */ - public function setOrderPendingPaymentReview($orderId) + public function setOrderPendingPaymentReview(mixed $orderId) { try { - if(!$orderId) { - throw new \Exception('orderId missing'); + if (!$orderId) { + throw new \InvalidArgumentException('orderId missing'); } $order = $this->orderRepository->get($orderId); // Update status to Pending Payment Review to support order placement before auth From c4d8cb8702a8a108137e2e55f6cf02619edab6a0 Mon Sep 17 00:00:00 2001 From: Dallin Layton Date: Tue, 14 May 2024 13:53:57 -0600 Subject: [PATCH 4/4] ASD-1193 explicitely sets order status only when successful --- Controller/Checkout/PlaceOrder.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Controller/Checkout/PlaceOrder.php b/Controller/Checkout/PlaceOrder.php index a1d56a7f..fe735cc4 100755 --- a/Controller/Checkout/PlaceOrder.php +++ b/Controller/Checkout/PlaceOrder.php @@ -87,12 +87,14 @@ public function execute() $amazonCheckoutSessionId = $this->request->getParam('amazonCheckoutSessionId'); $result = $this->amazonCheckoutSessionManagement->placeOrder($amazonCheckoutSessionId); - if (!$result['success']) { + + if ($result['success']) { + // for orders placed before payment authorization (Express checkout) + $this->amazonCheckoutSessionManagement->setOrderPendingPaymentReview($result['order_id'] ?? null); + } else { $this->messageManager->addErrorMessage($result['message']); } - // for orders placed before payment authorization (Express checkout) - $this->amazonCheckoutSessionManagement->setOrderPendingPaymentReview($result['order_id'] ?? null); } catch (\Exception $e) { $this->exceptionLogger->logException($e); $this->messageManager->addErrorMessage($e->getMessage());