Skip to content

Commit

Permalink
correct oxNew(CoreClass) not oxNew(ModelClass)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolorenz committed Sep 1, 2023
1 parent 3e45092 commit 14e1415
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 11 additions & 8 deletions src/Controller/DispatcherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

namespace OxidSolutionCatalysts\Unzer\Controller;

use Exception;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Registry;
Expand All @@ -28,6 +30,7 @@ class DispatcherController extends FrontendController
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws UnzerApiException
* @throws Exception
*
* @SuppressWarnings(PHPMD.StaticAccess)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
Expand All @@ -42,7 +45,7 @@ public function updatePaymentTransStatus(): void
$jsonRequest = file_get_contents('php://input');

/** @var array $aJson */
$aJson = json_decode($jsonRequest, true);
$aJson = json_decode($jsonRequest, true, 512, JSON_THROW_ON_ERROR);
/** @var array $url */
$url = parse_url($aJson['retrieveUrl']);
/** @var Transaction $transaction */
Expand All @@ -61,7 +64,7 @@ public function updatePaymentTransStatus(): void
}

if (
($url['scheme'] != "https" || ($url['host'] != "api.unzer.com" && $url['host'] != "sbx-api.heidelpay.com"))
($url['scheme'] !== "https" || ($url['host'] !== "api.unzer.com" && $url['host'] !== "sbx-api.heidelpay.com"))
) {
Registry::getUtils()->showMessageAndExit("No valid retrieveUrl");
}
Expand All @@ -76,28 +79,28 @@ public function updatePaymentTransStatus(): void
$paymentId = $resource->getId();
if (is_string($paymentId)) {
/** @var \OxidSolutionCatalysts\Unzer\Model\Order $order */
$order = oxNew(\OxidSolutionCatalysts\Unzer\Model\Order::class);
$order = oxNew(Order::class);
/** @var array $data */
$data = $transaction->getTransactionDataByPaymentId($paymentId);
$data = $transaction::getTransactionDataByPaymentId($paymentId);

$unzerPayment = $unzer->fetchPayment($paymentId);

if ($order->load($data[0]['OXORDERID'])) {
/** @var string $oxTransStatus */
$oxTransStatus = $order->getFieldData('oxtransstatus');
if ($unzerPayment->getState() == 1 && $oxTransStatus == "OK") {
if ($oxTransStatus === "OK" && $unzerPayment->getState() === 1) {
$order->markUnzerOrderAsPaid();
}

if ($unzerPayment->getState() == 2) {
if ($unzerPayment->getState() === 2) {
$order->cancelOrder();
}

$translator = $this->getServiceFromContainer(Translator::class);

if ($unzerPayment->getState() != 2 && $oxTransStatus != "OK") {
if ($oxTransStatus !== "OK" && $unzerPayment->getState() !== 2) {
$ret = $order->reinitializeOrder();
if ($ret != 1) {
if ($ret !== 1) {
$unzer->debugLog("Order-Recalculation failed and returned with code: " . $ret);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Controller/InstallmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Application\Model\Payment as PaymentModel;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Application\Model\Basket;
use OxidSolutionCatalysts\Unzer\Exception\Redirect;
use OxidSolutionCatalysts\Unzer\Service\Transaction;
use OxidSolutionCatalysts\Unzer\Service\Unzer;
use OxidSolutionCatalysts\Unzer\Service\Payment as PaymentService;
use OxidSolutionCatalysts\Unzer\Traits\ServiceContainer;
use UnzerSDK\Resources\Payment;
use UnzerSDK\Resources\PaymentTypes\InstallmentSecured;
Expand Down Expand Up @@ -117,7 +119,7 @@ public function getPayment()

// payment is set ?
$sPaymentid = $oBasket->getPaymentId();
$oPayment = oxNew(\OxidSolutionCatalysts\Unzer\Model\Payment::class);
$oPayment = oxNew(PaymentModel::class);

/** @var string $sShipSet */
$sShipSet = Registry::getSession()->getVariable('sShipSet');
Expand Down Expand Up @@ -156,7 +158,7 @@ protected function getUnzerSessionPayment(): ?Payment
if ($this->uzrPayment === null) {
/** @var \OxidSolutionCatalysts\Unzer\Service\Payment $payment */
$payment = $this->getServiceFromContainer(
\OxidSolutionCatalysts\Unzer\Service\Payment::class
PaymentService::class
);
/** @var Payment $sessionUnzerPayment */
$sessionUnzerPayment = $payment->getSessionUnzerPayment();
Expand All @@ -170,7 +172,7 @@ protected function getUnzerSessionPayment(): ?Payment
*/
public function cancelInstallment()
{
$paymentService = $this->getServiceFromContainer(\OxidSolutionCatalysts\Unzer\Service\Payment::class);
$paymentService = $this->getServiceFromContainer(PaymentService::class);
$paymentService->removeTemporaryOrder();

$unzerService = $this->getServiceFromContainer(Unzer::class);
Expand Down

0 comments on commit 14e1415

Please sign in to comment.