Skip to content

Commit

Permalink
Merge pull request #201 from Invertus/SL-219/final
Browse files Browse the repository at this point in the history
SL-219 Cards saving + CS-Fixer
  • Loading branch information
MarijusCoding authored Oct 3, 2024
2 parents f2fd394 + 6258091 commit 80732c1
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function postProcess()
// Refresh payments.
/** @var SaferPayRefreshPaymentsService $refreshPaymentsService */
$refreshPaymentsService = $this->module->getService(SaferPayRefreshPaymentsService::class);

try {
$refreshPaymentsService->refreshPayments();
} catch (SaferPayApiException $exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private function displayConfigurationSettings()
'title' => $this->module->l('Description', self::FILE_NAME),
'type' => 'text',
'desc' => 'This description is visible in payment page also in payment confirmation email',
'class' => 'fixed-width-xxl'
'class' => 'fixed-width-xxl',
],
],
'buttons' => [
Expand Down
2 changes: 1 addition & 1 deletion controllers/front/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function initializeSavedCardPayment()
$this->ajaxDie(json_encode([
'error' => false,
'url' => $redirectUrl,
'successUrl' => $this->getRedirectionToControllerUrl('success')
'successUrl' => $this->getRedirectionToControllerUrl('success'),
]));
} catch (Exception $e) {
$this->ajaxDie(json_encode([
Expand Down
5 changes: 2 additions & 3 deletions controllers/front/iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,13 @@ public function initContent()
$checkoutController = $this->module->getService(CheckoutController::class);

$checkoutData = CheckoutData::create(
(int)$this->context->cart->id,
(int) $this->context->cart->id,
$paymentMethod,
(int)Tools::getValue(SaferPayConfig::IS_BUSINESS_LICENCE),
(int) Tools::getValue(SaferPayConfig::IS_BUSINESS_LICENCE),
$selectedCard
);

$redirectUrl = $checkoutController->execute($checkoutData);

} catch (\Exception $exception) {
$redirectUrl = $this->context->link->getModuleLink(
$this->module->name,
Expand Down
3 changes: 2 additions & 1 deletion controllers/front/notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ public function postProcess()
die($this->module->l('Success', self::FILENAME));
}

private function assertTransaction($cartId) {
private function assertTransaction($cartId)
{
/** @var SaferPayTransactionAssertion $transactionAssert */
$transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class);

Expand Down
3 changes: 0 additions & 3 deletions controllers/front/successHosted.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
*@license SIX Payment Services
*/

use Invertus\SaferPay\Api\Enum\TransactionStatus;
use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\Controller\AbstractSaferPayController;
use Invertus\SaferPay\Enum\ControllerName;
use Invertus\SaferPay\Service\SaferPayOrderStatusService;
use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
36 changes: 0 additions & 36 deletions controllers/front/successIFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@
*@license SIX Payment Services
*/

use Invertus\SaferPay\Api\Enum\TransactionStatus;
use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\Controller\AbstractSaferPayController;
use Invertus\SaferPay\Enum\ControllerName;
use Invertus\SaferPay\Exception\Api\SaferPayApiException;
use Invertus\SaferPay\Service\SaferPayOrderStatusService;
use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -62,37 +57,6 @@ public function postProcess()

$this->redirectWithNotifications($this->getOrderLink());
}

try {
Tools::redirect($this->getOrderConfirmationLink($cartId, $moduleId, $orderId, $secureKey));
} catch (Exception $e) {
PrestaShopLogger::addLog(
sprintf(
'%s has caught an error: %s',
__CLASS__,
$e->getMessage()
),
1,
null,
null,
null,
true
);

Tools::redirect(
$this->context->link->getModuleLink(
$this->module->name,
ControllerName::FAIL_IFRAME,
[
'cartId' => $cartId,
'secureKey' => $secureKey,
'orderId' => $orderId,
\Invertus\SaferPay\Config\SaferPayConfig::IS_BUSINESS_LICENCE => true,
],
true
)
);
}
}

public function initContent()
Expand Down
2 changes: 1 addition & 1 deletion saferpayofficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ public function hookActionOrderHistoryAddAfter($params = [])
}

if ((int) \Configuration::get(SaferPayConfig::SAFERPAY_PAYMENT_AUTHORIZED) === (int) $orderStatus->id) {
$mailService->sendOrderConfMail($order, (int) $orderStatus->id);
$mailService->sendOrderConfMail($order, (int) $orderStatus->id);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Request/AssertService.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function assert(AssertRequest $assertRequest, $saferPayOrderId)
// also we call authorize method in some of the success controllers, so if we leave the logic here,
// we get an error with TRANSACTION_IN_WRONG_STATE
if ($saferPayOrder->is_transaction) {
$assertApi = self::ASSERT_API_TRANSACTION;
$assertApi = self::ASSERT_API_TRANSACTION;
}

try {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Front/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*@license SIX Payment Services
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
Expand Down
1 change: 0 additions & 1 deletion src/Core/Order/Action/UpdateOrderStatusAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,5 @@ public function run($orderId, $orderStatusId)
} catch (\Exception $exception) {
throw CouldNotChangeOrderStatus::unknownError($exception);
}

}
}
36 changes: 17 additions & 19 deletions src/Core/Payment/DTO/CheckoutData.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ class CheckoutData
private $status;

public function __construct(
$cartId,
$paymentMethod,
$isBusinessLicense,
$selectedCard = -1,
$fieldToken = null,
$successController = null,
$isTransaction = false
)
{
$cartId,
$paymentMethod,
$isBusinessLicense,
$selectedCard = -1,
$fieldToken = null,
$successController = null,
$isTransaction = false
) {
$this->cartId = $cartId;
$this->paymentMethod = $paymentMethod;
$this->isBusinessLicense = $isBusinessLicense;
Expand All @@ -65,15 +64,14 @@ public function __construct(
}

public static function create(
$cartId,
$paymentMethod,
$isBusinessLicense,
$selectedCard = -1,
$fieldToken = null,
$successController = null,
$isTransaction = false
)
{
$cartId,
$paymentMethod,
$isBusinessLicense,
$selectedCard = -1,
$fieldToken = null,
$successController = null,
$isTransaction = false
) {
return new self(
$cartId,
$paymentMethod,
Expand Down Expand Up @@ -184,4 +182,4 @@ public function setOrderStatus($status)
{
$this->status = $status;
}
}
}
2 changes: 1 addition & 1 deletion src/Exception/CouldNotProcessCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ public static function failedToCreateSaferPayOrder($cartId)
]
);
}
}
}
5 changes: 2 additions & 3 deletions src/Exception/SaferPayException.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ final public function __construct(
$internalMessage,
$code,
array $context = []
)
{
) {
parent::__construct($internalMessage, $code);
$this->context = $context;
}
Expand All @@ -53,4 +52,4 @@ public static function unknownError()
ExceptionCode::UNKNOWN_ERROR
);
}
}
}
4 changes: 2 additions & 2 deletions src/Processor/CheckoutProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function __construct(
$this->saferPayOrderRepository = $saferPayOrderRepository;
}

public function run(CheckoutData $data) {

public function run(CheckoutData $data)
{
$cart = new Cart($data->getCartId());

if (!$cart) {
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*@license SIX Payment Services
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
Expand Down
2 changes: 0 additions & 2 deletions src/Service/Request/InitializeRequestObjectCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
use Configuration;
use Customer;
use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\DTO\Request\RequestHeader;
use Invertus\SaferPay\DTO\Request\Initialize\InitializeRequest;
use Invertus\SaferPay\DTO\Request\Payer;
use PrestaShop\PrestaShop\Adapter\Shop\Context;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Invertus\SaferPay\Repository\SaferPayOrderRepository;
use Invertus\SaferPay\Service\Request\AuthorizationRequestObjectCreator;
use Invertus\SaferPay\Service\SaferPayOrderStatusService;
use Order;
use SaferPayOrder;

if (!defined('_PS_VERSION_')) {
Expand Down
2 changes: 1 addition & 1 deletion upgrade/install-1.1.8.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ function upgrade_module_1_1_8(SaferPayOfficial $module)
$module->registerHook('actionObjectOrderPaymentAddAfter');

return true;
}
}
1 change: 0 additions & 1 deletion upgrade/install-1.2.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ function upgrade_module_1_2_2($module)
&& $module->unregisterHook('actionOrderStatusUpdate')
&& Configuration::deleteByName('SAFERPAY_SEND_ORDER_CONFIRMATION');
}

0 comments on commit 80732c1

Please sign in to comment.