Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [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.

## [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.
Expand Down
13 changes: 11 additions & 2 deletions Controller/Adminhtml/System/Config/ChangeOrderStatusButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 11 additions & 3 deletions Model/Cron/UpdateOrderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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]);
}
Expand Down
Loading