Skip to content

Commit

Permalink
CheckOrderCommand: Fix internal logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek authored Feb 10, 2022
1 parent a5cb0e3 commit eb3bf15
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions src/Command/CheckOrderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Tracy\Debugger;
use Tracy\ILogger;

final class CheckOrderCommand extends Command
{
Expand Down Expand Up @@ -51,7 +49,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$orders = $this->entityManager->getRepository(Order::class)
->createQueryBuilder('orderEntity')
->leftJoin('orderEntity.status', 'status')
->where('status.code = :code')
->where('orderEntity.paid = FALSE')
->andWhere('status.code = :code')
->setParameter('code', OrderStatus::STATUS_NEW)
->getQuery()
->getResult();
Expand Down Expand Up @@ -126,27 +125,26 @@ private function updateStatusByWorkflow(Order $order): void
*/
private function checkUnmatchedTransactions(array $unauthorizedVariables, Authorizator $authorizator): void
{
try {
$processed = [];
$unmatchedTransactionsList = $authorizator->getUnmatchedTransactions($unauthorizedVariables);
foreach ($unmatchedTransactionsList as $transaction) {
assert($transaction instanceof \Baraja\FioPaymentAuthorizator\Transaction);
if (
isset($processed[$transaction->getIdTransaction()]) === false
&& $this->tm->transactionExist((int) $transaction->getIdTransaction()) === false
&& $this->tm->orderHasPaidByVariableSymbol($transaction->getVariableSymbol()) === false
) {
if ($transaction->getPrice() > 0) {
$this->tm->storeUnmatchedTransaction($transaction);
}
echo $transaction->getIdTransaction() . "\n";
$this->tm->storeTransaction($transaction, true);
$processed[$transaction->getIdTransaction()] = true;
$processed = [];
$unmatchedTransactionsList = $authorizator->getUnmatchedTransactions($unauthorizedVariables);
foreach ($unmatchedTransactionsList as $transaction) {
assert($transaction instanceof \Baraja\FioPaymentAuthorizator\Transaction);
$idTransaction = $transaction->getIdTransaction();
if ($idTransaction === null) {
continue;
}
if (
isset($processed[$idTransaction]) === false
&& $this->tm->transactionExist($idTransaction) === false
&& $this->tm->orderHasPaidByVariableSymbol($transaction->getVariableSymbol()) === false
) {
if ($transaction->getPrice() > 0) {
$this->tm->storeUnmatchedTransaction($transaction);
}
echo $idTransaction . "\n";
$this->tm->storeTransaction($transaction, true);
$processed[$idTransaction] = true;
}
} catch (\Throwable $e) {
Debugger::log($e, ILogger::CRITICAL);
die;
}
}

Expand Down Expand Up @@ -179,11 +177,10 @@ private function authOrders(array $unauthorizedVariables, array $orderByVariable
$unauthorizedVariables,
$callback,
'CZK',
0.25
0.25,
);
} catch (\Throwable $e) {
Debugger::log($e, ILogger::CRITICAL);
die;
throw new \RuntimeException(sprintf('Can not authorize orders: %s', $e->getMessage()), 500, $e);
}
}

Expand Down

0 comments on commit eb3bf15

Please # to comment.