/** * @dataProvider getUrlDataProvider * @covers \Magento\Catalog\Model\Product\Url::getUrl * @covers \Magento\Catalog\Model\Product\Url::getUrlInStore * @covers \Magento\Catalog\Model\Product\Url::getProductUrl * * @param $getUrlMethod * @param $routePath * @param $requestPathProduct * @param $storeId * @param $categoryId * @param $routeParams * @param $routeParamsUrl * @param $productId * @param $productUrlKey * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function testGetUrl($getUrlMethod, $routePath, $requestPathProduct, $storeId, $categoryId, $routeParams, $routeParamsUrl, $productId, $productUrlKey) { $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getStoreId', 'getEntityId', 'getId', 'getUrlKey', 'setRequestPath', 'hasUrlDataObject', 'getRequestPath', 'getCategoryId', 'getDoNotUseCategoryId', '__wakeup'])->getMock(); $product->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $product->expects($this->any())->method('getCategoryId')->will($this->returnValue($categoryId)); $product->expects($this->any())->method('getRequestPath')->will($this->returnValue($requestPathProduct)); $product->expects($this->any())->method('setRequestPath')->with(false)->will($this->returnSelf()); $product->expects($this->any())->method('getId')->will($this->returnValue($productId)); $product->expects($this->any())->method('getUrlKey')->will($this->returnValue($productUrlKey)); $this->url->expects($this->any())->method('setScope')->with($storeId)->will($this->returnSelf()); $this->url->expects($this->any())->method('getUrl')->with($routePath, $routeParamsUrl)->will($this->returnValue($requestPathProduct)); $this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue(false)); switch ($getUrlMethod) { case 'getUrl': $this->assertEquals($requestPathProduct, $this->model->getUrl($product, $routeParams)); break; case 'getUrlInStore': $this->assertEquals($requestPathProduct, $this->model->getUrlInStore($product, $routeParams)); break; case 'getProductUrl': $this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, true)); $this->sidResolver->expects($this->once())->method('getUseSessionInUrl')->will($this->returnValue(true)); $this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, null)); break; } }
/** * @test */ public function redirectUrl() { $result = $this->_controller->getBackUrl(null); $url = new \Magento\Framework\Url(); $expected = $url->getUrl('checkout/index/index'); $this->assert($expected, $result); }
public function execute() { $urls = ['confirm' => $this->_url->getUrl('wirecardcheckoutpage/checkout/confirm', ['_secure' => true, '_nosid' => true]), 'return' => $this->_url->getUrl('wirecardcheckoutpage/checkout/back', ['_secure' => true, '_nosid' => true])]; $payment = null; try { if ($this->getCheckoutMethod() == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) { $this->prepareGuestQuote(); } $customerDob = $this->_cart->getQuote()->getPayment()->getAdditionalInformation('customerDob'); if (strlen($customerDob)) { $this->_cart->getQuote()->setCustomerDob($customerDob); } /** @var \Wirecard\CheckoutPage\Model\AbstractPayment $payment */ $payment = $this->_cart->getQuote()->getPayment()->getMethodInstance(); $init = $payment->initPaymentByCart($this->_cart, $urls, new \Magento\Framework\DataObject($payment->getInfoInstance()->getAdditionalInformation())); if ($this->_dataHelper->getConfigData('options/order_creation') == 'before') { $this->_orderManagement->submitOrder($this->_cart->getQuote()); } $this->getResponse()->setRedirect($init->getRedirectUrl()); } catch (\Exception $e) { $this->_logger->debug(__METHOD__ . ':' . $e->getMessage()); $this->messageManager->addErrorMessage($this->_dataHelper->__('An error occurred during the payment process')); if ($payment === null) { $this->_redirect('/'); } else { $this->getResponse()->setRedirect($this->_url->getUrl('wirecardcheckoutpage/checkout/failed', ['_secure' => true, '_query' => ['iframeused' => (int) ($payment->getDisplayMode() != 'redirect')]])); } } }
/** * Get resolved back url, rewritten to return checkout URL instead of cart url * * @param \Magento\Checkout\Controller\Cart\Add $subject * @return string */ public function afterExecute(\Magento\Checkout\Controller\Cart\Add $subject, \Magento\Framework\Controller\Result\Redirect $redirect) { $shouldRedirectToCart = $this->_config->getValue('checkout/cart/redirect_to_cart', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if ($shouldRedirectToCart && !$subject->getRequest()->getParam('in_cart')) { $redirect->setUrl($this->_url->getUrl('checkout/index/index')); } return $redirect; }
protected function prepareAttemptToMinifyMock($fileExists, $rootDirExpectations = true, $originalExists = true) { $this->asset->expects($this->atLeastOnce())->method('getPath')->will($this->returnValue('test/admin.js')); $this->asset->expects($this->atLeastOnce())->method('getSourceFile')->will($this->returnValue('/foo/bar/test/admin.js')); if ($rootDirExpectations) { $this->rootDir->expects($this->once())->method('getRelativePath')->with('/foo/bar/test/admin.min.js')->will($this->returnValue('test/admin.min.js')); $this->rootDir->expects($this->once())->method('isExist')->with('test/admin.min.js')->will($this->returnValue(false)); } $this->baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://example.com/')); $this->staticViewDir->expects($this->exactly(2 - intval($originalExists)))->method('isExist')->will($this->returnValue($fileExists)); }
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); } }
/** * @covers \Magento\Config\Block\System\Config\Form\Field\Image::_getUrl */ public function testGetElementHtmlWithValue() { $type = 'media'; $url = 'http://test.example.com/media/'; $this->urlBuilderMock->expects($this->once())->method('getBaseUrl')->with(['_type' => $type])->will($this->returnValue($url)); $this->_image->setValue('test_value'); $this->_image->setFieldConfig(['id' => 'placeholder', 'type' => 'image', 'sortOrder' => '1', 'showInDefault' => '1', 'showInWebsite' => '1', 'showInStore' => '1', 'label' => null, 'backend_model' => 'Magento\\Backend\\Model\\Config\\Backend\\Image', 'upload_dir' => ['config' => 'system/filesystem/media', 'scope_info' => '1', 'value' => 'catalog/product/placeholder'], 'base_url' => ['type' => $type, 'scope_info' => '1', 'value' => 'catalog/product/placeholder'], '_elementType' => 'field', 'path' => 'catalog/placeholder']); $html = $this->_image->getElementHtml(); $this->assertContains('class="input-file"', $html); $this->assertContains('<input', $html); $this->assertContains('type="file"', $html); $this->assertContains('value="test_value"', $html); $this->assertContains('<a href="' . $url . 'catalog/product/placeholder/test_value" onclick="imagePreview(\'_image\'); return false;"', $html); $this->assertContains('<input type="checkbox"', $html); }
private function prepareAttemptToMinifyMock($fileExists, $rootDirExpectations = true) { $this->_asset->expects($this->atLeastOnce())->method('getPath')->will($this->returnValue('test/library.js')); $this->_asset->expects($this->atLeastOnce())->method('getSourceFile')->will($this->returnValue('/foo/bar/test/library.js')); if ($rootDirExpectations) { $this->_rootDir->expects($this->once())->method('getRelativePath')->with('/foo/bar/test/library.min.js')->will($this->returnValue('test/library.min.js')); $this->_rootDir->expects($this->once())->method('isExist')->with('test/library.min.js')->will($this->returnValue(false)); } $this->_baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://example.com/')); $this->_staticViewDir->expects($this->once())->method('isExist')->will($this->returnValue($fileExists)); }
/** * Retrieve route URL * * @param string $routePath * @param array $routeParams * @return string */ public function getRouteUrl($routePath = null, $routeParams = null) { $this->_hasThemeAndMode(); $url = parent::getRouteUrl($routePath, $routeParams); $baseUrl = trim($this->getBaseUrl(), '/'); $vdeBaseUrl = implode('/', array($baseUrl, $this->_helper->getFrontName(), $this->_mode, $this->_themeId)); if (strpos($url, $baseUrl) === 0 && strpos($url, $vdeBaseUrl) === false) { $url = str_replace($baseUrl, $vdeBaseUrl, $url); } return $url; }
/** * @param $customerId * @param $key * @param $backUrl * @param $successUrl * @param $resultUrl * @param $isSetFlag * @param $successMessage * * @dataProvider getSuccessRedirectDataProvider */ public function testSuccessRedirect($customerId, $key, $backUrl, $successUrl, $resultUrl, $isSetFlag, $successMessage) { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['id', false, $customerId], ['key', false, $key], ['back_url', false, $backUrl]]); $this->customerRepositoryMock->expects($this->any())->method('getById')->with($customerId)->will($this->returnValue($this->customerDataMock)); $email = '*****@*****.**'; $this->customerDataMock->expects($this->once())->method('getEmail')->will($this->returnValue($email)); $this->customerAccountManagementMock->expects($this->once())->method('activate')->with($this->equalTo($email), $this->equalTo($key))->will($this->returnValue($this->customerDataMock)); $this->customerSessionMock->expects($this->any())->method('setCustomerDataAsLoggedIn')->with($this->equalTo($this->customerDataMock))->willReturnSelf(); $this->messageManagerMock->expects($this->any())->method('addSuccess')->with($this->stringContains($successMessage))->willReturnSelf(); $this->storeMock->expects($this->any())->method('getFrontendName')->will($this->returnValue('frontend')); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock)); $this->urlMock->expects($this->any())->method('getUrl')->with($this->equalTo('*/*/index'), ['_secure' => true])->will($this->returnValue($successUrl)); $this->redirectMock->expects($this->never())->method('success')->with($this->equalTo($resultUrl))->willReturn($resultUrl); $this->scopeConfigMock->expects($this->never())->method('isSetFlag')->with(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD, ScopeInterface::SCOPE_STORE)->willReturn($isSetFlag); $this->model->execute(); }
/** * @dataProvider getConfigDataProvider */ public function testGetConfig($configData, $vaultData, $tokenNonceMap, $expectedResult) { foreach ($configData as $key => $value) { $this->configMock->expects($this->any())->method($key)->willReturn($value); } foreach ($vaultData as $key => $value) { $this->vaultMock->expects($this->any())->method($key)->willReturn($value); } $this->vaultMock->expects($this->any())->method('generatePaymentMethodToken')->willReturnMap($tokenNonceMap); $cardTypeMap = [['Visa', 'VI'], ['Master Card', 'MA'], ['American Express', 'AE'], ['Discover Card', 'DI']]; $this->helperMock->expects($this->any())->method('getCcTypeCodeByName')->willReturnMap($cardTypeMap); $this->helperMock->expects($this->once())->method('getTodayMonth')->willReturn(self::TODAY_MONTH); $this->helperMock->expects($this->once())->method('getTodayYear')->willReturn(self::TODAY_YEAR); $this->helperMock->expects($this->once())->method('getCcAvailableCardTypes')->willReturn($this->availableCardTypes); $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn(true); $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('braintree/creditcard/generate')->willReturn(self::PAYMENT_NONCE_GENERATION_URL); $this->assertEquals($expectedResult, $this->model->getConfig()); }
/** * @dataProvider getConfigDataProvider */ public function testGetConfig($configData, $vaultData, $tokenNonceMap, $expectedResult) { foreach ($configData as $key => $value) { $this->configMock->expects($this->any())->method($key)->willReturn($value); } foreach ($vaultData as $key => $value) { $this->vaultMock->expects($this->any())->method($key)->willReturn($value); } $this->vaultMock->expects($this->any())->method('generatePaymentMethodToken')->willReturnMap($tokenNonceMap); $quoteMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock(); $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn(new \Magento\Framework\Object(['country_id' => 'US'])); $this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($quoteMock); $cardTypeMap = [['Visa', 'VI'], ['Master Card', 'MA'], ['American Express', 'AE'], ['Discover Card', 'DI']]; $this->helperMock->expects($this->any())->method('getCcTypeCodeByName')->willReturnMap($cardTypeMap); $this->helperMock->expects($this->once())->method('getTodayMonth')->willReturn(self::TODAY_MONTH); $this->helperMock->expects($this->once())->method('getTodayYear')->willReturn(self::TODAY_YEAR); $this->helperMock->expects($this->once())->method('getCcAvailableCardTypes')->willReturn($this->availableCardTypes); $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn(true); $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('braintree/creditcard/generate')->willReturn(self::PAYMENT_NONCE_GENERATION_URL); $this->assertEquals($expectedResult, $this->model->getConfig()); }
public function testInitiatePasswordResetEmailReminder() { $customerId = 1; $email = '*****@*****.**'; $template = AccountManagement::EMAIL_REMINDER; $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; $storeId = 1; $isFrontendSecure = true; $resetUrl = 'reset url'; mt_srand(mt_rand() + 100000000 * microtime() % PHP_INT_MAX); $hash = md5(uniqid(microtime() . mt_rand(0, mt_getrandmax()), true)); $this->store->expects($this->once())->method('isFrontUrlSecure')->willReturn($isFrontendSecure); $this->url->expects($this->once())->method('setScope')->with($storeId)->willReturnSelf(); $this->url->expects($this->once())->method('getUrl')->with('customer/account/createPassword', ['_query' => ['id' => $customerId, 'token' => $hash], '_store' => $storeId, '_secure' => $isFrontendSecure])->willReturn($resetUrl); $this->scopeConfig->expects($this->at(0))->method('getValue')->with(AccountManagement::XML_PATH_REMIND_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $storeId)->willReturn($templateIdentifier); $this->scopeConfig->expects($this->at(1))->method('getValue')->with(AccountManagement::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $storeId)->willReturn($sender); $this->customerSecure->expects($this->any())->method('setResetPasswordUrl')->with($resetUrl)->willReturnSelf(); $this->prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash); $this->assertTrue($this->accountManagement->initiatePasswordReset($email, $template)); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testSendPasswordReminderEmail() { $customerId = 1; $customerStoreId = 2; $customerEmail = '*****@*****.**'; $passwordToken = 'token'; $isFrontendSecure = true; $resetUrl = 'reset url'; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->any())->method('getStoreId')->willReturn($customerStoreId); $customer->expects($this->any())->method('getId')->willReturn($customerId); $customer->expects($this->any())->method('getEmail')->willReturn($customerEmail); $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->storeManager->expects($this->any())->method('getStore')->with($customerStoreId)->willReturn($store); $store->expects($this->any())->method('isFrontUrlSecure')->willReturn($isFrontendSecure); $this->url->expects($this->once())->method('getUrl')->with('customer/account/createPassword', ['_query' => ['id' => $customerId, 'token' => $passwordToken], '_store' => $customerStoreId, '_secure' => $isFrontendSecure])->willReturn($resetUrl); $customerSecure = $this->getMockBuilder('\\Magento\\Customer\\Model\\Data\\CustomerSecure')->disableOriginalConstructor()->setMethods(['addData', 'setData', 'setResetPasswordUrl'])->getMock(); $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure); $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->with($customer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData); $this->customerViewHelper->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName); $customerSecure->expects($this->once())->method('addData')->with($customerData)->willReturnSelf(); $customerSecure->expects($this->once())->method('setData')->with('name', $customerName)->willReturnSelf(); $customerSecure->expects($this->once())->method('setResetPasswordUrl')->with($resetUrl); $this->scopeConfig->expects($this->at(0))->method('getValue')->with(AccountManagement::XML_PATH_REMIND_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($templateIdentifier); $this->scopeConfig->expects($this->at(1))->method('getValue')->with(AccountManagement::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($sender); $transport = $this->getMockBuilder('Magento\\Framework\\Mail\\TransportInterface')->getMock(); $this->transportBuilder->expects($this->once())->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setTemplateOptions')->with(['area' => Area::AREA_FRONTEND, 'store' => $customerStoreId])->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setTemplateVars')->with(['customer' => $customerSecure, 'store' => $store])->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setFrom')->with($sender)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('addTo')->with($customerEmail, $customerName)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('getTransport')->willReturn($transport); $transport->expects($this->once())->method('sendMessage'); $this->assertEquals($this->accountManagement, $this->accountManagement->sendPasswordReminderEmail($customer, $passwordToken)); }
/** * @param $customerId * @param $password * @param $confirmationStatus * @param $successUrl * @param $isSetFlag * @param $successMessage * * @dataProvider getSuccessRedirectDataProvider */ public function testSuccessRedirect($customerId, $password, $confirmationStatus, $successUrl, $isSetFlag, $successMessage) { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->registration->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); $this->customerSessionMock->expects($this->once())->method('regenerateId'); $this->customerMock->expects($this->any())->method('getId')->will($this->returnValue($customerId)); $this->customerExtractorMock->expects($this->any())->method('extract')->with($this->equalTo('customer_account_create'), $this->equalTo($this->requestMock))->will($this->returnValue($this->customerMock)); $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue(true)); $this->requestMock->expects($this->any())->method('getPost')->will($this->returnValue(false)); $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['password', null, $password], ['password_confirmation', null, $password], ['is_subscribed', false, true]]); $this->customerMock->expects($this->once())->method('setAddresses')->with($this->equalTo([]))->will($this->returnSelf()); $this->accountManagement->expects($this->once())->method('createAccount')->with($this->equalTo($this->customerDetailsMock), $this->equalTo($password), '')->will($this->returnValue($this->customerMock)); $this->accountManagement->expects($this->once())->method('getConfirmationStatus')->with($this->equalTo($customerId))->will($this->returnValue($confirmationStatus)); $this->subscriberMock->expects($this->once())->method('subscribeCustomerById')->with($this->equalTo($customerId)); $this->messageManagerMock->expects($this->any())->method('addSuccess')->with($this->stringContains($successMessage))->will($this->returnSelf()); $this->urlMock->expects($this->any())->method('getUrl')->willReturnMap([['*/*/index', ['_secure' => true], $successUrl], ['*/*/create', ['_secure' => true], $successUrl]]); $this->redirectMock->expects($this->once())->method('success')->with($this->equalTo($successUrl))->will($this->returnValue($successUrl)); $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with($this->equalTo(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD), $this->equalTo(ScopeInterface::SCOPE_STORE))->will($this->returnValue($isSetFlag)); $this->storeMock->expects($this->any())->method('getFrontendName')->will($this->returnValue('frontend')); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock)); $this->model->execute(); }
public function testExecuteCanNotSaveWishlistAndWithRedirect() { $referer = 'http://referer-url.com'; $exception = new \Exception('Message'); $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false); $wishlist->expects($this->once())->method('save')->willThrowException($exception); $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(2)->willReturn($wishlist); $this->messageManager->expects($this->once())->method('addError')->with('An error occurred while deleting the item from wish list.')->willReturn(true); $wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false); $wishlistHelper->expects($this->once())->method('calculate')->willReturnSelf(); $this->om->expects($this->once())->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper)); $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false); $item->expects($this->once())->method('load')->with(1)->willReturnSelf(); $item->expects($this->once())->method('getId')->willReturn(1); $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(2); $item->expects($this->once())->method('delete')->willReturn(true); $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item); $this->request->expects($this->once())->method('getServer')->with('HTTP_REFERER')->willReturn($referer); $this->request->expects($this->exactly(3))->method('getParam')->willReturnMap([['item', null, 1], ['referer_url', null, $referer], ['uenc', null, false]]); $this->url->expects($this->once())->method('getUrl')->with('*/*')->willReturn('http:/test.com/frontname/module/controller/action'); $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('http:/test.com/frontname/module/controller/action'); $this->response->expects($this->once())->method('setRedirect')->with('http:/test.com/frontname/module/controller/action')->willReturn(true); $this->getController()->execute(); }
/** * Retrieve action path. * Add backend area front name as a prefix to action path * * @return string */ protected function _getActionPath() { $path = parent::_getActionPath(); if ($path) { if ($this->getAreaFrontName()) { $path = $this->getAreaFrontName() . '/' . $path; } } return $path; }
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); } }
/** * Send email with new customer password * * @param CustomerInterface $customer * @param string $newPasswordToken * @return $this */ public function sendPasswordReminderEmail($customer, $newPasswordToken) { $this->url->setScope($customer->getStoreId()); //TODO : Fix how template is built. Maybe Framework Object or create new Email template data model? // Check template to see what values need to be set in the data model to be passed // Need to set the reset_password_url property of the object $store = $this->storeManager->getStore($customer->getStoreId()); $resetUrl = $this->url->getUrl('customer/account/createPassword', ['_query' => ['id' => $customer->getId(), 'token' => $newPasswordToken], '_store' => $customer->getStoreId(), '_secure' => $store->isFrontUrlSecure()]); $customerEmailData = $this->getFullCustomerObject($customer); $customerEmailData->setResetPasswordUrl($resetUrl); $this->sendEmailTemplate($customer, self::XML_PATH_REMIND_EMAIL_TEMPLATE, self::XML_PATH_FORGOT_EMAIL_IDENTITY, ['customer' => $customerEmailData, 'store' => $store], $customer->getStoreId()); return $this; }
/** * Function for getting controller url for given router path * @param string $routePath * @return string */ public function getControllerUrl($routePath) { return $this->_urlApp->getUrl($routePath); }
/** * @param Item $item * @return string */ public function getPurchasedLinkUrl($item) { return $this->frontendUrlBuilder->getUrl('downloadable/download/link', ['id' => $item->getLinkHash(), '_scope' => $this->getOrder()->getStore(), '_secure' => true, '_nosid' => true]); }
/** * Get generate nonce URL * * @return string */ public function getAjaxGenerateNonceUrl() { return $this->urlBuilder->getUrl('braintree/creditcard/generate', ['_secure' => true]); }