Skip to content

Commit

Permalink
UNZER-499 Fix paymentId handling in admin backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Oct 10, 2024
1 parent 7c74473 commit 75df115
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
4 changes: 3 additions & 1 deletion src/Controller/Admin/AdminOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public function render()

$transactionService = $this->getServiceFromContainer(TransactionService::class);
$orderId = $this->getEditObjectId();
$paymentId = $transactionService->getAdminPaymentIdByOrderId($orderId); //somthesing like s-chg-XXXX

$paymentId = $transactionService->getPaymentIdByOrderId($orderId, true); // ~ s-chg-XXXXX

$this->sTypeId = $paymentId; /** may@throws \TypeError if $paymentId due to wrong payment cancellation */
$this->_aViewData['sTypeId'] = $this->sTypeId;
if ($this->sTypeId) {
Expand Down
38 changes: 5 additions & 33 deletions src/Service/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OxidSolutionCatalysts\Unzer\Service;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\ResultStatement;
use OxidEsales\Eshop\Application\Model\User;
Expand Down Expand Up @@ -469,41 +470,12 @@ public function getPaymentIdByOrderId(string $orderid, bool $withoutCancel = fal
':oxaction' => $transActionConst
];

$queryResult = $query->setParameters($parameters)->execute();
if ($queryResult instanceof ResultStatement && $queryResult->columnCount()) {
$result = $queryResult->fetchOne();
$result = is_string($result) ? $result : '';
}

return $result;
}

/**
* @param string $orderid
* @return string
* @throws Exception
* @throws \Doctrine\DBAL\Exception
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function getAdminPaymentIdByOrderId(string $orderid): string
{
$result = '';

$queryBuilderFactory = $this->getServiceFromContainer(QueryBuilderFactoryInterface::class);
$queryBuilder = $queryBuilderFactory->create();

$query = $queryBuilder
->select('typeid')
->from('oscunzertransaction')
->distinct()
->where($queryBuilder->expr()->eq('oxorderid', ':oxorderid'))
->setMaxResults(1);

$parameters = [
':oxorderid' => $orderid,
$parameterTypes = [
':oxorderid' => \PDO::PARAM_STR,
':oxaction' => Connection::PARAM_STR_ARRAY // Specify array type
];

$queryResult = $query->setParameters($parameters)->execute();
$queryResult = $query->setParameters($parameters, $parameterTypes)->execute();
if ($queryResult instanceof ResultStatement && $queryResult->columnCount()) {
$result = $queryResult->fetchOne();
$result = is_string($result) ? $result : '';
Expand Down

0 comments on commit 75df115

Please sign in to comment.