From e92c281a9d1707d7b53d07e7143f1f1829690b3f Mon Sep 17 00:00:00 2001 From: Bushra Asif Date: Wed, 18 Feb 2026 10:12:16 +0500 Subject: [PATCH 1/2] Fix: Issue where failed AltaPay orders stayed in pending status and were not cancelled automatically. --- CHANGELOG.md | 5 +++++ .../System/Config/ChangeOrderStatusButton.php | 13 +++++++++++-- Model/Cron/UpdateOrderStatus.php | 14 +++++++++++--- Setup/Patch/Data/MaskedPanUpdate.php | 2 +- composer.json | 2 +- etc/module.xml | 2 +- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0ad9cc7..f360865c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog All notable changes to this project will be documented in this file. +## [4.2.2] +### Fixed +- Fix: Issue where failed AltaPay orders stayed in pending status and were not cancelled automatically. +- Improved the cancellation logic to keep stock in sync correctly. + ## [4.2.1] ### Added - Added a **Back to Shopping Cart** button on the payment form, allowing customers to cancel the payment and return to the cart. diff --git a/Controller/Adminhtml/System/Config/ChangeOrderStatusButton.php b/Controller/Adminhtml/System/Config/ChangeOrderStatusButton.php index ab8079f3..8ea90bce 100644 --- a/Controller/Adminhtml/System/Config/ChangeOrderStatusButton.php +++ b/Controller/Adminhtml/System/Config/ChangeOrderStatusButton.php @@ -18,6 +18,7 @@ use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; +use SDM\Altapay\Model\SystemConfig; class ChangeOrderStatusButton extends Action { @@ -90,8 +91,16 @@ public function execute() try { $orderCollection = $this->orderCollection->create(); - $orderCollection->addAttributeToFilter('status','pending') - ->addAttributeToFilter('altapay_payment_form_url', ['neq' => 'NULL']); + $orderCollection->addFieldToFilter('state', ['in' => ['new', 'pending_payment']]); + + $orderCollection->getSelect() + ->join( + ['payment' => $orderCollection->getTable('sales_order_payment')], + 'main_table.entity_id = payment.parent_id', + [] + ) + ->where('payment.method IN (?)', SystemConfig::getTerminalCodes()) + ->where('payment.last_trans_id IS NULL OR payment.last_trans_id = ?', ''); if (array_filter($orderCollection->getData())) { foreach ($orderCollection as $order) { diff --git a/Model/Cron/UpdateOrderStatus.php b/Model/Cron/UpdateOrderStatus.php index 86ee4f18..09201b4e 100644 --- a/Model/Cron/UpdateOrderStatus.php +++ b/Model/Cron/UpdateOrderStatus.php @@ -15,6 +15,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; use Magento\Sales\Api\OrderManagementInterface; +use SDM\Altapay\Model\SystemConfig; class UpdateOrderStatus { @@ -91,10 +92,17 @@ public function execute() $orderCollection = $this->orderCollection->create(); $orderCollection->addFieldToSelect('entity_id') ->addFieldToFilter('created_at', ['lt' => date('Y-m-d H:i:s', $cutoffTime)]) - ->addAttributeToFilter('status','pending') - ->addAttributeToFilter('state','new') - ->addAttributeToFilter('altapay_payment_form_url', ['neq' => 'NULL']); + ->addFieldToFilter('state', ['in' => ['new', 'pending_payment']]); + $orderCollection->getSelect() + ->join( + ['payment' => $orderCollection->getTable('sales_order_payment')], + 'main_table.entity_id = payment.parent_id', + [] + ) + ->where('payment.method IN (?)', SystemConfig::getTerminalCodes()) + ->where('payment.last_trans_id IS NULL OR payment.last_trans_id = ?', ''); + if ($this->scopeConfig->getValue(self::EXCLUDE_ADMIN_ORDER, $storeScope)) { $orderCollection->addFieldToFilter('remote_ip', ['neq' => null]); } diff --git a/Setup/Patch/Data/MaskedPanUpdate.php b/Setup/Patch/Data/MaskedPanUpdate.php index d224cf36..bb54df91 100644 --- a/Setup/Patch/Data/MaskedPanUpdate.php +++ b/Setup/Patch/Data/MaskedPanUpdate.php @@ -75,6 +75,6 @@ public static function getDependencies() */ public static function getVersion() { - return '4.2.1'; + return '4.2.2'; } } diff --git a/composer.json b/composer.json index 3a4c7242..92fc3897 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "altapay/magento2-community", "license": "MIT", "description": "AltaPay: Payments less complicated", - "version": "4.2.1", + "version": "4.2.2", "require": { "php": "^7.0 || ^8.1", "altapay/api-php": "^3.5.4" diff --git a/etc/module.xml b/etc/module.xml index 68fd39ea..e37f068e 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -10,6 +10,6 @@ --> - + From 1a9219640ea30c44dc768f2e978a736fd07db021 Mon Sep 17 00:00:00 2001 From: Bushra Asif Date: Thu, 19 Feb 2026 10:17:55 +0500 Subject: [PATCH 2/2] Update release notes --- CHANGELOG.md | 2 +- Setup/Patch/Data/MaskedPanUpdate.php | 2 +- composer.json | 2 +- etc/module.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f360865c..a7555b58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog All notable changes to this project will be documented in this file. -## [4.2.2] +## [unreleased] ### Fixed - Fix: Issue where failed AltaPay orders stayed in pending status and were not cancelled automatically. - Improved the cancellation logic to keep stock in sync correctly. diff --git a/Setup/Patch/Data/MaskedPanUpdate.php b/Setup/Patch/Data/MaskedPanUpdate.php index bb54df91..d224cf36 100644 --- a/Setup/Patch/Data/MaskedPanUpdate.php +++ b/Setup/Patch/Data/MaskedPanUpdate.php @@ -75,6 +75,6 @@ public static function getDependencies() */ public static function getVersion() { - return '4.2.2'; + return '4.2.1'; } } diff --git a/composer.json b/composer.json index 92fc3897..3a4c7242 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "altapay/magento2-community", "license": "MIT", "description": "AltaPay: Payments less complicated", - "version": "4.2.2", + "version": "4.2.1", "require": { "php": "^7.0 || ^8.1", "altapay/api-php": "^3.5.4" diff --git a/etc/module.xml b/etc/module.xml index e37f068e..68fd39ea 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -10,6 +10,6 @@ --> - +