Skip to content

Commit

Permalink
1.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dyd committed Jul 22, 2024
1 parent 0ce3a39 commit b6b31b5
Show file tree
Hide file tree
Showing 57 changed files with 2,845 additions and 524 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
.idea
vendor
vendor
auth.json
/Test/Dummy
phpunit_report.xml
phpcs_report.xml
phpmd_report.xml
*.zip
23 changes: 8 additions & 15 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
<ruleset name="emerchantpay Gateway Module Coding Standards">
<description>Generally-applicable sniffs for emerchantpay Gateway Module</description>

<rule ref="EcgM2"/>

<rule ref="MEQP2">
<!-- Disable Rule: Use of protected class members is discouraged -->
<exclude name="MEQP2.PHP.ProtectedClassMember.FoundProtected" />
<!-- Allow passing Session Objects to Constructors (it is in this way in Magento2 Core) -->
<exclude name="MEQP2.Classes.MutableObjects.MutableObjects" />
<exclude name="MEQP2.Classes.ObjectInstantiation.FoundDirectInstantiation" />
<exclude name="MEQP2.Classes.ConstructorOperations.CustomOperationsFound" />
<exclude name="MEQP2.Classes.ObjectManager.ObjectManagerFound" />
</rule>

<rule ref="MEQP2.Classes.PublicNonInterfaceMethods.PublicMethodFound">
<exclude-pattern>./Test/*</exclude-pattern>
</rule>
<rule ref="Magento2"/>

<rule ref="PSR2">
<!-- Allow protected properties (Magento 2 also use them in base classes) -->
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore" />
</rule>

<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/setup/*</exclude-pattern>
<exclude-pattern>*/pub/*</exclude-pattern>
<exclude-pattern>*/phpserver/*</exclude-pattern>
<exclude-pattern>*/Test/Dummy/*</exclude-pattern>
</ruleset>
4 changes: 4 additions & 0 deletions .phpmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@
</rule>

<rule ref="rulesets/unusedcode.xml" />

<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/Test/Dummy/*</exclude-pattern>
</ruleset>
9 changes: 0 additions & 9 deletions .pronto.yml

This file was deleted.

36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

63 changes: 63 additions & 0 deletions Block/Frontend/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/*
* Copyright (C) 2018-2024 emerchantpay Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* @author emerchantpay
* @copyright 2018-2024 emerchantpay Ltd.
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
*/

namespace EMerchantPay\Genesis\Block\Frontend;

use EMerchantPay\Genesis\Model\Config as BackendConfig;
use EMerchantPay\Genesis\Model\Method\Checkout;
use Magento\Framework\View\Element\Template;

/**
* Get iframe payment processing option to the frontend
*
* Class Config
*/
class Config extends Template
{
/**
* @var BackendConfig
*/
protected BackendConfig $_backendConfig;

/**
* @param Template\Context $context
* @param BackendConfig $backendConfig
* @param array $data
*/
public function __construct(
Template\Context $context,
BackendConfig $backendConfig,
array $data = []
) {
$this->_backendConfig = $backendConfig;
parent::__construct($context, $data);
}

/**
* Return for frontend is the payment in iframe enabled
*
* @return bool
*/
public function isIframeProcessingEnabled(): bool
{
$this->_backendConfig->setMethodCode(Checkout::CODE);

return $this->_backendConfig->isIframeProcessingEnabled();
}
}
134 changes: 111 additions & 23 deletions Controller/AbstractCheckoutAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@

namespace EMerchantPay\Genesis\Controller;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Raw;
use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\OrderFactory;
use Psr\Log\LoggerInterface;
use Magento\Framework\UrlInterface;

/**
* Base Checkout Controller Class
* Class AbstractCheckoutAction
Expand All @@ -36,35 +45,53 @@ abstract class AbstractCheckoutAction extends \EMerchantPay\Genesis\Controller\A
const ROUTE_PATTERN_CHECKOUT_FRAGMENT_PAYMENT_ARGS = ['_fragment' => 'payment'];

/**
* @var \Magento\Checkout\Model\Session
* @var Session
*/
protected $_checkoutSession;

/**
* @var \Magento\Sales\Model\OrderFactory
* @var OrderFactory
*/
protected $_orderFactory;

/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @var ResultFactory
*/
private $_resultFactory;

/**
* @var UrlInterface
*/
private $_urlBuilder;

/**
* @param Context $context
* @param LoggerInterface $logger
* @param Session $checkoutSession
* @param OrderFactory $orderFactory
* @param ResultFactory $resultFactory
* @param UrlInterface $urlBuilder
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Psr\Log\LoggerInterface $logger,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Sales\Model\OrderFactory $orderFactory
Context $context,
LoggerInterface $logger,
Session $checkoutSession,
OrderFactory $orderFactory,
ResultFactory $resultFactory,
UrlInterface $urlBuilder
) {
parent::__construct($context, $logger);

$this->_checkoutSession = $checkoutSession;
$this->_orderFactory = $orderFactory;
$this->_orderFactory = $orderFactory;
$this->_resultFactory = $resultFactory;
$this->_urlBuilder = $urlBuilder;
}

/**
* Get an Instance of the Magento Checkout Session
* @return \Magento\Checkout\Model\Session
*
* @return Session
*/
protected function getCheckoutSession()
{
Expand All @@ -73,8 +100,10 @@ protected function getCheckoutSession()

/**
* Get an Instance of the Magento Order Factory
*
* It can be used to instantiate an order
* @return \Magento\Sales\Model\OrderFactory
*
* @return OrderFactory
*/
protected function getOrderFactory()
{
Expand Down Expand Up @@ -118,25 +147,84 @@ protected function redirectToCheckoutFragmentPayment()

/**
* Does a redirect to the Checkout Success Page
* @return void
*
* @param bool $iframeRedirect
*
* @return ResponseInterface|Raw
*/
protected function redirectToCheckoutOnePageSuccess()
protected function redirectToCheckoutOnePageSuccess(bool $iframeRedirect)
{
$this->_redirect(
self::ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_PATH,
self::ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_ARGS
return $this->selectResponse(
$iframeRedirect,
[
self::ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_PATH,
self::ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_ARGS
]
);
}

/**
* Does a redirect to the Checkout Cart Page
* @return void
*
* @param bool $iframeRedirect
*
* @return ResponseInterface|Raw
*/
protected function redirectToCheckoutCart()
protected function redirectToCheckoutCart(bool $iframeRedirect)
{
$this->_redirect(
self::ROUTE_PATTERN_CHECKOUT_CART_PATH,
self::ROUTE_PATTERN_CHECKOUT_CART_ARGS
return $this->selectResponse(
$iframeRedirect,
[
self::ROUTE_PATTERN_CHECKOUT_CART_PATH,
self::ROUTE_PATTERN_CHECKOUT_CART_ARGS
]
);
}

/**
* Return html code with embedded js in <script> tag to break the iframe jail
*
* @param string $redirectPath
* @param array $params
*
* @return Raw
*/
private function breakIframeAndRedirect(string $redirectPath, array $params)
{
$redirectUrl = $this->_urlBuilder->getUrl($redirectPath, ['_query' => $params]);

$html = '<html><body>';
$html .= '<script type="text/javascript">';
$html .= 'if (window.top !== window.self) {';
$html .= 'window.top.location.href = "' . $redirectUrl . '";';
$html .= '} else {';
$html .= 'window.location.href = "' . $redirectUrl . '";';
$html .= '}';
$html .= '</script>';
$html .= '</body></html>';

/** @var Raw $result */
$result = $this->_resultFactory->create(ResultFactory::TYPE_RAW);
$result->setHeader('Content-Type', 'text/html');
$result->setContents($html);

return $result;
}

/**
* Return response based on if iframe payment processing is used or not
*
* @param bool $iframeRedirect
* @param array $returnUrl
*
* @return ResponseInterface|Raw
*/
private function selectResponse(bool $iframeRedirect, array $returnUrl)
{
if ($iframeRedirect) {
return $this->breakIframeAndRedirect(...$returnUrl);
}

return $this->_redirect(...$returnUrl);
}
}
Loading

0 comments on commit b6b31b5

Please sign in to comment.