Skip to content

Commit

Permalink
create webhook controller #229
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed Mar 13, 2018
1 parent 500b2b2 commit fed9fad
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions Controller/Adminhtml/Ecommerce/CreateWebhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* mc-magento2 Magento Component
*
* @category Ebizmarts
* @package mc-magento2
* @author Ebizmarts Team <info@ebizmarts.com>
* @copyright Ebizmarts (http://ebizmarts.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @date: 3/12/18 4:14 PM
* @file: CreateWebhook.php
*/

namespace Ebizmarts\MailChimp\Controller\Adminhtml\Ecommerce;

use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Exception\ValidatorException;
use Symfony\Component\Config\Definition\Exception\Exception;

class CreateWebhook extends \Magento\Backend\App\Action
{
/**
* @var JsonFactory
*/
protected $resultJsonFactory;
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
protected $helper;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;

/**
* DeleteStore constructor.
* @param \Magento\Backend\App\Action\Context $context
* @param JsonFactory $resultJsonFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManagerInterface
* @param \Ebizmarts\MailChimp\Helper\Data $helper
* @param \Magento\Config\Model\ResourceModel\Config $config
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
JsonFactory $resultJsonFactory,
\Magento\Store\Model\StoreManagerInterface $storeManagerInterface,
\Ebizmarts\MailChimp\Helper\Data $helper,
\Magento\Config\Model\ResourceModel\Config $config
)
{
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->helper = $helper;
$this->storeManager = $storeManagerInterface;
}

public function execute()
{
$valid = 1;
$message = '';
$params = $this->getRequest()->getParams();
$apiKey = $params['apikey'];
$listId = $params['listId'];
$return = $this->helper->createWebHook($apiKey, $listId);
if(isset($return['message'])) {
$valid = 0;
$message = $return['message'];
}
$resultJson = $this->resultJsonFactory->create();

return $resultJson->setData([
'valid' => (int)$valid,
'message' => $message,
]);

}
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Ebizmarts_MailChimp::config_mailchimp');
}

}

0 comments on commit fed9fad

Please sign in to comment.