diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index 262d30a3..9340267a 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -94,7 +94,9 @@ public function initContent() (int) $this->context->cart->id, $paymentMethod, (int) Tools::getValue(SaferPayConfig::IS_BUSINESS_LICENCE), - $selectedCard + $selectedCard, + null, + ControllerName::SUCCESS_IFRAME ); $redirectUrl = $checkoutController->execute($checkoutData); diff --git a/controllers/front/return.php b/controllers/front/return.php index 29995d93..f8e55d2c 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -79,7 +79,7 @@ public function postProcess() /** * NOTE: This flow is for hosted iframe payment method */ - if (Tools::getValue('isBusinessLicence')) { + if (Configuration::get(SaferPayConfig::BUSINESS_LICENSE . SaferPayConfig::getConfigSuffix())) { try { /** @var CheckoutProcessor $checkoutProcessor * */ $checkoutProcessor = $this->module->getService(CheckoutProcessor::class); @@ -161,6 +161,8 @@ public function initContent() : Configuration::get(SaferPayConfig::FIELDS_ACCESS_TOKEN . SaferPayConfig::getConfigSuffix()); $moduleId = $this->module->id; $selectedCard = Tools::getValue('selectedCard'); + $isIframe = Tools::getValue('successController') === ControllerName::SUCCESS_IFRAME; + $cart = new Cart($cartId); if (!Validate::isLoadedObject($cart)) { @@ -193,7 +195,7 @@ public function initContent() if ((int) $order->current_state === $saferPayAuthorizedStatus || (int) $order->current_state === $saferPayCapturedStatus) { Tools::redirect($this->context->link->getModuleLink( $this->module->name, - $this->getSuccessControllerName($isBusinessLicence, $fieldToken), + $this->getSuccessControllerName($isBusinessLicence, $fieldToken, $isIframe), [ 'cartId' => $cartId, 'orderId' => $orderId, @@ -228,7 +230,7 @@ public function initContent() $this->setTemplate('saferpay_wait_16.tpl'); } - private function getSuccessControllerName($isBusinessLicence, $fieldToken) + private function getSuccessControllerName($isBusinessLicence, $fieldToken, $isIframe = false) { $successController = ControllerName::SUCCESS; @@ -240,6 +242,10 @@ private function getSuccessControllerName($isBusinessLicence, $fieldToken) $successController = ControllerName::SUCCESS_HOSTED; } + if ($isIframe) { + $successController = ControllerName::SUCCESS_IFRAME; + } + return $successController; } diff --git a/controllers/front/validation.php b/controllers/front/validation.php index de8d1cf2..4976e525 100755 --- a/controllers/front/validation.php +++ b/controllers/front/validation.php @@ -44,6 +44,7 @@ class SaferPayOfficialValidationModuleFrontController extends AbstractSaferPayCo public function postProcess() { $paymentMethod = Tools::getValue('saved_card_method'); + $isBusiness = $paymentMethod === 'ACCOUNTTOACCOUNT' ? false : (bool) Tools::getValue(SaferPayConfig::IS_BUSINESS_LICENCE); $cart = $this->context->cart; $redirectLink = $this->context->link->getPageLink( 'order', @@ -85,7 +86,7 @@ public function postProcess() $checkoutData = CheckoutData::create( (int) $this->context->cart->id, $paymentMethod, - (int) Tools::getValue(SaferPayConfig::IS_BUSINESS_LICENCE) + (int) $isBusiness ); $redirectLink = $checkoutController->execute($checkoutData); diff --git a/src/Api/Request/AssertService.php b/src/Api/Request/AssertService.php index ff14bfff..97259a20 100755 --- a/src/Api/Request/AssertService.php +++ b/src/Api/Request/AssertService.php @@ -78,7 +78,7 @@ public function __construct( * @return object|null * @throws \Exception */ - public function assert(AssertRequest $assertRequest) + public function assert(AssertRequest $assertRequest, $isAccount = null) { $assertApi = self::ASSERT_API_PAYMENT; @@ -88,6 +88,10 @@ public function assert(AssertRequest $assertRequest) $assertApi = self::ASSERT_API_TRANSACTION; } + if ($isAccount) { + $assertApi = self::ASSERT_API_PAYMENT; + } + try { return $this->apiRequest->post( $assertApi, diff --git a/src/Api/Request/InitializeService.php b/src/Api/Request/InitializeService.php index 3cee4204..99c22a01 100755 --- a/src/Api/Request/InitializeService.php +++ b/src/Api/Request/InitializeService.php @@ -56,6 +56,7 @@ public function initialize(InitializeRequest $initializeRequest, $isBusinessLice if ($isBusinessLicence) { $initializeApi = self::INITIALIZE_API_TRANSACTION; } + return $this->apiRequest->post( $initializeApi, $initializeRequest->getAsArray() diff --git a/src/Provider/PaymentRedirectionProvider.php b/src/Provider/PaymentRedirectionProvider.php index b2f6f131..cddcd118 100755 --- a/src/Provider/PaymentRedirectionProvider.php +++ b/src/Provider/PaymentRedirectionProvider.php @@ -23,6 +23,7 @@ namespace Invertus\SaferPay\Provider; +use Invertus\SaferPay\Adapter\Configuration; use Invertus\SaferPay\Adapter\LegacyContext; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Enum\ControllerName; @@ -41,11 +42,16 @@ class PaymentRedirectionProvider /** @var PaymentTypeProvider */ private $paymentTypeProvider; + /** + * @var Configuration + */ + private $configuration; - public function __construct(LegacyContext $context, PaymentTypeProvider $paymentTypeProvider) + public function __construct(LegacyContext $context, PaymentTypeProvider $paymentTypeProvider, Configuration $configuration) { $this->context = $context; $this->paymentTypeProvider = $paymentTypeProvider; + $this->configuration = $configuration; } /** @@ -56,12 +62,15 @@ public function __construct(LegacyContext $context, PaymentTypeProvider $payment public function provideRedirectionLinkByPaymentMethod($paymentMethod) { $paymentType = $this->paymentTypeProvider->get($paymentMethod); - + $isBusiness = $this->configuration->getAsInteger(SaferPayConfig::BUSINESS_LICENSE . SaferPayConfig::getConfigSuffix()); if ($paymentType === PaymentType::HOSTED_IFRAME) { return $this->context->getLink()->getModuleLink( 'saferpayofficial', ControllerName::HOSTED_IFRAME, - ['saved_card_method' => $paymentMethod, SaferPayConfig::IS_BUSINESS_LICENCE => true], + [ + 'saved_card_method' => $paymentMethod, + SaferPayConfig::IS_BUSINESS_LICENCE => $isBusiness, + ], true ); } @@ -70,7 +79,10 @@ public function provideRedirectionLinkByPaymentMethod($paymentMethod) return $this->context->getLink()->getModuleLink( 'saferpayofficial', ControllerName::IFRAME, - ['saved_card_method' => $paymentMethod, SaferPayConfig::IS_BUSINESS_LICENCE => true], + [ + 'saved_card_method' => $paymentMethod, + SaferPayConfig::IS_BUSINESS_LICENCE => $isBusiness + ], true ); } @@ -78,7 +90,10 @@ public function provideRedirectionLinkByPaymentMethod($paymentMethod) return $this->context->getLink()->getModuleLink( 'saferpayofficial', ControllerName::VALIDATION, - ['saved_card_method' => $paymentMethod, SaferPayConfig::IS_BUSINESS_LICENCE => false], + [ + 'saved_card_method' => $paymentMethod, + SaferPayConfig::IS_BUSINESS_LICENCE => $isBusiness + ], true ); } diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php index e4822f7e..450f1e3a 100755 --- a/src/Service/SaferPayInitialize.php +++ b/src/Service/SaferPayInitialize.php @@ -116,6 +116,7 @@ public function buildRequest( 'selectedCard' => $selectedCard, 'isBusinessLicence' => $isBusinessLicence, 'fieldToken' => $fieldToken, + 'successController' => $successController, ], true ); diff --git a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php index 451ff69b..568e7d42 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php @@ -25,6 +25,7 @@ use Invertus\SaferPay\Api\Request\AssertService; use Invertus\SaferPay\Config\SaferPayConfig; +use Invertus\SaferPay\DTO\Request\Order; use Invertus\SaferPay\DTO\Response\Assert\AssertBody; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\Request\AssertRequestObjectCreator; @@ -71,11 +72,19 @@ public function assert($cartId, $saveCard, $selectedCard, $update = true) { $cart = new \Cart($cartId); + if (version_compare(_PS_VERSION_, '1.7.1.0', '>=')) { + $orderId = \Order::getIdByCartId($cartId); + } else { + $orderId = \Order::getOrderByCartId($cartId); + } + $order = new \Order($orderId); + + $isAccount = $order->payment === 'ACCOUNTTOACCOUNT' ? true : null; $saferPayOrder = new SaferPayOrder($this->orderRepository->getIdByCartId($cartId)); \PrestaShopLogger::addLog('saferpayOrderId:' . $saferPayOrder->id); $assertRequest = $this->assertRequestCreator->create($saferPayOrder->token, $saveCard); - $assertResponse = $this->assertionService->assert($assertRequest); + $assertResponse = $this->assertionService->assert($assertRequest, $isAccount); if (empty($assertResponse)) { return null;