public function testToHtmlMethodSetBmlData() { $isInCatalog = true; $paymentMethodCode = ''; $bmlMethodCode = ''; $hash = 'hash'; $this->shortcut->setIsInCatalogProduct($isInCatalog); $expressMethod = $this->getMockBuilder('Magento\\Paypal\\Model\\Express')->disableOriginalConstructor()->setMethods([])->getMock(); $expectedData = ['is_in_catalog_product' => $isInCatalog, 'shortcut_html_id' => $hash, 'checkout_url' => null, 'image_url' => 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-medium.png', 'additional_link_image' => ['href' => 'https://www.securecheckout.billmelater.com/paycapture-content/' . 'fetch?hash=AU826TU8&content=/bmlweb/ppwpsiw.html', 'src' => 'https://www.paypalobjects.com/webstatic/en_US/btn/btn_bml_text.png']]; $this->paypalShortcutHelperMock->expects($this->once())->method('validate')->with($paymentMethodCode, $isInCatalog)->will($this->returnValue(true)); $this->paymentHelperMock->expects($this->once())->method('getMethodInstance')->with($bmlMethodCode)->will($this->returnValue($expressMethod)); $expressMethod->expects($this->once())->method('isAvailable')->will($this->returnValue(true)); $this->randomMock->expects($this->once())->method('getUniqueHash')->with('ec_shortcut_bml_')->will($this->returnValue($hash)); $this->assertEmpty($this->shortcut->toHtml()); $this->assertContains($expectedData, $this->shortcut->getData()); }
/** * @return \Magento\Framework\View\Element\AbstractBlock */ protected function _beforeToHtml() { $result = parent::_beforeToHtml(); /** @var \Magento\Paypal\Model\Config $config */ $config = $this->_paypalConfigFactory->create(); $config->setMethod($this->_paymentMethodCode); $isInCatalog = $this->getIsInCatalogProduct(); if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) { $this->_shouldRender = false; return $result; } $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote(); // set misc data $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction)); // use static image if in catalog if ($isInCatalog || null === $quote) { $this->setImageUrl($config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale())); } else { /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */ $parameters = ['params' => ['quote' => $quote, 'config' => $config]]; $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters); $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl()); } // ask whether to create a billing agreement $customerId = $this->currentCustomer->getCustomerId(); // potential issue for caching if ($this->_paypalData->shouldAskToCreateBillingAgreement($config, $customerId)) { $this->setConfirmationUrl($this->getUrl($this->_startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1])); $this->setConfirmationMessage(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?')); } return $result; }
/** * @return \Magento\Framework\View\Element\AbstractBlock */ protected function _beforeToHtml() { $result = parent::_beforeToHtml(); $isInCatalog = $this->getIsInCatalogProduct(); if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) { $this->_shouldRender = false; return $result; } /** @var \Magento\Paypal\Model\Express $method */ $method = $this->_paymentData->getMethodInstance($this->_bmlMethodCode); if (!$method->isAvailable()) { $this->_shouldRender = false; return $result; } $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_bml_'))->setCheckoutUrl($this->getUrl($this->_startAction))->setImageUrl(self::SHORTCUT_IMAGE)->setAdditionalLinkImage(['href' => 'https://www.securecheckout.billmelater.com/paycapture-content/' . 'fetch?hash=AU826TU8&content=/bmlweb/ppwpsiw.html', 'src' => 'https://www.paypalobjects.com/webstatic/en_US/btn/btn_bml_text.png']); return $result; }
/** * @return \Magento\Framework\View\Element\AbstractBlock */ protected function _beforeToHtml() { $result = parent::_beforeToHtml(); $isInCatalog = $this->getIsInCatalogProduct(); if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) { $this->_shouldRender = false; return $result; } $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote(); // set misc data $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction)); // use static image if in catalog if ($isInCatalog || null === $quote) { $this->setImageUrl($this->config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale())); } else { /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */ $parameters = ['params' => ['quote' => $quote, 'config' => $this->config]]; $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters); $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl()); } return $result; }