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 e568000 commit 538d768
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/PaymentExtensions/UnzerPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ private function performTransactionForSavedPayment(
false,
null,
null,
\UnzerSDK\Constants\RecurrenceTypes::ONE_CLICK
RecurrenceTypes::ONE_CLICK
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Service/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace OxidSolutionCatalysts\Unzer\Service;

use Exception;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Payment as PaymentModel;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
Expand All @@ -19,7 +20,7 @@
use OxidSolutionCatalysts\Unzer\Exception\RedirectWithMessage;
use OxidSolutionCatalysts\Unzer\Exception\UnzerException;
use OxidSolutionCatalysts\Unzer\Model\TmpOrder;
use OxidSolutionCatalysts\Unzer\Model\Order;

use OxidSolutionCatalysts\Unzer\PaymentExtensions\UnzerPayment as AbstractUnzerPayment;
use OxidSolutionCatalysts\Unzer\Service\Transaction as TransactionService;
use stdClass;
Expand Down
40 changes: 33 additions & 7 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 @@ -228,22 +228,19 @@ protected function prepareTransactionOxid(array $params): string
protected function saveTransaction(array $params): bool
{
$result = false;

$transaction = $this->getNewTransactionObject();

//check if metadata exists
$params['metadata'] = $params['metadata'] ?? json_encode('', JSON_THROW_ON_ERROR);

// building oxid from unique index columns
// only write to DB if oxid doesn't exist to prevent multiple entries of the same transaction
$oxid = $this->prepareTransactionOxid($params);
if (!$transaction->load($oxid)) {

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

$result = true;
}

return $result;
}

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

private function canSaveTransaction($transaction, array $params): bool

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

View workflow job for this annotation

GitHub Actions / styles (8.0)

Method OxidSolutionCatalysts\Unzer\Service\Transaction::canSaveTransaction() has parameter $transaction with no type specified.
{
$orderId = $params['oxorderid'] ?? '';
if (!$orderId) {
return true;
}

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

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

if (
$transaction->getFieldData('oxorderid') === $params['oxorderid']
&& $transaction->getFieldData('traceid') === $params['traceid']
&& $transaction->getFieldData('shortid') === $params['shortid']

) {
return false;
}

return true;
}
}

0 comments on commit 538d768

Please sign in to comment.