/** * Check whether payment method can be used * * @param CartInterface|null $quote * @return bool */ public function isAvailable(CartInterface $quote = null) { if ($quote !== null) { $accessCheck = $this->accessCheckFactory->create(array("storeId" => $this->getStore())); if ($accessCheck->check($quote->getCustomer()->getGroupId()) === false) { return false; } } return parent::isAvailable($quote); }
/** * Returns customer ID * * @return int|null */ public function getCustomerId() { return $this->quote->getCustomer()->getId(); }
/** * 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()]; }
/** * @param Quote|\Magento\Quote\Api\Data\CartInterface $quote * * @return bool */ protected function _isAvailableRatePay($quote) { $dob = $quote->getCustomer()->getDob(); $minAge = (int) $this->getConfigData('min_age'); if ($minAge <= 0) { $this->_logger->debug(__METHOD__ . ':warning min-age not set for ratepay'); return false; } //we only need to check the dob if it's set. Else we ask for dob on payment selection page. if ($dob) { $dobObject = new \DateTime($dob); $currentYear = date('Y'); $currentMonth = date('m'); $currentDay = date('d'); $ageCheckDate = $currentYear - $minAge . '-' . $currentMonth . '-' . $currentDay; $ageCheckObject = new \DateTime($ageCheckDate); if ($ageCheckObject < $dobObject) { return false; } } if ($quote->hasVirtualItems()) { return false; } if ($this->getConfigData('billing_shipping_address_identical') && !$this->compareAddresses($quote)) { return false; } $currencies = explode(',', $this->getConfigData('currency')); if (!in_array($quote->getQuoteCurrencyCode(), $currencies)) { return false; } if (strlen($this->getConfigData('shippingcountry'))) { $countries = explode(',', $this->getConfigData('shippingcountry')); if (!in_array($quote->getShippingAddress()->getCountry(), $countries)) { return false; } } if (strlen($this->getConfigData('max_basket_size'))) { if ($quote->getItemsQty() > $this->getConfigData('max_basket_size')) { return false; } } if (strlen($this->getConfigData('min_basket_size'))) { if ($quote->getItemsQty() < $this->getConfigData('min_basket_size')) { return false; } } return parent::isAvailable($quote); }