From 4a2cb46881d156ab9c376f5edd5243ed96f2a2a8 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Tue, 8 Aug 2023 13:41:59 +0200 Subject: [PATCH] throw an error if mandantory field is missing --- src/Controller/ProxyController.php | 33 ++++++++++++++++++------------ src/Core/InputValidator.php | 14 ++++++------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/Controller/ProxyController.php b/src/Controller/ProxyController.php index d6f74bef..6fac6b54 100644 --- a/src/Controller/ProxyController.php +++ b/src/Controller/ProxyController.php @@ -9,7 +9,6 @@ use Exception; use OxidEsales\Eshop\Application\Model\Address; -use OxidEsales\Eshop\Application\Model\PaymentList; use OxidEsales\Eshop\Application\Model\DeliverySetList; use OxidEsales\Eshop\Application\Controller\FrontendController; use OxidEsales\Eshop\Application\Component\UserComponent; @@ -17,6 +16,7 @@ use OxidEsales\Eshop\Core\Exception\NoArticleException; use OxidEsales\Eshop\Core\Exception\OutOfStockException; use OxidEsales\Eshop\Core\Registry; +use OxidEsales\Eshop\Core\Exception\StandardException; use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPal\Service\Payment as PaymentService; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; @@ -115,18 +115,25 @@ public function approveOrder() $userInvoiceAddress = $user->getInvoiceAddress(); // add PayPal-Address as Delivery-Address $deliveryAddress = PayPalAddressResponseToOxidAddress::mapUserDeliveryAddress($response); - $user->changeUserData( - $user->oxuser__oxusername->value, - '', - '', - $userInvoiceAddress, - $deliveryAddress - ); - - // use a deliveryaddress in oxid-checkout - Registry::getSession()->setVariable('blshowshipaddress', false); - - $this->setPayPalPaymentMethod(); + try { + $user->changeUserData( + $user->oxuser__oxusername->value, + '', + '', + $userInvoiceAddress, + $deliveryAddress + ); + + // use a deliveryaddress in oxid-checkout + Registry::getSession()->setVariable('blshowshipaddress', false); + + $this->setPayPalPaymentMethod(); + } catch (StandardException $exception) { + Registry::getUtilsView()->addErrorToDisplay($exception); + $response->status = 'ERROR'; + PayPalSession::unsetPayPalOrderId(); + Registry::getSession()->getBasket()->setPayment(null); + } } elseif ($nonGuestAccountDetected && !$isLoggedIn) { // PPExpress is actual no possible so we switch to PP-Standard $this->setPayPalPaymentMethod(PayPalDefinitions::STANDARD_PAYPAL_PAYMENT_ID); diff --git a/src/Core/InputValidator.php b/src/Core/InputValidator.php index a715eb9f..98924ee6 100644 --- a/src/Core/InputValidator.php +++ b/src/Core/InputValidator.php @@ -8,7 +8,7 @@ namespace OxidSolutionCatalysts\PayPal\Core; use OxidEsales\Eshop\Application\Model\User; -use OxidEsales\Eshop\Core\Exception\UserException; +use OxidEsales\Eshop\Core\Exception\InputException; use OxidEsales\Eshop\Core\Registry; /** @@ -25,7 +25,7 @@ public function checkCountries($user, $invAddress, $deliveryAddress) $fieldValidationErrors = $this->getFieldValidationErrors(); if (isset($fieldValidationErrors['oxuser__oxcountryid']) && PayPalSession::getCheckoutOrderId()) { $this->_aInputValidationErrors = []; - $exception = oxNew(UserException::class); + $exception = oxNew(InputException::class); $exception->setMessage( Registry::getLang()->translateString( 'OSC_PAYPAL_PAY_EXPRESS_ERROR_DELCOUNTRY' @@ -46,17 +46,17 @@ public function checkCountries($user, $invAddress, $deliveryAddress) public function checkRequiredFields($user, $billingAddress, $deliveryAddress) { parent::checkRequiredFields($user, $billingAddress, $deliveryAddress); - $firstValidationError = $this->getFirstValidationError(); - if ($firstValidationError && PayPalSession::getCheckoutOrderId()) { + $allValidationErrors = $this->getFieldValidationErrors(); + if (count($allValidationErrors) && PayPalSession::getCheckoutOrderId()) { $this->_aInputValidationErrors = []; - $firstValidationErrorKey = key($firstValidationError); - $exception = oxNew(UserException::class); + $validationErrorKey = key($allValidationErrors); + $exception = oxNew(InputException::class); $exception->setMessage( Registry::getLang()->translateString( 'OSC_PAYPAL_PAY_EXPRESS_ERROR_INPUTVALIDATION' ) ); - $this->_addValidationError($firstValidationErrorKey, $exception); + $this->_addValidationError($validationErrorKey, $exception); } } }