/**
  * Retrieve payment method instance
  *
  * @return \Magento\Payment\Model\MethodInterface
  */
 public function getPaymentMethodInstance()
 {
     if ($this->_paymentMethodInstance === null) {
         $this->_paymentMethodInstance = $this->_paymentData->getMethodInstance($this->getMethodCode());
         $this->_paymentMethodInstance->setStore($this->getStoreId());
     }
     return $this->_paymentMethodInstance;
 }
Esempio n. 2
0
 /**
  * Method code setter
  *
  * @param string|MethodInterface $method
  *
  * @return $this
  */
 public function setMethod($method)
 {
     if ($method instanceof MethodInterface) {
         $this->_methodCode = $method->getCode();
     } elseif (is_string($method)) {
         $this->_methodCode = $method;
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * Check whether payment method is applicable to quote
  *
  * @param MethodInterface $paymentMethod
  * @param \Magento\Quote\Model\Quote $quote
  * @return bool
  */
 public function isApplicable(MethodInterface $paymentMethod, Quote $quote)
 {
     $total = $quote->getBaseGrandTotal();
     $minTotal = $paymentMethod->getConfigData(self::MIN_ORDER_TOTAL);
     $maxTotal = $paymentMethod->getConfigData(self::MAX_ORDER_TOTAL);
     if (!empty($minTotal) && $total < $minTotal || !empty($maxTotal) && $total > $maxTotal) {
         return false;
     }
     return true;
 }
 public function testGetTransactionUrlWithTestModeEmptyAndSandboxOff()
 {
     $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(0);
     $this->methodInterfaceMock->expects($this->once())->method('getConfigData')->with('transaction_url')->willReturn('transaction_url');
     $this->config->setMethodInstance($this->methodInterfaceMock);
     $this->assertEquals('transaction_url', $this->config->getTransactionUrl());
 }
 /**
  * Return standard configs
  *
  * @return array
  */
 public function getConfig()
 {
     $config = [];
     if ($this->methodInstance->isAvailable()) {
         $config = ['payment' => [$this->methodCode => ['actionUrl' => $this->methodInstance->getActionUrl(), 'bannerUrl' => $this->methodInstance->getConfigData('banner_checkout'), 'type_checkout' => $this->methodInstance->getConfigData('type_checkout'), 'logoUrl' => $this->getImageUrl('mp_logo.png')]]];
         if ($this->methodInstance->getConfigData('type_checkout') == 'iframe') {
             $config['payment'][$this->methodCode]['iframe_height'] = $this->methodInstance->getConfigData('iframe_height');
         }
     }
     return $config;
 }
Esempio n. 6
0
 /**
  * Returns payment configuration value
  *
  * @param string $key
  * @param null $storeId
  * @return null|string
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function getValue($key, $storeId = null)
 {
     switch ($key) {
         case 'getDebugReplacePrivateDataKeys':
             return $this->methodInstance->getDebugReplacePrivateDataKeys();
         default:
             $underscored = strtolower(preg_replace('/(.)([A-Z])/', "\$1_\$2", $key));
             $path = $this->_getSpecificConfigPath($underscored);
             if ($path !== null) {
                 $value = $this->_scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $this->_storeId);
                 $value = $this->_prepareValue($underscored, $value);
                 return $value;
             }
     }
     return null;
 }
Esempio n. 7
0
 /**
  * Check whether payment method is applicable to quote
  * Purposed to allow use in controllers some logic that was implemented in blocks only before
  *
  * @param MethodInterface $paymentMethod
  * @param \Magento\Quote\Model\Quote $quote
  * @return bool
  */
 public function isApplicable(MethodInterface $paymentMethod, Quote $quote)
 {
     return !($quote->getBaseGrandTotal() < 0.0001 && $paymentMethod->getCode() != 'free');
 }
 /**
  * Gather information to be sent to javascript method renderer
  *
  * @return array
  */
 public function getConfig()
 {
     return $this->methodInstance->isAvailable() ? ['payment' => [$this->methodCode => ['bannerUrl' => $this->_scopeConfig->getValue('payment/mercadopago_custom/banner_checkout'), 'country' => strtoupper($this->_scopeConfig->getValue('payment/mercadopago/country', 'default', $this->_storeManager->getStore()->getId())), 'grand_total' => $this->_checkoutSession->getQuote()->getGrandTotal(), 'base_url' => $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK), 'success_url' => $this->methodInstance->getConfigData('order_place_redirect_url'), 'logEnabled' => $this->_scopeConfig->getValue('payment/mercadopago/logs', 'default', $this->_storeManager->getStore()->getId()), 'discount_coupon' => $this->_scopeConfig->isSetFlag('payment/mercadopago_custom/coupon_mercadopago', 'default', $this->_storeManager->getStore()->getId()), 'route' => $this->_request->getRouteName(), 'public_key' => $this->_scopeConfig->getValue('payment/mercadopago_custom/public_key'), 'customer' => $this->methodInstance->getCustomerAndCards(), 'loading_gif' => $this->_assetRepo->getUrl('MercadoPago_Core::images/loading.gif'), 'text-currency' => __('$'), 'text-choice' => __('Choice'), 'default-issuer' => __('Default issuer'), 'text-installment' => __('Enter the card number'), 'logoUrl' => $this->_assetRepo->getUrl("MercadoPago_Core::images/mp_logo.png")]]] : [];
 }
Esempio n. 9
0
 /**
  * Check and prepare payment method model
  *
  * Redeclare this method in child classes for declaring method info instance
  *
  * @param \Magento\Payment\Model\MethodInterface $method
  * @return $this
  */
 protected function _assignMethod($method)
 {
     $method->setInfoInstance($this->getQuote()->getPayment());
     return $this;
 }
Esempio n. 10
0
 /**
  * Retrieve payment method form html
  *
  * @param MethodInterface $method
  * @param LayoutInterface $layout
  * @return Form
  */
 public function getMethodFormBlock(MethodInterface $method, LayoutInterface $layout)
 {
     $block = $layout->createBlock($method->getFormBlockType(), $method->getCode());
     $block->setMethod($method);
     return $block;
 }
 /**
  * @return bool
  */
 protected function shouldRender()
 {
     return $this->payment->isAvailable($this->session->getQuote()) && $this->isMiniCart && $this->isInContext();
 }
 /**
  * Check whether payment method is applicable to quote
  * Purposed to allow use in controllers some logic that was implemented in blocks only before
  *
  * @param MethodInterface $paymentMethod
  * @param \Magento\Quote\Model\Quote $quote
  * @return bool
  */
 public function isApplicable(MethodInterface $paymentMethod, Quote $quote)
 {
     return $paymentMethod->canUseForCurrency($quote->getStore()->getBaseCurrencyCode());
 }
Esempio n. 13
0
 /**
  * Retrieve payment method form html
  *
  * @param \Magento\Payment\Model\MethodInterface $method
  * @return Form
  */
 public function getMethodFormBlock(\Magento\Payment\Model\MethodInterface $method)
 {
     $block = false;
     $blockType = $method->getFormBlockType();
     if ($this->_layout) {
         $block = $this->_layout->createBlock($blockType, $method->getCode());
         $block->setMethod($method);
     }
     return $block;
 }
Esempio n. 14
0
 /**
  * Check payment method model
  *
  * @param \Magento\Payment\Model\MethodInterface|null $method
  * @return bool
  */
 protected function _canUseMethod($method)
 {
     return $method && $method->canUseInternal() && parent::_canUseMethod($method);
 }
Esempio n. 15
0
 /**
  * Check whether payment method is applicable to quote
  * Purposed to allow use in controllers some logic that was implemented in blocks only before
  *
  * @param MethodInterface $paymentMethod
  * @param \Magento\Quote\Model\Quote $quote
  * @return bool
  */
 public function isApplicable(MethodInterface $paymentMethod, Quote $quote)
 {
     return $paymentMethod->canUseInternal();
 }
 /**
  * @return bool
  */
 public function isActive()
 {
     return $this->payment->isAvailable($this->checkoutSession->getQuote()) && $this->config->isDisplayShoppingCart();
 }
 /**
  * @return array
  */
 public function getConfig()
 {
     return $this->methodInstance->isAvailable() ? ['payment' => [$this->methodCode => ['bannerUrl' => $this->methodInstance->getConfigData('banner_checkout'), 'options' => $this->methodInstance->getTicketsOptions(), 'country' => strtoupper($this->_scopeConfig->getValue('payment/mercadopago/country')), 'grand_total' => $this->_checkoutSession->getQuote()->getGrandTotal(), 'success_url' => $this->methodInstance->getConfigData('order_place_redirect_url'), 'route' => $this->_request->getRouteName(), 'base_url' => $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK), 'discount_coupon' => $this->_scopeConfig->getValue('payment/mercadopago_customticket/coupon_mercadopago'), 'loading_gif' => $this->_assetRepo->getUrl('MercadoPago_Core::images/loading.gif'), 'logEnabled' => $this->_scopeConfig->getValue('payment/mercadopago/logs'), 'logoUrl' => $this->_assetRepo->getUrl("MercadoPago_Core::images/mp_logo.png")]]] : [];
 }
 /**
  * Check whether payment method is applicable to quote
  * @param MethodInterface $paymentMethod
  * @param Quote $quote
  * @return bool
  */
 public function isApplicable(MethodInterface $paymentMethod, Quote $quote)
 {
     return $paymentMethod->canUseForCountry($this->countryProvider->getCountry($quote));
 }
Esempio n. 19
0
 /**
  * Check whether payment method is applicable to quote
  * @param MethodInterface $paymentMethod
  * @param Quote $quote
  * @return bool
  */
 public function isApplicable(MethodInterface $paymentMethod, Quote $quote)
 {
     return $paymentMethod->canUseForCountry($quote->getBillingAddress()->getCountry());
 }
Esempio n. 20
0
 /**
  * Payment method additional label part getter
  *
  * @param \Magento\Payment\Model\MethodInterface $method
  * @return string
  */
 public function getMethodLabelAfterHtml(\Magento\Payment\Model\MethodInterface $method)
 {
     $form = $this->getChildBlock('payment.method.' . $method->getCode());
     if ($form) {
         return $form->getMethodLabelAfterHtml();
     }
 }
Esempio n. 21
0
 /**
  * Convert quote payment object to payment data object
  *
  * @param \Magento\Payment\Model\MethodInterface $object
  * @return \Magento\Checkout\Service\V1\Data\Cart\PaymentMethod
  */
 public function toDataObject(\Magento\Payment\Model\MethodInterface $object)
 {
     $data = [QuotePaymentMethod::CODE => $object->getCode(), QuotePaymentMethod::TITLE => $object->getTitle()];
     return $this->builder->populateWithArray($data)->create();
 }