Example #1
0
 /**
  * @param string $localeCode
  * @param float|null $orderTotal
  * @param string|null $pal
  * @param string $areButtonDynamic
  * @param bool $sandboxFlag
  * @param string $buttonType
  * @param string $result
  * @dataProvider dataProviderGetExpressCheckoutShortcutImageUrl
  */
 public function testGetExpressCheckoutShortcutImageUrl($localeCode, $orderTotal, $pal, $areButtonDynamic, $sandboxFlag, $buttonType, $result)
 {
     $this->_model->setMethod(Config::METHOD_WPP_EXPRESS);
     $this->_model->setStoreId(123);
     $this->_scopeConfig->expects($this->any())->method('getValue')->willReturnMap([['paypal/wpp/button_flavor', ScopeInterface::SCOPE_STORE, 123, $areButtonDynamic], ['paypal/wpp/sandbox_flag', ScopeInterface::SCOPE_STORE, 123, $sandboxFlag], ['paypal/wpp/button_type', ScopeInterface::SCOPE_STORE, 123, $buttonType]]);
     $this->assertEquals($result, $this->_model->getExpressCheckoutShortcutImageUrl($localeCode, $orderTotal, $pal));
 }
 /**
  * @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());
     }
     // ask whether to create a billing agreement
     $customerId = $this->currentCustomer->getCustomerId();
     // potential issue for caching
     if ($this->_paypalData->shouldAskToCreateBillingAgreement($this->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;
 }
Example #3
0
 /**
  * @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;
 }
Example #4
0
 /**
  * Checkout with PayPal image URL getter
  * Spares API calls of getting "pal" variable, by putting it into cache per store view
  *
  * @return string
  */
 public function getCheckoutShortcutImageUrl()
 {
     // get "pal" thing from cache or lookup it via API
     $pal = null;
     if ($this->_config->areButtonsDynamic()) {
         $cacheId = self::PAL_CACHE_ID . $this->_storeManager->getStore()->getId();
         $pal = $this->_configCacheType->load($cacheId);
         if (self::PAL_CACHE_ID == $pal) {
             $pal = null;
         } elseif (!$pal) {
             $pal = null;
             $this->_getApi();
             try {
                 $this->_api->callGetPalDetails();
                 $pal = $this->_api->getPal();
                 $this->_configCacheType->save($pal, $cacheId);
             } catch (\Exception $e) {
                 $this->_configCacheType->save(self::PAL_CACHE_ID, $cacheId);
                 $this->_logger->critical($e);
             }
         }
     }
     return $this->_config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale(), $this->_quote->getBaseGrandTotal(), $pal);
 }