Skip to content

Commit

Permalink
Merge pull request #203 from OXID-eSales/PSPAYPAL-681_AdditionalManda…
Browse files Browse the repository at this point in the history
…ntoryFieldsExpressPP

throw an error if mandantory field is missing
  • Loading branch information
HonkDerHase authored Aug 8, 2023
2 parents 90cc7cf + 4a2cb46 commit 48c1c89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
33 changes: 20 additions & 13 deletions src/Controller/ProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

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;
use OxidEsales\Eshop\Core\Exception\ArticleInputException;
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;
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/Core/InputValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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'
Expand All @@ -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);
}
}
}

0 comments on commit 48c1c89

Please sign in to comment.