Esempio n. 1
0
 /**
  * @param \Magento\Quote\Api\Data\CartInterface $quote
  * @return \Magento\Payment\Model\MethodInterface[]
  * @api
  */
 public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote = null)
 {
     $store = $quote ? $quote->getStoreId() : null;
     $methods = [];
     foreach ($this->paymentHelper->getStoreMethods($store, $quote) as $method) {
         if ($this->_canUseMethod($method, $quote)) {
             $method->setInfoInstance($quote->getPayment());
             $methods[] = $method;
         }
     }
     return $methods;
 }
Esempio n. 2
0
 /**
  * @param \Magento\Quote\Api\Data\CartInterface $quote
  * @return \Magento\Payment\Model\MethodInterface[]
  * @api
  */
 public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote = null)
 {
     $store = $quote ? $quote->getStoreId() : null;
     $methods = [];
     $specification = $this->methodSpecificationFactory->create([AbstractMethod::CHECK_ZERO_TOTAL]);
     foreach ($this->paymentHelper->getStoreMethods($store, $quote) as $method) {
         if ($this->_canUseMethod($method, $quote) && $specification->isApplicable($method, $quote)) {
             $method->setInfoInstance($quote->getPayment());
             $methods[] = $method;
         }
     }
     return $methods;
 }
Esempio n. 3
0
 /**
  * @param \Magento\Quote\Api\Data\CartInterface $quote
  * @return \Magento\Payment\Model\MethodInterface[]
  * @api
  */
 public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote = null)
 {
     $store = $quote ? $quote->getStoreId() : null;
     $methods = [];
     $isFreeAdded = false;
     foreach ($this->paymentHelper->getStoreMethods($store, $quote) as $method) {
         if ($this->_canUseMethod($method, $quote)) {
             $method->setInfoInstance($quote->getPayment());
             $methods[] = $method;
             if ($method->getCode() == Free::PAYMENT_METHOD_FREE_CODE) {
                 $isFreeAdded = true;
             }
         }
     }
     if (!$isFreeAdded) {
         /** @var \Magento\Payment\Model\Method\Free $freeMethod */
         $freeMethod = $this->paymentHelper->getMethodInstance(Free::PAYMENT_METHOD_FREE_CODE);
         if ($freeMethod->isAvailableInConfig()) {
             $freeMethod->setInfoInstance($quote->getPayment());
             $methods[] = $freeMethod;
         }
     }
     return $methods;
 }
Esempio n. 4
0
 /**
  * {inheritdoc}
  */
 public function isAvailable(CartInterface $quote = null)
 {
     if (!$this->isActive($quote ? $quote->getStoreId() : null)) {
         return false;
     }
     $checkResult = new DataObject();
     $checkResult->setData('is_available', true);
     try {
         $validator = $this->validatorPool->get('availability');
         $result = $validator->validate(['payment' => $this->paymentDataObjectFactory->create($this->getInfoInstance())]);
         $checkResult->setData('is_available', $result->isValid());
     } catch (NotFoundException $e) {
         // pass
     }
     // for future use in observers
     $this->eventManager->dispatch('payment_method_is_active', ['result' => $checkResult, 'method_instance' => $this, 'quote' => $quote]);
     return $checkResult->getData('is_available');
 }
 /**
  * Check whether payment method can be used
  *
  * @param \Magento\Quote\Api\Data\CartInterface|null $quote
  * @return bool
  */
 public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
 {
     if (!$this->isActive($quote ? $quote->getStoreId() : null)) {
         return false;
     }
     $checkResult = new DataObject();
     $checkResult->setData('is_available', true);
     // for future use in observers
     $this->_eventManager->dispatch('payment_method_is_active', ['result' => $checkResult, 'method_instance' => $this, 'quote' => $quote]);
     return $checkResult->getData('is_available');
 }
Esempio n. 6
0
 /**
  * Check whether there are CC types set in configuration
  *
  * @param \Magento\Quote\Api\Data\CartInterface|null $quote
  * @return bool
  */
 public function isAvailable($quote = null)
 {
     return $this->getConfigData('cctypes', $quote ? $quote->getStoreId() : null) && parent::isAvailable($quote);
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Quote\Api\Data\CartInterface $quote)
 {
     if ($quote->getId()) {
         $currentQuote = $this->get($quote->getId(), [$quote->getStoreId()]);
         foreach ($currentQuote->getData() as $key => $value) {
             if (!$quote->hasData($key)) {
                 $quote->setData($key, $value);
             }
         }
     }
     $this->getSaveHandler()->save($quote);
     unset($this->quotesById[$quote->getId()]);
     unset($this->quotesByCustomerId[$quote->getCustomerId()]);
 }
Esempio n. 8
0
 /**
  * Check whether there are CC types set in configuration
  *
  * @param \Magento\Quote\Api\Data\CartInterface|null $quote
  * @return bool
  */
 public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
 {
     return $this->getConfigData('cctypes', $quote ? $quote->getStoreId() : null) && parent::isAvailable($quote);
 }
Esempio n. 9
0
 /**
  * Check whether payment method can be used with the quote
  *
  * @param \Magento\Quote\Api\Data\CartInterface|null $quote
  * @return bool
  */
 public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
 {
     return $this->isActive($quote ? $quote->getStoreId() : null);
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Quote\Api\Data\CartInterface $quote)
 {
     if ($quote->getId()) {
         $currentQuote = $this->get($quote->getId(), [$quote->getStoreId()]);
         $currentQuote->setStoreId($quote->getStoreId());
         // This part has to be refactored
         if ($quote->getBillingAddress()) {
             $currentQuote->setBillingAddress($quote->getBillingAddress());
         }
         $currentQuote->addData($quote->getData());
         $quote = $currentQuote;
     }
     $this->getSaveHandler()->save($quote);
     unset($this->quotesById[$quote->getId()]);
     unset($this->quotesByCustomerId[$quote->getCustomerId()]);
 }
Esempio n. 11
0
 /**
  * Check whether payment method can be used with the quote
  *
  * @param \Magento\Quote\Api\Data\CartInterface|null $quote
  * @return bool
  */
 public function isAvailable($quote = null)
 {
     return $this->isActive($quote ? $quote->getStoreId() : null);
 }
Esempio n. 12
0
 /**
  * 2016-02-15
  * @override
  * How is a payment method's isAvailable() used? https://mage2.pro/t/721
  *
  * @see \Magento\Payment\Model\MethodInterface::isAvailable()
  * https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L343-L350
  * @see \Magento\Payment\Model\Method\AbstractMethod::isAvailable()
  * https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L805-L825
  *
  * @param CartInterface|Q $quote [optional]
  * @return bool
  */
 public function isAvailable(CartInterface $quote = null)
 {
     /** @var bool $result */
     $result = ($this->availableInBackend() || !df_is_backend()) && $this->isActive($quote ? $quote->getStoreId() : null);
     if ($result) {
         /** @var DataObject $checkResult */
         $checkResult = new DataObject(['is_available' => true]);
         df_dispatch('payment_method_is_active', ['result' => $checkResult, 'method_instance' => $this, 'quote' => $quote]);
         $result = $checkResult['is_available'];
     }
     if ($result && $quote) {
         /** @var float $amount */
         $amount = $this->s()->cFromBase($quote->getBaseGrandTotal(), $quote);
         /** @var int|float $min */
         /** @var int|float $max */
         list($min, $max) = dfa($this->amountLimits(), $this->s()->currencyC($quote), [null, null]);
         $result = (is_null($min) || $amount >= $min) && (is_null($max) || $amount <= $max);
     }
     return $result;
 }
Esempio n. 13
0
 /**
  * Returns order store id
  *
  * @return int
  */
 public function getStoreId()
 {
     return $this->quote->getStoreId();
 }
Esempio n. 14
0
 /**
  * Check whether payment method can be used
  *
  * @param \Magento\Quote\Api\Data\CartInterface|null $quote
  * @return bool
  */
 public function isAvailable($quote = null)
 {
     $checkResult = new \StdClass();
     $isActive = $this->isActive($quote ? $quote->getStoreId() : null);
     $checkResult->isAvailable = $isActive;
     $checkResult->isDeniedInConfig = !$isActive;
     // for future use in observers
     $this->_eventManager->dispatch('payment_method_is_active', ['result' => $checkResult, 'method_instance' => $this, 'quote' => $quote]);
     return $checkResult->isAvailable;
 }
Esempio n. 15
0
 /**
  * Convert Tax Quote Details into data to be converted to a GetTax Request
  *
  * @param \Magento\Tax\Api\Data\QuoteDetailsInterface $taxQuoteDetails
  * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
  * @param \Magento\Quote\Api\Data\CartInterface $quote
  * @return array|null
  */
 protected function convertTaxQuoteDetailsToData(\Magento\Tax\Api\Data\QuoteDetailsInterface $taxQuoteDetails, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Api\Data\CartInterface $quote)
 {
     $lines = [];
     $items = $taxQuoteDetails->getItems();
     $keyedItems = $this->taxCalculation->getKeyedItems($items);
     $childrenItems = $this->taxCalculation->getChildrenItems($items);
     /** @var \Magento\Tax\Api\Data\QuoteDetailsItemInterface $item */
     foreach ($keyedItems as $item) {
         /**
          * If a quote has children and they are calculated (e.g., Bundled products with dynamic pricing)
          * @see \Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector::mapItems
          * then we only need to pass child items to AvaTax. Due to the logic in
          * @see \ClassyLlama\AvaTax\Framework\Interaction\TaxCalculation::calculateTaxDetails
          * the parent tax gets calculated based on children items
          */
         //
         if (isset($childrenItems[$item->getCode()])) {
             /** @var \Magento\Tax\Api\Data\QuoteDetailsItemInterface $childItem */
             foreach ($childrenItems[$item->getCode()] as $childItem) {
                 $line = $this->interactionLine->getLine($childItem);
                 if ($line) {
                     $lines[] = $line;
                 }
             }
         } else {
             $line = $this->interactionLine->getLine($item);
             if ($line) {
                 $lines[] = $line;
             }
         }
     }
     // Shipping Address not documented in the interface for some reason
     // they do have a constant for it but not a method in the interface
     //
     // If quote is virtual, getShipping will return billing address, so no need to check if quote is virtual
     $shippingAddress = $shippingAssignment->getShipping()->getAddress();
     $address = $this->address->getAddress($shippingAddress);
     $store = $this->storeRepository->getById($quote->getStoreId());
     $currentDate = $this->getFormattedDate($store);
     // Quote created/updated date is not relevant, so just pass the current date
     $docDate = $currentDate;
     $customerUsageType = $quote->getCustomer() ? $this->taxClassHelper->getAvataxTaxCodeForCustomer($quote->getCustomer()) : null;
     return ['StoreId' => $store->getId(), 'Commit' => false, 'CurrencyCode' => $quote->getCurrency()->getQuoteCurrencyCode(), 'CustomerCode' => $this->getCustomerCode($quote), 'CustomerUsageType' => $customerUsageType, 'DestinationAddress' => $address, 'DocCode' => self::AVATAX_DOC_CODE_PREFIX . $quote->getId(), 'DocDate' => $docDate, 'DocType' => DocumentType::$SalesOrder, 'ExchangeRate' => $this->getExchangeRate($store, $quote->getCurrency()->getBaseCurrencyCode(), $quote->getCurrency()->getQuoteCurrencyCode()), 'ExchangeRateEffDate' => $currentDate, 'Lines' => $lines, 'DetailLevel' => DetailLevel::$Line, 'PurchaseOrderNo' => $quote->getReservedOrderId()];
 }