Skip to content

Commit

Permalink
fixed a2c
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijusCoding committed Oct 7, 2024
1 parent 54bce19 commit 21cdd45
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 12 deletions.
4 changes: 3 additions & 1 deletion controllers/front/iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions controllers/front/return.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand All @@ -240,6 +242,10 @@ private function getSuccessControllerName($isBusinessLicence, $fieldToken)
$successController = ControllerName::SUCCESS_HOSTED;
}

if ($isIframe) {
$successController = ControllerName::SUCCESS_IFRAME;
}

return $successController;
}

Expand Down
3 changes: 2 additions & 1 deletion controllers/front/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/Api/Request/AssertService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/Api/Request/InitializeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function initialize(InitializeRequest $initializeRequest, $isBusinessLice
if ($isBusinessLicence) {
$initializeApi = self::INITIALIZE_API_TRANSACTION;
}

return $this->apiRequest->post(
$initializeApi,
$initializeRequest->getAsArray()
Expand Down
25 changes: 20 additions & 5 deletions src/Provider/PaymentRedirectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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
);
}
Expand All @@ -70,15 +79,21 @@ 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
);
}

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
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Service/SaferPayInitialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function buildRequest(
'selectedCard' => $selectedCard,
'isBusinessLicence' => $isBusinessLicence,
'fieldToken' => $fieldToken,
'successController' => $successController,
],
true
);
Expand Down
11 changes: 10 additions & 1 deletion src/Service/TransactionFlow/SaferPayTransactionAssertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 21cdd45

Please sign in to comment.