Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
462 changes: 333 additions & 129 deletions Model/Api.php

Large diffs are not rendered by default.

41 changes: 26 additions & 15 deletions Model/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ class Tax extends \Magento\Tax\Model\Sales\Total\Quote\Tax
*
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $_scopeConfig = null;
protected $scopeConfig = null;

/**
* TaxCloud Api Object
*
* @var \Taxcloud\Magento2\Model\Api
*/
protected $_tcapi;
protected $tcapi;

/**
* TaxCloud Logger
*
* @var \Taxcloud\Magento2\Logger\Logger
*/
protected $_tclogger;
protected $tclogger;

/**
* Class constructor
Expand Down Expand Up @@ -75,13 +75,13 @@ public function __construct(
\Taxcloud\Magento2\Model\Api $tcapi,
\Taxcloud\Magento2\Logger\Logger $tclogger
) {
$this->_scopeConfig = $scopeConfig;
$this->_tcapi = $tcapi;
$this->scopeConfig = $scopeConfig;
$this->tcapi = $tcapi;

if ($scopeConfig->getValue('tax/taxcloud_settings/logging', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
$this->_tclogger = $tclogger;
$this->tclogger = $tclogger;
} else {
$this->_tclogger = new class {
$this->tclogger = new class {
public function info()
{
}
Expand Down Expand Up @@ -117,7 +117,10 @@ public function collect(
\Magento\Quote\Model\Quote\Address\Total $total
) {

if (!$this->_scopeConfig->getValue('tax/taxcloud_settings/enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
if (!$this->scopeConfig->getValue(
'tax/taxcloud_settings/enabled',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)) {
return parent::collect($quote, $shippingAssignment, $total);
}

Expand All @@ -133,8 +136,8 @@ public function collect(
$itemsByType = $this->organizeItemTaxDetailsByType($taxDetails, $baseTaxDetails);

// Fetch tax amount from TaxCloud
$taxAmounts = $this->_tcapi->lookupTaxes($itemsByType, $shippingAssignment, $quote);
// $this->_tclogger->info(json_encode($taxAmounts, JSON_PRETTY_PRINT));
$taxAmounts = $this->tcapi->lookupTaxes($itemsByType, $shippingAssignment, $quote);
// $this->tclogger->info(json_encode($taxAmounts, JSON_PRETTY_PRINT));

$keyedAddressItems = [];
foreach ($shippingAssignment->getItems() as $item) {
Expand Down Expand Up @@ -171,7 +174,9 @@ public function collect(
$baseTaxDetail->setRowTotalInclTax($baseTaxDetail->getRowTotal() + $taxAmount);
$baseTaxDetail->setAppliedTaxes([]);
if ($baseTaxDetail->getRowTotal() > 0) {
$baseTaxDetail->setTaxPercent(round(100 * $baseTaxDetail->getRowTax() / $baseTaxDetail->getRowTotal(), 2));
$baseTaxDetail->setTaxPercent(
round(100 * $baseTaxDetail->getRowTax() / $baseTaxDetail->getRowTotal(), 2)
);
} else {
$baseTaxDetail->setTaxPercent(0);
}
Expand All @@ -181,8 +186,10 @@ public function collect(
}

if (isset($itemsByType[self::ITEM_TYPE_SHIPPING])) {
$shippingTaxDetails = $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_ITEM];
$baseShippingTaxDetails = $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_BASE_ITEM];
$shippingTaxDetails = $itemsByType[self::ITEM_TYPE_SHIPPING]
[self::ITEM_CODE_SHIPPING][self::KEY_ITEM];
$baseShippingTaxDetails = $itemsByType[self::ITEM_TYPE_SHIPPING]
[self::ITEM_CODE_SHIPPING][self::KEY_BASE_ITEM];

$taxAmount = $taxAmounts[self::ITEM_TYPE_SHIPPING];
$taxAmountPer = $taxAmount / 1;
Expand All @@ -192,7 +199,9 @@ public function collect(
$shippingTaxDetails->setRowTotalInclTax($shippingTaxDetails->getRowTotal() + $taxAmount);
$shippingTaxDetails->setAppliedTaxes([]);
if ($shippingTaxDetails->getRowTotal() > 0) {
$shippingTaxDetails->setTaxPercent(round(100 * $shippingTaxDetails->getRowTax() / $shippingTaxDetails->getRowTotal(), 2));
$shippingTaxDetails->setTaxPercent(
round(100 * $shippingTaxDetails->getRowTax() / $shippingTaxDetails->getRowTotal(), 2)
);
} else {
$shippingTaxDetails->setTaxPercent(0);
}
Expand All @@ -202,7 +211,9 @@ public function collect(
$baseShippingTaxDetails->setRowTotalInclTax($baseShippingTaxDetails->getRowTotal() + $taxAmount);
$baseShippingTaxDetails->setAppliedTaxes([]);
if ($baseShippingTaxDetails->getRowTotal() > 0) {
$baseShippingTaxDetails->setTaxPercent(round(100 * $baseShippingTaxDetails->getRowTax() / $baseShippingTaxDetails->getRowTotal(), 2));
$baseShippingTaxDetails->setTaxPercent(
round(100 * $baseShippingTaxDetails->getRowTax() / $baseShippingTaxDetails->getRowTotal(), 2)
);
} else {
$baseShippingTaxDetails->setTaxPercent(0);
}
Expand Down
28 changes: 17 additions & 11 deletions Observer/Sales/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ class Address implements ObserverInterface
*
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $_scopeConfig = null;
protected $scopeConfig = null;

/**
* TaxCloud Api Object
*
* @var \Taxcloud\Magento2\Model\Api
*/
protected $_tcapi;
protected $tcapi;

/**
* TaxCloud Logger
*
* @var \Taxcloud\Magento2\Logger\Logger
*/
protected $_tclogger;
protected $tclogger;

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
Expand All @@ -54,13 +54,13 @@ public function __construct(
\Taxcloud\Magento2\Model\Api $tcapi,
\Taxcloud\Magento2\Logger\Logger $tclogger
) {
$this->_scopeConfig = $scopeConfig;
$this->_tcapi = $tcapi;
$this->scopeConfig = $scopeConfig;
$this->tcapi = $tcapi;

if ($scopeConfig->getValue('tax/taxcloud_settings/logging', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
$this->_tclogger = $tclogger;
$this->tclogger = $tclogger;
} else {
$this->_tclogger = new class {
$this->tclogger = new class {
public function info()
{
}
Expand All @@ -74,20 +74,26 @@ public function info()
public function execute(
Observer $observer
) {
if (!$this->_scopeConfig->getValue('tax/taxcloud_settings/enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
if (!$this->scopeConfig->getValue(
'tax/taxcloud_settings/enabled',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)) {
return;
}

if (!$this->_scopeConfig->getValue('tax/taxcloud_settings/verify_address', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
if (!$this->scopeConfig->getValue(
'tax/taxcloud_settings/verify_address',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)) {
return;
}

$this->_tclogger->info('Running Observer taxcloud_lookup_before');
$this->tclogger->info('Running Observer taxcloud_lookup_before');

$obj = $observer->getEvent()->getObj();
$params = $obj->getParams();

$result = $this->_tcapi->verifyAddress($params['destination']);
$result = $this->tcapi->verifyAddress($params['destination']);

if ($result) {
$params['destination'] = $result;
Expand Down
23 changes: 13 additions & 10 deletions Observer/Sales/Complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ class Complete implements ObserverInterface
*
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $_scopeConfig = null;
protected $scopeConfig = null;

/**
* TaxCloud Api Object
*
* @var \Taxcloud\Magento2\Model\Api
*/
protected $_tcapi;
protected $tcapi;

/**
* TaxCloud Logger
*
* @var \Taxcloud\Magento2\Logger\Logger
*/
protected $_tclogger;
protected $tclogger;

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
Expand All @@ -54,13 +54,13 @@ public function __construct(
\Taxcloud\Magento2\Model\Api $tcapi,
\Taxcloud\Magento2\Logger\Logger $tclogger
) {
$this->_scopeConfig = $scopeConfig;
$this->_tcapi = $tcapi;
$this->scopeConfig = $scopeConfig;
$this->tcapi = $tcapi;

if ($scopeConfig->getValue('tax/taxcloud_settings/logging', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
$this->_tclogger = $tclogger;
$this->tclogger = $tclogger;
} else {
$this->_tclogger = new class {
$this->tclogger = new class {
public function info()
{
}
Expand All @@ -74,14 +74,17 @@ public function info()
public function execute(
Observer $observer
) {
if (!$this->_scopeConfig->getValue('tax/taxcloud_settings/enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
if (!$this->scopeConfig->getValue(
'tax/taxcloud_settings/enabled',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)) {
return;
}

$this->_tclogger->info('Running Observer sales_order_place_after');
$this->tclogger->info('Running Observer sales_order_place_after');

$order = $observer->getEvent()->getOrder();

$this->_tcapi->authorizeCapture($order);
$this->tcapi->authorizeCapture($order);
}
}
5 changes: 4 additions & 1 deletion Observer/Sales/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public function info()
public function execute(
Observer $observer
) {
if (!$this->scopeConfig->getValue('tax/taxcloud_settings/enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
if (!$this->scopeConfig->getValue(
'tax/taxcloud_settings/enabled',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)) {
return;
}

Expand Down
Loading
Loading