Example #1
0
 public function testTryToSaveInvalidDataShouldFailWithErrors()
 {
     $validatorClass = 'Magento\\MediaStorage\\Model\\File\\Validator\\AvailablePath';
     $helperClass = 'Magento\\Sitemap\\Helper\\Data';
     $validPaths = [];
     $messages = ['message1', 'message2'];
     $sessionClass = 'Magento\\Backend\\Model\\Session';
     $data = ['sitemap_filename' => 'sitemap_filename', 'sitemap_path' => '/sitemap_path'];
     $siteMapId = 1;
     $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($data);
     $this->requestMock->expects($this->once())->method('getParam')->with('sitemap_id')->willReturn($siteMapId);
     $validator = $this->getMock($validatorClass, [], [], '', false);
     $validator->expects($this->once())->method('setPaths')->with($validPaths)->willReturnSelf();
     $validator->expects($this->once())->method('isValid')->with('/sitemap_path/sitemap_filename')->willReturn(false);
     $validator->expects($this->once())->method('getMessages')->willReturn($messages);
     $helper = $this->getMock($helperClass, [], [], '', false);
     $helper->expects($this->once())->method('getValidPaths')->willReturn($validPaths);
     $session = $this->getMock($sessionClass, ['setFormData'], [], '', false);
     $session->expects($this->once())->method('setFormData')->with($data)->willReturnSelf();
     $this->objectManagerMock->expects($this->once())->method('create')->with($validatorClass)->willReturn($validator);
     $this->objectManagerMock->expects($this->any())->method('get')->willReturnMap([[$helperClass, $helper], [$sessionClass, $session]]);
     $this->messageManagerMock->expects($this->at(0))->method('addError')->withConsecutive([$messages[0]], [$messages[1]])->willReturnSelf();
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('adminhtml/*/edit', ['sitemap_id' => $siteMapId])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->saveController->execute());
 }
Example #2
0
 /**
  * @return \GeoIp2\Model\City|bool
  */
 public function getCity()
 {
     try {
         $ip = $this->httpRequest->getClientIp();
         $city = $this->getReader()->city($ip);
     } catch (\Exception $e) {
         $this->logger->critical($e);
         $city = false;
     }
     return $city;
 }
Example #3
0
 public function execute()
 {
     $redirectTo = 'checkout/cart';
     if ($this->_request->getParam('iframeused')) {
         $redirectUrl = $this->_url->getUrl($redirectTo);
         $page = $this->_resultPageFactory->create();
         $page->getLayout()->getBlock('checkout.failed')->addData(['redirectUrl' => $redirectUrl]);
         return $page;
     } else {
         $this->_redirect($redirectTo);
     }
 }
 /**
  * get user code.
  *
  * @param mixed $id
  *
  * @return string
  */
 protected function getUserCode($id)
 {
     $ipAddress = $this->_phpEnvironmentRequest->getClientIp(true);
     $cookiefrontend = $this->_cookieManager->getCookie('frontend');
     $usercode = $ipAddress . $cookiefrontend . $id;
     return md5($usercode);
 }
Example #5
0
 /**
  * {@inheritdoc}
  *
  * Added CGI environment support.
  */
 public function getHeader($header, $default = false)
 {
     $headerValue = parent::getHeader($header, $default);
     if ($headerValue == false) {
         /** Workaround for hhvm environment */
         $header = 'REDIRECT_HTTP_' . strtoupper(str_replace('-', '_', $header));
         if (isset($_SERVER[$header])) {
             $headerValue = $_SERVER[$header];
         }
     }
     return $headerValue;
 }
Example #6
0
 public function execute()
 {
     $this->_logger->debug(__METHOD__ . ':' . print_r($this->_request->getPost()->toArray(), true));
     try {
         $return = \WirecardCEE_QPay_ReturnFactory::getInstance($this->_request->getPost()->toArray(), $this->_dataHelper->getConfigData('basicdata/secret'));
         if (!$return->validate()) {
             throw new \Exception('Validation error: invalid response');
         }
         if (!strlen($return->mage_orderId)) {
             throw new \Exception('Magento OrderId is missing');
         }
         if (!strlen($return->mage_quoteId)) {
             throw new \Exception('Magento QuoteId is missing');
         }
         $this->_orderManagement->processOrder($return);
         die(\WirecardCEE_QPay_ReturnFactory::generateConfirmResponseString());
     } catch (\Exception $e) {
         $this->_logger->debug(__METHOD__ . ':' . $e->getMessage());
         $this->_logger->debug(__METHOD__ . ':' . $e->getTraceAsString());
         die(\WirecardCEE_QPay_ReturnFactory::generateConfirmResponseString($e->getMessage()));
     }
 }
Example #7
0
 protected function configureHttpRequest($ip)
 {
     $this->httpRequest->expects($this->once())->method('getClientIp')->willReturn($ip);
 }
Example #8
0
 /**
  * @param HttpRequest $request
  */
 public function __construct(HttpRequest $request)
 {
     $this->pathInfo = str_replace('..', '', ltrim($request->getPathInfo(), '/'));
 }
Example #9
0
 /**
  * Get base path
  *
  * @return string
  */
 public function getBasePath()
 {
     $path = parent::getBasePath();
     if (empty($path)) {
         $path = '/';
     } else {
         $path = str_replace('\\', '/', $path);
     }
     return $path;
 }
Example #10
0
 public function testGetAliasWhenAliasAreEmpty()
 {
     $this->model = $this->getModel();
     $this->assertNull($this->model->getAlias(''));
 }
Example #11
0
 public function execute()
 {
     $redirectTo = 'checkout/cart';
     $defaultErrorMessage = $this->_dataHelper->__('An error occurred during the payment process.');
     try {
         $this->_logger->debug(__METHOD__ . ':' . print_r($this->_request->getPost()->toArray(), true));
         $this->_cart->getCustomerSession()->unsUniqueId();
         if (!$this->_request->isPost()) {
             throw new \Exception('Not a post request');
         }
         $return = \WirecardCEE_QPay_ReturnFactory::getInstance($this->_request->getPost()->toArray(), $this->_dataHelper->getConfigData('basicdata/secret'));
         if (!$return->validate()) {
             throw new \Exception('Validation error: invalid response');
         }
         if (!strlen($return->mage_orderId)) {
             throw new \Exception('Magento OrderId is missing');
         }
         if (!strlen($return->mage_quoteId)) {
             throw new \Exception('Magento QuoteId is missing');
         }
         $orderId = $this->_request->getPost('mage_orderId');
         /** @var \Magento\Sales\Model\Order $order */
         $order = $this->_objectManager->create('\\Magento\\Sales\\Model\\Order');
         $order->loadByIncrementId($orderId);
         $orderExists = (bool) $order->getId();
         if ($return->mage_orderCreation == 'before') {
             if (!$orderExists) {
                 throw new \Exception('Order not found');
             }
             $payment = $order->getPayment();
             if (!strlen($payment->getAdditionalInformation('paymentState'))) {
                 $this->_logger->debug(__METHOD__ . ':order not processed via confirm server2server request, check your packetfilter!');
                 $order = $this->_orderManagement->processOrder($return);
             }
         }
         if ($return->mage_orderCreation == 'after') {
             if (!$orderExists && ($return->getPaymentState() == \WirecardCEE_QPay_ReturnFactory::STATE_SUCCESS || $return->getPaymentState() == \WirecardCEE_QPay_ReturnFactory::STATE_PENDING)) {
                 $this->_logger->debug(__METHOD__ . ':order not processed via confirm server2server request, check your packetfilter!');
                 $order = $this->_orderManagement->processOrder($return);
             }
         }
         switch ($return->getPaymentState()) {
             case \WirecardCEE_QPay_ReturnFactory::STATE_SUCCESS:
             case \WirecardCEE_QPay_ReturnFactory::STATE_PENDING:
                 if ($return->getPaymentState() == \WirecardCEE_QPay_ReturnFactory::STATE_PENDING) {
                     $this->messageManager->addNoticeMessage($this->_dataHelper->__('Your order will be processed as soon as we receive the payment confirmation from your bank.'));
                 }
                 /* needed for success page otherwise magento redirects to cart */
                 $this->_checkoutSession->setLastQuoteId($order->getQuoteId());
                 $this->_checkoutSession->setLastSuccessQuoteId($order->getQuoteId());
                 $this->_checkoutSession->setLastOrderId($order->getId());
                 $this->_checkoutSession->setLastRealOrderId($order->getIncrementId());
                 $this->_checkoutSession->setLastOrderStatus($order->getStatus());
                 $redirectTo = 'checkout/onepage/success';
                 break;
             case \WirecardCEE_QPay_ReturnFactory::STATE_CANCEL:
                 /** @var \WirecardCEE_QPay_Return_Cancel $return */
                 $this->messageManager->addNoticeMessage($this->_dataHelper->__('You have canceled the payment process!'));
                 if ($return->mage_orderCreation == 'before') {
                     $quote = $this->_orderManagement->reOrder($return->mage_quoteId);
                     $this->_checkoutSession->replaceQuote($quote)->unsLastRealOrderId();
                 }
                 break;
             case \WirecardCEE_QPay_ReturnFactory::STATE_FAILURE:
                 /** @var \WirecardCEE_QPay_Return_Failure $return */
                 $msg = $return->getErrors()->getConsumerMessage();
                 if (!strlen($msg)) {
                     $msg = $defaultErrorMessage;
                 }
                 $this->messageManager->addErrorMessage($msg);
                 if ($return->mage_orderCreation == 'before') {
                     $quote = $this->_orderManagement->reOrder($return->mage_quoteId);
                     $this->_checkoutSession->replaceQuote($quote)->unsLastRealOrderId();
                 }
                 break;
             default:
                 throw new \Exception('Unhandled Wirecard Checkout Page payment state:' . $return->getPaymentState());
         }
         if ($this->_request->getPost('iframeUsed')) {
             $redirectUrl = $this->_url->getUrl($redirectTo);
             $page = $this->_resultPageFactory->create();
             $page->getLayout()->getBlock('checkout.back')->addData(['redirectUrl' => $redirectUrl]);
             return $page;
         } else {
             $this->_redirect($redirectTo);
         }
     } catch (\Exception $e) {
         if (!$this->messageManager->getMessages()->getCount()) {
             $this->messageManager->addErrorMessage($defaultErrorMessage);
         }
         $this->_logger->debug(__METHOD__ . ':' . $e->getMessage());
         $this->_redirect($redirectTo);
     }
 }
 /**
  * @param \Magento\Framework\ObjectManagerInterface $objectManager
  * @param \Magento\Backend\Model\Auth\Session $backendAuthSession
  * @param \Magento\Framework\HTTP\PhpEnvironment\Request $request
  * @param \Owebia\AdvancedSettingCore\Helper\Registry $registry
  * @param string $carrierCode
  */
 public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Backend\Model\Auth\Session $backendAuthSession, \Magento\Framework\HTTP\PhpEnvironment\Request $request, \Owebia\AdvancedSettingCore\Helper\Registry $registry, $carrierCode = null)
 {
     parent::__construct($objectManager, $backendAuthSession, $registry, ['server_os' => PHP_OS, 'server_software' => $request->getServerValue('SERVER_SOFTWARE'), 'php_version' => PHP_VERSION, 'carrier_code' => $carrierCode]);
 }