diff --git a/Api/RestCustomerInterface.php b/Api/RestCustomerInterface.php
index 60e6cf0e..3aa2283f 100644
--- a/Api/RestCustomerInterface.php
+++ b/Api/RestCustomerInterface.php
@@ -73,6 +73,24 @@ public function deleteCertificate(
$scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
+ /**
+ * Perform REST request to unlink certificate.
+ *
+ * @param DataObject $request
+ * @param bool|null $isProduction
+ * @param string|int|null $scopeId
+ * @param string $scopeType
+ *
+ * @return mixed
+ * @throws \ClassyLlama\AvaTax\Exception\AvataxConnectionException
+ */
+ public function unlinkCertificate(
+ $request,
+ $isProduction = null,
+ $scopeId = null,
+ $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE
+ );
+
/**
* Perform REST request to update a customer.
*
diff --git a/BaseProvider/Framework/Rest/ApiClient.php b/BaseProvider/Framework/Rest/ApiClient.php
index 46e39928..4fc52c07 100644
--- a/BaseProvider/Framework/Rest/ApiClient.php
+++ b/BaseProvider/Framework/Rest/ApiClient.php
@@ -21,6 +21,7 @@
use GuzzleHttp\ClientFactory;
use GuzzleHttp\Psr7\ResponseFactory;
use Magento\Framework\Webapi\Rest\Request;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* Class ApiClient
@@ -58,20 +59,28 @@ class ApiClient
protected $appVersion;
protected $machineName;
protected $authType;
+
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
/**
* GitApiService constructor
*
* @param ClientFactory $clientFactory
* @param ResponseFactory $responseFactory
+ * @param ApiLog $apiLog
*/
public function __construct(
ClientFactory $clientFactory,
- ResponseFactory $responseFactory
+ ResponseFactory $responseFactory,
+ ApiLog $apiLog
) {
$this->clientFactory = $clientFactory;
$this->responseFactory = $responseFactory;
$this->catchExceptions = true;
+ $this->apiLog = $apiLog;
}
/**
@@ -159,6 +168,14 @@ public function restCall(
return $body;
}
} catch (\Exception $e) {
+
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'restCall';
+ $debugLogContext['operation'] = 'BaseProvider_Framework_Rest_ApiClient';
+ $debugLogContext['function_name'] = 'restCall';
+ $this->apiLog->debugLog($debugLogContext);
+
if (!$this->catchExceptions) {
throw $e;
}
diff --git a/BaseProvider/Model/Log/Clear.php b/BaseProvider/Model/Log/Clear.php
index ad86a0f7..4904d7f3 100644
--- a/BaseProvider/Model/Log/Clear.php
+++ b/BaseProvider/Model/Log/Clear.php
@@ -18,6 +18,7 @@
use ClassyLlama\AvaTax\BaseProvider\Helper\Application\Config as ApplicationLoggerConfig;
use ClassyLlama\AvaTax\BaseProvider\Model\ResourceModel\Log\CollectionFactory as LogCollFactory;
use Magento\Framework\Stdlib\DateTime\DateTime;
+use ClassyLlama\AvaTax\Helper\ApiLog;
class Clear
{
@@ -40,23 +41,31 @@ class Clear
* @var DateTime
*/
protected $dateTime;
+
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
/**
* @param LoggerInterface $applicationLogger
* @param ApplicationLoggerConfig $applicationLoggerConfig
* @param LogCollFactory $logCollFactory
* @param DateTime $dateTime
+ * @param ApiLog $apiLog
*/
public function __construct(
LoggerInterface $applicationLogger,
ApplicationLoggerConfig $applicationLoggerConfig,
LogCollFactory $logCollFactory,
- DateTime $dateTime
+ DateTime $dateTime,
+ ApiLog $apiLog
) {
$this->applicationLogger = $applicationLogger;
$this->applicationLoggerConfig = $applicationLoggerConfig;
$this->logCollFactory = $logCollFactory;
$this->dateTime = $dateTime;
+ $this->apiLog = $apiLog;
}
/**
@@ -100,6 +109,12 @@ public function clearDbLogs()
$log->delete();
$size++;
} catch(\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'clearlog';
+ $debugLogContext['operation'] = 'BaseProvider_Model_Log_Clear';
+ $debugLogContext['function_name'] = 'clearDbLogs';
+ $this->apiLog->debugLog($debugLogContext);
$e->getMessage();
}
}
diff --git a/BaseProvider/Model/Queue/Clear.php b/BaseProvider/Model/Queue/Clear.php
index 5af43f2f..ff3ed32d 100644
--- a/BaseProvider/Model/Queue/Clear.php
+++ b/BaseProvider/Model/Queue/Clear.php
@@ -18,6 +18,7 @@
use ClassyLlama\AvaTax\BaseProvider\Helper\Config as QueueConfig;
use ClassyLlama\AvaTax\BaseProvider\Model\ResourceModel\Queue\CollectionFactory as QueueCollFactory;
use Magento\Framework\Stdlib\DateTime\DateTime;
+use ClassyLlama\AvaTax\Helper\ApiLog;
class Clear
{
@@ -42,22 +43,30 @@ class Clear
*/
protected $dateTime;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* @param LoggerInterface
* @param QueueConfig $queueConfig
* @param QueueCollFactory $queueCollFactory
* @param DateTime $dateTime
+ * @param ApiLog $apiLog
*/
public function __construct(
LoggerInterface $logger,
QueueConfig $queueConfig,
QueueCollFactory $queueCollFactory,
- DateTime $dateTime
+ DateTime $dateTime,
+ ApiLog $apiLog
) {
$this->logger = $logger;
$this->queueConfig = $queueConfig;
$this->queueCollFactory = $queueCollFactory;
$this->dateTime = $dateTime;
+ $this->apiLog = $apiLog;
}
/**
@@ -95,6 +104,12 @@ public function clearDbQueues()
$queue->delete();
$size++;
} catch(\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'clearqueue';
+ $debugLogContext['operation'] = 'BaseProvider_Model_Queue_Clear';
+ $debugLogContext['function_name'] = 'clearDbQueues';
+ $this->apiLog->debugLog($debugLogContext);
$this->logger->debug($e->getMessage());
}
}
diff --git a/BaseProvider/Model/Queue/Consumer.php b/BaseProvider/Model/Queue/Consumer.php
index 45beed64..b82dddc4 100644
--- a/BaseProvider/Model/Queue/Consumer.php
+++ b/BaseProvider/Model/Queue/Consumer.php
@@ -72,17 +72,19 @@ public function __construct(
*/
public function process()
{
- $this->logger->debug(__('Initiating queue processing from cron job'));
$size = $this->consumeJobs();
- $this->logger->debug(
- __('Completed queue processing from cron job.'),
- [
- 'total_count' => $size,
- 'extra' => [
- 'class' => __METHOD__
+ if($size > 0)
+ {
+ $this->logger->debug(
+ __('Completed queue processing from cron job.'),
+ [
+ 'total_count' => $size,
+ 'extra' => [
+ 'class' => __METHOD__
+ ]
]
- ]
- );
+ );
+ }
}
/**
diff --git a/BaseProvider/etc/di.xml b/BaseProvider/etc/di.xml
index ce9d0a7a..e657a912 100644
--- a/BaseProvider/etc/di.xml
+++ b/BaseProvider/etc/di.xml
@@ -62,11 +62,11 @@
- - AvaTaxLogGridDataProvider
+ - AvaTaxBaseProviderLogGridDataProvider
-
+
baseprovider_logs
ClassyLlama\AvaTax\BaseProvider\Model\ResourceModel\Log
diff --git a/Block/Adminhtml/Form/Field/TransportColumn.php b/Block/Adminhtml/Form/Field/TransportColumn.php
index c1f68570..edabafc6 100644
--- a/Block/Adminhtml/Form/Field/TransportColumn.php
+++ b/Block/Adminhtml/Form/Field/TransportColumn.php
@@ -8,6 +8,8 @@
use Magento\Framework\DataObjectFactory;
use ClassyLlama\AvaTax\Api\RestDefinitionsInterface;
use ClassyLlama\AvaTax\Helper\Config;
+use ClassyLlama\AvaTax\Helper\ApiLog;
+
/**
* @codeCoverageIgnore
*/
@@ -33,6 +35,11 @@ class TransportColumn extends Select
* @var RestDefinitionsInterface
*/
protected $definitionsService;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* @param Context $context
* @param StoreManagerInterface $storeManager
@@ -40,6 +47,7 @@ class TransportColumn extends Select
* @param RestDefinitionsInterface $definitionsService
* @param \Magento\Framework\Message\ManagerInterface $messageManager
* @param Config $config
+ * @param ApiLog $apiLog
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
@@ -48,6 +56,7 @@ public function __construct(
RestDefinitionsInterface $definitionsService,
\Magento\Framework\Message\ManagerInterface $messageManager,
Config $config,
+ ApiLog $apiLog,
array $data = []
)
{
@@ -57,6 +66,7 @@ public function __construct(
$this->definitionsService = $definitionsService;
$this->messageManager = $messageManager;
$this->config = $config;
+ $this->apiLog = $apiLog;
}
/**
@@ -111,6 +121,12 @@ private function getSourceOptions(): array
try {
$validateResult = $this->definitionsService->parameters($isProduction, $storeId);
} catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'TransportColumn';
+ $debugLogContext['operation'] = 'Block_Adminhtml_Form_Field_TransportColumn';
+ $debugLogContext['function_name'] = 'getSourceOptions';
+ $this->apiLog->debugLog($debugLogContext, $storeId, $scopeType);
$this->messageManager->addError($e->getMessage());
return [];
}
diff --git a/Block/ViewModel/CustomerCertificates.php b/Block/ViewModel/CustomerCertificates.php
index cdd375ab..29b1575b 100644
--- a/Block/ViewModel/CustomerCertificates.php
+++ b/Block/ViewModel/CustomerCertificates.php
@@ -63,9 +63,9 @@ class CustomerCertificates implements \Magento\Framework\View\Element\Block\Argu
protected $urlBuilder;
/**
- * @var \ClassyLlama\AvaTax\Helper\CertificateDeleteHelper
+ * @var \ClassyLlama\AvaTax\Helper\certificateUnlinkHelper
*/
- protected $certificateDeleteHelper;
+ protected $certificateUnlinkHelper;
/**
* @var \ClassyLlama\AvaTax\Helper\CertificateHelper
@@ -79,7 +79,7 @@ class CustomerCertificates implements \Magento\Framework\View\Element\Block\Argu
* @param UrlSigner $urlSigner
* @param \ClassyLlama\AvaTax\Model\ResourceModel\Config $configResourceModel
* @param \Magento\Framework\UrlInterface $urlBuilder
- * @param \ClassyLlama\AvaTax\Helper\CertificateDeleteHelper $certificateDeleteHelper
+ * @param \ClassyLlama\AvaTax\Helper\CertificateUnlinkHelper $certificateUnlinkHelper
* @param \ClassyLlama\AvaTax\Helper\CertificateHelper $certificateHelper
*/
public function __construct(
@@ -89,7 +89,7 @@ public function __construct(
UrlSigner $urlSigner,
\ClassyLlama\AvaTax\Model\ResourceModel\Config $configResourceModel,
\Magento\Framework\UrlInterface $urlBuilder,
- \ClassyLlama\AvaTax\Helper\CertificateDeleteHelper $certificateDeleteHelper,
+ \ClassyLlama\AvaTax\Helper\CertificateUnlinkHelper $certificateUnlinkHelper,
\ClassyLlama\AvaTax\Helper\CertificateHelper $certificateHelper
)
{
@@ -99,7 +99,7 @@ public function __construct(
$this->urlSigner = $urlSigner;
$this->configResourceModel = $configResourceModel;
$this->urlBuilder = $urlBuilder;
- $this->certificateDeleteHelper = $certificateDeleteHelper;
+ $this->certificateUnlinkHelper = $certificateUnlinkHelper;
$this->certificateHelper = $certificateHelper;
}
@@ -139,15 +139,15 @@ public function getCertificateUrl($certificateId)
}
/**
- * Build delete cert url
+ * Build unlink cert url
*
* @param int $certificateId
*
* @return string
*/
- public function getDeleteCertificateUrl(int $certificateId)
+ public function getUnlinkCertificateUrl(int $certificateId)
{
- return $this->certificateHelper->getCertificateDeleteUrl($certificateId, $this->getCustomerId());
+ return $this->certificateHelper->getCertificateUnlinkUrl($certificateId, $this->getCustomerId());
}
/**
diff --git a/Controller/Adminhtml/Certificates/Unlink.php b/Controller/Adminhtml/Certificates/Unlink.php
new file mode 100644
index 00000000..d58f218c
--- /dev/null
+++ b/Controller/Adminhtml/Certificates/Unlink.php
@@ -0,0 +1,68 @@
+certificateUnlinkHelper = $certificateUnlinkHelper;
+ }
+
+ /**
+ * Action to delete a certificate.
+ *
+ * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface
+ */
+ public function execute()
+ {
+ //Forward any action to delete helper where delete logic is contained.
+ $this->certificateUnlinkHelper->unlink();
+
+ return $this->_redirect($this->_redirect->getRefererUrl());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function _isAllowed()
+ {
+ return $this->_authorization->isAllowed(
+ static::CERTIFICATES_RESOURCE
+ );
+ }
+}
\ No newline at end of file
diff --git a/Controller/Adminhtml/CrossBorderType/Delete.php b/Controller/Adminhtml/CrossBorderType/Delete.php
index aec431bd..c1e15863 100644
--- a/Controller/Adminhtml/CrossBorderType/Delete.php
+++ b/Controller/Adminhtml/CrossBorderType/Delete.php
@@ -16,6 +16,7 @@
namespace ClassyLlama\AvaTax\Controller\Adminhtml\CrossBorderType;
use ClassyLlama\AvaTax\Api\CrossBorderTypeRepositoryInterface;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* @codeCoverageIgnore
@@ -26,21 +27,29 @@ class Delete extends \ClassyLlama\AvaTax\Controller\Adminhtml\CrossBorderType
* @var CrossBorderTypeRepositoryInterface
*/
protected $crossBorderTypeRepository;
+
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
/**
* @param CrossBorderTypeRepositoryInterface $crossBorderTypeRepository
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
+ * @param ApiLog $apiLog
*/
public function __construct(
CrossBorderTypeRepositoryInterface $crossBorderTypeRepository,
\Magento\Backend\App\Action\Context $context,
- \Magento\Framework\Registry $coreRegistry
+ \Magento\Framework\Registry $coreRegistry,
+ ApiLog $apiLog
)
{
parent::__construct($context, $coreRegistry);
$this->crossBorderTypeRepository = $crossBorderTypeRepository;
+ $this->apiLog = $apiLog;
}
/**
@@ -64,6 +73,12 @@ public function execute()
// go to grid
return $resultRedirect->setPath('*/*/');
} catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'DeleteCrossBorderType';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_CrossborderType_Delete';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
// display error message
$this->messageManager->addErrorMessage($e->getMessage());
diff --git a/Controller/Adminhtml/CrossBorderType/Edit.php b/Controller/Adminhtml/CrossBorderType/Edit.php
index 5e2370b3..820ac5e7 100644
--- a/Controller/Adminhtml/CrossBorderType/Edit.php
+++ b/Controller/Adminhtml/CrossBorderType/Edit.php
@@ -17,6 +17,7 @@
use ClassyLlama\AvaTax\Api\CrossBorderTypeRepositoryInterface;
use Magento\Framework\Exception\LocalizedException;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* @codeCoverageIgnore
@@ -33,23 +34,31 @@ class Edit extends \ClassyLlama\AvaTax\Controller\Adminhtml\CrossBorderType
*/
protected $crossBorderTypeRepository;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* @param \Magento\Backend\App\Action\Context $context
* @param CrossBorderTypeRepositoryInterface $crossBorderTypeRepository
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
+ * @param ApiLog $apiLog
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
CrossBorderTypeRepositoryInterface $crossBorderTypeRepository,
\Magento\Framework\Registry $coreRegistry,
- \Magento\Framework\View\Result\PageFactory $resultPageFactory
+ \Magento\Framework\View\Result\PageFactory $resultPageFactory,
+ ApiLog $apiLog
)
{
parent::__construct($context, $coreRegistry);
$this->resultPageFactory = $resultPageFactory;
$this->crossBorderTypeRepository = $crossBorderTypeRepository;
+ $this->apiLog = $apiLog;
}
/**
@@ -69,6 +78,12 @@ public function execute()
$this->coreRegistry->register('classyllama_avatax_crossbordertype', $model);
} catch (LocalizedException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'EditCrossBorderType';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_CrossborderType_Edit';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addErrorMessage(__('This Cross Border Type no longer exists.'));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
diff --git a/Controller/Adminhtml/CrossBorderType/InlineEdit.php b/Controller/Adminhtml/CrossBorderType/InlineEdit.php
index c5779fcb..fec43b9d 100644
--- a/Controller/Adminhtml/CrossBorderType/InlineEdit.php
+++ b/Controller/Adminhtml/CrossBorderType/InlineEdit.php
@@ -17,6 +17,7 @@
use ClassyLlama\AvaTax\Api\CrossBorderTypeRepositoryInterface;
use ClassyLlama\AvaTax\Api\Data\CrossBorderTypeInterfaceFactory;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* @codeCoverageIgnore
@@ -38,23 +39,31 @@ class InlineEdit extends \Magento\Backend\App\Action
*/
protected $crossBorderTypeInterfaceFactory;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Controller\Result\JsonFactory $jsonFactory
* @param CrossBorderTypeRepositoryInterface $crossBorderTypeRepository
* @param CrossBorderTypeInterfaceFactory $crossBorderTypeInterfaceFactory
+ * @param ApiLog $apiLog
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Controller\Result\JsonFactory $jsonFactory,
CrossBorderTypeRepositoryInterface $crossBorderTypeRepository,
- CrossBorderTypeInterfaceFactory $crossBorderTypeInterfaceFactory
+ CrossBorderTypeInterfaceFactory $crossBorderTypeInterfaceFactory,
+ ApiLog $apiLog
)
{
parent::__construct($context);
$this->jsonFactory = $jsonFactory;
$this->crossBorderTypeRepository = $crossBorderTypeRepository;
$this->crossBorderTypeInterfaceFactory = $crossBorderTypeInterfaceFactory;
+ $this->apiLog = $apiLog;
}
/**
@@ -82,6 +91,12 @@ public function execute()
$this->crossBorderTypeRepository->save($model);
} catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'InlineEditCrossBorderType';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_CrossborderType_InlineEdit';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$messages[] = "[Cross Border Type ID: {$modelid}] {$e->getMessage()}";
$error = true;
}
diff --git a/Controller/Adminhtml/CrossBorderType/Save.php b/Controller/Adminhtml/CrossBorderType/Save.php
index d866d916..eb61f5fc 100644
--- a/Controller/Adminhtml/CrossBorderType/Save.php
+++ b/Controller/Adminhtml/CrossBorderType/Save.php
@@ -18,6 +18,7 @@
use ClassyLlama\AvaTax\Api\CrossBorderTypeRepositoryInterface;
use ClassyLlama\AvaTax\Api\Data\CrossBorderTypeInterfaceFactory;
use Magento\Framework\Exception\LocalizedException;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* @codeCoverageIgnore
@@ -39,23 +40,31 @@ class Save extends \Magento\Backend\App\Action
*/
protected $crossBorderTypeInterfaceFactory;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor
* @param CrossBorderTypeRepositoryInterface $crossBorderTypeRepository
* @param CrossBorderTypeInterfaceFactory $crossBorderTypeInterfaceFactory
+ * @param ApiLog $apiLog
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\App\Request\DataPersistorInterface $dataPersistor,
CrossBorderTypeRepositoryInterface $crossBorderTypeRepository,
- CrossBorderTypeInterfaceFactory $crossBorderTypeInterfaceFactory
+ CrossBorderTypeInterfaceFactory $crossBorderTypeInterfaceFactory,
+ ApiLog $apiLog
)
{
parent::__construct($context);
$this->dataPersistor = $dataPersistor;
$this->crossBorderTypeRepository = $crossBorderTypeRepository;
$this->crossBorderTypeInterfaceFactory = $crossBorderTypeInterfaceFactory;
+ $this->apiLog = $apiLog;
}
/**
@@ -93,8 +102,20 @@ public function execute()
return $resultRedirect->setPath('*/*/');
} catch (LocalizedException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'SaveCrossBorderType';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_CrossborderType_Save';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'SaveCrossBorderType';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_CrossborderType_Save';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addExceptionMessage(
$e,
__('Something went wrong while saving the Cross Border Type.')
diff --git a/Controller/Adminhtml/Crossborder/Classes/Delete.php b/Controller/Adminhtml/Crossborder/Classes/Delete.php
index 30ce05bb..508a7753 100644
--- a/Controller/Adminhtml/Crossborder/Classes/Delete.php
+++ b/Controller/Adminhtml/Crossborder/Classes/Delete.php
@@ -20,6 +20,7 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\Exception\LocalizedException;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* @codeCoverageIgnore
@@ -33,19 +34,27 @@ class Delete extends \ClassyLlama\AvaTax\Controller\Adminhtml\Crossborder\Classe
protected $dataPersistor;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* @param Context $context
* @param CrossBorderClassRepositoryInterface $crossBorderClassRepository
* @param DataPersistorInterface $dataPersistor
+ * @param ApiLog $apiLog
*/
public function __construct(
Context $context,
CrossBorderClassRepositoryInterface $crossBorderClassRepository,
- DataPersistorInterface $dataPersistor
+ DataPersistorInterface $dataPersistor,
+ ApiLog $apiLog
) {
parent::__construct($context);
$this->crossBorderClassRepository = $crossBorderClassRepository;
$this->dataPersistor = $dataPersistor;
+ $this->apiLog = $apiLog;
}
/**
@@ -67,10 +76,28 @@ public function execute()
$this->crossBorderClassRepository->deleteById($id);
$this->messageManager->addSuccessMessage(__('You deleted the Cross Border Class'));
} catch (NoSuchEntityException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'DeleteCrossBorderClass';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Crossborder_Classes_Delete';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addErrorMessage($e->getMessage());
} catch (LocalizedException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'DeleteCrossBorderClass';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Crossborder_Classes_Delete';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'DeleteCrossBorderClass';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Crossborder_Classes_Delete';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Cross Border Class'));
}
diff --git a/Controller/Adminhtml/Crossborder/Classes/Edit.php b/Controller/Adminhtml/Crossborder/Classes/Edit.php
index a5eb3371..74cceaa5 100644
--- a/Controller/Adminhtml/Crossborder/Classes/Edit.php
+++ b/Controller/Adminhtml/Crossborder/Classes/Edit.php
@@ -21,6 +21,7 @@
use ClassyLlama\AvaTax\Api\Data\CrossBorderClassRepositoryInterface;
use Magento\Framework\Registry;
use Magento\Framework\Exception\NoSuchEntityException;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* @codeCoverageIgnore
@@ -37,19 +38,27 @@ class Edit extends \ClassyLlama\AvaTax\Controller\Adminhtml\Crossborder\ClassesA
*/
protected $coreRegistry;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* @param Context $context
* @param CrossBorderClassRepositoryInterface $crossBorderClassRepository
* @param Registry $coreRegistry
+ * @param ApiLog $apiLog
*/
public function __construct(
Context $context,
CrossBorderClassRepositoryInterface $crossBorderClassRepository,
- Registry $coreRegistry
+ Registry $coreRegistry,
+ ApiLog $apiLog
) {
parent::__construct($context);
$this->crossBorderClassRepository = $crossBorderClassRepository;
$this->coreRegistry = $coreRegistry;
+ $this->apiLog = $apiLog;
}
/**
@@ -66,11 +75,23 @@ public function execute()
try {
$crossBorderClass = $this->crossBorderClassRepository->getById($classId);
} catch (NoSuchEntityException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'EditCrossBorderClass';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Crossborder_Classes_Edit';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addExceptionMessage($e, __('Cross Border Class does not exist'));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/*/index');
return $resultRedirect;
} catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'EditCrossBorderClass';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Crossborder_Classes_Edit';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addExceptionMessage($e, __('An error occurred while loading the class'));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/*/index');
diff --git a/Controller/Adminhtml/Crossborder/Classes/Save.php b/Controller/Adminhtml/Crossborder/Classes/Save.php
index 146781da..63ad8d7b 100644
--- a/Controller/Adminhtml/Crossborder/Classes/Save.php
+++ b/Controller/Adminhtml/Crossborder/Classes/Save.php
@@ -20,6 +20,7 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\Exception\LocalizedException;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* @codeCoverageIgnore
@@ -33,19 +34,27 @@ class Save extends \ClassyLlama\AvaTax\Controller\Adminhtml\Crossborder\ClassesA
protected $dataPersistor;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* @param Context $context
* @param CrossBorderClassRepositoryInterface $crossBorderClassRepository
* @param DataPersistorInterface $dataPersistor
+ * @param ApiLog $apiLog
*/
public function __construct(
Context $context,
CrossBorderClassRepositoryInterface $crossBorderClassRepository,
- DataPersistorInterface $dataPersistor
+ DataPersistorInterface $dataPersistor,
+ ApiLog $apiLog
) {
parent::__construct($context);
$this->crossBorderClassRepository = $crossBorderClassRepository;
$this->dataPersistor = $dataPersistor;
+ $this->apiLog = $apiLog;
}
/**
@@ -69,9 +78,21 @@ public function execute()
try {
$class = ($id) ? $this->crossBorderClassRepository->getById($id) : $this->crossBorderClassRepository->create();
} catch (NoSuchEntityException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'SaveCrossBorderClass';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Crossborder_Classes_Save';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addErrorMessage(__('Cross Border Class does not exist'));
return $resultRedirect->setPath('*/*');
} catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'SaveCrossBorderClass';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Crossborder_Classes_Save';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addErrorMessage(__('A problem occurred while trying to initialize Cross Border Class'));
return $resultRedirect->setPath('*/*');
}
@@ -112,8 +133,20 @@ public function execute()
}
return $resultRedirect->setPath('*/*');
} catch (LocalizedException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'SaveCrossBorderClass';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Crossborder_Classes_Save';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'SaveCrossBorderClass';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Crossborder_Classes_Save';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Cross Border Class'));
}
diff --git a/Controller/Adminhtml/Invite/Index.php b/Controller/Adminhtml/Invite/Index.php
index f8596205..96ec5628 100644
--- a/Controller/Adminhtml/Invite/Index.php
+++ b/Controller/Adminhtml/Invite/Index.php
@@ -107,6 +107,10 @@ public function execute()
'Avalara has emailed the customer so they can add an exemption certificate.'
);
- return $resultRedirect->setPath('customer/index/edit', ['id' => $parameters['customer_id']]);
+ if(isset($parameters['redirect'])){
+ return $resultRedirect->setPath('customer/index/index');
+ }else{
+ return $resultRedirect->setPath('customer/index/edit', ['id' => $parameters['customer_id']]);
+ }
}
}
diff --git a/Controller/Adminhtml/Log/Clear.php b/Controller/Adminhtml/Log/Clear.php
index 2afa570e..30ffc963 100644
--- a/Controller/Adminhtml/Log/Clear.php
+++ b/Controller/Adminhtml/Log/Clear.php
@@ -21,7 +21,7 @@
use Magento\Backend\App\Action\Context;
use ClassyLlama\AvaTax\Model\Log\Task;
use ClassyLlama\AvaTax\Model\Logger\AvaTaxLogger;
-
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* @codeCoverageIgnore
*/
@@ -37,20 +37,28 @@ class Clear extends Log
*/
protected $avaTaxLogger;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* Process constructor
*
* @param Context $context
* @param Task $logTask
* @param AvaTaxLogger $avaTaxLogger
+ * @param ApiLog $apiLog
*/
public function __construct(
Context $context,
Task $logTask,
- AvaTaxLogger $avaTaxLogger
+ AvaTaxLogger $avaTaxLogger,
+ ApiLog $apiLog
) {
$this->logTask = $logTask;
$this->avaTaxLogger = $avaTaxLogger;
+ $this->apiLog = $apiLog;
parent::__construct($context);
}
@@ -77,7 +85,12 @@ public function execute()
$this->messageManager->addSuccess(__('No logs needed to be cleared.'));
}
} catch (\Exception $e) {
-
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'ClearLog';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Log_Clear';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
// Build error message
$message = __('An error occurred while clearing the log.');
diff --git a/Controller/Adminhtml/Queue/Clear.php b/Controller/Adminhtml/Queue/Clear.php
index 1ce604fe..6939c2ec 100644
--- a/Controller/Adminhtml/Queue/Clear.php
+++ b/Controller/Adminhtml/Queue/Clear.php
@@ -21,6 +21,7 @@
use Magento\Backend\App\Action\Context;
use ClassyLlama\AvaTax\Model\Queue\Task;
use ClassyLlama\AvaTax\Model\Logger\AvaTaxLogger;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* @codeCoverageIgnore
@@ -37,20 +38,28 @@ class Clear extends Queue
*/
protected $avaTaxLogger;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* Process constructor
*
* @param Context $context
* @param Task $queueTask
* @param AvaTaxLogger $avaTaxLogger
+ * @param ApiLog $apiLog
*/
public function __construct(
Context $context,
Task $queueTask,
- AvaTaxLogger $avaTaxLogger
+ AvaTaxLogger $avaTaxLogger,
+ ApiLog $apiLog
) {
$this->queueTask = $queueTask;
$this->avaTaxLogger = $avaTaxLogger;
+ $this->apiLog = $apiLog;
parent::__construct($context);
}
@@ -84,6 +93,13 @@ public function execute()
}
} catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'ClearQueue';
+ $debugLogContext['operation'] = 'Controller_Adminhtml_Queue_Clear';
+ $debugLogContext['function_name'] = 'execute';
+ $this->apiLog->debugLog($debugLogContext);
+
// Build error message
$message = __('An error occurred while clearing the queue.');
diff --git a/Controller/Certificates/Unlink.php b/Controller/Certificates/Unlink.php
new file mode 100644
index 00000000..e2fe8d8c
--- /dev/null
+++ b/Controller/Certificates/Unlink.php
@@ -0,0 +1,57 @@
+certificateUnlinkHelper = $certificateUnlinkHelper;
+ }
+
+ /**
+ * Action to unlink a certificate.
+ *
+ * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface
+ */
+ public function execute()
+ {
+ //Forward any action to unlink helper where delete logic is contained.
+ $this->certificateUnlinkHelper->unlink();
+
+ return $this->_redirect($this->_redirect->getRefererUrl());
+ }
+}
\ No newline at end of file
diff --git a/Framework/AppInterface.php b/Framework/AppInterface.php
index 6697962f..6c518da9 100644
--- a/Framework/AppInterface.php
+++ b/Framework/AppInterface.php
@@ -20,14 +20,17 @@ interface AppInterface
/**
* Connector version
*/
- const APP_VERSION = '2.4.2';
+ const APP_VERSION = '2.5.0';
/**
* Avalara APP String
*/
- const CONNECTOR_STRING = 'a0o5a000007ULusAAG';
-
+ const CONNECTOR_STRING = 'a0o5a000007hWJMAA2';
+ /**
+ * Avalara Connector name
+ */
+ const CONNECTOR_NAME = 'Magento for SalesTax';
/**
* Avalara APP name
*/
- const APP_NAME = 'Magento for SalesTax || '.self::APP_VERSION.'v2';
+ const APP_NAME = self::CONNECTOR_NAME.' || '.self::APP_VERSION.'v2';
}
diff --git a/Framework/Interaction/Address.php b/Framework/Interaction/Address.php
index cd98d292..dcdff4bc 100644
--- a/Framework/Interaction/Address.php
+++ b/Framework/Interaction/Address.php
@@ -30,6 +30,7 @@
use Magento\Quote\Api\Data\AddressInterface as QuoteAddressInterface;
use Magento\Quote\Api\Data\AddressInterfaceFactory as QuoteAddressInterfaceFactory;
use Magento\Sales\Api\Data\OrderAddressInterface;
+use ClassyLlama\AvaTax\Helper\ApiLog;
class Address
{
@@ -67,6 +68,11 @@ class Address
* @var \ClassyLlama\AvaTax\Model\Logger\AvaTaxLogger
*/
protected $avaTaxLogger;
+
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
/**
* Validation based on API documentation found here:
@@ -97,6 +103,7 @@ class Address
* @param QuoteAddressInterfaceFactory $quoteAddressFactory
* @param DataObjectHelper $dataObjectHelper
* @param \ClassyLlama\AvaTax\Model\Logger\AvaTaxLogger $avaTaxLogger
+ * @param ApiLog $apiLog
*/
public function __construct(
MetaDataObjectFactory $metaDataObjectFactory,
@@ -105,7 +112,8 @@ public function __construct(
CustomerAddressInterfaceFactory $customerAddressFactory,
QuoteAddressInterfaceFactory $quoteAddressFactory,
DataObjectHelper $dataObjectHelper,
- \ClassyLlama\AvaTax\Model\Logger\AvaTaxLogger $avaTaxLogger
+ \ClassyLlama\AvaTax\Model\Logger\AvaTaxLogger $avaTaxLogger,
+ ApiLog $apiLog
) {
$this->metaDataObject = $metaDataObjectFactory->create(['metaDataProperties' => $this::$validFields]);
$this->dataObjectFactory = $dataObjectFactory;
@@ -114,6 +122,7 @@ public function __construct(
$this->quoteAddressFactory = $quoteAddressFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->avaTaxLogger = $avaTaxLogger;
+ $this->apiLog = $apiLog;
}
/**
@@ -159,6 +168,14 @@ public function getAddress($data)
$validatedData = $this->metaDataObject->validateData($address->getData());
$address->setData($validatedData);
} catch (ValidationException $e) {
+
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'getAddress';
+ $debugLogContext['operation'] = 'Framework_Interaction_Address';
+ $debugLogContext['function_name'] = 'getAddress';
+ $this->apiLog->debugLog($debugLogContext);
+
$this->avaTaxLogger->error('Error validating address: ' . $e->getMessage(), [
'data' => var_export($address->getData(), true)
]);
diff --git a/Framework/Interaction/Request/AddressBuilder.php b/Framework/Interaction/Request/AddressBuilder.php
index b344e37c..2deaf476 100755
--- a/Framework/Interaction/Request/AddressBuilder.php
+++ b/Framework/Interaction/Request/AddressBuilder.php
@@ -11,6 +11,7 @@
use Magento\Sales\Api\Data\OrderAddressInterface as OrderAddress;
use ClassyLlama\AvaTax\Helper\Rest\Config as AvaTaxHelperRestConfig;
use ClassyLlama\AvaTax\Model\Logger\AvaTaxLogger;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* Class AddressBuilder
@@ -43,6 +44,11 @@ class AddressBuilder implements AddressBuilderInterface
*/
private $avaTaxLogger;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* AddressBuilder constructor.
* @param AvaTaxLogger $avaTaxLogger
@@ -50,19 +56,22 @@ class AddressBuilder implements AddressBuilderInterface
* @param FrameworkInteractionAddress $interactionAddress
* @param FrameworkInteractionAddress $frameworkInteractionAddress
* @param AvaTaxHelperConfig $avataxHelperConfig
+ * @param ApiLog $apiLog
*/
public function __construct(
AvaTaxLogger $avaTaxLogger,
AvaTaxHelperRestConfig $avaTaxHelperRestConfig,
InteractionAddress $interactionAddress,
FrameworkInteractionAddress $frameworkInteractionAddress,
- AvaTaxHelperConfig $avataxHelperConfig
+ AvaTaxHelperConfig $avataxHelperConfig,
+ ApiLog $apiLog
) {
$this->interactionAddress = $interactionAddress;
$this->frameworkInteractionAddress = $frameworkInteractionAddress;
$this->avataxHelperConfig = $avataxHelperConfig;
$this->avaTaxHelperRestConfig = $avaTaxHelperRestConfig;
$this->avaTaxLogger = $avaTaxLogger;
+ $this->apiLog = $apiLog;
}
/**
@@ -88,6 +97,13 @@ public function build(Order $order, int $storeId): array
];
} catch (\Throwable $exception) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $exception->getMessage();
+ $debugLogContext['source'] = 'AddressBuilder';
+ $debugLogContext['operation'] = 'Framework_Interaction_Request_AddressBuilder';
+ $debugLogContext['function_name'] = 'build';
+ $this->apiLog->debugLog($debugLogContext);
+
$this->avaTaxLogger->error($exception->getMessage(), [
'class' => self::class,
'trace' => $exception->getTraceAsString()
diff --git a/Framework/Interaction/Request/CreditmemoRequestBuilder.php b/Framework/Interaction/Request/CreditmemoRequestBuilder.php
index 59e2a809..69f92c41 100755
--- a/Framework/Interaction/Request/CreditmemoRequestBuilder.php
+++ b/Framework/Interaction/Request/CreditmemoRequestBuilder.php
@@ -41,6 +41,7 @@
use ClassyLlama\AvaTax\Helper\CustomsConfig;
use Magento\Framework\Api\AttributeInterface;
use ClassyLlama\AvaTax\Model\Logger\AvaTaxLogger;
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* Class CreditmemoRequestBuilder
@@ -170,6 +171,11 @@ class CreditmemoRequestBuilder implements CreditmemoRequestBuilderInterface
*/
private $avaTaxLogger;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* CreditmemoRequestBuilder constructor.
* @param AvaTaxLogger $avaTaxLogger
@@ -189,6 +195,7 @@ class CreditmemoRequestBuilder implements CreditmemoRequestBuilderInterface
* @param AvaTaxTaxClassHelper $taxClassHelper
* @param OrderRepositoryInterface $orderRepository
* @param RequestFactory $requestFactory
+ * @param ApiLog $apiLog
*/
public function __construct(
AvaTaxLogger $avaTaxLogger,
@@ -207,7 +214,8 @@ public function __construct(
LineBuilder $lineBuilder,
TaxClassHelper $taxClassHelper,
OrderRepositoryInterface $orderRepository,
- RequestFactory $requestFactory
+ RequestFactory $requestFactory,
+ ApiLog $apiLog
) {
$this->avaTaxLogger = $avaTaxLogger;
$this->requestFactory = $requestFactory;
@@ -225,6 +233,7 @@ public function __construct(
$this->avataxHelperConfig = $avataxHelperConfig;
$this->addressBuilder = $addressBuilder;
$this->priceCurrency = $priceCurrency;
+ $this->apiLog = $apiLog;
$this->metaDataObject = $metaDataObjectFactory->create([
'metaDataProperties' => FrameworkInteractionTax::$validTaxOverrideFields
]);
@@ -246,6 +255,13 @@ public function build(CreditmemoInterface $creditmemo): RequestInterface
/** @var Order $order */
$order = $this->orderRepository->get((int)$creditmemo->getOrderId());
} catch (\Throwable $exception) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $exception->getMessage();
+ $debugLogContext['source'] = 'CreditmemoRequestBuilder';
+ $debugLogContext['operation'] = 'Framework_Interaction_Request_CreditmemoRequestBuilder';
+ $debugLogContext['function_name'] = 'build';
+ $this->apiLog->debugLog($debugLogContext);
+
$this->avaTaxLogger->error($exception->getMessage(), [
'class' => self::class,
'trace' => $exception->getTraceAsString()
@@ -305,6 +321,13 @@ public function build(CreditmemoInterface $creditmemo): RequestInterface
return $request;
} catch (\Throwable $exception) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $exception->getMessage();
+ $debugLogContext['source'] = 'CreditmemoRequestBuilder';
+ $debugLogContext['operation'] = 'Framework_Interaction_Request_CreditmemoRequestBuilder';
+ $debugLogContext['function_name'] = 'build';
+ $this->apiLog->debugLog($debugLogContext);
+
$this->avaTaxLogger->error($exception->getMessage(), [
'class' => self::class,
'trace' => $exception->getTraceAsString()
@@ -606,6 +629,12 @@ private function createAndValidateRequest(
$validatedData = $this->validationMetadataObject->validateData($request->getData());
$request->setData($validatedData);
} catch (\Throwable $exception) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $exception->getMessage();
+ $debugLogContext['source'] = 'CreditmemoRequestBuilder';
+ $debugLogContext['operation'] = 'Framework_Interaction_Request_CreditmemoRequestBuilder';
+ $debugLogContext['function_name'] = 'createAndValidateRequest';
+ $this->apiLog->debugLog($debugLogContext);
$this->avaTaxLogger->error('Error validating data: ' . $exception->getMessage(), [
'data' => var_export($request->getData(), true)
]);
diff --git a/Framework/Interaction/Request/TaxComposite.php b/Framework/Interaction/Request/TaxComposite.php
index 717268a0..d573784b 100755
--- a/Framework/Interaction/Request/TaxComposite.php
+++ b/Framework/Interaction/Request/TaxComposite.php
@@ -88,6 +88,10 @@ public function __construct(
*/
public function calculateTax(RequestInterface $request, int $storeId, string $scopeType, array $params = [], $isProduction = null): RestTaxResult
{
+ $forceNew = false;
+ if (isset($params[\ClassyLlama\AvaTax\Api\RestTaxInterface::FLAG_FORCE_NEW_RATES])) {
+ $forceNew = $params[\ClassyLlama\AvaTax\Api\RestTaxInterface::FLAG_FORCE_NEW_RATES];
+ }
/**
* @var CreditmemoRequest $request
* @var RequestInterface $cacheKey
@@ -105,7 +109,7 @@ public function calculateTax(RequestInterface $request, int $storeId, string $sc
/** @var RestTaxResult|null $taxes */
$taxes = $this->resultStorage->find($cacheKey);
- if (null !== $taxes) {
+ if (null !== $taxes && !$forceNew) {
return $taxes;
}
diff --git a/Framework/Interaction/Rest/Address.php b/Framework/Interaction/Rest/Address.php
index a6876a80..857b54e5 100644
--- a/Framework/Interaction/Rest/Address.php
+++ b/Framework/Interaction/Rest/Address.php
@@ -21,6 +21,7 @@
use ClassyLlama\AvaTax\Helper\Rest\Config as RestConfig;
use Magento\Framework\DataObjectFactory;
use Psr\Log\LoggerInterface;
+use ClassyLlama\AvaTax\Helper\ApiLog;
class Address extends \ClassyLlama\AvaTax\Framework\Interaction\Rest
implements \ClassyLlama\AvaTax\Api\RestAddressInterface
@@ -31,24 +32,30 @@ class Address extends \ClassyLlama\AvaTax\Framework\Interaction\Rest
protected $restConfig;
protected $addressResultFactory;
-
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
/**
* @param LoggerInterface $logger
* @param DataObjectFactory $dataObjectFactory
* @param ClientPool $clientPool
* @param RestConfig $restConfig
* @param AddressResultFactory $addressResultFactory
+ * @param ApiLog $apiLog
*/
public function __construct(
LoggerInterface $logger,
DataObjectFactory $dataObjectFactory,
ClientPool $clientPool,
RestConfig $restConfig,
- AddressResultFactory $addressResultFactory
+ AddressResultFactory $addressResultFactory,
+ ApiLog $apiLog
) {
parent::__construct($logger, $dataObjectFactory, $clientPool);
$this->restConfig = $restConfig;
$this->addressResultFactory = $addressResultFactory;
+ $this->apiLog = $apiLog;
}
/**
@@ -90,6 +97,12 @@ public function validate(
null
);
} catch (\GuzzleHttp\Exception\RequestException $clientException) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'validate_address';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Address';
+ $debugLogContext['function_name'] ='validate';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
$this->handleException($clientException, $request);
}
diff --git a/Framework/Interaction/Rest/Company.php b/Framework/Interaction/Rest/Company.php
index 25332c06..7f93afee 100644
--- a/Framework/Interaction/Rest/Company.php
+++ b/Framework/Interaction/Rest/Company.php
@@ -17,18 +17,52 @@
use ClassyLlama\AvaTax\Api\RestCompanyInterface;
use ClassyLlama\AvaTax\Framework\Interaction\Rest;
+use Exception;
+use GuzzleHttp\Exception\RequestException;
use Magento\Framework\DataObject;
+use Magento\Framework\DataObjectFactory;
+use Psr\Log\LoggerInterface;
+use ClassyLlama\AvaTax\Framework\Interaction\Rest\ClientPool;
+use ClassyLlama\AvaTax\Helper\ApiLog;
class Company extends Rest implements RestCompanyInterface
{
/**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
+ /**
+ * @param LoggerInterface $logger
+ * @param DataObjectFactory $dataObjectFactory
+ * @param ClientPool $clientPool
+ * @param ApiLog $apiLog
+ */
+ public function __construct(
+ LoggerInterface $logger,
+ DataObjectFactory $dataObjectFactory,
+ ClientPool $clientPool,
+ ApiLog $apiLog
+ ) {
+ $this->apiLog = $apiLog;
+ parent::__construct($logger, $dataObjectFactory, $clientPool);
+ }
+
+ /**
+ * REST call to get Companies
+ *
* @param \ClassyLlama\AvaTax\Helper\AvaTaxClientWrapper $client
* @param DataObject|null $request
- *
+ *
* @return DataObject[]
* @throws \ClassyLlama\AvaTax\Exception\AvataxConnectionException
*/
- protected function getCompaniesFromClient( $client, $request = null )
+ protected function getCompaniesFromClient(
+ $client,
+ $request = null,
+ $scopeId = null,
+ $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE
+ )
{
if ($request === null)
{
@@ -46,7 +80,21 @@ protected function getCompaniesFromClient( $client, $request = null )
$request->getData('order_by')
);
} catch (\GuzzleHttp\Exception\RequestException $clientException) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'companies';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Company';
+ $debugLogContext['function_name'] = 'getCompaniesFromClient';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
$this->handleException($clientException, $request);
+ } catch (\Throwable $exception) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $exception->getMessage();
+ $debugLogContext['source'] = 'companies';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Company';
+ $debugLogContext['function_name'] = 'getCompaniesFromClient';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
+ throw $exception;
}
return $this->formatResult($clientResult)->getData('value');
@@ -64,7 +112,7 @@ public function getCompanies(
{
$client = $this->getClient( $isProduction, $scopeId, $scopeType );
- return $this->getCompaniesFromClient( $client, $request );
+ return $this->getCompaniesFromClient( $client, $request, $scopeId, $scopeType );
}
/**
@@ -100,8 +148,14 @@ public function getCertificateExposureZones(
$scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
{
- $client = $this->getClient($isProduction, $scopeId, $scopeType);
-
- return $client->listCertificateExposureZones(null, null, null, null);
+ try {
+ $client = $this->getClient($isProduction, $scopeId, $scopeType);
+ return $client->listCertificateExposureZones(null, null, null, null);
+ } catch (\GuzzleHttp\Exception\RequestException $clientException) {
+ // in case if Avatax account info is missing we will return false, no need to add CEP exception logging
+ return false;
+ } catch (\Exception $e){
+ return false;
+ }
}
}
diff --git a/Framework/Interaction/Rest/Customer.php b/Framework/Interaction/Rest/Customer.php
index 777b22b4..e10466f6 100644
--- a/Framework/Interaction/Rest/Customer.php
+++ b/Framework/Interaction/Rest/Customer.php
@@ -27,7 +27,7 @@
use GuzzleHttp\Exception\ClientException as GuzzleHttpClientException;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\DataObject;
-
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* Class Customer
* @package ClassyLlama\AvaTax\Framework\Interaction\Rest
@@ -58,7 +58,10 @@ class Customer extends Rest implements RestCustomerInterface
* @var \Magento\Customer\Api\AddressRepositoryInterface
*/
protected $addressRepository;
-
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
/**
* @param CustomerHelper $customerHelper
* @param Config $config
@@ -68,6 +71,7 @@ class Customer extends Rest implements RestCustomerInterface
* @param \ClassyLlama\AvaTax\Model\Factory\CustomerModelFactory $customerModelFactory
* @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
* @param LinkCustomersModelFactory $customersModelFactory
+ * @param ApiLog $apiLog
*/
public function __construct(
CustomerHelper $customerHelper,
@@ -77,7 +81,8 @@ public function __construct(
ClientPool $clientPool,
\ClassyLlama\AvaTax\Model\Factory\CustomerModelFactory $customerModelFactory,
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
- LinkCustomersModelFactory $customersModelFactory
+ LinkCustomersModelFactory $customersModelFactory,
+ ApiLog $apiLog
) {
parent::__construct($logger, $dataObjectFactory, $clientPool);
$this->customerHelper = $customerHelper;
@@ -85,6 +90,7 @@ public function __construct(
$this->customerModelFactory = $customerModelFactory;
$this->addressRepository = $addressRepository;
$this->customersModelFactory = $customersModelFactory;
+ $this->apiLog = $apiLog;
}
/**
@@ -116,6 +122,12 @@ public function getCertificatesList(
$request->getData('order_by')
);
} catch (\GuzzleHttp\Exception\RequestException $clientException) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'customer';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Customer';
+ $debugLogContext['function_name'] = 'getCertificatesList';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
// TODO: Possibly specifically handle no entity exception as an empty array of certificates?
$this->handleException($clientException, $request);
}
@@ -147,12 +159,73 @@ public function downloadCertificate(
);
return $result;
} catch (GuzzleHttpClientException $clientException) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'customer';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Customer';
+ $debugLogContext['function_name'] = 'downloadCertificate';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
throw $clientException;
} catch (\Throwable $exception) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $exception->getMessage();
+ $debugLogContext['source'] = 'customer';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Customer';
+ $debugLogContext['function_name'] = 'downloadCertificate';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
throw $exception;
}
}
+ /**
+ * {@inheritdoc}
+ * @codeCoverageIgnore
+ */
+ public function unlinkCertificate(
+ $request,
+ $isProduction = null,
+ $scopeId = null,
+ $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE
+ ) {
+ /** @var \Avalara\AvaTaxClient $client */
+ $client = $this->getClient($isProduction, $scopeId, $scopeType);
+ $client->withCatchExceptions(false);
+
+ try {
+ $customerId = $this->customerHelper->getCustomerCodeByCustomerId(
+ $request->getData('customer_id'),
+ null,
+ $scopeId
+ );
+
+ //unlink request requires a LinkCustomersModel which contains a string[] of all customer ids.
+ /** @var \Avalara\LinkCustomersModel $customerModel */
+ $certificateId = $request->getData('certificate_id');
+ $customerModel = $this->customersModelFactory->create();
+ $customerModel->certificates = [$certificateId];
+
+ //Customer(s) must be unlinked from cert before it can be deleted.
+ $client->unlinkCertificatesFromCustomer(
+ $this->config->getCompanyId($scopeId, $scopeType),
+ $customerId,
+ $customerModel
+ );
+ } catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'customer';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Customer';
+ $debugLogContext['function_name'] = 'unlinkCertificate';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
+ //Swallow this error. Continue to try and delete the cert.
+ //If the deletion errors, then we'll notify the user that something has gone wrong.
+ }
+
+ $result = null;
+
+ return $this->formatResult($result);
+ }
+
/**
* {@inheritdoc}
*/
@@ -185,6 +258,12 @@ public function deleteCertificate(
$customerModel
);
} catch (\Exception $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'customer';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Customer';
+ $debugLogContext['function_name'] = 'deleteCertificate';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
//Swallow this error. Continue to try and delete the cert.
//If the deletion errors, then we'll notify the user that something has gone wrong.
}
@@ -198,6 +277,12 @@ public function deleteCertificate(
$request->getData('id')
);
} catch (\GuzzleHttp\Exception\RequestException $clientException) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'customer';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Customer';
+ $debugLogContext['function_name'] = 'deleteCertificate';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
$this->handleException($clientException, $request, LOG_ERR, true);
}
@@ -227,6 +312,12 @@ public function updateCustomer(
$customerModel
);
} catch (\GuzzleHttp\Exception\RequestException $clientException) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'customer';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Customer';
+ $debugLogContext['function_name'] = 'updateCustomer';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
// Validate the response; pass the customer id for context in case of an error.
$this->handleException(
$clientException,
@@ -261,6 +352,12 @@ public function createCustomer(
[$customerModel]
);
} catch (\GuzzleHttp\Exception\RequestException $clientException) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'customer';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Customer';
+ $debugLogContext['function_name'] = 'createCustomer';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
// Validate the response; pass the customer id for context in case of an error.
$this->handleException(
$clientException,
@@ -297,6 +394,12 @@ public function sendCertExpressInvite(
]
);
} catch (\GuzzleHttp\Exception\RequestException $clientException) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'customer';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Customer';
+ $debugLogContext['function_name'] = 'sendCertExpressInvite';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
// Validate the response; pass the customer id for context in case of an error.
$this->handleException(
$clientException,
diff --git a/Framework/Interaction/Rest/Definitions.php b/Framework/Interaction/Rest/Definitions.php
index 138d0a66..9bfda3a6 100644
--- a/Framework/Interaction/Rest/Definitions.php
+++ b/Framework/Interaction/Rest/Definitions.php
@@ -21,6 +21,7 @@
use ClassyLlama\AvaTax\Helper\Rest\Config as RestConfig;
use Magento\Framework\DataObjectFactory;
use Psr\Log\LoggerInterface;
+use ClassyLlama\AvaTax\Helper\ApiLog;
class Definitions extends \ClassyLlama\AvaTax\Framework\Interaction\Rest
implements \ClassyLlama\AvaTax\Api\RestDefinitionsInterface
@@ -39,17 +40,20 @@ class Definitions extends \ClassyLlama\AvaTax\Framework\Interaction\Rest
* @param ClientPool $clientPool
* @param RestConfig $restConfig
* @param DefinitionsResultFactory $definitionsResultFactory
+ * @param ApiLog $apiLog
*/
public function __construct(
LoggerInterface $logger,
DataObjectFactory $dataObjectFactory,
ClientPool $clientPool,
RestConfig $restConfig,
- DefinitionsResultFactory $definitionsResultFactory
+ DefinitionsResultFactory $definitionsResultFactory,
+ ApiLog $apiLog
) {
parent::__construct($logger, $dataObjectFactory, $clientPool);
$this->restConfig = $restConfig;
$this->definitionsResultFactory = $definitionsResultFactory;
+ $this->apiLog = $apiLog;
}
/**
@@ -75,6 +79,12 @@ public function parameters(
try {
$resultObj = $client->listParameters( $filter );
} catch (\GuzzleHttp\Exception\RequestException $clientException) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'definitions';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Definitions';
+ $debugLogContext['function_name'] = 'parameters';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
$this->handleException($clientException);
}
diff --git a/Framework/Interaction/Rest/Tax.php b/Framework/Interaction/Rest/Tax.php
index 29a361b9..956311f2 100644
--- a/Framework/Interaction/Rest/Tax.php
+++ b/Framework/Interaction/Rest/Tax.php
@@ -165,7 +165,21 @@ public function getTax( $request, $isProduction = null, $scopeId = null, $scopeT
}
catch (\GuzzleHttp\Exception\RequestException $clientException) {
$sendLog = false;
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'tax';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Tax';
+ $debugLogContext['function_name'] = 'getTax';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
$this->handleException($clientException, $request);
+ } catch (\Throwable $exception) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $exception->getMessage();
+ $debugLogContext['source'] = 'customer';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Customer';
+ $debugLogContext['function_name'] = 'getTax';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
+ throw $exception;
}
@@ -203,10 +217,6 @@ public function getTax( $request, $isProduction = null, $scopeId = null, $scopeT
case \Avalara\DocumentType::C_SALESORDER :
$eventBlock = "PostCalculateTax";
$docType = "SalesOrder";
- if (isset($resultObj->totalAmount))
- $logContext['extra']['amount'] = $resultObj->totalAmount;
- if (isset($resultObj->totalTax))
- $logContext['extra']['tax'] = $resultObj->totalTax;
break;
}
if (!empty($docType)) {
@@ -278,6 +288,9 @@ protected function setTransactionDetails($transactionBuilder, $request)
if ($request->hasTransportParameters()) {
$transactionBuilder->withParameter($this->customsConfigHelper->getNextIncrementForWithParameter(), ['name'=>$request->getShippingMethod(), 'value'=>$request->getTransportParametersValue()] );
}
+ if ($request->hasShippingParameters()) {
+ $transactionBuilder->withParameter($this->customsConfigHelper->getNextIncrementForWithParameter(), ['name'=>$request->getShippingParametersName(), 'value'=>$request->getShippingParametersValue()]);
+ }
}
/**
@@ -419,6 +432,12 @@ public function getTaxBatch(
$apiEndTime = microtime(true);
} catch (RequestException $clientException) {
$sendLogs = false;
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'tax';
+ $debugLogContext['operation'] = 'Framework_Interaction_Rest_Tax';
+ $debugLogContext['function_name'] = 'getTaxBatch';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
$this->handleException($clientException);
}
$resultGeneric = $this->formatResult($resultObj);
diff --git a/Framework/Interaction/Tax.php b/Framework/Interaction/Tax.php
index c16ae437..aa9f8487 100644
--- a/Framework/Interaction/Tax.php
+++ b/Framework/Interaction/Tax.php
@@ -34,6 +34,8 @@
use Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
+use ClassyLlama\AvaTax\Helper\ApiLog;
+
/**
* Class Tax
*/
@@ -123,6 +125,11 @@ class Tax
*/
protected $restConfig;
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
+
/**
* A list of valid fields for the data array and meta data about their types to use in validation
* based on the API documentation. If any fields are added or removed, the same should be done in getTaxRequest.
@@ -173,7 +180,10 @@ class Tax
'shipping_mode' => ['type' => 'string'],
'transport_parameters'=> ['type' => 'boolean'],
'shipping_method' => ['type' => 'string'],
- 'transport_parameters_value'=> ['type' => 'string']
+ 'transport_parameters_value'=> ['type' => 'string'],
+ 'shipping_parameters'=> ['type' => 'boolean'],
+ 'shipping_parameters_name' => ['type' => 'string'],
+ 'shipping_parameters_value'=> ['type' => 'string']
];
public static $validTaxOverrideFields = [
@@ -259,6 +269,7 @@ class Tax
* @param AddressRepositoryInterface $customerAddressRepository
* @param ScopeConfigInterface $scopeConfig
* @param Json $serialize
+ * @param ApiLog $apiLog
*/
public function __construct(
Address $address,
@@ -280,7 +291,8 @@ public function __construct(
Customer $customer,
AddressRepositoryInterface $customerAddressRepository,
ScopeConfigInterface $scopeConfig,
- \Magento\Framework\Serialize\Serializer\Json $serialize
+ \Magento\Framework\Serialize\Serializer\Json $serialize,
+ ApiLog $apiLog
) {
$this->address = $address;
$this->config = $config;
@@ -303,6 +315,7 @@ public function __construct(
$this->customerAddressRepository = $customerAddressRepository;
$this->scopeConfig = $scopeConfig;
$this->serialize = $serialize;
+ $this->apiLog = $apiLog;
}
/**
@@ -319,6 +332,12 @@ protected function getCustomerById($customerId)
try {
return $this->customerRepository->getById($customerId);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'Tax';
+ $debugLogContext['operation'] = 'Framework_Interaction_Tax';
+ $debugLogContext['function_name'] = 'getCustomerById';
+ $this->apiLog->debugLog($debugLogContext);
return null;
}
}
@@ -435,7 +454,7 @@ protected function convertTaxQuoteDetailsToRequest(
if($serialized_transport && !empty($serialized_transport))
{
$config_transports = $this->serialize->unserialize($serialized_transport);
- if($config_transports && !empty($config_transports))
+ if($config_transports && !empty($config_transports) && count($config_transports) > 0 )
{
foreach($config_transports as $config_transport)
{
@@ -447,6 +466,9 @@ protected function convertTaxQuoteDetailsToRequest(
}
}
}
+ $currencyCode = $quote->getCurrency()->getQuoteCurrencyCode();
+ $shippingAmount = number_format($shippingAddress->getAddress()->getShippingAmount(), '2', '.', ',');
+ $shippingParametersValue = $shipToAddress->getCountry().":".$shipToAddress->getRegion().":".$shippingAddress->getMethod().":".$shippingAmount." ".$currencyCode;
$data = [
'store_id' => $store->getId(),
'commit' => false, // quotes should never be committed
@@ -473,7 +495,10 @@ protected function convertTaxQuoteDetailsToRequest(
),
'transport_parameters'=> true,
'shipping_method' => $this->config::AVATAX_PARAMETERS_TRANSPORT_KEY,
- 'transport_parameters_value' => $transport_parameters_value
+ 'transport_parameters_value' => $transport_parameters_value,
+ 'shipping_parameters'=> true,
+ 'shipping_parameters_name' => $this->config::AVATAX_SHIPPING_PARAMETERS_NAME,
+ 'shipping_parameters_value' => $shippingParametersValue
];
if (!empty($billToAddress) && !empty($billToAddress->getPostalCode()) && !empty($billToAddress->getCountry())) {
@@ -571,6 +596,13 @@ public function getTaxRequestForQuote(
$validatedData = $this->metaDataObject->validateData($request->getData());
$request->setData($validatedData);
} catch (ValidationException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'Tax';
+ $debugLogContext['operation'] = 'Framework_Interaction_Tax';
+ $debugLogContext['function_name'] = 'getTaxRequestForQuote';
+ $this->apiLog->debugLog($debugLogContext);
+
$this->avaTaxLogger->error('Error validating data: ' . $e->getMessage(), [
'data' => var_export($request->getData(), true)
]);
@@ -703,24 +735,35 @@ public function getTaxRequestForSalesObject($object) {
$orderIncrementId = $order->getIncrementId();
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
// Do nothing
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'Tax';
+ $debugLogContext['operation'] = 'Framework_Interaction_Tax';
+ $debugLogContext['function_name'] = 'getTaxRequestForSalesObject';
+ $this->apiLog->debugLog($debugLogContext);
}
$storeId = $order->getStoreId();
$serialized_transport = $this->config->getVATTransport($storeId);
$shipping_method = $order->getShippingMethod();
- $config_transports = $this->serialize->unserialize($serialized_transport);
$transport_parameters_value = $this->config::AVATAX_PARAMETERS_TRANSPORT_DEFAULT_VALUE;
- if($config_transports && !empty($config_transports))
+ if($serialized_transport && !empty($serialized_transport))
{
- foreach($config_transports as $config_transport)
+ $config_transports = $this->serialize->unserialize($serialized_transport);
+ if( $config_transports && !empty($config_transports) && count($config_transports) > 0 )
{
- if($shipping_method == $config_transport['transport_shipping'])
+ foreach($config_transports as $config_transport)
{
- $transport_parameters_value = $config_transport['transport'];
- break;
- }
+ if($shipping_method == $config_transport['transport_shipping'])
+ {
+ $transport_parameters_value = $config_transport['transport'];
+ break;
+ }
+ }
}
}
-
+ $currencyCode = $order->getOrderCurrencyCode();
+ $shippingAmount = number_format($order->getShippingAmount(), '2', '.', ',');
+ $shippingParametersValue = $shipToAddress->getCountry().":".$shipToAddress->getRegion().":".$order->getShippingMethod().":".$shippingAmount." ".$currencyCode;
$data = [
'store_id' => $store->getId(),
'commit' => $this->config->getCommitSubmittedTransactions($store),
@@ -746,7 +789,10 @@ public function getTaxRequestForSalesObject($object) {
'reference_code' => $orderIncrementId,
'transport_parameters'=> true,
'shipping_method' => $this->config::AVATAX_PARAMETERS_TRANSPORT_KEY,
- 'transport_parameters_value' => $transport_parameters_value
+ 'transport_parameters_value' => $transport_parameters_value,
+ 'shipping_parameters'=> true,
+ 'shipping_parameters_name' => $this->config::AVATAX_SHIPPING_PARAMETERS_NAME,
+ 'shipping_parameters_value' => $shippingParametersValue
];
if(!empty($billToAddress) && !empty($billToAddress->getPostalCode()) && !empty($billToAddress->getCountry()))
@@ -765,6 +811,12 @@ public function getTaxRequestForSalesObject($object) {
$validatedData = $this->metaDataObject->validateData($request->getData());
$request->setData($validatedData);
} catch (ValidationException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'Tax';
+ $debugLogContext['operation'] = 'Framework_Interaction_Tax';
+ $debugLogContext['function_name'] = 'getTaxRequestForSalesObject';
+ $this->apiLog->debugLog($debugLogContext);
$this->avaTaxLogger->error('Error validating data: ' . $e->getMessage(), [
'data' => var_export($request->getData(), true)
]);
@@ -787,6 +839,12 @@ protected function getInvoice($invoiceId)
try {
return $this->invoiceRepository->get($invoiceId);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $e->getMessage();
+ $debugLogContext['source'] = 'Tax';
+ $debugLogContext['operation'] = 'Framework_Interaction_Tax';
+ $debugLogContext['function_name'] = 'getInvoice';
+ $this->apiLog->debugLog($debugLogContext);
return null;
}
}
@@ -851,6 +909,12 @@ protected function getBusinessIdentificationNumber($store, $address, $customer)
}
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
// No actions needed
+ $debugLogContext = [];
+ $debugLogContext['message'] = $exception->getMessage();
+ $debugLogContext['source'] = 'Tax';
+ $debugLogContext['operation'] = 'Framework_Interaction_Tax';
+ $debugLogContext['function_name'] = 'getBusinessIdentificationNumber';
+ $this->apiLog->debugLog($debugLogContext);
}
}
if ($customer && $customer->getTaxvat()) {
diff --git a/Helper/ApiLog.php b/Helper/ApiLog.php
index 8380debf..6801f08d 100644
--- a/Helper/ApiLog.php
+++ b/Helper/ApiLog.php
@@ -24,9 +24,9 @@ class ApiLog extends AbstractHelper
{
const CONNECTOR_ID = 'a0o5a000007TuRvAAK'; //Do not change this value as this is whitlisted for logging
- const CONNECTOR_STRING = AppInterface::CONNECTOR_STRING;
-
- const CONNECTOR_NAME = AppInterface::APP_NAME;
+ const APP_VERSION = AppInterface::APP_VERSION;
+ const APP_NAME = AppInterface::APP_NAME;
+ const CONNECTOR_NAME = AppInterface::CONNECTOR_NAME;
const HTML_ESCAPE_PATTERN = '/<(.*) ?.*>(.*)<\/(.*)>/';
@@ -69,7 +69,9 @@ public function apiLog(string $message, array $context = [], $scopeId = null, $s
$accountNumber = $this->config->getAccountNumber($scopeId, $scopeType, $isProduction);
$accountSecret = $this->config->getLicenseKey($scopeId, $scopeType, $isProduction);
$connectorId = self::CONNECTOR_ID;
- $clientString = self::CONNECTOR_STRING;
+ $clientString = self::APP_NAME;
+ $connectorVersion = self::APP_VERSION;
+
$mode = $isProduction ? \ClassyLlama\AvaTax\BaseProvider\Helper\Generic\Config::API_MODE_PRODUCTION : \ClassyLlama\AvaTax\BaseProvider\Helper\Generic\Config::API_MODE_SANDBOX;
$connectorName = self::CONNECTOR_NAME;
$source = isset($context['config']['source']) ? $context['config']['source'] : 'MagentoPage';
@@ -86,7 +88,7 @@ public function apiLog(string $message, array $context = [], $scopeId = null, $s
'client_string' => $clientString,
'mode' => $mode,
'connector_name' => $connectorName,
- 'connector_version' => $clientString,
+ 'connector_version' => $connectorVersion,
'source' => $source,
'operation' => $operation,
'log_type' => $logType,
@@ -130,7 +132,41 @@ public function testConnectionLog(string $message, $scopeId, $scopeType)
//do nothing as this is internal logging
}
}
-
+ /**
+ * Debug Log with AvaTax
+ *
+ * @param array $logContext
+ * @param $scopeId
+ * @param $scopeType
+ * @return void
+ */
+ public function debugLog(
+ array $logContext,
+ $scopeId = null,
+ $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE
+ )
+ {
+ try {
+ $message = isset($logContext['message']) ? $logContext['message'] : 'Debug Log : Exception Occured.';
+ $method = isset($logContext['method']) ? $logContext['method'] : __METHOD__;
+ $source = isset($logContext['source']) ? $logContext['source'] : 'TransactionPage';
+ $operation = isset($logContext['operation']) ? $logContext['operation'] : 'TransactionOperation';
+ $logType = \ClassyLlama\AvaTax\BaseProvider\Helper\Generic\Config::API_LOG_TYPE_CONFIG;
+ $logLevel = \ClassyLlama\AvaTax\BaseProvider\Helper\Generic\Config::API_LOG_LEVEL_EXCEPTION;
+ $context = [
+ 'config' => [
+ 'source' => $source,
+ 'operation' => $operation,
+ 'log_type' => $logType,
+ 'log_level' => $logLevel,
+ 'function_name' => $method
+ ]
+ ];
+ $this->apiLog($message, $context, $scopeId, $scopeType);
+ } catch(\Exception $e) {
+ //do nothing as this is internal logging
+ }
+ }
/**
* configSaveLog API Logging
*
@@ -175,13 +211,6 @@ public function configSaveLog($scopeId, $scopeType)
public function makeTransactionRequestLog(array $logContext, $scopeId, $scopeType)
{
try {
- $message = "Transaction Request Log";
- if (isset($logContext['extra']['amount'])) {
- $message .= " Total: ".$logContext['extra']['amount'];
- }
- if (isset($logContext['extra']['tax'])) {
- $message .= " Tax: ".$logContext['extra']['tax'];
- }
$source = isset($logContext['source']) ? $logContext['source'] : 'TransactionPage';
$operation = isset($logContext['operation']) ? $logContext['operation'] : 'TransactionOperation';
$logType = \ClassyLlama\AvaTax\BaseProvider\Helper\Generic\Config::API_LOG_TYPE_PERFORMANCE;
@@ -206,6 +235,20 @@ public function makeTransactionRequestLog(array $logContext, $scopeId, $scopeTyp
'extra_params' => isset($logContext['extra']) ? $logContext['extra'] : []
]
];
+ $message = "CONNECTORMETRICS";
+ $message .= ", TYPE - getTax";
+ if (isset($logContext['extra']['DocCode'])) {
+ $message .= ", DocCode - ".$logContext['extra']['DocCode'];
+ }
+ if (isset($logContext['extra']['LineCount'])) {
+ $message .= ", LineCount - ".$logContext['extra']['LineCount'];
+ }
+ if (isset($logContext['extra']['ConnectorTime'])) {
+ $message .= ", ConnectorTime - ".$logContext['extra']['ConnectorTime'];
+ }
+ if (isset($logContext['extra']['ConnectorLatency'])) {
+ $message .= ", ConnectorLatency - ".$logContext['extra']['ConnectorLatency'];
+ }
$this->apiLog($message, $context, $scopeId, $scopeType);
} catch(\Exception $e) {
//do nothing as this is internal logging
diff --git a/Helper/CertificateHelper.php b/Helper/CertificateHelper.php
index d8983fca..6046281b 100644
--- a/Helper/CertificateHelper.php
+++ b/Helper/CertificateHelper.php
@@ -81,21 +81,21 @@ public function __construct(
}
/**
- * Build url for certificate delete action.
+ * Build url for certificate unlink action.
*
* @param $certificateId
* @param $customerId
*
* @return string
*/
- public function getCertificateDeleteUrl($certificateId, $customerId)
+ public function getCertificateUnlinkUrl($certificateId, $customerId)
{
$params = [
'certificate_id' => $certificateId,
'customer_id' => $customerId
];
- return $this->urlBuilder->getUrl('avatax/certificates/delete', $params);
+ return $this->urlBuilder->getUrl('avatax/certificates/unlink', $params);
}
/**
diff --git a/Helper/CertificateUnlinkHelper.php b/Helper/CertificateUnlinkHelper.php
new file mode 100644
index 00000000..9b7276f9
--- /dev/null
+++ b/Helper/CertificateUnlinkHelper.php
@@ -0,0 +1,115 @@
+request = $request;
+ $this->customerRepository = $customerRepository;
+ $this->customerRest = $customerRest;
+ $this->dataObjectFactory = $dataObjectFactory;
+ $this->messageManager = $messageManager;
+ $this->taxCache = $taxCache;
+ }
+
+ /**
+ * Handle a certificate invalidate (unlink) request.
+ */
+ public function unlink()
+ {
+ try {
+ $customerId = $this->request->getParam('customer_id');
+ $certificateId = $this->request->getParam('certificate_id');
+ $storeId = null;
+
+ // If we have specified a customer ID, use the store that user is associated with, otherwise default to session
+ if ($customerId !== null) {
+ $customerModel = $this->customerRepository->getById($customerId);
+ $storeId = $customerModel->getStoreId();
+ }
+
+ //try to unlink cert. Any/all errors during process caught below.
+ $this->customerRest->unlinkCertificate(
+ $this->dataObjectFactory->create(
+ ['data' => [
+ 'certificate_id' => $certificateId,
+ 'customer_id' => $customerId
+ ]]
+ ),
+ null,
+ $storeId
+ );
+ // Ensure that all caches for tax calculation have been cleared for this customer to ensure accurate tax
+ // during checkout
+ $this->taxCache->clearCacheByCustomerId($customerId);
+
+ $this->messageManager->addSuccessMessage(__('Your certificate has been successfully invalidated.'));
+ } catch (\Exception $e) {
+ $this->messageManager->addErrorMessage(__('There was a problem invalidating your certificate.'));
+ }
+ }
+}
diff --git a/Helper/Config.php b/Helper/Config.php
index 9ead5db1..efb82514 100644
--- a/Helper/Config.php
+++ b/Helper/Config.php
@@ -165,6 +165,7 @@ class Config extends AbstractHelper
const XML_PATH_AVATAX_ADVANCED_AVATAX_TABLE_EXEMPTIONS = 'tax/avatax_advanced/avatax_table_exemptions';
const XML_PATH_AVATAX_VAT_TRANSPORT = 'tax/avatax_general/vat_transport';
+
/**
* Tax Calculation API parameters tag default value
*/
@@ -175,6 +176,11 @@ class Config extends AbstractHelper
const AVATAX_PARAMETERS_TRANSPORT_DEFAULT_VALUE = 'Seller';
/**#@-*/
+ /**
+ * Tax Calculation API shipping parameters name
+ */
+ const AVATAX_SHIPPING_PARAMETERS_NAME = 'Shipping';
+
/**
* List of countries that are enabled by default
*/
diff --git a/Helper/DocumentManagementConfig.php b/Helper/DocumentManagementConfig.php
index d2c59f7d..b6312b6a 100644
--- a/Helper/DocumentManagementConfig.php
+++ b/Helper/DocumentManagementConfig.php
@@ -33,6 +33,7 @@ class DocumentManagementConfig extends AbstractHelper
const XML_PATH_CERTCAPTURE_AUTO_VALIDATION = 'tax/avatax_certificate_capture/disable_certcapture_auto_validation';
/**
+ * code for check certcapture enable
* @param int|null $store
* @param string|null $scopeType
*
diff --git a/Model/BatchQueueTransactionRepository.php b/Model/BatchQueueTransactionRepository.php
index 9703c90d..15ce134c 100644
--- a/Model/BatchQueueTransactionRepository.php
+++ b/Model/BatchQueueTransactionRepository.php
@@ -25,6 +25,9 @@
*
* @package ClassyLlama\AvaTax\Model
*/
+/**
+ * @codeCoverageIgnore
+ */
class BatchQueueTransactionRepository implements BatchQueueTransactionRepositoryInterface
{
/**
diff --git a/Model/Certificates.php b/Model/Certificates.php
index 8b2664f6..79bace74 100755
--- a/Model/Certificates.php
+++ b/Model/Certificates.php
@@ -86,10 +86,11 @@ private function prepareCertificateURLs(array $certificates = [], int $userId =
foreach ($certificates as $certificate) {
/** @var string $viewUrl */
$viewUrl = (string)$this->certificateHelper->getCertificateUrl($certificate->getData('id'), $userId);
- /** @var string $deleteUrl */
- $deleteUrl = (string)$this->certificateHelper->getCertificateDeleteUrl($certificate->getData('id'), $userId);
+ /** @var string $invalidateUrl */
+ //code for invalidate url update
+ $invalidateUrl = (string)$this->certificateHelper->getCertificateUnlinkUrl($certificate->getData('id'), $userId);
$certificate->setData('certificate_url', $viewUrl);
- $certificate->setData('certificate_delete_url', $deleteUrl);
+ $certificate->setData('certificate_invalidate_url', $invalidateUrl);
}
}
return $certificates;
diff --git a/Model/Config/Backend/ConnectorStatus.php b/Model/Config/Backend/ConnectorStatus.php
new file mode 100644
index 00000000..e1f87100
--- /dev/null
+++ b/Model/Config/Backend/ConnectorStatus.php
@@ -0,0 +1,61 @@
+_cache = $cache;
+ parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
+ }
+
+ /**
+ * @return $this
+ */
+ public function afterSave()
+ {
+ $this->_cache->clean([\Magento\Backend\Block\Menu::CACHE_TAGS]);
+ return parent::afterSave();
+ }
+}
diff --git a/Model/Log.php b/Model/Log.php
index 41fbca62..f23f5837 100644
--- a/Model/Log.php
+++ b/Model/Log.php
@@ -29,6 +29,9 @@
* @method string getResult() getResult()
* @method string getAdditional() getAdditional()
*/
+/**
+ * @codeCoverageIgnore
+ */
class Log extends AbstractModel
{
/**
diff --git a/Model/Logger/FileFormatter.php b/Model/Logger/FileFormatter.php
index 05f93f66..f5cde9b0 100644
--- a/Model/Logger/FileFormatter.php
+++ b/Model/Logger/FileFormatter.php
@@ -47,14 +47,14 @@ public function format(array $record): string
$output = $this->format;
foreach ($vars['extra'] as $var => $val) {
- if (false !== strpos($output, '%extra.'.$var.'%')) {
+ if (false !== strpos((string)$output, (string)'%extra.'.$var.'%')) {
$output = str_replace('%extra.' . $var . '%', var_export($val, true), $output);
unset($vars['extra'][$var]);
}
}
foreach ($vars as $var => $val) {
- if (false !== strpos($output, '%'.$var.'%')) {
+ if (false !== strpos((string)$output, (string)'%'.$var.'%')) {
$val_output = '';
if ((is_array($val) && count($val) > 0) || is_array($val) === false) {
$val_output = var_export($val, true);
diff --git a/Model/Order/Creditmemo/Total/AvataxAdjustmentTaxes.php b/Model/Order/Creditmemo/Total/AvataxAdjustmentTaxes.php
index 9ef3470c..ae992f86 100755
--- a/Model/Order/Creditmemo/Total/AvataxAdjustmentTaxes.php
+++ b/Model/Order/Creditmemo/Total/AvataxAdjustmentTaxes.php
@@ -15,6 +15,7 @@
use ClassyLlama\AvaTax\Model\Logger\AvaTaxLogger;
use ClassyLlama\AvaTax\Framework\Interaction\Rest\Tax\Result as RestTaxResult;
use ClassyLlama\AvaTax\Framework\Interaction\Line as FrameworkInteractionLine;
+use ClassyLlama\AvaTax\Helper\Config;
/**
* Class AvataxAdjustmentTaxes
@@ -60,7 +61,10 @@ class AvataxAdjustmentTaxes extends AbstractTotal
* @var AvaTaxLogger
*/
private $avataxLogger;
-
+ /**
+ * @var Config
+ */
+ protected $config = null;
/**
* AvataxAdjustmentTaxes constructor.
* @param AvaTaxLogger $avataxLogger
@@ -68,6 +72,7 @@ class AvataxAdjustmentTaxes extends AbstractTotal
* @param CreditmemoRequestBuilder $creditmemoRequestBuilder
* @param StoreManagerInterface $storeManager
* @param ScopeConfigInterface $scopeConfig
+ * @param Config $config
* @param array $data
*/
public function __construct(
@@ -76,6 +81,7 @@ public function __construct(
CreditmemoRequestBuilder $creditmemoRequestBuilder,
StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig,
+ Config $config,
array $data = []
) {
parent::__construct($data);
@@ -84,6 +90,7 @@ public function __construct(
$this->creditmemoRequestBuilder = $creditmemoRequestBuilder;
$this->taxCompositeService = $taxCompositeService;
$this->avataxLogger = $avataxLogger;
+ $this->config = $config;
}
/**
@@ -94,15 +101,22 @@ public function __construct(
*/
public function collect(Creditmemo $creditmemo): self
{
- if ($this->isTaxCalculationEnabledForAdjustments() && $this->adjustmentsAreNotEmpty($creditmemo)) {
+ /** @var int $storeId */
+ $storeId = (int)$creditmemo->getStoreId();
+ if ( ( $this->isTaxCalculationEnabledForAdjustments() && $this->adjustmentsAreNotEmpty($creditmemo) ) ||
+ ( !$this->isTaxCalculationEnabledForAdjustments() && $this->config->getTaxationPolicy($storeId) && $this->adjustmentsAreNotEmpty($creditmemo) )
+ )
+ {
+ // If isTaxCalculationEnabledForAdjustments : Yes, adjustmentsAreNotEmpty : true
+ // OR
+ // isTaxCalculationEnabledForAdjustments : No, getTaxationPolicy : Gross, adjustmentsAreNotEmpty : true
try {
/** @var CreditmemoRequest|null $creditmemoRequest */
$creditmemoRequest = $this->creditmemoRequestBuilder->build($creditmemo);
if (null !== $creditmemoRequest) {
- /** @var int $storeId */
- $storeId = (int)$creditmemo->getStoreId();
+
/** @var RestTaxResult $response */
$response = $this->taxCompositeService->calculateTax(
$creditmemoRequest,
@@ -111,11 +125,15 @@ public function collect(Creditmemo $creditmemo): self
[RestTaxInterface::FLAG_FORCE_NEW_RATES => true],
null
);
- $this->avataxLogger->debug(
- 'response',
- [
- 'lines' => print_r($response->getLines() ?? [], true)]
- );
+
+ $getTaxResultData = $response->getData('raw_result');
+ $getTaxRequestData = $response->getData('raw_request');
+ $this->avataxLogger->addDebug('Credit Memo API log | Date : '.$response->getDate().' | Tax Total : '.$response->getTotalTax(), [
+ 'request' => json_encode($getTaxRequestData, JSON_PRETTY_PRINT),
+ 'result' => json_encode($getTaxResultData, JSON_PRETTY_PRINT)
+ ]);
+
+
/** @var float|null $adjustmentRefundTax */
$adjustmentRefundTax = $baseAdjustmentRefundTax = (float)$this->getAdjustmentRefundTaxes($this->getCreditmemoTaxesForAdjustments($response));
/** @var float|null $adjustmentFeeTax */
@@ -128,6 +146,19 @@ public function collect(Creditmemo $creditmemo): self
*/
$creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $adjustmentRefundTax - $adjustmentFeeTax);
$creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseAdjustmentRefundTax - $baseAdjustmentFeeTax);
+ $existingTax = $creditmemo->getTaxAmount();
+ $existingBaseTax = $creditmemo->getBaseTaxAmount();
+ $existingDiscountTaxCompensationAmount = $creditmemo->getDiscountTaxCompensationAmount();
+ $existingBaseDiscountTaxCompensationAmount = $creditmemo->getBaseDiscountTaxCompensationAmount();
+ if ($this->config->getTaxationPolicy($storeId))
+ { // if taxation policy is set to : Gross and adjustments are NOT EMPTY
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $existingDiscountTaxCompensationAmount - $existingTax + $adjustmentRefundTax - $adjustmentFeeTax);
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $existingBaseDiscountTaxCompensationAmount - $existingBaseTax + $adjustmentRefundTax - $adjustmentFeeTax);
+ }else
+ { // if taxation policy is set to : Net and adjustments are NOT EMPTY
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $adjustmentRefundTax - $adjustmentFeeTax);
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $adjustmentRefundTax - $adjustmentFeeTax);
+ }
}
} catch (\Throwable $exception) {
$this->avataxLogger->error($exception->getMessage(), [
@@ -135,8 +166,16 @@ public function collect(Creditmemo $creditmemo): self
'trace' => $exception->getTraceAsString()
]);
}
+ } else if ( $this->config->getTaxationPolicy($storeId) && !$this->adjustmentsAreNotEmpty($creditmemo) )
+ { // if isTaxCalculationEnabledForAdjustments is Yes, Taxation Policy is set to : Gross and adjustments are EMPTY
+ $existingTax = $creditmemo->getTaxAmount();
+ $existingBaseTax = $creditmemo->getBaseTaxAmount();
+ $existingDiscountTaxCompensationAmount = $creditmemo->getDiscountTaxCompensationAmount();
+ $existingBaseDiscountTaxCompensationAmount = $creditmemo->getBaseDiscountTaxCompensationAmount();
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $existingDiscountTaxCompensationAmount - $existingTax);
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $existingBaseDiscountTaxCompensationAmount - $existingBaseTax);
}
-
+
return $this;
}
diff --git a/Model/Queue/Processing/NormalProcessing.php b/Model/Queue/Processing/NormalProcessing.php
index 9b08f0a2..42e3f6fa 100644
--- a/Model/Queue/Processing/NormalProcessing.php
+++ b/Model/Queue/Processing/NormalProcessing.php
@@ -81,7 +81,6 @@ public function __construct(
public function execute()
{
- $this->avaTaxLogger->debug(__('Starting Normal Queue processing'));
// Initialize the queue collection
$queueCollection = $this->queueCollectionFactory->create();
$queueCollection->addQueueStatusFilter(Queue::QUEUE_STATUS_PENDING)
diff --git a/Model/Queue/Task.php b/Model/Queue/Task.php
index 23b5df92..8c38921e 100644
--- a/Model/Queue/Task.php
+++ b/Model/Queue/Task.php
@@ -154,7 +154,6 @@ public function getDeleteFailedCount()
*/
public function cronProcessQueue()
{
- $this->avaTaxLogger->debug(__('Initiating queue processing from cron job'));
$this->processPendingQueue();
$this->resetHungQueuedRecords();
}
@@ -166,7 +165,6 @@ public function cronProcessQueue()
*/
public function processPendingQueue($limit = false)
{
- $this->avaTaxLogger->debug(__('Starting queue processing'));
$this->queueProcessor->setLimit($limit);
$this->queueProcessor->execute();
$this->errorMessages = $this->queueProcessor->getErrorMessages();
@@ -181,10 +179,6 @@ public function processPendingQueue($limit = false)
$context['error_messages'] = implode("\n", $this->getErrorMessages());
}
- $this->avaTaxLogger->debug(
- __('Finished queue processing'),
- $context
- );
}
/**
@@ -193,8 +187,6 @@ public function processPendingQueue($limit = false)
*/
public function resetHungQueuedRecords()
{
- $this->avaTaxLogger->debug(__('Resetting hung queue records'));
-
// Initialize the queue collection
$queueCollection = $this->queueCollectionFactory->create();
$queueCollection->addQueueStatusFilter(Queue::QUEUE_STATUS_PROCESSING);
@@ -208,13 +200,15 @@ public function resetHungQueuedRecords()
try {
$this->resetCount = $queueCollection->updateTableRecords($condition,
['queue_status' => Queue::QUEUE_STATUS_PENDING]);
-
- $this->avaTaxLogger->debug(
- __('Finished resetting hung queued records'),
- [ /* context */
- 'reset_count' => $this->resetCount
- ]
- );
+ if($this->resetCount > 0)
+ {
+ $this->avaTaxLogger->debug(
+ __('Finished resetting hung queued records'),
+ [ /* context */
+ 'reset_count' => $this->resetCount
+ ]
+ );
+ }
} catch (Zend_Db_Select_Exception $exception) {
$this->avaTaxLogger->error($exception->getMessage());
}
diff --git a/Model/QueueRepository.php b/Model/QueueRepository.php
index eb054c0a..7dd096ed 100644
--- a/Model/QueueRepository.php
+++ b/Model/QueueRepository.php
@@ -14,6 +14,9 @@
*
* @package ClassyLlama\AvaTax\Model
*/
+/**
+ * @codeCoverageIgnore
+ */
class QueueRepository implements QueueRepositoryInterface
{
/**
diff --git a/Model/ResourceModel/BatchQueue/Collection.php b/Model/ResourceModel/BatchQueue/Collection.php
index 06eb58b2..6bb9fd78 100644
--- a/Model/ResourceModel/BatchQueue/Collection.php
+++ b/Model/ResourceModel/BatchQueue/Collection.php
@@ -23,6 +23,9 @@
*
* @package ClassyLlama\AvaTax\Model\ResourceModel\BatchQueue
*/
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends AbstractCollection
{
/**
diff --git a/Model/ResourceModel/BatchQueueTransaction.php b/Model/ResourceModel/BatchQueueTransaction.php
index 3158eb34..f30ffc12 100644
--- a/Model/ResourceModel/BatchQueueTransaction.php
+++ b/Model/ResourceModel/BatchQueueTransaction.php
@@ -11,6 +11,9 @@
*
* @package ClassyLlama\AvaTax\Model\ResourceModel
*/
+/**
+ * @codeCoverageIgnore
+ */
class BatchQueueTransaction extends AbstractDb
{
/**
diff --git a/Model/ResourceModel/Config.php b/Model/ResourceModel/Config.php
index 6354e3d9..5449968f 100644
--- a/Model/ResourceModel/Config.php
+++ b/Model/ResourceModel/Config.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel;
+/**
+ * @codeCoverageIgnore
+ */
class Config extends \Magento\Config\Model\ResourceModel\Config
{
/**
diff --git a/Model/ResourceModel/CreditMemo.php b/Model/ResourceModel/CreditMemo.php
index bc84d144..ae10042f 100644
--- a/Model/ResourceModel/CreditMemo.php
+++ b/Model/ResourceModel/CreditMemo.php
@@ -6,6 +6,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel;
+/**
+ * @codeCoverageIgnore
+ */
class CreditMemo extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**#@+
diff --git a/Model/ResourceModel/CrossBorderClass.php b/Model/ResourceModel/CrossBorderClass.php
index 9eba9df4..316813be 100644
--- a/Model/ResourceModel/CrossBorderClass.php
+++ b/Model/ResourceModel/CrossBorderClass.php
@@ -22,6 +22,9 @@
use ClassyLlama\AvaTax\Model\ResourceModel\CrossBorderClass\CountryLinkFactory as CountryLinkResourceFactory;
use ClassyLlama\AvaTax\Model\CrossBorderClass\CountryLinkFactory;
+/**
+ * @codeCoverageIgnore
+ */
class CrossBorderClass extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
diff --git a/Model/ResourceModel/CrossBorderClass/Collection.php b/Model/ResourceModel/CrossBorderClass/Collection.php
index 92dedce6..6765f532 100644
--- a/Model/ResourceModel/CrossBorderClass/Collection.php
+++ b/Model/ResourceModel/CrossBorderClass/Collection.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\CrossBorderClass;
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
diff --git a/Model/ResourceModel/CrossBorderClass/CountryLink.php b/Model/ResourceModel/CrossBorderClass/CountryLink.php
index 941086e2..5a31fd72 100644
--- a/Model/ResourceModel/CrossBorderClass/CountryLink.php
+++ b/Model/ResourceModel/CrossBorderClass/CountryLink.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\CrossBorderClass;
+/**
+ * @codeCoverageIgnore
+ */
class CountryLink extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
diff --git a/Model/ResourceModel/CrossBorderClass/CountryLink/Collection.php b/Model/ResourceModel/CrossBorderClass/CountryLink/Collection.php
index 85233cc7..6815949c 100644
--- a/Model/ResourceModel/CrossBorderClass/CountryLink/Collection.php
+++ b/Model/ResourceModel/CrossBorderClass/CountryLink/Collection.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\CrossBorderClass\CountryLink;
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
diff --git a/Model/ResourceModel/CrossBorderClass/Grid/Collection.php b/Model/ResourceModel/CrossBorderClass/Grid/Collection.php
index d4a2b2d2..6d58f76f 100644
--- a/Model/ResourceModel/CrossBorderClass/Grid/Collection.php
+++ b/Model/ResourceModel/CrossBorderClass/Grid/Collection.php
@@ -27,6 +27,9 @@
use ClassyLlama\AvaTax\Api\Data\CrossBorderClassRepositoryInterface;
use ClassyLlama\AvaTax\Api\Data\CrossBorderClassInterface;
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends SearchResult
{
/**
diff --git a/Model/ResourceModel/CrossBorderType.php b/Model/ResourceModel/CrossBorderType.php
index ad66bdc8..55030bb0 100644
--- a/Model/ResourceModel/CrossBorderType.php
+++ b/Model/ResourceModel/CrossBorderType.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel;
+/**
+ * @codeCoverageIgnore
+ */
class CrossBorderType extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
diff --git a/Model/ResourceModel/CrossBorderType/Collection.php b/Model/ResourceModel/CrossBorderType/Collection.php
index d430ddaf..9b9c024f 100644
--- a/Model/ResourceModel/CrossBorderType/Collection.php
+++ b/Model/ResourceModel/CrossBorderType/Collection.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\CrossBorderType;
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
diff --git a/Model/ResourceModel/Invoice.php b/Model/ResourceModel/Invoice.php
index 02435a77..ecd1168a 100644
--- a/Model/ResourceModel/Invoice.php
+++ b/Model/ResourceModel/Invoice.php
@@ -6,6 +6,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel;
+/**
+ * @codeCoverageIgnore
+ */
class Invoice extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**#@+
diff --git a/Model/ResourceModel/Log.php b/Model/ResourceModel/Log.php
index 0965e321..7477569e 100644
--- a/Model/ResourceModel/Log.php
+++ b/Model/ResourceModel/Log.php
@@ -20,6 +20,9 @@
/**
* Log
*/
+/**
+ * @codeCoverageIgnore
+ */
class Log extends AbstractDb
{
/**#@+
diff --git a/Model/ResourceModel/Log/Collection.php b/Model/ResourceModel/Log/Collection.php
index 22b06bf9..660b38be 100644
--- a/Model/ResourceModel/Log/Collection.php
+++ b/Model/ResourceModel/Log/Collection.php
@@ -25,6 +25,9 @@
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magento\Framework\Stdlib\DateTime;
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends AbstractCollection
{
/**
diff --git a/Model/ResourceModel/Order/Creditmemo/Item.php b/Model/ResourceModel/Order/Creditmemo/Item.php
index ffb802c2..705c5767 100644
--- a/Model/ResourceModel/Order/Creditmemo/Item.php
+++ b/Model/ResourceModel/Order/Creditmemo/Item.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\Order\Creditmemo;
+/**
+ * @codeCoverageIgnore
+ */
class Item extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
diff --git a/Model/ResourceModel/Order/Creditmemo/Item/Collection.php b/Model/ResourceModel/Order/Creditmemo/Item/Collection.php
index bb721d92..edd2d003 100644
--- a/Model/ResourceModel/Order/Creditmemo/Item/Collection.php
+++ b/Model/ResourceModel/Order/Creditmemo/Item/Collection.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\Order\Creditmemo\Item;
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
diff --git a/Model/ResourceModel/Order/Invoice/Item.php b/Model/ResourceModel/Order/Invoice/Item.php
index 33b81b62..e5bb76ea 100644
--- a/Model/ResourceModel/Order/Invoice/Item.php
+++ b/Model/ResourceModel/Order/Invoice/Item.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\Order\Invoice;
+/**
+ * @codeCoverageIgnore
+ */
class Item extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
diff --git a/Model/ResourceModel/Order/Invoice/Item/Collection.php b/Model/ResourceModel/Order/Invoice/Item/Collection.php
index 21872411..ef377a8d 100644
--- a/Model/ResourceModel/Order/Invoice/Item/Collection.php
+++ b/Model/ResourceModel/Order/Invoice/Item/Collection.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\Order\Invoice\Item;
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
diff --git a/Model/ResourceModel/Order/Item.php b/Model/ResourceModel/Order/Item.php
index aabe0ce4..bb675b1c 100644
--- a/Model/ResourceModel/Order/Item.php
+++ b/Model/ResourceModel/Order/Item.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\Order;
+/**
+ * @codeCoverageIgnore
+ */
class Item extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
diff --git a/Model/ResourceModel/Order/Item/Collection.php b/Model/ResourceModel/Order/Item/Collection.php
index 47d4bdba..7020c1e6 100644
--- a/Model/ResourceModel/Order/Item/Collection.php
+++ b/Model/ResourceModel/Order/Item/Collection.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\Order\Item;
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
diff --git a/Model/ResourceModel/Queue.php b/Model/ResourceModel/Queue.php
index ad1780ed..81e5a84e 100644
--- a/Model/ResourceModel/Queue.php
+++ b/Model/ResourceModel/Queue.php
@@ -23,6 +23,9 @@
/**
* Queue
*/
+/**
+ * @codeCoverageIgnore
+ */
class Queue extends AbstractDb
{
/**#@+
diff --git a/Model/ResourceModel/Queue/Collection.php b/Model/ResourceModel/Queue/Collection.php
index 56240217..e45891e3 100644
--- a/Model/ResourceModel/Queue/Collection.php
+++ b/Model/ResourceModel/Queue/Collection.php
@@ -30,6 +30,9 @@
use Zend_Db_Expr;
use Magento\Framework\DB\Select;
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends AbstractCollection
{
/**#@+
diff --git a/Model/ResourceModel/Quote/Item.php b/Model/ResourceModel/Quote/Item.php
index e005c305..00551ef1 100644
--- a/Model/ResourceModel/Quote/Item.php
+++ b/Model/ResourceModel/Quote/Item.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\Quote;
+/**
+ * @codeCoverageIgnore
+ */
class Item extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
diff --git a/Model/ResourceModel/Quote/Item/Collection.php b/Model/ResourceModel/Quote/Item/Collection.php
index 3b263839..1f236d13 100644
--- a/Model/ResourceModel/Quote/Item/Collection.php
+++ b/Model/ResourceModel/Quote/Item/Collection.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Model\ResourceModel\Quote\Item;
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
diff --git a/Model/ResourceModel/Tax/Classes/Customer.php b/Model/ResourceModel/Tax/Classes/Customer.php
index 4f3120f6..8102a128 100644
--- a/Model/ResourceModel/Tax/Classes/Customer.php
+++ b/Model/ResourceModel/Tax/Classes/Customer.php
@@ -20,6 +20,9 @@
/**
* Class Customer
*/
+/**
+ * @codeCoverageIgnore
+ */
class Customer extends AbstractDb
{
/**
diff --git a/Model/ResourceModel/Tax/Classes/Customer/Collection.php b/Model/ResourceModel/Tax/Classes/Customer/Collection.php
index b9a5d4de..adc1d03d 100644
--- a/Model/ResourceModel/Tax/Classes/Customer/Collection.php
+++ b/Model/ResourceModel/Tax/Classes/Customer/Collection.php
@@ -20,6 +20,9 @@
/**
* Class Collection
*/
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends SearchResult
{
/**
diff --git a/Model/ResourceModel/Tax/Classes/Product.php b/Model/ResourceModel/Tax/Classes/Product.php
index 7c09c1ef..f51e14b8 100644
--- a/Model/ResourceModel/Tax/Classes/Product.php
+++ b/Model/ResourceModel/Tax/Classes/Product.php
@@ -20,6 +20,9 @@
/**
* Class Product
*/
+/**
+ * @codeCoverageIgnore
+ */
class Product extends AbstractDb
{
/**
diff --git a/Model/ResourceModel/Tax/Classes/Product/Collection.php b/Model/ResourceModel/Tax/Classes/Product/Collection.php
index 664548b0..38200391 100644
--- a/Model/ResourceModel/Tax/Classes/Product/Collection.php
+++ b/Model/ResourceModel/Tax/Classes/Product/Collection.php
@@ -20,6 +20,9 @@
/**
* Class Collection
*/
+/**
+ * @codeCoverageIgnore
+ */
class Collection extends SearchResult
{
/**
diff --git a/Model/Token.php b/Model/Token.php
index 23077bcd..2fef77f5 100644
--- a/Model/Token.php
+++ b/Model/Token.php
@@ -18,7 +18,7 @@
use ClassyLlama\AvaTax\Api\Data\SDKTokenInterfaceFactory;
use ClassyLlama\AvaTax\Api\TokenInterface;
use ClassyLlama\AvaTax\Framework\Interaction\Rest;
-
+use ClassyLlama\AvaTax\Helper\ApiLog;
/**
* Class Token
*
@@ -69,7 +69,10 @@ class Token extends Rest implements TokenInterface
* @var \ClassyLlama\AvaTax\Model\Factory\CreateECommerceTokenInputModelFactory
*/
protected $createECommerceTokenInputModelFactory;
-
+ /**
+ * @var ApiLog
+ */
+ protected $apiLog;
/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
@@ -81,6 +84,7 @@ class Token extends Rest implements TokenInterface
* @param \Magento\Framework\DataObjectFactory $dataObjectFactory
* @param \ClassyLlama\AvaTax\Framework\Interaction\Rest\ClientPool $clientPool
* @param \ClassyLlama\AvaTax\Model\Factory\CreateECommerceTokenInputModelFactory $createECommerceTokenInputModelFactory
+ * @param ApiLog $apiLog
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
@@ -92,7 +96,8 @@ public function __construct(
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\DataObjectFactory $dataObjectFactory,
\ClassyLlama\AvaTax\Framework\Interaction\Rest\ClientPool $clientPool,
- \ClassyLlama\AvaTax\Model\Factory\CreateECommerceTokenInputModelFactory $createECommerceTokenInputModelFactory
+ \ClassyLlama\AvaTax\Model\Factory\CreateECommerceTokenInputModelFactory $createECommerceTokenInputModelFactory,
+ ApiLog $apiLog
)
{
parent::__construct($logger, $dataObjectFactory, $clientPool);
@@ -103,6 +108,7 @@ public function __construct(
$this->config = $config;
$this->customerHelper = $customerHelper;
$this->createECommerceTokenInputModelFactory = $createECommerceTokenInputModelFactory;
+ $this->apiLog = $apiLog;
}
/**
@@ -148,6 +154,12 @@ public function getTokenForCustomerId($customerId)
$ECommerceTokenInputModel
);
} catch (\GuzzleHttp\Exception\RequestException $clientException) {
+ $debugLogContext = [];
+ $debugLogContext['message'] = $clientException->getMessage();
+ $debugLogContext['source'] = 'token';
+ $debugLogContext['operation'] = 'Model_Token';
+ $debugLogContext['function_name'] = 'getTokenForCustomerId';
+ $this->apiLog->debugLog($debugLogContext, $scopeId, $scopeType);
// Validate the response; pass the customer id for context in case of an error.
$this->handleException(
$clientException,
diff --git a/Plugin/Checkout/Model/ShippingInformationManagement.php b/Plugin/Checkout/Model/ShippingInformationManagement.php
index 7ad22c70..32dc2bbd 100644
--- a/Plugin/Checkout/Model/ShippingInformationManagement.php
+++ b/Plugin/Checkout/Model/ShippingInformationManagement.php
@@ -34,6 +34,9 @@
/**
* Class ShippingInformationManagement
*/
+/**
+ * @codeCoverageIgnore
+ */
class ShippingInformationManagement
{
/**
@@ -250,8 +253,8 @@ public function aroundSaveAddressInformation(
} catch (NoSuchEntityException $e) {
if (
(
- strpos(strtolower($e->getMessage()), 'carrier') !== false
- || strpos(strtolower($e->getMessage()), 'shipping') !== false
+ strpos((string)strtolower((string)$e->getMessage()), (string)'carrier') !== false
+ || strpos((string)strtolower((string)$e->getMessage()), (string)'shipping') !== false
)
&& strpos(strtolower($e->getMessage()), 'not found') !== false
) {
diff --git a/Plugin/Component/FormPlugin.php b/Plugin/Component/FormPlugin.php
index 26661630..f5d98174 100644
--- a/Plugin/Component/FormPlugin.php
+++ b/Plugin/Component/FormPlugin.php
@@ -7,6 +7,9 @@
namespace ClassyLlama\AvaTax\Plugin\Component;
+/**
+ * @codeCoverageIgnore
+ */
class FormPlugin
{
/**
diff --git a/Plugin/Controller/Account/CreatePostPlugin.php b/Plugin/Controller/Account/CreatePostPlugin.php
index a1003d63..5fb5209b 100644
--- a/Plugin/Controller/Account/CreatePostPlugin.php
+++ b/Plugin/Controller/Account/CreatePostPlugin.php
@@ -15,6 +15,9 @@
namespace ClassyLlama\AvaTax\Plugin\Controller\Account;
+/**
+ * @codeCoverageIgnore
+ */
class CreatePostPlugin
{
/**
diff --git a/Plugin/Data/Collection/ExtensionAttributeCollectionLoader.php b/Plugin/Data/Collection/ExtensionAttributeCollectionLoader.php
index c934656e..e285961d 100644
--- a/Plugin/Data/Collection/ExtensionAttributeCollectionLoader.php
+++ b/Plugin/Data/Collection/ExtensionAttributeCollectionLoader.php
@@ -7,6 +7,9 @@
namespace ClassyLlama\AvaTax\Plugin\Data\Collection;
+/**
+ * @codeCoverageIgnore
+ */
class ExtensionAttributeCollectionLoader
{
/**
diff --git a/Plugin/DataProviders/Overview.php b/Plugin/DataProviders/Overview.php
index c40a8fc7..8b6d7eee 100644
--- a/Plugin/DataProviders/Overview.php
+++ b/Plugin/DataProviders/Overview.php
@@ -7,6 +7,9 @@
*
* @package ClassyLlama\AvaTax\Plugin\DataProviders
*/
+/**
+ * @codeCoverageIgnore
+ */
class Overview
{
/**
diff --git a/Plugin/Model/ConfigPlugin.php b/Plugin/Model/ConfigPlugin.php
index 98a107f4..5956f045 100644
--- a/Plugin/Model/ConfigPlugin.php
+++ b/Plugin/Model/ConfigPlugin.php
@@ -17,6 +17,9 @@
use Magento\Config\Model\Config;
+/**
+ * @codeCoverageIgnore
+ */
class ConfigPlugin
{
diff --git a/Plugin/Model/Convert/OrderPlugin.php b/Plugin/Model/Convert/OrderPlugin.php
index be356f0b..f92c7143 100644
--- a/Plugin/Model/Convert/OrderPlugin.php
+++ b/Plugin/Model/Convert/OrderPlugin.php
@@ -7,6 +7,9 @@
namespace ClassyLlama\AvaTax\Plugin\Model\Convert;
+/**
+ * @codeCoverageIgnore
+ */
class OrderPlugin
{
/**
diff --git a/Plugin/Model/Customer/DataProviderPlugin.php b/Plugin/Model/Customer/DataProviderPlugin.php
index 0d217d81..5b848528 100644
--- a/Plugin/Model/Customer/DataProviderPlugin.php
+++ b/Plugin/Model/Customer/DataProviderPlugin.php
@@ -20,6 +20,9 @@
use Magento\Framework\DataObject;
use Magento\Framework\DataObjectFactory;
+/**
+ * @codeCoverageIgnore
+ */
class DataProviderPlugin
{
// 24 hours in seconds
@@ -124,8 +127,8 @@ public function getCertificates($customerId)
);
$certificate->setData(
- 'certificate_delete_url',
- $this->certificateHelper->getCertificateDeleteUrl($certificate->getData('id'), $customerId)
+ 'certificate_invalidate_url',
+ $this->certificateHelper->getCertificateUnlinkUrl($certificate->getData('id'), $customerId)
);
}
diff --git a/Plugin/Model/Quote/GrandTotalDetailsSorter.php b/Plugin/Model/Quote/GrandTotalDetailsSorter.php
index 0703abe0..86afcea8 100644
--- a/Plugin/Model/Quote/GrandTotalDetailsSorter.php
+++ b/Plugin/Model/Quote/GrandTotalDetailsSorter.php
@@ -6,6 +6,9 @@
*/
namespace ClassyLlama\AvaTax\Plugin\Model\Quote;
+/**
+ * @codeCoverageIgnore
+ */
class GrandTotalDetailsSorter
{
const CUSTOMS_RATE_TITLE = 'Duty';
diff --git a/Plugin/Model/ResourceModel/ExtensionAttributesPersistencePlugin.php b/Plugin/Model/ResourceModel/ExtensionAttributesPersistencePlugin.php
index 3d2a13c2..41b48222 100644
--- a/Plugin/Model/ResourceModel/ExtensionAttributesPersistencePlugin.php
+++ b/Plugin/Model/ResourceModel/ExtensionAttributesPersistencePlugin.php
@@ -15,6 +15,9 @@
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
+/**
+ * @codeCoverageIgnore
+ */
class ExtensionAttributesPersistencePlugin
{
/**
diff --git a/Plugin/Model/Sales/Pdf/TaxPlugin.php b/Plugin/Model/Sales/Pdf/TaxPlugin.php
index 9c7a700f..88a1c87b 100644
--- a/Plugin/Model/Sales/Pdf/TaxPlugin.php
+++ b/Plugin/Model/Sales/Pdf/TaxPlugin.php
@@ -13,6 +13,9 @@
*
* @package ClassyLlama\AvaTax\Plugin\Model\Sales\Pdf
*/
+/**
+ * @codeCoverageIgnore
+ */
class TaxPlugin
{
const TOTAL_TAX_LABEL = 'Tax';
diff --git a/Plugin/Multishipping/Checkout/Results.php b/Plugin/Multishipping/Checkout/Results.php
index 1ea49c7f..7238c036 100644
--- a/Plugin/Multishipping/Checkout/Results.php
+++ b/Plugin/Multishipping/Checkout/Results.php
@@ -10,6 +10,9 @@
*
* @package ClassyLlama\AvaTax\Plugin\Multishipping\Checkout
*/
+/**
+ * @codeCoverageIgnore
+ */
class Results
{
/**
diff --git a/Plugin/Quote/Model/Quote/Config.php b/Plugin/Quote/Model/Quote/Config.php
index 011dd91a..ab61ef94 100644
--- a/Plugin/Quote/Model/Quote/Config.php
+++ b/Plugin/Quote/Model/Quote/Config.php
@@ -21,6 +21,9 @@
/**
* Class Config
*/
+/**
+ * @codeCoverageIgnore
+ */
class Config
{
/**
diff --git a/Plugin/Sales/Admin/Order/Create/Form/Account.php b/Plugin/Sales/Admin/Order/Create/Form/Account.php
index fe7017b5..7f2a0a09 100644
--- a/Plugin/Sales/Admin/Order/Create/Form/Account.php
+++ b/Plugin/Sales/Admin/Order/Create/Form/Account.php
@@ -16,6 +16,9 @@
namespace ClassyLlama\AvaTax\Plugin\Sales\Admin\Order\Create\Form;
+/**
+ * @codeCoverageIgnore
+ */
class Account
{
/**
diff --git a/Plugin/Sales/Model/AdminOrder/Create.php b/Plugin/Sales/Model/AdminOrder/Create.php
index 44f03b3b..3c64e2c8 100644
--- a/Plugin/Sales/Model/AdminOrder/Create.php
+++ b/Plugin/Sales/Model/AdminOrder/Create.php
@@ -22,6 +22,9 @@
/**
* Class Create
*/
+/**
+ * @codeCoverageIgnore
+ */
class Create
{
/**
diff --git a/Plugin/Sales/Model/Spi/CreditmemoResource.php b/Plugin/Sales/Model/Spi/CreditmemoResource.php
index c90760e0..96a72aba 100644
--- a/Plugin/Sales/Model/Spi/CreditmemoResource.php
+++ b/Plugin/Sales/Model/Spi/CreditmemoResource.php
@@ -29,6 +29,9 @@
/**
* Class CreditmemoResource
*/
+/**
+ * @codeCoverageIgnore
+ */
class CreditmemoResource
{
/**
@@ -133,7 +136,7 @@ public function aroundSave(
$queue->save();
$this->avaTaxLogger->debug(
- __('Added entity to the queue'),
+ __('Added entity to the queue. queue_id: '.$queue->getId().' | entity_id: '.$entity->getEntityId().' | entity_type_code: '.Queue::ENTITY_TYPE_CODE_CREDITMEMO),
[ /* context */
'queue_id' => $queue->getId(),
'entity_type_code' => Queue::ENTITY_TYPE_CODE_CREDITMEMO,
diff --git a/Plugin/Sales/Model/Spi/InvoiceResource.php b/Plugin/Sales/Model/Spi/InvoiceResource.php
index c18bd468..c36f5905 100644
--- a/Plugin/Sales/Model/Spi/InvoiceResource.php
+++ b/Plugin/Sales/Model/Spi/InvoiceResource.php
@@ -29,6 +29,9 @@
/**
* Class InvoiceResource
*/
+/**
+ * @codeCoverageIgnore
+ */
class InvoiceResource
{
/**
@@ -133,7 +136,7 @@ public function aroundSave(
$queue->save();
$this->avaTaxLogger->debug(
- __('Added entity to the queue'),
+ __('Added entity to the queue. queue_id: '.$queue->getId().' | entity_id: '.$entity->getEntityId().' | entity_type_code: '.Queue::ENTITY_TYPE_CODE_INVOICE),
[ /* context */
'queue_id' => $queue->getId(),
'entity_type_code' => Queue::ENTITY_TYPE_CODE_INVOICE,
diff --git a/Plugin/Tax/Model/Sales/Total/Quote/Shipping.php b/Plugin/Tax/Model/Sales/Total/Quote/Shipping.php
index 637ce919..6e876502 100644
--- a/Plugin/Tax/Model/Sales/Total/Quote/Shipping.php
+++ b/Plugin/Tax/Model/Sales/Total/Quote/Shipping.php
@@ -17,6 +17,9 @@
use ClassyLlama\AvaTax\Helper\Config;
+/**
+ * @codeCoverageIgnore
+ */
class Shipping
{
/**
diff --git a/Plugin/Tax/Model/Sales/Total/Quote/Subtotal.php b/Plugin/Tax/Model/Sales/Total/Quote/Subtotal.php
index eb8ad6d0..5b1ccfa4 100644
--- a/Plugin/Tax/Model/Sales/Total/Quote/Subtotal.php
+++ b/Plugin/Tax/Model/Sales/Total/Quote/Subtotal.php
@@ -17,6 +17,9 @@
use ClassyLlama\AvaTax\Helper\Config;
+/**
+ * @codeCoverageIgnore
+ */
class Subtotal
{
/**
diff --git a/Plugin/View/Layout/GenericPlugin.php b/Plugin/View/Layout/GenericPlugin.php
index a8849ce1..4ab68b1d 100644
--- a/Plugin/View/Layout/GenericPlugin.php
+++ b/Plugin/View/Layout/GenericPlugin.php
@@ -30,6 +30,9 @@
* Class GenericPlugin
* @package ClassyLlama\AvaTax\Plugin\View\Layout
*/
+/**
+ * @codeCoverageIgnore
+ */
class GenericPlugin
{
/**
diff --git a/Ui/Component/Listing/Column/Certinvite.php b/Ui/Component/Listing/Column/Certinvite.php
new file mode 100644
index 00000000..24f438d9
--- /dev/null
+++ b/Ui/Component/Listing/Column/Certinvite.php
@@ -0,0 +1,76 @@
+urlBuilder = $urlBuilder;
+ $this->formKey = $formKey;
+ $this->documentManagementConfig = $documentManagementConfig;
+ parent::__construct($context, $uiComponentFactory, $components, $data);
+ }
+ /**
+ * Prepare Data Source
+ *
+ * @param array $dataSource
+ * @return array
+ */
+ public function prepareDataSource(array $dataSource)
+ {
+
+ if (isset($dataSource['data']['items'])) {
+ foreach ($dataSource['data']['items'] as & $item) {
+ $fieldName = $this->getData('name');
+ $url = $this->urlBuilder->getUrl('avatax/invite/index',['form_key' => $this->formKey->getFormKey(), 'customer_id' => $item['entity_id'], 'redirect' => "1"]);
+ $confirmMsg = "return confirm('This customer will be synced to AvaTax (using the customer\'s email and default billing address) and AvaTax will send an email to the customer, asking them to add an exemption certificate in the AvaTax interface. Would you like to proceed?', 'title hre')";
+ $item[$fieldName] = '';
+
+ }
+ }
+ return $dataSource;
+ }
+
+ public function prepare()
+ {
+ // if certCapture is disabled hide certExpress column
+ $certCaptureEnable = $this->documentManagementConfig->isEnabled();
+ if (!$certCaptureEnable) {
+ $this->_data['config']['componentDisabled'] = true; // for removing the column
+ }
+ parent::prepare();
+ }
+}
\ No newline at end of file
diff --git a/Ui/Component/TaxCertificates.php b/Ui/Component/TaxCertificates.php
index 8ca3c847..d136327a 100644
--- a/Ui/Component/TaxCertificates.php
+++ b/Ui/Component/TaxCertificates.php
@@ -56,6 +56,9 @@ class TaxCertificates extends AbstractComponent implements TabInterface
*/
const COMPONENT = 'ClassyLlama_AvaTax/js/form/certificates-fieldset';
+ /** @var string */
+ const VALID_PENDING_STATUS = 'PENDING';
+
/**
* @var ResourceModelConfig
*/
@@ -198,13 +201,14 @@ public function shouldShowWarning()
protected function getAvailableExemptionZones()
{
$zones = $this->companyRest->getCertificateExposureZones();
-
- return array_map(
- function ($zone) {
- return $zone->name;
- },
- $zones->value
- );
+ if($zones){
+ return array_map(
+ function ($zone) {
+ return $zone->name;
+ },
+ $zones->value
+ );
+ }
}
/**
@@ -238,7 +242,6 @@ public function prepare()
if ($certificate instanceof DataObject) {
/** @var array $item */
$item = $certificate->getData();
-
// case, when a certificate does not have signed_date/expiration_date at the Avalara side
!$certificate->hasData('signed_date') ? $item['signed_date'] = [] : false;
!$certificate->hasData('expiration_date') ? $item['expiration_date'] = [] : false;
@@ -246,7 +249,17 @@ public function prepare()
$item['exemption_reason'] = $this->configureAdditionalInformation($certificate, 'exemption_reason');
$item['exposure_zone'] = $this->configureAdditionalInformation($certificate, 'exposure_zone');
$item['validated_exemption_reason'] = $this->configureAdditionalInformation($certificate, 'validated_exemption_reason');
-
+ // code to get certificate status
+ $status = $item['status'];
+ $valid = $item['valid'];
+ if($valid && ($status == self::VALID_PENDING_STATUS)){
+ $item['valid'] = "Pending";
+ }elseif($valid){
+ $item['valid'] = "Approved";
+ }else{
+ $item['valid'] = "Denied";
+ }
+
$data[] = $item;
}
}
diff --git a/composer.json b/composer.json
index f6055408..46cfedf8 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "avalara/avatax-magento",
"type": "magento2-module",
- "version": "2.4.2",
+ "version": "2.5.0",
"license": "OSL-3.0",
"description": "Magento module for Avalara's AvaTax suite of business tax calculation and processing services. Uses the AvaTax REST v2 API.",
"require": {
diff --git a/etc/adminhtml/menu.xml b/etc/adminhtml/menu.xml
index 840c39c4..839d62ce 100644
--- a/etc/adminhtml/menu.xml
+++ b/etc/adminhtml/menu.xml
@@ -20,10 +20,10 @@
-
+
-
+
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 731d031a..c0823210 100755
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -19,7 +19,7 @@
- Connector for Magento 2 for Sales Tax.
+ Connector for Magento 2 for Sales Tax.
]]>
ClassyLlama\AvaTax\Block\Adminhtml\System\Config\AvaTax
diff --git a/etc/adminhtml/system/address_validation.xml b/etc/adminhtml/system/address_validation.xml
index f226317a..d449d69b 100644
--- a/etc/adminhtml/system/address_validation.xml
+++ b/etc/adminhtml/system/address_validation.xml
@@ -68,5 +68,8 @@
1
+
+ 1
+
\ No newline at end of file
diff --git a/etc/adminhtml/system/exemption_certcapture_management.xml b/etc/adminhtml/system/exemption_certcapture_management.xml
index 8c61e9b3..a7995c50 100644
--- a/etc/adminhtml/system/exemption_certcapture_management.xml
+++ b/etc/adminhtml/system/exemption_certcapture_management.xml
@@ -16,11 +16,11 @@
-->
-
+
ClassyLlama\AvaTax\Block\Adminhtml\System\Config\ExpandedFieldSet
tax/avatax_document_management/enabled
-
+
Magento\Config\Model\Config\Source\Yesno
AvaTax Document Management allows users to upload documents that verify that they’re tax exempt and if they do, they won’t be charged tax in the checkout. This feature must be enabled in your Avalara account.
diff --git a/etc/adminhtml/system/extension_mode.xml b/etc/adminhtml/system/extension_mode.xml
index 3b294d98..af289157 100644
--- a/etc/adminhtml/system/extension_mode.xml
+++ b/etc/adminhtml/system/extension_mode.xml
@@ -26,6 +26,7 @@
tax/avatax/enabled
Magento\Config\Model\Config\Source\Yesno
+ ClassyLlama\AvaTax\Model\Config\Backend\ConnectorStatus
tax/avatax/live_mode
diff --git a/view/adminhtml/ui_component/customer_listing.xml b/view/adminhtml/ui_component/customer_listing.xml
new file mode 100644
index 00000000..afbff359
--- /dev/null
+++ b/view/adminhtml/ui_component/customer_listing.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+ -
+
- Proceed
+ - entity_id
+ - CertExpress
+ - ui/grid/cells/html
+ - false
+
+
+
+
+
\ No newline at end of file
diff --git a/view/adminhtml/web/js/action/avatax-invite-account.js b/view/adminhtml/web/js/action/avatax-invite-account.js
index fd000bcc..8964971c 100644
--- a/view/adminhtml/web/js/action/avatax-invite-account.js
+++ b/view/adminhtml/web/js/action/avatax-invite-account.js
@@ -30,7 +30,9 @@ define(['jquery', 'uiComponent', 'Magento_Ui/js/modal/modal', 'mage/translate'],
},
sendInvite: function sendInvite() {
- window.location.href = this.inviteUrl;
+ if (confirm('This customer will be synced to AvaTax (using the customer\'s email and default billing address) and AvaTax will send an email to the customer, asking them to add an exemption certificate in the AvaTax interface. Would you like to proceed?')) {
+ window.location.href = this.inviteUrl;
+ }
}
});
});
diff --git a/view/adminhtml/web/js/view/certificates-grid.js b/view/adminhtml/web/js/view/certificates-grid.js
index 5a64b5d1..649a4b9e 100644
--- a/view/adminhtml/web/js/view/certificates-grid.js
+++ b/view/adminhtml/web/js/view/certificates-grid.js
@@ -30,14 +30,14 @@ define([
shouldShowWarning: false
},
- handleDelete: function(deleteUrl) {
+ handleDelete: function(unlinkUrl) {
confirm({
- title: $t('Delete Certificate'),
- content: $t('Are you sure you’d like to delete this certificate?'),
+ title: $t('Invalidate Certificate'),
+ content: $t('Are you sure you’d like to invalidate this certificate?'),
actions: {
confirm: function() {
//make delete request.
- window.location = deleteUrl;
+ window.location = unlinkUrl;
}
}
});
diff --git a/view/adminhtml/web/template/form/certificates-fieldset.html b/view/adminhtml/web/template/form/certificates-fieldset.html
index 11b35b2c..07f2f1f8 100644
--- a/view/adminhtml/web/template/form/certificates-fieldset.html
+++ b/view/adminhtml/web/template/form/certificates-fieldset.html
@@ -54,7 +54,7 @@
-
+
|
|
-
|
+
|
+
|
@@ -21,7 +22,7 @@
|
|
|
-
|
+
|
@@ -29,9 +30,10 @@
|
+
+ click: $parent.handleDelete.bind($parent, certificate_invalidate_url),
+ i18n: 'Invalidate Certificate'">
|
diff --git a/view/frontend/templates/certificates/list.phtml b/view/frontend/templates/certificates/list.phtml
index 1b1d2293..44eebdd4 100644
--- a/view/frontend/templates/certificates/list.phtml
+++ b/view/frontend/templates/certificates/list.phtml
@@ -34,7 +34,8 @@ $statuses = $viewModel->getCertificateStatusName();
|
|
|
-
|
+
|
+
|
@@ -65,9 +66,9 @@ $statuses = $viewModel->getCertificateStatusName();
getData('valid')): ?>
"
+ "unlinkUrl":"= $viewModel->getUnlinkCertificateUrl($certificate->getData('id')) ?>"
}}'>
- = __('Delete Certificate') ?>
+ = __('Invalidate Certificate') ?>
|
diff --git a/view/frontend/web/js/delete-certificate.js b/view/frontend/web/js/delete-certificate.js
index 2c31fa6d..d6ea5021 100644
--- a/view/frontend/web/js/delete-certificate.js
+++ b/view/frontend/web/js/delete-certificate.js
@@ -16,12 +16,12 @@ define(['jquery', 'mage/translate', 'Magento_Ui/js/modal/confirm'], function ($,
return function (options, element) {
$(element).click(function() {
confirm({
- title: $t('Delete Certificate'),
- content: $t('Are you sure you’d like to delete this certificate?'),
+ title: $t('Invalidate Certificate'),
+ content: $t('Are you sure you’d like to invalidate this certificate?'),
actions: {
confirm: function() {
- //make delete request.
- window.location = options.deleteUrl;
+ //make unlink request.
+ window.location = options.unlinkUrl;
}
}
});