Your IP : 216.73.216.52


Current Path : /home/rtorresani/www/app/code/Webkul/BuyButton/Controller/LoadButton/
Upload File :
Current File : //home/rtorresani/www/app/code/Webkul/BuyButton/Controller/LoadButton/Index.php

<?php
/**
 * Webkul Software.
 *
 * @category  Webkul
 * @package   Webkul_BuyButton
 * @author    Webkul
 * @copyright Copyright (c)  Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */
namespace Webkul\BuyButton\Controller\LoadButton;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;

class Index extends Action
{

    protected $_helper;
    
    /**
     * constructor
     *
     * @param Context $context
     * @param \Webkul\BuyButton\Helper\Data $helper
     */
    public function __construct(
        Context $context,
        \Webkul\BuyButton\Helper\Data $helper,
        \Webkul\BuyButton\Model\App $app
    ) {
        $this->_helper = $helper;
        $this->app = $app;
        parent::__construct($context);
    }

    /**
     * set javascript response
     *
     * @return string
     */
    public function execute()
    {
        $token = $this->getRequest()->getParam('access');
        $response = $this->resultFactory->create(ResultFactory::TYPE_RAW);
        if ($token && $token == $this->_helper->getAccessKey()) {
            
            $response->setHeader('Content-type', 'application/javascript');
            $response->setHeader('Access-Control-Allow-Origin', '*');
            
            $response->setContents(
                $this->app->createWidget()
            );
            
        } else {
            $response->setHeader('Content-type', 'plain/text');
            $response->setHttpResponseCode(\Magento\Framework\App\Response\Http::STATUS_CODE_403);
        }
        return $response;
    }
}