Skip to content

Commit 48bdda9

Browse files
AC-10042::/V1/transactions REST API returns error when parent_txn_id = txn_id
1 parent 91cb4d4 commit 48bdda9

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Transaction.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,23 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
139139
$orderId = $transaction->getData('order_id');
140140
$paymentId = $transaction->getData('payment_id');
141141
$idFieldName = $this->getIdFieldName();
142-
142+
$txnType = $transaction->getData('txn_type');
143143
if ($parentTxnId) {
144144
if (!$txnId || !$orderId || !$paymentId) {
145145
throw new \Magento\Framework\Exception\LocalizedException(
146146
__('We don\'t have enough information to save the parent transaction ID.')
147147
);
148148
}
149149
$parentId = (int)$this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName);
150-
if ($parentId) {
150+
if ($parentId && $txnType == 'authorization') {
151151
$transaction->setData('parent_id', $parentId);
152+
$transaction->setData('txn_type',\Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE);
153+
}
154+
} else {
155+
$result = $this->getParentId($orderId);
156+
if ($result) {
157+
$transaction->setData('parent_id', $result[0]['transaction_id']);
158+
$transaction->setData('parent_txn_id', $result[0]['parent_txn_id']);
152159
}
153160
}
154161

@@ -211,4 +218,23 @@ private function _getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $column
211218
$txnId
212219
);
213220
}
221+
222+
/**
223+
* Retrieve transaction by the unique key of order_id
224+
*
225+
* @param int $orderId
226+
* @return array
227+
*/
228+
protected function getParentId(int $orderId): array
229+
{
230+
$connection = $this->getConnection();
231+
$select = $connection->select()->from(
232+
$this->getMainTable(),
233+
['transaction_id','parent_txn_id']
234+
)->where(
235+
'order_id = ?',
236+
$orderId
237+
)->order('transaction_id','ASC')->limit(1);
238+
return $connection->fetchAll($select);
239+
}
214240
}

dev/tests/integration/testsuite/Magento/Sales/_files/transactions_detailed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
$payment->setIsTransactionClosed(false);
2626
$payment->setTransactionAdditionalInfo('capture_key', 'data');
2727
$payment->setParentTransactionId('trx_auth');
28-
$payment->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE);
28+
$payment->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_AUTH);
2929

3030
$order->save();

dev/tests/integration/testsuite/Magento/Sales/_files/transactions_list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
/** @var array $transactionData */
5555
foreach ($transactions as $transactionData) {
5656
$payment->addData($transactionData);
57-
$payment->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE);
57+
$payment->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_AUTH);
5858
}
5959

6060
$order->save();

0 commit comments

Comments
 (0)