-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
658 additions
and
110 deletions.
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
Block/Adminhtml/System/Config/Form/Field/ContactSupport.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.