Skip to content

Commit 38f35d6

Browse files
update: enhance transaction handling for Apple Pay by ensuring txn_id records are saved and logged properly
1 parent ecdcf08 commit 38f35d6

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

Model/Method/AbstractMethod.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,15 +805,36 @@ public function order(InfoInterface $payment, $amount)
805805

806806
$this->saveTransactionData($response[0], $payment, $this->closeOrderTransaction, true);
807807

808+
$order = $payment->getOrder();
809+
if (!empty($order) && !empty($order->getId())) {
810+
try {
811+
$payment->save();
812+
813+
$this->logger2->addDebug(sprintf(
814+
'[%s] Payment transaction persisted successfully for order: %s, transaction ID: %s',
815+
__METHOD__,
816+
$order->getIncrementId(),
817+
$payment->getTransactionId()
818+
));
819+
} catch (\Exception $e) {
820+
$this->logger2->addError(sprintf(
821+
'[%s] Failed to persist payment transaction - Order: %s, Transaction ID: %s, Error: %s',
822+
__METHOD__,
823+
$order->getIncrementId(),
824+
$payment->getTransactionId(),
825+
$e->getMessage()
826+
));
827+
throw $e;
828+
}
829+
}
830+
808831
// SET REGISTRY BUCKAROO REDIRECT
809832
$this->_registry->unregister('buckaroo_response');
810833
$this->_registry->register('buckaroo_response', $response);
811834

812835
if (!(isset($response[0]->RequiredAction->Type) && $response[0]->RequiredAction->Type === 'Redirect')) {
813836
$this->setPaymentInTransit($payment, false);
814837
}
815-
816-
$order = $payment->getOrder();
817838
$this->helper->setRestoreQuoteLastOrder($order->getId());
818839

819840
$this->eventManager->dispatch('buckaroo_order_after', ['order' => $order]);

Model/Push.php

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,15 @@ public function receivePush()
275275

276276
$this->logging->addDebug(__METHOD__ . '|1_2|');
277277
$orderIncrementID = $this->getOrderIncrementId();
278-
$this->logging->addDebug(__METHOD__ . '|Lock Name| - ' . var_export($orderIncrementID, true));
278+
$transactionKey = $this->getTransactionKey();
279+
280+
$this->logging->addDebug(sprintf(
281+
'%s|Processing push for Order: %s, Transaction: %s',
282+
__METHOD__,
283+
$orderIncrementID,
284+
$transactionKey
285+
));
286+
279287
$lockAcquired = $this->lockManager->lockOrder($orderIncrementID, 5);
280288

281289
if (!$lockAcquired) {
@@ -1294,14 +1302,47 @@ protected function getOrderByTransactionKey()
12941302
{
12951303
$trxId = $this->getTransactionKey();
12961304

1297-
$this->transaction->load($trxId, 'txn_id');
1298-
$order = $this->transaction->getOrder();
1305+
$this->searchCriteriaBuilder->addFilter('txn_id', $trxId, 'eq');
1306+
$searchCriteria = $this->searchCriteriaBuilder->create();
12991307

1300-
if (!$order) {
1308+
try {
1309+
$transactionList = $this->transactionRepository->getList($searchCriteria);
1310+
$items = $transactionList->getItems();
1311+
1312+
if (empty($items)) {
1313+
$this->logging->addError(sprintf(
1314+
'%s|No transaction found for txn_id: %s. This may indicate the transaction was not saved properly or a database transaction was rolled back.',
1315+
__METHOD__,
1316+
$trxId
1317+
));
1318+
throw new Exception(__('There was no order found by transaction Id'));
1319+
}
1320+
1321+
// Get the first (and should be only) transaction
1322+
$transaction = reset($items);
1323+
$order = $transaction->getOrder();
1324+
1325+
if (!$order || !$order->getId()) {
1326+
$this->logging->addError(sprintf(
1327+
'%s|Transaction found but order is missing for txn_id: %s. Transaction ID: %s',
1328+
__METHOD__,
1329+
$trxId,
1330+
$transaction->getTransactionId()
1331+
));
1332+
throw new Exception(__('There was no order found by transaction Id'));
1333+
}
1334+
1335+
return $order;
1336+
1337+
} catch (\Exception $e) {
1338+
$this->logging->addError(sprintf(
1339+
'%s|Error loading transaction by txn_id: %s. Error: %s',
1340+
__METHOD__,
1341+
$trxId,
1342+
$e->getMessage()
1343+
));
13011344
throw new Exception(__('There was no order found by transaction Id'));
13021345
}
1303-
1304-
return $order;
13051346
}
13061347

13071348
/**

0 commit comments

Comments
 (0)