/**
  * Delete frontend session cookie if customer session is expired
  *
  * @param SessionManager $sessionManager
  */
 public function beforeStart(SessionManager $sessionManager)
 {
     if (!$this->cookieManager->getCookie($sessionManager->getName()) && $this->cookieManager->getCookie('mage-cache-sessid')) {
         $metadata = $this->cookieMetadataFactory->createCookieMetadata();
         $metadata->setPath('/');
         $this->cookieManager->deleteCookie('mage-cache-sessid', $metadata);
     }
 }
 /**
  * Send request to PayfloPro gateway for get Secure Token
  *
  * @return ResultInterface
  */
 public function execute()
 {
     $this->sessionTransparent->setQuoteId($this->sessionManager->getQuote()->getId());
     $token = $this->secureTokenService->requestToken($this->sessionManager->getQuote());
     $result = [];
     $result[$this->transparent->getCode()]['fields'] = $token->getData();
     $result['success'] = $token->getSecuretoken() ? true : false;
     if (!$result['success']) {
         $result['error'] = true;
         $result['error_messages'] = __('Secure Token Error. Try again.');
     }
     return $this->resultJsonFactory->create()->setData($result);
 }
 public function testCheckContactUsFormWhenCaptchaIsRequiredAndValid()
 {
     $formId = 'contact_us';
     $captchaValue = 'some-value';
     $controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([$formId => $captchaValue]);
     $controller->expects($this->any())->method('getRequest')->willReturn($request);
     $this->captchaMock->expects($this->any())->method('isRequired')->willReturn(true);
     $this->captchaMock->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(true);
     $this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, $formId)->willReturn($captchaValue);
     $this->helperMock->expects($this->any())->method('getCaptcha')->with($formId)->willReturn($this->captchaMock);
     $this->sessionMock->expects($this->never())->method('addError');
     $this->checkContactUsFormObserver->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
 }
Exemple #4
0
 /**
  * @param \Magento\Framework\App\Request\Http $request
  * @param \Magento\Framework\Session\SidResolverInterface $sidResolver
  * @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
  * @param \Magento\Framework\Session\SaveHandlerInterface $saveHandler
  * @param \Magento\Framework\Session\ValidatorInterface $validator
  * @param \Magento\Framework\Session\StorageInterface $storage
  * @param CookieManagerInterface $cookieManager
  * @param CookieMetadataFactory $cookieMetadataFactory
  * @param \Magento\Framework\App\State $appState
  * @param \Magento\Framework\Acl\Builder $aclBuilder
  * @param \Magento\Backend\Model\UrlInterface $backendUrl
  * @param \Magento\Backend\App\ConfigInterface $config
  * @throws \Magento\Framework\Exception\SessionException
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\App\Request\Http $request, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Session\Config\ConfigInterface $sessionConfig, \Magento\Framework\Session\SaveHandlerInterface $saveHandler, \Magento\Framework\Session\ValidatorInterface $validator, \Magento\Framework\Session\StorageInterface $storage, CookieManagerInterface $cookieManager, CookieMetadataFactory $cookieMetadataFactory, \Magento\Framework\App\State $appState, \Magento\Framework\Acl\Builder $aclBuilder, \Magento\Backend\Model\UrlInterface $backendUrl, \Magento\Backend\App\ConfigInterface $config)
 {
     $this->_config = $config;
     $this->_aclBuilder = $aclBuilder;
     $this->_backendUrl = $backendUrl;
     parent::__construct($request, $sidResolver, $sessionConfig, $saveHandler, $validator, $storage, $cookieManager, $cookieMetadataFactory, $appState);
 }
 /**
  * Send request to PayfloPro gateway for get Secure Token
  *
  * @return ResultInterface
  */
 public function executeInternal()
 {
     /** @var Quote $quote */
     $quote = $this->sessionManager->getQuote();
     if (!$quote or !$quote instanceof Quote) {
         return $this->getErrorResponse();
     }
     $this->sessionTransparent->setQuoteId($quote->getId());
     try {
         $token = $this->secureTokenService->requestToken($quote);
         if (!$token->getData('securetoken')) {
             throw new \LogicException();
         }
         return $this->resultJsonFactory->create()->setData([$this->transparent->getCode() => ['fields' => $token->getData()], 'success' => true, 'error' => false]);
     } catch (\Exception $e) {
         return $this->getErrorResponse();
     }
 }
 /**
  * Run test execute method
  *
  * @param array $result
  * @param array $resultExpectation
  *
  * @dataProvider executeDataProvider
  */
 public function testExecute(array $result, array $resultExpectation)
 {
     $quoteId = 99;
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $tokenMock = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['getData', 'getSecuretoken'])->disableOriginalConstructor()->getMock();
     $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock();
     $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent');
     $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock);
     $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId);
     $this->sessionTransparentMock->expects($this->once())->method('setQuoteId')->with($quoteId);
     $this->secureTokenServiceMock->expects($this->once())->method('requestToken')->with($quoteMock)->willReturn($tokenMock);
     $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent');
     $tokenMock->expects($this->once())->method('getData')->willReturn($result['transparent']['fields']);
     $tokenMock->expects($this->once())->method('getSecuretoken')->willReturn($result['success']);
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock);
     $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf();
     $this->assertEquals($jsonMock, $this->controller->execute());
 }
 public function testExecuteEmptyQuoteError()
 {
     $resultExpectation = ['success' => false, 'error' => true, 'error_messages' => __('Your payment has been declined. Please try again.')];
     $quoteMock = null;
     $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock();
     $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock);
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock);
     $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf();
     $this->assertEquals($jsonMock, $this->controller->execute());
 }
Exemple #8
0
 /**
  * Reset core session hosts after reseting session ID
  *
  * @return $this
  */
 public function regenerateId()
 {
     parent::regenerateId();
     $this->_cleanHosts();
     return $this;
 }
Exemple #9
0
 /**
  * Unset all session data and quote
  *
  * @return $this
  */
 public function clearStorage()
 {
     parent::clearStorage();
     $this->_quote = null;
     return $this;
 }
Exemple #10
0
 /**
  * @param \Magento\Framework\App\Request\Http $request
  * @param \Magento\Framework\Session\SidResolverInterface $sidResolver
  * @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
  * @param \Magento\Framework\Session\SaveHandlerInterface $saveHandler
  * @param \Magento\Framework\Session\ValidatorInterface $validator
  * @param \Magento\Framework\Session\StorageInterface $storage
  * @param string|null $sessionName
  * @internal param array $data
  */
 public function __construct(\Magento\Framework\App\Request\Http $request, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Session\Config\ConfigInterface $sessionConfig, \Magento\Framework\Session\SaveHandlerInterface $saveHandler, \Magento\Framework\Session\ValidatorInterface $validator, \Magento\Framework\Session\StorageInterface $storage, $sessionName = null)
 {
     parent::__construct($request, $sidResolver, $sessionConfig, $saveHandler, $validator, $storage);
     $this->start($sessionName);
 }
Exemple #11
0
 /**
  * @param \Magento\Framework\App\Request\Http $request
  * @param \Magento\Framework\Session\SidResolverInterface $sidResolver
  * @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
  * @param \Magento\Framework\Session\SaveHandlerInterface $saveHandler
  * @param \Magento\Framework\Session\ValidatorInterface $validator
  * @param \Magento\Framework\Session\StorageInterface $storage
  * @param \Magento\Connect\Helper\Data $connectData
  */
 public function __construct(\Magento\Framework\App\Request\Http $request, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Session\Config\ConfigInterface $sessionConfig, \Magento\Framework\Session\SaveHandlerInterface $saveHandler, \Magento\Framework\Session\ValidatorInterface $validator, \Magento\Framework\Session\StorageInterface $storage, \Magento\Connect\Helper\Data $connectData)
 {
     $this->_connectData = $connectData;
     parent::__construct($request, $sidResolver, $sessionConfig, $saveHandler, $validator, $storage);
     $this->start();
 }
Exemple #12
0
 /**
  * Reset core session hosts after reseting session ID
  *
  * @param bool $deleteOldSession
  * @return $this
  */
 public function regenerateId($deleteOldSession = true)
 {
     parent::regenerateId($deleteOldSession);
     $this->_cleanHosts();
     return $this;
 }
Exemple #13
0
 /**
  * @param \Magento\Framework\App\Request\Http $request
  * @param \Magento\Framework\Session\SidResolverInterface $sidResolver
  * @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
  * @param \Magento\Framework\Session\SaveHandlerInterface $saveHandler
  * @param \Magento\Framework\Session\ValidatorInterface $validator
  * @param \Magento\Framework\Session\StorageInterface $storage
  * @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
  * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
  * @param CustomerRepositoryInterface $customerRepository
  * @param \Magento\Quote\Model\QuoteRepository $quoteRepository
  * @param \Magento\Sales\Model\OrderFactory $orderFactory
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param GroupManagementInterface $groupManagement
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\App\Request\Http $request, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Session\Config\ConfigInterface $sessionConfig, \Magento\Framework\Session\SaveHandlerInterface $saveHandler, \Magento\Framework\Session\ValidatorInterface $validator, \Magento\Framework\Session\StorageInterface $storage, \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, CustomerRepositoryInterface $customerRepository, \Magento\Quote\Model\QuoteRepository $quoteRepository, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, GroupManagementInterface $groupManagement)
 {
     $this->customerRepository = $customerRepository;
     $this->quoteRepository = $quoteRepository;
     $this->_orderFactory = $orderFactory;
     $this->_storeManager = $storeManager;
     $this->groupManagement = $groupManagement;
     parent::__construct($request, $sidResolver, $sessionConfig, $saveHandler, $validator, $storage, $cookieManager, $cookieMetadataFactory);
     $this->start();
     if ($this->_storeManager->hasSingleStore()) {
         $this->setStoreId($this->_storeManager->getStore(true)->getId());
     }
 }
Exemple #14
0
 /**
  * @param \Magento\Framework\App\Request\Http $request
  * @param \Magento\Framework\Session\SidResolverInterface $sidResolver
  * @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
  * @param \Magento\Framework\Session\SaveHandlerInterface $saveHandler
  * @param \Magento\Framework\Session\ValidatorInterface $validator
  * @param \Magento\Framework\Session\StorageInterface $storage
  * @param \Magento\Framework\Stdlib\CookieManager $cookieManager
  * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
  * @param \Magento\Sales\Model\QuoteFactory $quoteFactory
  * @param \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerService
  * @param \Magento\Sales\Model\OrderFactory $orderFactory
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  */
 public function __construct(\Magento\Framework\App\Request\Http $request, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Session\Config\ConfigInterface $sessionConfig, \Magento\Framework\Session\SaveHandlerInterface $saveHandler, \Magento\Framework\Session\ValidatorInterface $validator, \Magento\Framework\Session\StorageInterface $storage, \Magento\Framework\Stdlib\CookieManager $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, \Magento\Sales\Model\QuoteFactory $quoteFactory, \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerService, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
 {
     $this->_quoteFactory = $quoteFactory;
     $this->_customerService = $customerService;
     $this->_orderFactory = $orderFactory;
     $this->_storeManager = $storeManager;
     $this->_scopeConfig = $scopeConfig;
     parent::__construct($request, $sidResolver, $sessionConfig, $saveHandler, $validator, $storage, $cookieManager, $cookieMetadataFactory);
     $this->start();
     if ($this->_storeManager->hasSingleStore()) {
         $this->setStoreId($this->_storeManager->getStore(true)->getId());
     }
 }
Exemple #15
0
 public function testSet()
 {
     $formKeyValue = 'Form key';
     $this->sessionMock->expects(static::once())->method('setData')->with(FormKey::FORM_KEY, $formKeyValue);
     $this->formKey->set($formKeyValue);
 }
Exemple #16
0
 /**
  * @param \Magento\Framework\App\Request\Http $request
  * @param \Magento\Framework\Session\SidResolverInterface $sidResolver
  * @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
  * @param \Magento\Framework\Session\SaveHandlerInterface $saveHandler
  * @param \Magento\Framework\Session\ValidatorInterface $validator
  * @param \Magento\Framework\Session\StorageInterface $storage
  * @param \Magento\Framework\Stdlib\CookieManager $cookieManager
  * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
  * @internal param array $data
  */
 public function __construct(\Magento\Framework\App\Request\Http $request, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Session\Config\ConfigInterface $sessionConfig, \Magento\Framework\Session\SaveHandlerInterface $saveHandler, \Magento\Framework\Session\ValidatorInterface $validator, \Magento\Framework\Session\StorageInterface $storage, \Magento\Framework\Stdlib\CookieManager $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory)
 {
     parent::__construct($request, $sidResolver, $sessionConfig, $saveHandler, $validator, $storage, $cookieManager, $cookieMetadataFactory);
     $this->start();
 }
Exemple #17
0
 /**
  * @param \Magento\Framework\App\Request\Http $request
  * @param \Magento\Framework\Session\SidResolverInterface $sidResolver
  * @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
  * @param \Magento\Framework\Session\SaveHandlerInterface $saveHandler
  * @param \Magento\Framework\Session\ValidatorInterface $validator
  * @param \Magento\Framework\Session\StorageInterface $storage
  * @param \Magento\Framework\Acl\Builder $aclBuilder
  * @param \Magento\Backend\Model\UrlInterface $backendUrl
  * @param \Magento\Backend\App\ConfigInterface $config
  * @param \Magento\Framework\Stdlib\Cookie $cookie
  */
 public function __construct(\Magento\Framework\App\Request\Http $request, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Session\Config\ConfigInterface $sessionConfig, \Magento\Framework\Session\SaveHandlerInterface $saveHandler, \Magento\Framework\Session\ValidatorInterface $validator, \Magento\Framework\Session\StorageInterface $storage, \Magento\Framework\Acl\Builder $aclBuilder, \Magento\Backend\Model\UrlInterface $backendUrl, \Magento\Backend\App\ConfigInterface $config, \Magento\Framework\Stdlib\Cookie $cookie)
 {
     $this->_config = $config;
     $this->_aclBuilder = $aclBuilder;
     $this->_backendUrl = $backendUrl;
     $this->_cookie = $cookie;
     parent::__construct($request, $sidResolver, $sessionConfig, $saveHandler, $validator, $storage);
     $this->start();
 }