From 0d01867f09d1d939caa08f1bd6b12e041779f8a5 Mon Sep 17 00:00:00 2001 From: dimosKougiou Date: Mon, 30 Sep 2024 15:29:48 +0300 Subject: [PATCH] IRIS support --- README.md | 41 ++++++++++--------- .../Checkout/Controller/Payment/Response.php | 28 +++++++++++-- app/code/Cardlink/Checkout/Helper/Payment.php | 2 +- .../Checkout/etc/adminhtml/system.xml | 5 +-- app/code/Cardlink/Checkout/etc/config.xml | 4 +- app/code/Cardlink/Checkout/etc/module.xml | 2 +- .../layout/checkout_onepage_success.xml | 6 +++ .../view/frontend/layout/checkout_success.xml | 6 +++ .../web/js/invalidate-localstorage-cart.js | 7 ++++ 9 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 app/code/Cardlink/Checkout/view/frontend/layout/checkout_onepage_success.xml create mode 100644 app/code/Cardlink/Checkout/view/frontend/layout/checkout_success.xml create mode 100644 app/code/Cardlink/Checkout/view/frontend/web/js/invalidate-localstorage-cart.js diff --git a/README.md b/README.md index d3b0518..4a68be3 100644 --- a/README.md +++ b/README.md @@ -10,27 +10,24 @@ ## Changelog -- **1.0.5** - - Fixed guest checkout bug. - -- **1.0.4** - - Minor bug fixes. - +- **1.0.0** + - Initial release +- **1.0.1** + - Only send order confirmation email to customer when the order has been successfully paid for. + - Auto cancel order after 30 minutes in pending payment state. +- **1.0.2** + - Fixed a bug that failed checkout with PayPal Standard. + - Changed auto cancel order period to 60 minutes. - **1.0.3** - Order creation only happens after successful payment. - Fixed bug with credit memo creation. - Fixed bug with reorder in admin. - -- **1.0.2** - - Fixed a bug that failed checkout with PayPal Standard. - - Changed auto cancel order period to 60 minutes. - -- **1.0.1** - - Only send order confirmation email to customer when the order has been successfully paid for. - - Auto cancel order after 30 minutes in pending payment state. - -- **1.0.0** - - Initial release +- **1.0.4** + - Minor bug fixes. +- **1.0.5** + - Fixed guest checkout bug. +- **1.1.0** + - Added support for IRIS payments. ## Description @@ -53,10 +50,11 @@ Once you have completed the requested tests and any changes to your website, you 9. Translation ready for Greek & English languages. 10. Automatically cancel pending payment orders after 60 minutes. 11. Only send the order confirmation email to the customer after a successful payment. +12. Support for IRIS payments. ## Installation -You need to manually upload the contents of the .zip file of the module’s latest version to your server’s web root folder that your Magento store is installed. You will first need to extract the file’s contents to a temporary folder. Then, go to the ``Cardlink\Checkout\Controller\Payment`` folder. Replace the Response.php file with the file that corresponds to your installed Magento version, ``Response-v2.2.php`` for any 2.2.x version and ``Response-v2.3.php`` for any version 2.3.x-2.4.x. +You need to manually upload the contents of the .zip file of the module’s latest version to your server’s web root folder that your Magento store is installed. You will first need to extract the file’s contents to a temporary folder. Then, go to the ``Cardlink\Checkout\Controller\Payment`` folder. If you are using previous Magento version 2.2.x, replace the ``Response.php`` file with the contents of file ``Response-v2.2.php``. Depending on your hosting provider, you will probably have to be familiar with the process of transferring files using an FTP or SFTP client. If no FTP/SFTP access is provided, use your hosting provider’s administration panel to upload the folders to the folder of your Magento installation. @@ -109,8 +107,13 @@ Header always edit Set-Cookie ^(.*)$ $1;SameSite=None;Secure ``` +#### Custom or Unknown Hosting + +If you do not have full control of your hosting services, or not very confident with such changes, you can try installing the [Veriteworks CookieFix](https://github.com/Veriteworks/CookieFix) extension. +Follow the instructions on the extensions Github page and set the SameSite setting to None. + -If you are unsure or unfamiliar with the actions described above, please ask a trained IT person or contact your hosting provider to do them for you. +If you are still unsure or unfamiliar with the actions described above, please ask a trained IT person or contact your hosting provider to do them for you. ## Screenshots diff --git a/app/code/Cardlink/Checkout/Controller/Payment/Response.php b/app/code/Cardlink/Checkout/Controller/Payment/Response.php index 90a7918..597e371 100644 --- a/app/code/Cardlink/Checkout/Controller/Payment/Response.php +++ b/app/code/Cardlink/Checkout/Controller/Payment/Response.php @@ -8,9 +8,14 @@ use Cardlink\Checkout\Helper\Data; use Cardlink\Checkout\Helper\Payment; use Magento\Checkout\Model\Session; + +use Magento\Framework\App\CsrfAwareActionInterface; + use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Data\Form\FormKey; use Magento\Framework\UrlInterface; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Controller\Result\RedirectFactory; @@ -18,13 +23,19 @@ use Magento\Framework\App\RequestInterface; use Magento\Sales\Model\OrderFactory; + /** * Controller action used to handle responses from the payment gateway. * * @author Cardlink S.A. */ -class Response extends Action +class Response extends Action implements CsrfAwareActionInterface, HttpPostActionInterface { + /** + * @var FormKey + */ + protected $formKey; + /** * @var Logger */ @@ -82,8 +93,8 @@ public function __construct( Logger $logger, Data $dataHelper, Payment $paymentHelper, - OrderFactory $orderFactory - + OrderFactory $orderFactory, + FormKey $formKey ) { $this->checkoutSession = $checkoutSession; $this->messageManager = $messageManager; @@ -94,6 +105,7 @@ public function __construct( $this->dataHelper = $dataHelper; $this->paymentHelper = $paymentHelper; $this->orderFactory = $orderFactory; + $this->formKey = $formKey; return parent::__construct($context); } @@ -162,6 +174,9 @@ public function execute() // Mark the payment as successful and remove the quote from the customer's session. $this->paymentHelper->markSuccessfulPayment($order, $responseData); + $quote->setIsActive(false); + $quote->save(); + $message = array_key_exists(ApiFields::Message, $responseData) ? $responseData[ApiFields::Message] : ''; @@ -189,6 +204,12 @@ public function execute() } } + // Regenerate a new form key + $newFormKey = $this->formKey->getFormKey(); + + // Optionally set the new form key in the request + $this->getRequest()->setParam('form_key', $newFormKey); + // If the payment flow executed inside the IFRAME, send out a redirection form page to force open the final response page in the parent frame (store window/tab). if ($this->dataHelper->doCheckoutInIframe()) { $redirectUrl = $success @@ -237,5 +258,4 @@ public function createCsrfValidationException(RequestInterface $request): Invali { return null; } - } \ No newline at end of file diff --git a/app/code/Cardlink/Checkout/Helper/Payment.php b/app/code/Cardlink/Checkout/Helper/Payment.php index c5e0ff8..cb70497 100644 --- a/app/code/Cardlink/Checkout/Helper/Payment.php +++ b/app/code/Cardlink/Checkout/Helper/Payment.php @@ -477,7 +477,7 @@ public static function generateIrisRFCode(string $diasCustomerCode, $orderId, $a $orderIdNum = (int) filter_var($orderId, FILTER_SANITIZE_NUMBER_INT); - $randomNumber = str_pad($orderIdNum, 13, '0', STR_PAD_LEFT); + $randomNumber = substr(str_pad($orderIdNum, 13, '0', STR_PAD_LEFT), -13); $paymentCode = $paymentSum ? ($paymentSum % 8) : '8'; $systemCode = '12'; $tempCode = $diasCustomerCode . $paymentCode . $systemCode . $randomNumber . '271500'; diff --git a/app/code/Cardlink/Checkout/etc/adminhtml/system.xml b/app/code/Cardlink/Checkout/etc/adminhtml/system.xml index 8941224..134e73c 100644 --- a/app/code/Cardlink/Checkout/etc/adminhtml/system.xml +++ b/app/code/Cardlink/Checkout/etc/adminhtml/system.xml @@ -169,10 +169,9 @@ 1 - - + \ No newline at end of file diff --git a/app/code/Cardlink/Checkout/etc/config.xml b/app/code/Cardlink/Checkout/etc/config.xml index f852353..9ccb985 100644 --- a/app/code/Cardlink/Checkout/etc/config.xml +++ b/app/code/Cardlink/Checkout/etc/config.xml @@ -46,7 +46,6 @@ - + \ No newline at end of file diff --git a/app/code/Cardlink/Checkout/etc/module.xml b/app/code/Cardlink/Checkout/etc/module.xml index ce061fe..5c80755 100644 --- a/app/code/Cardlink/Checkout/etc/module.xml +++ b/app/code/Cardlink/Checkout/etc/module.xml @@ -1,7 +1,7 @@ - + diff --git a/app/code/Cardlink/Checkout/view/frontend/layout/checkout_onepage_success.xml b/app/code/Cardlink/Checkout/view/frontend/layout/checkout_onepage_success.xml new file mode 100644 index 0000000..ca75c99 --- /dev/null +++ b/app/code/Cardlink/Checkout/view/frontend/layout/checkout_onepage_success.xml @@ -0,0 +1,6 @@ + + + +