Skip to content

Commit

Permalink
fix: Update order status for failed orders when auto-cancel is disabl…
Browse files Browse the repository at this point in the history
…ed (#36)
  • Loading branch information
samumaretiya authored and soleilcot committed Aug 31, 2023
1 parent 121e0f3 commit 0bb3820
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
11 changes: 11 additions & 0 deletions Cron/OrderFraudStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ public function updateOrdersFromNoFraudApiResult($orders, $storeId)
}
continue;
}
} else {
if (isset($decision) && ($decision == 'fail' || $decision == "fraudulent")) {
if (!empty($newStatus)) {
$this->dataHelper->addDataToLog("Updating Order#" . $order['increment_id'] . " to " . $newStatus);
$this->orderProcessor->updateOrderStatusFromNoFraudResult($newStatus, $order, $response);
}
$order->setNofraudStatus($decision);
$order->save();
}
continue;
}
}
if (isset($decision) && ($decision == 'pass')) {
if (!empty($newStatus)) {
Expand Down
18 changes: 3 additions & 15 deletions Observer/SalesOrderPaymentPlaceEnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$nofraudDecision = $resultMap['http']['response']['body']['decision'] ?? "";
if (isset($nofraudDecision) && !empty($nofraudDecision)) {
$newStatus = $this->orderProcessor->getCustomOrderStatus($resultMap['http']['response'], $storeId);
if (isset($nofraudDecision) && ($nofraudDecision == 'error')) {
if (!empty($newStatus)) {
$this->orderProcessor->updateOrderStatusFromNoFraudResult($newStatus, $order, $resultMap);
}
}
if (isset($nofraudDecision) && ($nofraudDecision == 'pass')) {
if (!empty($newStatus)) {
$this->orderProcessor->updateOrderStatusFromNoFraudResult($newStatus, $order, $resultMap);
}
}
if (isset($nofraudDecision) && ($nofraudDecision == 'review')) {
if (!empty($newStatus)) {
$this->orderProcessor->updateOrderStatusFromNoFraudResult($newStatus, $order, $resultMap);
}
} else {
Expand All @@ -212,10 +202,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$order->save();

// If order fails screening and auto-cancel is enabled in admin config, cancel the order
if ($this->configHelper->getAutoCancel($storeId)) {
if (isset($nofraudDecision) && $nofraudDecision == 'fail') {
$this->orderProcessor->handleAutocancel($order, $nofraudDecision);
}
if ($this->configHelper->getAutoCancel($storeId) && isset($nofraudDecision) && $nofraudDecision == 'fail') {
$this->orderProcessor->handleAutocancel($order, $nofraudDecision);
}
} catch (\Exception $exception) {
$this->logger->logFailure($order, $exception);
Expand Down

0 comments on commit 0bb3820

Please sign in to comment.