Skip to content

Commit

Permalink
UNZER-523 Fix issue with orders on return from auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Nov 19, 2024
1 parent 7e29c6a commit a48e78e
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/Service/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function writeChargeToDB(string $orderid, string $userId, ?Charge $unzerC
*/
protected function prepareTransactionOxid(array $params): string
{
unset($params['oxactiondate'], $params['serialized_basket'], $params['customertype']);
unset($params['oxactiondate'], $params['oxtimestamp'], $params['serialized_basket'], $params['customertype']);

/** @var string $jsonEncode */
$jsonEncode = json_encode($params, JSON_THROW_ON_ERROR);
Expand All @@ -232,18 +232,15 @@ protected function saveTransaction(array $params): bool

$params['metadata'] = $params['metadata'] ?? json_encode('', JSON_THROW_ON_ERROR);

$oxid = $this->getTransactionIdByOrderId($params['oxorderid']);
$oxid = $this->prepareTransactionOxid($params);

if (!$oxid) {
$oxid = $this->prepareTransactionOxid($params);
}

if (!$transaction->load($oxid)) {
if (!$transaction->load($oxid) && $this->canSaveTransaction($params)) {
$transaction->assign($params);
$transaction->setId($oxid);
$transaction->save();

$result = true;
}

return $result;
}

Expand Down Expand Up @@ -706,4 +703,26 @@ private function extendSaveParameters(
->getTransactionParameters($unzerPayment)
);
}

private function canSaveTransaction(array $params): bool
{
$orderId = $params['oxorderid'] ?? '';
if (!$orderId) {
return true;
}

$transactionId = $this->getTransactionIdByOrderId($orderId);
if (!$transactionId) {
return true;
}

$transaction = ($this->getNewTransactionObject())->load($transactionId);
if (!$transaction) {
return true;
}

if ($transaction->getFieldData('oxaction') === 'init') {

Check failure on line 724 in src/Service/Transaction.php

View workflow job for this annotation

GitHub Actions / styles (8.0)

Cannot call method getFieldData() on true.

Check failure on line 724 in src/Service/Transaction.php

View workflow job for this annotation

GitHub Actions / styles (8.0)

Method OxidSolutionCatalysts\Unzer\Service\Transaction::canSaveTransaction() should return bool but return statement is missing.
return true;
}
}
}

0 comments on commit a48e78e

Please sign in to comment.