Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SL-219/saved card modal in payment step [wip] #157

Open
wants to merge 11 commits into
base: release-1.2.2
Choose a base branch
from
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
47 changes: 47 additions & 0 deletions controllers/front/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function postProcess()
case 'submitHostedFields':
$this->submitHostedFields();
break;
case 'initializeSavedCardPayment':
$this->initializeSavedCardPayment();
break;
}
}

Expand Down Expand Up @@ -108,4 +111,48 @@ private function getRedirectionToControllerUrl($controllerName)
true
);
}


public function initializeSavedCardPayment()
{
try {
if (Order::getOrderByCartId($this->context->cart->id)) {
$this->ajaxDie(json_encode([
'error' => true,
'message' => $this->module->l('Order already exists', self::FILE_NAME),
'url' => $this->getRedirectionToControllerUrl('fail'),
]));
}

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

/** @var CheckoutController $checkoutController */
$checkoutController = $this->module->getService(CheckoutController::class);
$redirectUrl = $checkoutController->execute($checkoutData);

if (empty($redirectUrl)) {
$redirectUrl = $this->getRedirectionToControllerUrl('successHosted');
}

$this->ajaxDie(json_encode([
'error' => false,
'url' => $redirectUrl,
'successUrl' => $this->getRedirectionToControllerUrl('success'),
]));
} catch (Exception $e) {
$this->ajaxDie(json_encode([
'error' => true,
'message' => $e->getMessage(),
'url' => $this->getRedirectionToControllerUrl('fail'),
]));
}
}
}
2 changes: 0 additions & 2 deletions controllers/front/iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public function initContent()
/** @var CheckoutController $checkoutController */
$checkoutController = $this->module->getService(CheckoutController::class);

// refactor it to create checkout data from validator request
$checkoutData = CheckoutData::create(
(int) $this->context->cart->id,
$paymentMethod,
Expand All @@ -98,7 +97,6 @@ public function initContent()
);

$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
38 changes: 1 addition & 37 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 All @@ -48,7 +43,7 @@ public function init()
parent::init();
}

public function postProcess() // todo refactor this by the logic provided
public function postProcess()
{
$cartId = Tools::getValue('cartId');
$orderId = Tools::getValue('orderId');
Expand All @@ -62,37 +57,6 @@ public function postProcess() // todo refactor this by the logic provided

$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
11 changes: 10 additions & 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 Expand Up @@ -759,4 +759,13 @@ public function addFlash($msg, $type)

return true;
}

public function hookDisplayHeader()
{
if (true) {
return $this->context->smarty->fetch(
$this->getLocalPath() . 'views/templates/front/saferpay_iframe_modal.tpl'
);
}
}
}
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
);
}
}
}
2 changes: 1 addition & 1 deletion src/Install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ private function registerHooks()
$this->module->registerHook('displayAdminOrder');
$this->module->registerHook('actionFrontControllerSetMedia');
$this->module->registerHook('displayCustomerAccount');
$this->module->registerHook('displayPayment');
$this->module->registerHook('paymentReturn');
$this->module->registerHook('actionEmailSendBefore');
$this->module->registerHook('displayAdminOrderTabContent');
$this->module->registerHook('actionAdminControllerSetMedia');
$this->module->registerHook('actionOrderHistoryAddAfter');
$this->module->registerHook('actionObjectOrderPaymentAddAfter');
$this->module->registerHook('displayHeader');
}

private function installConfiguration()
Expand Down
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;
}
}
4 changes: 2 additions & 2 deletions upgrade/install-1.2.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
*/
function upgrade_module_1_2_2($module)
{
return $module->registerHook('actionOrderHistoryAddAfter')
return $module->registerHook('displayHeader')
&& $module->registerHook('actionOrderStatusPostUpdate')
&& $module->unregisterHook('actionOrderStatusUpdate')
&& Configuration::deleteByName('SAFERPAY_SEND_ORDER_CONFIRMATION');
}

Loading