Skip to content

Commit

Permalink
Merge pull request #11 from taxjar/none-tax-class-fix
Browse files Browse the repository at this point in the history
Fully Exempt "None" Tax Class Products
  • Loading branch information
fastdivision committed Aug 15, 2017
2 parents 66789a9 + 5553213 commit e124f21
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 11 deletions.
7 changes: 1 addition & 6 deletions Model/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@

class Client
{
/**
* @var string
*/
const API_URL = 'https://api.taxjar.com/v2';

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
Expand Down Expand Up @@ -195,7 +190,7 @@ private function _getRequest($client, $errors = [])
*/
private function _getApiUrl($resource)
{
$apiUrl = self::API_URL;
$apiUrl = TaxjarConfig::TAXJAR_API_URL;

switch ($resource) {
case 'config':
Expand Down
2 changes: 2 additions & 0 deletions Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Configuration
{
const TAXJAR_VERSION = '0.7.3';
const TAXJAR_AUTH_URL = 'https://app.taxjar.com';
const TAXJAR_API_URL = 'https://api.taxjar.com/v2';
const TAXJAR_APIKEY = 'tax/taxjar/apikey';
const TAXJAR_BACKUP = 'tax/taxjar/backup';
const TAXJAR_CATEGORIES = 'tax/taxjar/categories';
Expand All @@ -37,6 +38,7 @@ class Configuration
const TAXJAR_STATES = 'tax/taxjar/states';
const TAXJAR_TRANSACTION_AUTH = 'tax/taxjar/transaction_auth';
const TAXJAR_TRANSACTION_SYNC = 'tax/taxjar/transactions';
const TAXJAR_EXEMPT_TAX_CODE = '99999';

/**
* @var \Magento\Config\Model\ResourceModel\Config
Expand Down
10 changes: 5 additions & 5 deletions Model/Smartcalcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
*/
class Smartcalcs
{
const API_URL = 'https://api.taxjar.com/v2';

/**
* @var \Magento\Checkout\Model\Session
*/
Expand Down Expand Up @@ -169,7 +167,7 @@ public function getTaxForOrder(

if ($this->_orderChanged($order)) {
$client = $this->clientFactory->create();
$client->setUri(self::API_URL . '/magento/taxes');
$client->setUri(TaxjarConfig::TAXJAR_API_URL . '/magento/taxes');
$client->setHeaders('Authorization', 'Bearer ' . $apiKey);
$client->setRawData(json_encode($order), 'application/json');

Expand Down Expand Up @@ -307,7 +305,7 @@ private function _isCustomerExempt(
$customerTaxClass = $this->taxClassRepository->get($address->getQuote()->getCustomerTaxClassId());
$customerTaxCode = $customerTaxClass->getTjSalestaxCode();

if ($customerTaxCode == '99999') {
if ($customerTaxCode == TaxjarConfig::TAXJAR_EXEMPT_TAX_CODE) {
return true;
}
}
Expand Down Expand Up @@ -347,6 +345,8 @@ private function _getLineItems(
if ($item->getTaxClassKey()->getValue()) {
$taxClass = $this->taxClassRepository->get($item->getTaxClassKey()->getValue());
$taxCode = $taxClass->getTjSalestaxCode();
} else {
$taxCode = TaxjarConfig::TAXJAR_EXEMPT_TAX_CODE;
}

if ($this->productMetadata->getEdition() == 'Enterprise') {
Expand All @@ -358,7 +358,7 @@ private function _getLineItems(
$giftTaxClassCode = $giftTaxClass->getTjSalestaxCode();
$taxCode = $giftTaxClassCode;
} else {
$taxCode = '99999';
$taxCode = TaxjarConfig::TAXJAR_EXEMPT_TAX_CODE;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Taxjar_SalesTax
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category Taxjar
* @package Taxjar_SalesTax
* @copyright Copyright (c) 2017 TaxJar. TaxJar is a trademark of TPS Unlimited, Inc. (http://www.taxjar.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Magento\Tax\Model\Calculation;
use Magento\Tax\Model\Config;
use Taxjar\SalesTax\Test\Integration\Model\Tax\Sales\Total\Quote\SetupUtil;

$taxCalculationData['none_tax_class_exemption'] = [
'config_data' => [
SetupUtil::CONFIG_OVERRIDES => array_merge($taxjarCredentials, [
'shipping/origin/street_line1' => '600 Montgomery St',
'shipping/origin/city' => 'San Francisco',
'shipping/origin/region_id' => SetupUtil::REGION_CA,
'shipping/origin/country_id' => 'US',
'shipping/origin/postcode' => '94111'
])
],
'quote_data' => [
'billing_address' => [
'firstname' => 'Jake',
'lastname' => 'Johnson',
'street' => '123 Westcreek Pkwy',
'city' => 'Westlake Village',
'region_id' => SetupUtil::REGION_CA,
'postcode' => '91362',
'country_id' => SetupUtil::COUNTRY_US,
'telephone' => '011-899-9881'
],
'shipping_address' => [
'firstname' => 'Jake',
'lastname' => 'Johnson',
'street' => '123 Westcreek Pkwy',
'city' => 'Westlake Village',
'region_id' => SetupUtil::REGION_CA,
'postcode' => '91362',
'country_id' => SetupUtil::COUNTRY_US,
'telephone' => '011-899-9881'
],
'items' => [
[
'type' => \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
'sku' => 'taxjar-tshirt',
'price' => 29.99,
'qty' => 1,
'tax_class_name' => ''
]
],
],
'expected_results' => [
'address_data' => [
'tax_amount' => 0,
'subtotal' => 29.99,
'subtotal_incl_tax' => 29.99,
'grand_total' => 29.99
],
'items_data' => [
'taxjar-tshirt' => [
'tax_amount' => 0,
'tax_percent' => 0,
'price' => 29.99,
'price_incl_tax' => 29.99,
'row_total' => 29.99,
'row_total_incl_tax' => 29.99
],
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
require_once __DIR__ . '/scenarios/currencies/aud_with_usd_base_currency.php';
require_once __DIR__ . '/scenarios/currencies/cad_with_usd_base_currency.php';
require_once __DIR__ . '/scenarios/currencies/eur_with_usd_base_currency.php';
require_once __DIR__ . '/scenarios/exemptions/none_tax_class_exemption.php';
require_once __DIR__ . '/scenarios/exemptions/us_ca_grocery_exemption.php';
require_once __DIR__ . '/scenarios/exemptions/us_ny_clothing_exemption.php';
require_once __DIR__ . '/scenarios/fallbacks/invalid_token_fallback.php';
Expand Down

0 comments on commit e124f21

Please sign in to comment.