Skip to content

Commit

Permalink
Merge branch 'hotfix/2.5.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabil Berhouche committed May 27, 2021
2 parents 067e653 + 2e994c7 commit 97c8020
Show file tree
Hide file tree
Showing 36 changed files with 658 additions and 110 deletions.
143 changes: 143 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/ContactSupport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php
/**
* Copyright © Lyra Network.
* This file is part of PayZen plugin for Magento 2. See COPYING.md for license details.
*
* @author Lyra Network (https://www.lyra.com/)
* @copyright Lyra Network
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace Lyranetwork\Payzen\Block\Adminhtml\System\Config\Form\Field;

/**
* Custom renderer for the contact support link.
*/
class ContactSupport extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* @var \Lyranetwork\Payzen\Helper\Data
*/
protected $dataHelper;

/**
* @var \Magento\Framework\Locale\ResolverInterface
*/
protected $localeResolver;

/**
* @var \Magento\Framework\Module\FullModuleList
*/
protected $fullModuleList;

/**
* @var \Magento\Backend\Model\Auth\Session
*/
protected $authSession;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Lyranetwork\Payzen\Helper\Data $dataHelper,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Framework\Module\FullModuleList $fullModuleList,
\Magento\Backend\Model\Auth\Session $authSession,
array $data = []
)
{
parent::__construct($context, $data);

$this->dataHelper = $dataHelper;
$this->localeResolver = $localeResolver;
$this->fullModuleList = $fullModuleList;
$this->authSession = $authSession;
}

public function getStoreInfo($order = null)
{
$info = [];

$storeId = $order ? $order->getStore()->getId() : null;

$info['shop-id'] = $this->dataHelper->getCommonConfigData('site_id', $storeId);
$info['context-mode'] = $this->dataHelper->getCommonConfigData('ctx_mode', $storeId);
$info['sign-algo'] = $this->dataHelper->getCommonConfigData('sign_algo', $storeId);

$info['contrib'] = $this->dataHelper->getContribParam();
$info['integration-mode'] = $this->dataHelper->getCardDataEntryMode($storeId);

$modulesList = $this->fullModuleList->getNames();
foreach ($modulesList as $id => $module) {
// Do not include Magento default modules.
if (strpos($module, 'Magento_') === 0) {
unset($modulesList[$id]);
}
}

$info['plugins'] = implode(' / ', $modulesList);
$info['first-name'] = $this->authSession->getUser()->getFirstName();
$info['last-name'] = $this->authSession->getUser()->getLastName();
$info['from-email'] = $this->authSession->getUser()->getEmail();
$info['to-email'] = $this->dataHelper->getCommonConfigData('support_email');
$info['language'] = strtolower(substr($this->localeResolver->getLocale(), 0, 2));

return $info;
}

/**
* Set template to itself.
*/
protected function _prepareLayout()
{
parent::_prepareLayout();

if (! $this->getTemplate()) {
$this->setTemplate('Lyranetwork_Payzen::system/config/form/field/contact_support.phtml');
}

return $this;
}

/**
* Unset some non-related element parameters.
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$element->unsScope()
->unsCanUseWebsiteValue()
->unsCanUseDefaultValue();
return parent::render($element);
}

/**
* Get the button and scripts contents.
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$fieldConfig = $element->getFieldConfig();

$this->addData(
[
'button_label' => __($fieldConfig['button_label']),
'button_url' => $this->getUrl(
$fieldConfig['button_url'],
[
'_nosid' => true
]
),
'html_id' => $element->getHtmlId()
]
);

return $this->_toHtml();
}

public function sendMailUrl()
{
return $this->getUrl('payzen/system_config/support', ['_nosid' => true]);
}
}
18 changes: 18 additions & 0 deletions Block/Payment/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,28 @@ class Info extends \Magento\Payment\Block\Info
*/
protected $trsCollectionFactory;

/**
* @var \Lyranetwork\Payzen\Block\Adminhtml\System\Config\Form\Field\ContactSupport
*/
protected $supportBlock;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
* @param \Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory $trsCollectionFactory
* @param \Lyranetwork\Payzen\Block\Adminhtml\System\Config\Form\Field\ContactSupport $supportBlock
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory $trsCollectionFactory,
\Lyranetwork\Payzen\Block\Adminhtml\System\Config\Form\Field\ContactSupport $supportBlock,
array $data = []
) {
$this->localeResolver = $localeResolver;
$this->trsCollectionFactory = $trsCollectionFactory;
$this->supportBlock = $supportBlock;

parent::__construct($context, $data);
}
Expand Down Expand Up @@ -174,4 +182,14 @@ public function translate($code, $type, $appendCode = false)
$lang = strtolower(substr($this->localeResolver->getLocale(), 0, 2));
return PayzenResponse::translate($code, $type, $lang, $appendCode);
}

public function getStoreInfo($order)
{
return $this->supportBlock->getStoreInfo($order);
}

public function sendMailUrl()
{
return $this->supportBlock->sendMailUrl();
}
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.5.6, 2021-05-27:
- Possibility to open support issue from the plugin configuration panel or an order details page.
- Update 3DS management option description.
- Improve REST API keys configuration display.
- Improve plugin logs.

2.5.5, 2021-03-09:
- Use online payment means logos.
- [franfinance] Send cart details for FranFinance payments.
Expand Down
8 changes: 3 additions & 5 deletions Controller/Adminhtml/Payment/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,19 @@ private function getAndCheckOrder()
$order = $this->orderRepository->get($id);
} catch (\Exception $e) {
$this->dataHelper->log("No order to pay. It may be a direct access to redirection page."
. " [Order = {$id}] [IP = {$this->dataHelper->getIpAddress()}].");
. " [Order = {$id}].");
throw new OrderException('Order not found in session.');
}

// Check that there is products in cart.
if (! $order->getTotalDue()) {
$this->dataHelper->log("Payment attempt with no amount. [Order = {$order->getIncrementId()}]"
. " [IP = {$this->dataHelper->getIpAddress()}].");
$this->dataHelper->log("Payment attempt with no amount. [Order = {$order->getIncrementId()}].");
throw new OrderException('Order total is empty.');
}

// Check that order is not processed yet.
if (! $this->dataHelper->getCheckout()->getLastSuccessQuoteId()) {
$this->dataHelper->log("Payment attempt with a quote already processed. [Order = {$order->getIncrementId()}]"
. " [IP = {$this->dataHelper->getIpAddress()}].");
$this->dataHelper->log("Payment attempt with a quote already processed. [Order = {$order->getIncrementId()}].");
throw new OrderException('Order payment already processed.');
}

Expand Down
6 changes: 3 additions & 3 deletions Controller/Adminhtml/Payment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private function redirectResponse($order, $case, $checkUrlWarn = false)
$features = \Lyranetwork\Payzen\Helper\Data::$pluginFeatures;
if ($features['prodfaq']) {
// Display going to production message.
$message = __('<u><p>GOING INTO PRODUCTION:</u></p> You want to know how to put your shop into production mode, please read chapters &laquo; Proceeding to test phase &raquo; and &laquo; Shifting the shop to production mode &raquo; in the documentation of the module.');
$message = __('GOING INTO PRODUCTION: You want to know how to put your shop into production mode, please read chapters &laquo; Proceeding to test phase &raquo; and &laquo; Shifting the shop to production mode &raquo; in the documentation of the module.');
$this->messageManager->addNoticeMessage($message);
}

Expand All @@ -113,8 +113,8 @@ private function redirectResponse($order, $case, $checkUrlWarn = false)
$message = __('The shop is in maintenance mode.The automatic notification cannot work.');
} else {
$message = __('The automatic validation has not worked. Have you correctly set up the notification URL in your PayZen Back Office?');
$message .= '&nbsp;<br /><br />';
$message .= __('For understanding the problem, please read the documentation of the module:<br />&nbsp;&nbsp;&nbsp;- Chapter &laquo; To read carefully before going further &raquo;<br />&nbsp;&nbsp;&nbsp;- Chapter &laquo; Notification URL settings &raquo;');
$message .= '&nbsp;';
$message .= __('For understanding the problem, please read the documentation of the module:&nbsp;&nbsp;&nbsp;- Chapter &laquo; To read carefully before going further &raquo;&nbsp;&nbsp;&nbsp;- Chapter &laquo; Notification URL settings &raquo;');
}

$this->messageManager->addErrorMessage($message);
Expand Down
80 changes: 80 additions & 0 deletions Controller/Adminhtml/System/Config/Support.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Copyright © Lyra Network.
* This file is part of PayZen plugin for Magento 2. See COPYING.md for license details.
*
* @author Lyra Network (https://www.lyra.com/)
* @copyright Lyra Network
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace Lyranetwork\Payzen\Controller\Adminhtml\System\Config;

use Magento\Framework\DataObject;

class Support extends \Magento\Backend\App\AbstractAction
{
/**
* @var \Lyranetwork\Payzen\Helper\Data
*/
protected $dataHelper;

/**
* @var \Magento\Framework\Controller\Result\JsonFactory
*/
protected $resultJsonFactory;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Lyranetwork\Payzen\Helper\Data $dataHelper
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Lyranetwork\Payzen\Helper\Data $dataHelper,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
) {
parent::__construct($context);

$this->dataHelper = $dataHelper;
$this->resultJsonFactory = $resultJsonFactory;
}

public function execute()
{
// Clear all messages in session.
$this->messageManager->getMessages(true);

$params = $this->getRequest()->getPost();

if (isset($params['submitter']) && $params['submitter'] === 'payzen_send_support') {
if (isset($params['sender']) && isset($params['subject']) && isset($params['message'])) {
$recipient = $this->dataHelper->getCommonConfigData('support_email');
$subject = $params['subject'];
$content = $params['message'];

try {
$email = new \Zend_Mail('UTF-8');
$email->setSubject($subject);
$email->setBodyHtml($content);
$email->setFrom($params['sender']);
$email->addTo($recipient);

$email->send();
$this->messageManager->addSuccessMessage(__('Thank you for contacting us. Your email has been successfully sent.'));
} catch (\Exception $e) {
$this->dataHelper->log('An error occurred when trying to send email to Support: ' . $e->getMessage());
$this->messageManager->addErrorMessage(__('An error has occurred. Your email was not sent.'));
}
} else {
$this->messageManager->addWarningMessage(__('Please make sure to configure all required fields.'));
}
}

$result = $this->resultJsonFactory->create();

$data = new DataObject();
$data->setData('success', true);

return $result->setData($data->getData());
}
}
4 changes: 2 additions & 2 deletions Controller/Payment/Iframe/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public function __construct(

public function execute()
{
// Check if it is a canceled order.
// Check if it is a cancelled order.
if ($this->getRequest()->getParam('mode', false) === 'cancel') {
// Load order.
$checkout = $this->dataHelper->getCheckout();
$lastIncrementId = $checkout->getData('payzen_last_real_id');

$this->dataHelper->log("Payment within iframe is canceled for order #{$lastIncrementId}.");
$this->dataHelper->log("Payment within iframe is cancelled for order #{$lastIncrementId}.");

$lastIncrementId = $checkout->getData('payzen_last_real_id');
$order = $this->orderFactory->create();
Expand Down
9 changes: 3 additions & 6 deletions Controller/Payment/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ private function getAndCheckOrder()

// Check that there is an order to pay.
if (empty($lastIncrementId)) {
$this->dataHelper->log("No order to pay. It may be a direct access to redirection page." .
" [IP = {$this->dataHelper->getIpAddress()}].");
$this->dataHelper->log("No order to pay. It may be a direct access to redirection page.");
throw new OrderException('Order not found in session.');
}

Expand All @@ -91,15 +90,13 @@ private function getAndCheckOrder()

// Check that there is products in cart.
if (! $order->getTotalDue()) {
$this->dataHelper->log("Payment attempt with no amount. [Order = {$order->getIncrementId()}]" .
" [IP = {$this->dataHelper->getIpAddress()}].");
$this->dataHelper->log("Payment attempt with no amount. [Order = {$order->getIncrementId()}].");
throw new OrderException('Order total is empty.');
}

// Check that order is not processed yet.
if (! $checkout->getLastSuccessQuoteId()) {
$this->dataHelper->log("Payment attempt with a quote already processed. [Order = {$order->getIncrementId()}]" .
" [IP = {$this->dataHelper->getIpAddress()}].");
$this->dataHelper->log("Payment attempt with a quote already processed. [Order = {$order->getIncrementId()}].");
throw new OrderException('Order payment already processed.');
}

Expand Down
6 changes: 3 additions & 3 deletions Controller/Payment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function redirectResponse($order, $case, $checkUrlWarn = false)
$features = \Lyranetwork\Payzen\Helper\Data::$pluginFeatures;
if ($features['prodfaq']) {
// Display going to production message.
$message = __('<u><p>GOING INTO PRODUCTION:</u></p> You want to know how to put your shop into production mode, please read chapters &laquo; Proceeding to test phase &raquo; and &laquo; Shifting the shop to production mode &raquo; in the documentation of the module.');
$message = __('GOING INTO PRODUCTION: You want to know how to put your shop into production mode, please read chapters &laquo; Proceeding to test phase &raquo; and &laquo; Shifting the shop to production mode &raquo; in the documentation of the module.');
$this->messageManager->addNoticeMessage($message);
}

Expand All @@ -132,8 +132,8 @@ protected function redirectResponse($order, $case, $checkUrlWarn = false)
$message = __('The shop is in maintenance mode.The automatic notification cannot work.');
} else {
$message = __('The automatic validation has not worked. Have you correctly set up the notification URL in your PayZen Back Office?');
$message .= '&nbsp;<br /><br />';
$message .= __('For understanding the problem, please read the documentation of the module:<br />&nbsp;&nbsp;&nbsp;- Chapter &laquo; To read carefully before going further &raquo;<br />&nbsp;&nbsp;&nbsp;- Chapter &laquo; Notification URL settings &raquo;');
$message .= '&nbsp;';
$message .= __('For understanding the problem, please read the documentation of the module:&nbsp;&nbsp;&nbsp;- Chapter &laquo; To read carefully before going further &raquo;&nbsp;&nbsp;&nbsp;- Chapter &laquo; Notification URL settings &raquo;');
}

$this->messageManager->addErrorMessage($message);
Expand Down
Loading

0 comments on commit 97c8020

Please sign in to comment.