/** * Ping AvaTax using configured live/production mode * * @param $scopeId * @param $scopeType * @return array */ protected function sendPing($scopeId, $scopeType) { $errors = []; if (!$this->config->isModuleEnabled($scopeId, $scopeType)) { return $errors; } $message = ''; $type = $this->config->getLiveMode() ? Config::API_PROFILE_NAME_PROD : Config::API_PROFILE_NAME_DEV; try { $result = $this->interactionTax->getTaxService($type, $scopeId, $scopeType)->ping(); if (is_object($result) && $result->getResultCode() != \AvaTax\SeverityLevel::$Success) { foreach ($result->getMessages() as $messages) { $message .= $messages->getName() . ': ' . $messages->getSummary() . "\n"; } } elseif (is_object($result) && $result->getResultCode() == \AvaTax\SeverityLevel::$Success) { $this->messageManager->addSuccess(__('Successfully connected to AvaTax using the ' . '<a href="#row_tax_avatax_connection_settings_header">%1 credentials</a>', $type)); } } catch (\Exception $exception) { $message = $exception->getMessage(); } if ($message) { $errors[] = __('Error connecting to AvaTax using the ' . '<a href="#row_tax_avatax_connection_settings_header">%1 credentials</a>: %2', $type, $message); } return $errors; }
/** * Get address service by type and cache instances by type to avoid duplicate instantiation * * @param string $type * @param $storeId * @return AddressServiceSoap */ public function getAddressService($type = null, $storeId = null) { if (is_null($type)) { $type = $this->config->getLiveMode() ? Config::API_PROFILE_NAME_PROD : Config::API_PROFILE_NAME_DEV; } if (!isset($this->addressServiceSoap[$type])) { $this->config->createAvaTaxProfile($storeId); $this->addressServiceSoap[$type] = $this->addressServiceSoapFactory->create(['configurationName' => $type]); } return $this->addressServiceSoap[$type]; }
/** * Get details for GetTaxRequest * * @param \Magento\Store\Api\Data\StoreInterface $store * @param $address \Magento\Quote\Api\Data\AddressInterface|\Magento\Sales\Api\Data\OrderAddressInterface * @param \Magento\Quote\Api\Data\CartInterface|\Magento\Sales\Api\Data\OrderInterface $object * @return array * @throws LocalizedException */ protected function retrieveGetTaxRequestFields(StoreInterface $store, $address, $object) { $customerId = $object->getCustomerId(); $customer = $this->getCustomerById($customerId); $storeId = $store->getId(); if ($this->config->getLiveMode() == Config::API_PROFILE_NAME_PROD) { $companyCode = $this->config->getCompanyCode($storeId); } else { $companyCode = $this->config->getDevelopmentCompanyCode($storeId); } $businessIdentificationNumber = $this->getBusinessIdentificationNumber($store, $address, $customer); $locationCode = $this->config->getLocationCode($store); return ['BusinessIdentificationNo' => $businessIdentificationNumber, 'CompanyCode' => $companyCode, 'LocationCode' => $locationCode, 'OriginAddress' => $this->address->getAddress($this->config->getOriginAddress($storeId))]; }