Skip to content

Commit

Permalink
UNZER-529 Fix class chaining in deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Dec 11, 2024
1 parent 4471053 commit 58cbd28
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion Tests/Unit/Service/UnzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public function getPaymentProcedureDataProvider(): array
return [
['paypal', 'special'],
['card', 'special'],
['applepay', 'special'],
['installment-secured', 'authorize'],
['paylater-installment', 'authorize'],
['paylater-invoice', 'authorize'],
Expand Down
3 changes: 1 addition & 2 deletions src/Controller/Admin/AdminOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use OxidEsales\Eshop\Core\Registry;
use OxidSolutionCatalysts\Unzer\Traits\Request;
use OxidEsales\Eshop\Application\Model\Payment;
use OxidSolutionCatalysts\Unzer\Model\Order as UnzerOrder;
use OxidSolutionCatalysts\Unzer\Model\TransactionList;
use OxidSolutionCatalysts\Unzer\Service\Payment as UnzerPaymentService;
use OxidSolutionCatalysts\Unzer\Service\Transaction as TransactionService;
Expand Down Expand Up @@ -194,7 +193,7 @@ protected function getUnzerViewData(string $sPaymentId, string $sTypeId): void
$editObject->getFieldData('oxpaid') == '0000-00-00 00:00:00' &&
$fCharged == $unzerPayment->getAmount()->getTotal()
) {
/** @var UnzerOrder $editObject */
/** @var \OxidSolutionCatalysts\Unzer\Model\Order $editObject */
$editObject->markUnzerOrderAsPaid();
$this->forceReloadListFrame();
}
Expand Down
8 changes: 6 additions & 2 deletions src/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,12 @@ private function cleanUpCancelledPayments(): void

$isOrderAlreadyCancelled = Registry::getSession()->getVariable('orderCancellationProcessed');
if (!$isOrderAlreadyCancelled) {
$iSuccess = (int)$oOrder->finalizeUnzerOrderAfterRedirect($oBasket, $oUser);
$iSuccess = (int)$oOrder->finalizeUnzerOrderAfterRedirect(
$oBasket,
$oUser,
['finalizeCancellation' => true]
);

$oUser->onOrderExecute($oBasket, $iSuccess);
}
Registry::getSession()->deleteVariable('orderCancellationProcessed');
Expand All @@ -506,7 +511,6 @@ private function cleanUpCancelledPayments(): void

Registry::getSession()->setVariable('sess_challenge', $this->getUtilsObjectInstance()->generateUID());
Registry::getSession()->setBasket($oBasket);
Registry::getSession()->deleteVariable('orderCancellationProcessed');
$this->redirectUserToCheckout($unzerService, $oOrder);
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class Order extends Order_parent
*/
public function finalizeUnzerOrderAfterRedirect(
Basket $oBasket,
User $oUser
User $oUser,
array $params = []
) {
$orderId = Registry::getSession()->getVariable('sess_challenge');
$orderId = is_string($orderId) ? $orderId : '';
Expand Down Expand Up @@ -97,10 +98,18 @@ public function finalizeUnzerOrderAfterRedirect(
} else {
if ($unzerPaymentStatus !== PaymentService::STATUS_NOT_FINISHED) {
Registry::getSession()->setVariable('orderCancellationProcessed', true);
$iRet = 1; //TODO: not sure if this is correct - this is hardcoded for the Paypal cancellaction
}
$this->_setOrderStatus($unzerPaymentStatus); //ERROR if paypal

$this->_setOrderStatus($unzerPaymentStatus);
$this->setTmpOrderStatus($unzerOrderId, $unzerPaymentStatus);

if (!isset($params['finalizeCancellation']))
{
// then we consider this is a payment with only auth mode and the order is completed
$this->sendOrderConfirmationEmail($oUser, $oBasket, $oUserPayment);
}

$iRet = 1;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Service/FlexibleSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ private function makeSerializable($data)
/**
* Restore unserializable data, including objects of allowed classes.
*
* @param mixed $data The data to be restored.
* @param mixed $data The data to be restored.
* @param array $allowedClasses An array of fully qualified class names that are allowed to be restored.
* @return mixed The restored data.
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ElseExpression)
* @throws \ReflectionException
*/
private function restoreUnserializable($data, array $allowedClasses)
{
Expand All @@ -127,7 +128,7 @@ private function restoreUnserializable($data, array $allowedClasses)
}

if (is_object($data) && isset($data->__class)) {
$className = $data->__class;
$className = get_parent_class($data->__class);
if ($this->isAllowedClass($className, $allowedClasses)) {

Check failure on line 132 in src/Service/FlexibleSerializer.php

View workflow job for this annotation

GitHub Actions / styles (8.0)

Parameter #1 $className of method OxidSolutionCatalysts\Unzer\Service\FlexibleSerializer::isAllowedClass() expects string, class-string|false given.
$reflection = new ReflectionClass($className);

Check failure on line 133 in src/Service/FlexibleSerializer.php

View workflow job for this annotation

GitHub Actions / styles (8.0)

Parameter #1 $objectOrClass of class ReflectionClass constructor expects class-string<object>|object, class-string|false given.
$restored = $reflection->newInstanceWithoutConstructor();
Expand Down
3 changes: 0 additions & 3 deletions src/Service/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Session;
use OxidSolutionCatalysts\Unzer\Traits\Request;
use OxidSolutionCatalysts\Unzer\Core\UnzerDefinitions;
use OxidSolutionCatalysts\Unzer\Exception\Redirect;
use OxidSolutionCatalysts\Unzer\Exception\RedirectWithMessage;
use OxidSolutionCatalysts\Unzer\Exception\UnzerException;
use OxidSolutionCatalysts\Unzer\Model\TmpOrder;
use OxidSolutionCatalysts\Unzer\PaymentExtensions\UnzerPayment as AbstractUnzerPayment;
use OxidSolutionCatalysts\Unzer\Service\Transaction as TransactionService;
use stdClass;
use UnzerSDK\Constants\PaymentState;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\Payment as UnzerPayment;
Expand Down

0 comments on commit 58cbd28

Please sign in to comment.