Version Notes
Collect sales tax without changing your Magento Store’s checkout process.
TaxJar’s Sales Tax Automation makes collecting sales tax easy by removing complex configuration and
providing accurate rates and reporting that eliminate precious hours wasted on filing sales tax returns.
Sales Tax Automation Benefits:
- Easy first-time install
- Automated sales tax configuration
- Avoid shopping cart abandonment
- Calculations don’t impact store’s performance
- Free rates for your state
- No setup fee
Download this release
Release Info
| Developer | TaxJar |
| Extension | Taxjar_Salestaxautomation |
| Version | 1.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0
- app/code/community/Taxjar/.DS_Store +0 -0
- app/code/community/Taxjar/Salestaxautomation/Helper/Data.php +4 -0
- app/code/community/Taxjar/Salestaxautomation/Model/Client.php +23 -0
- app/code/community/Taxjar/Salestaxautomation/Model/Comment.php +14 -0
- app/code/community/Taxjar/Salestaxautomation/Model/Configuration.php +256 -0
- app/code/community/Taxjar/Salestaxautomation/Model/Observer.php +69 -0
- app/code/community/Taxjar/Salestaxautomation/Model/Rate.php +19 -0
- app/code/community/Taxjar/Salestaxautomation/Model/Rule.php +19 -0
- app/code/community/Taxjar/Salestaxautomation/etc/config.xml +75 -0
- app/code/community/Taxjar/Salestaxautomation/etc/system.xml +43 -0
- app/etc/modules/Taxjar_Salestaxautomation.xml +9 -0
- package.xml +39 -0
app/code/community/Taxjar/.DS_Store
ADDED
|
Binary file
|
app/code/community/Taxjar/Salestaxautomation/Helper/Data.php
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Taxjar_Salestaxautomation_Helper_Data extends Mage_Core_Helper_Abstract
|
| 3 |
+
{
|
| 4 |
+
}
|
app/code/community/Taxjar/Salestaxautomation/Model/Client.php
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Taxjar_Salestaxautomation_Model_Client {
|
| 3 |
+
|
| 4 |
+
public function getResource($apiKey, $url) {
|
| 5 |
+
$response = $this->_getClient($apiKey, $url)->request();
|
| 6 |
+
if ($response->isSuccessful()) {
|
| 7 |
+
$json = $response->getBody();
|
| 8 |
+
return json_decode($json, true);
|
| 9 |
+
} else {
|
| 10 |
+
throw new Exception('Could not connect to TaxJar.');
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
private function _getClient($apiKey, $url) {
|
| 15 |
+
$client = new Varien_Http_Client($url);
|
| 16 |
+
$client->setMethod(Varien_Http_Client::GET);
|
| 17 |
+
$client->setHeaders('Authorization', 'Token token="' . $apiKey . '"');
|
| 18 |
+
return $client;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
?>
|
app/code/community/Taxjar/Salestaxautomation/Model/Comment.php
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Taxjar_Salestaxautomation_Model_Comment{
|
| 3 |
+
public function getCommentText(){ //this method must exits. It returns the text for the comment
|
| 4 |
+
$regionId = Mage::getStoreConfig('shipping/origin/region_id');
|
| 5 |
+
$regionName = Mage::getModel('directory/region')->load($regionId)->getDefaultName();
|
| 6 |
+
$lastUpdate = Mage::getStoreConfig('salestaxautomation/config/last_update');
|
| 7 |
+
if($lastUpdate){
|
| 8 |
+
return "<br/><p>Your " . $regionName . " sales tax rates were last updated on: <ul><li>" . $lastUpdate . "</li></ul></p><p>If you would like to uninstall TaxJar, remove the API Token from the box above, then save the config. This will remove all the rates. You can then uninstall in the Magento Connect Manager.</p>";
|
| 9 |
+
} else {
|
| 10 |
+
return "<br/><p>Enter your TaxJar API Token to import current sales tax rates for all zip codes in " . $regionName . ", your state of origin as set in Shipping Settings. To get an API Token, go to <a href='https://app.taxjar.com/account' target='_blank'>TaxJar's Account Screen.</a></p><p>For more information on how your tax settings are changed, <a href='http://taxjar.com/magento/tax-settings' target='_blank'>click here</a>.</p>";
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
?>
|
app/code/community/Taxjar/Salestaxautomation/Model/Configuration.php
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Taxjar_Salestaxautomation_Model_Configuration {
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
public function setShippingTaxability($configJson) {
|
| 6 |
+
$taxClass = 0;
|
| 7 |
+
if($configJson['freight_taxable']) {
|
| 8 |
+
$taxClass = 4;
|
| 9 |
+
}
|
| 10 |
+
$this->_setConfig('tax/classes/shipping_tax_class', $taxClass);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
public function setTaxBasis($configJson) {
|
| 14 |
+
$basis = 'shipping';
|
| 15 |
+
if($configJson['tax_source']==='origin') {
|
| 16 |
+
$basis = 'origin';
|
| 17 |
+
}
|
| 18 |
+
$this->_setConfig('tax/calculation/based_on', $basis);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
public function setDisplaySettings() {
|
| 22 |
+
$settings = array(
|
| 23 |
+
'tax/display/type',
|
| 24 |
+
'tax/display/shipping',
|
| 25 |
+
'tax/cart_display/price',
|
| 26 |
+
'tax/cart_display/subtotal',
|
| 27 |
+
'tax/cart_display/shipping'
|
| 28 |
+
);
|
| 29 |
+
foreach($settings as $setting) {
|
| 30 |
+
$this->_setConfig($setting, 1);
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
public function setApiSettings($apiKey) {
|
| 35 |
+
$apiUser = Mage::getModel('api/user');
|
| 36 |
+
$existingUserId = $apiUser->load('taxjar', 'username')->getUserId();
|
| 37 |
+
if(!$existingUserId) {
|
| 38 |
+
$apiUserId = $this->_createApiUser($apiKey);
|
| 39 |
+
$parentRoleId = $this->_createApiRoles($apiUserId);
|
| 40 |
+
$this->_createApiRules($parentRoleId);
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
private function _createApiRules($parentRoleId) {
|
| 45 |
+
foreach($this->_resourcesToAllow() as $resource){
|
| 46 |
+
$apiRule = Mage::getModel('api/rules');
|
| 47 |
+
$apiRule->setRoleId($parentRoleId);
|
| 48 |
+
$apiRule->setResourceId($resource);
|
| 49 |
+
$apiRule->setRoleType('G');
|
| 50 |
+
$apiRule->setApiPermission('allow');
|
| 51 |
+
$apiRule->save();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
foreach($this->_resourcesToDeny() as $resource){
|
| 55 |
+
$apiRule = Mage::getModel('api/rules');
|
| 56 |
+
$apiRule->setRoleId($parentRoleId);
|
| 57 |
+
$apiRule->setResourceId($resource);
|
| 58 |
+
$apiRule->setRoleType('G');
|
| 59 |
+
$apiRule->setApiPermission('deny');
|
| 60 |
+
$apiRule->save();
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
private function _createApiRoles($apiUserId) {
|
| 65 |
+
$parentApiRole = Mage::getModel('api/role');
|
| 66 |
+
$parentApiRole->setRoleName('taxjar_api');
|
| 67 |
+
$parentApiRole->setTreeLevel(1);
|
| 68 |
+
$parentApiRole->setRoleType('G');
|
| 69 |
+
$parentApiRole->save();
|
| 70 |
+
$parentRoleId = $parentApiRole->getId();
|
| 71 |
+
|
| 72 |
+
$childApiRole = Mage::getModel('api/role');
|
| 73 |
+
$childApiRole->setRoleName('Mark');
|
| 74 |
+
$childApiRole->setTreeLevel(1);
|
| 75 |
+
$childApiRole->setParentId($parentRoleId);
|
| 76 |
+
$childApiRole->setRoleType('U');
|
| 77 |
+
$childApiRole->setUserId($apiUserId);
|
| 78 |
+
$childApiRole->save();
|
| 79 |
+
return $parentRoleId;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
private function _createApiUser($apiKey) {
|
| 83 |
+
$apiUser = Mage::getModel('api/user');
|
| 84 |
+
$apiUser->setUsername('taxjar');
|
| 85 |
+
$apiUser->setFirstname('Mark');
|
| 86 |
+
$apiUser->setLastname('Faggiano');
|
| 87 |
+
$apiUser->setEmail('admin@taxjar.com');
|
| 88 |
+
$apiUser->setApiKey($apiKey);
|
| 89 |
+
$apiUser->setIsActive(1);
|
| 90 |
+
$apiUser->save();
|
| 91 |
+
return $apiUser->getUserId();
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
private function _setConfig($path, $value){
|
| 95 |
+
$config = new Mage_Core_Model_Config();
|
| 96 |
+
$config->saveConfig($path, $value, 'default', 0);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
private function _resourcesToAllow() {
|
| 100 |
+
return array(
|
| 101 |
+
'sales',
|
| 102 |
+
'sales/order',
|
| 103 |
+
'sales/order/change',
|
| 104 |
+
'sales/order/info',
|
| 105 |
+
'sales/order/shipment',
|
| 106 |
+
'sales/order/shipment/create',
|
| 107 |
+
'sales/order/shipment/comment',
|
| 108 |
+
'sales/order/shipment/track',
|
| 109 |
+
'sales/order/shipment/info',
|
| 110 |
+
'sales/order/shipment/send',
|
| 111 |
+
'sales/order/invoice',
|
| 112 |
+
'sales/order/invoice/create',
|
| 113 |
+
'sales/order/invoice/comment',
|
| 114 |
+
'sales/order/invoice/capture',
|
| 115 |
+
'sales/order/invoice/void',
|
| 116 |
+
'sales/order/invoice/cancel',
|
| 117 |
+
'sales/order/invoice/info',
|
| 118 |
+
'sales/order/creditmemo',
|
| 119 |
+
'sales/order/creditmemo/create',
|
| 120 |
+
'sales/order/creditmemo/comment',
|
| 121 |
+
'sales/order/creditmemo/cancel',
|
| 122 |
+
'sales/order/creditmemo/info',
|
| 123 |
+
'sales/order/creditmemo/list'
|
| 124 |
+
);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
private function _resourcesToDeny() {
|
| 128 |
+
return array(
|
| 129 |
+
'core',
|
| 130 |
+
'core/store',
|
| 131 |
+
'core/store/info',
|
| 132 |
+
'core/store/list',
|
| 133 |
+
'core/magento',
|
| 134 |
+
'core/magento/info',
|
| 135 |
+
'directory',
|
| 136 |
+
'directory/country',
|
| 137 |
+
'directory/region',
|
| 138 |
+
'customer',
|
| 139 |
+
'customer/create',
|
| 140 |
+
'customer/update',
|
| 141 |
+
'customer/delete',
|
| 142 |
+
'customer/info',
|
| 143 |
+
'customer/address',
|
| 144 |
+
'customer/address/create',
|
| 145 |
+
'customer/address/update',
|
| 146 |
+
'customer/address/delete',
|
| 147 |
+
'customer/address/info',
|
| 148 |
+
'catalog',
|
| 149 |
+
'catalog/category',
|
| 150 |
+
'catalog/category/create',
|
| 151 |
+
'catalog/category/update',
|
| 152 |
+
'catalog/category/move',
|
| 153 |
+
'catalog/category/delete',
|
| 154 |
+
'catalog/category/tree',
|
| 155 |
+
'catalog/category/info',
|
| 156 |
+
'catalog/category/attributes',
|
| 157 |
+
'catalog/category/product',
|
| 158 |
+
'catalog/category/product/assign',
|
| 159 |
+
'catalog/category/product/update',
|
| 160 |
+
'catalog/category/product/remove',
|
| 161 |
+
'catalog/product',
|
| 162 |
+
'catalog/product/create',
|
| 163 |
+
'catalog/product/update',
|
| 164 |
+
'catalog/product/delete',
|
| 165 |
+
'catalog/product/update_tier_price',
|
| 166 |
+
'catalog/product/info',
|
| 167 |
+
'catalog/product/listOfAdditionalAttributes',
|
| 168 |
+
'catalog/product/attributes',
|
| 169 |
+
'catalog/product/attribute',
|
| 170 |
+
'catalog/product/attribute/read',
|
| 171 |
+
'catalog/product/attribute/write',
|
| 172 |
+
'catalog/product/attribute/types',
|
| 173 |
+
'catalog/product/attribute/create',
|
| 174 |
+
'catalog/product/attribute/update',
|
| 175 |
+
'catalog/product/attribute/remove',
|
| 176 |
+
'catalog/product/attribute/info',
|
| 177 |
+
'catalog/product/attribute/option',
|
| 178 |
+
'catalog/product/attribute/option/add',
|
| 179 |
+
'catalog/product/attribute/option/remove',
|
| 180 |
+
'catalog/product/attribute/set',
|
| 181 |
+
'catalog/product/attribute/set/list',
|
| 182 |
+
'catalog/product/attribute/set/create',
|
| 183 |
+
'catalog/product/attribute/set/remove',
|
| 184 |
+
'catalog/product/attribute/set/attribute_add',
|
| 185 |
+
'catalog/product/attribute/set/attribute_remove',
|
| 186 |
+
'catalog/product/attribute/set/group_add',
|
| 187 |
+
'catalog/product/attribute/set/group_rename',
|
| 188 |
+
'catalog/product/attribute/set/group_remove',
|
| 189 |
+
'catalog/product/link',
|
| 190 |
+
'catalog/product/link/assign',
|
| 191 |
+
'catalog/product/link/update',
|
| 192 |
+
'catalog/product/link/remove',
|
| 193 |
+
'catalog/product/media',
|
| 194 |
+
'catalog/product/media/create',
|
| 195 |
+
'catalog/product/media/update',
|
| 196 |
+
'catalog/product/media/remove',
|
| 197 |
+
'catalog/product/option',
|
| 198 |
+
'catalog/product/option/add',
|
| 199 |
+
'catalog/product/option/update',
|
| 200 |
+
'catalog/product/option/types',
|
| 201 |
+
'catalog/product/option/info',
|
| 202 |
+
'catalog/product/option/list',
|
| 203 |
+
'catalog/product/option/remove',
|
| 204 |
+
'catalog/product/option/value',
|
| 205 |
+
'catalog/product/option/value/list',
|
| 206 |
+
'catalog/product/option/value/info',
|
| 207 |
+
'catalog/product/option/value/add',
|
| 208 |
+
'catalog/product/option/value/update',
|
| 209 |
+
'catalog/product/option/value/remove',
|
| 210 |
+
'catalog/product/tag',
|
| 211 |
+
'catalog/product/tag/list',
|
| 212 |
+
'catalog/product/tag/info',
|
| 213 |
+
'catalog/product/tag/add',
|
| 214 |
+
'catalog/product/tag/update',
|
| 215 |
+
'catalog/product/tag/remove',
|
| 216 |
+
'catalog/product/downloadable_link',
|
| 217 |
+
'catalog/product/downloadable_link/add',
|
| 218 |
+
'catalog/product/downloadable_link/list',
|
| 219 |
+
'catalog/product/downloadable_link/remove',
|
| 220 |
+
'cataloginventory',
|
| 221 |
+
'cataloginventory/update',
|
| 222 |
+
'cataloginventory/info',
|
| 223 |
+
'cart',
|
| 224 |
+
'cart/create',
|
| 225 |
+
'cart/order',
|
| 226 |
+
'cart/info',
|
| 227 |
+
'cart/totals',
|
| 228 |
+
'cart/license',
|
| 229 |
+
'cart/product',
|
| 230 |
+
'cart/product/add',
|
| 231 |
+
'cart/product/update',
|
| 232 |
+
'cart/product/remove',
|
| 233 |
+
'cart/product/list',
|
| 234 |
+
'cart/product/moveToCustomerQuote',
|
| 235 |
+
'cart/customer',
|
| 236 |
+
'cart/customer/set',
|
| 237 |
+
'cart/customer/addresses',
|
| 238 |
+
'cart/shipping',
|
| 239 |
+
'cart/shipping/method',
|
| 240 |
+
'cart/shipping/list',
|
| 241 |
+
'cart/payment',
|
| 242 |
+
'cart/payment/method',
|
| 243 |
+
'cart/payment/list',
|
| 244 |
+
'cart/coupon',
|
| 245 |
+
'cart/coupon/add',
|
| 246 |
+
'cart/coupon/remove',
|
| 247 |
+
'giftmessage',
|
| 248 |
+
'giftmessage/set',
|
| 249 |
+
'all'
|
| 250 |
+
);
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
}
|
| 256 |
+
?>
|
app/code/community/Taxjar/Salestaxautomation/Model/Observer.php
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Taxjar_Salestaxautomation_Model_Observer {
|
| 3 |
+
|
| 4 |
+
public function execute($observer) {
|
| 5 |
+
$apiKey = Mage::getStoreConfig('salestaxautomation/config/salestaxautomation_apikey');
|
| 6 |
+
if ($apiKey){
|
| 7 |
+
$this->newRates = array();
|
| 8 |
+
$client = Mage::getModel('salestaxautomation/client');
|
| 9 |
+
$configuration = Mage::getModel('salestaxautomation/configuration');
|
| 10 |
+
$rule = Mage::getModel('salestaxautomation/rule');
|
| 11 |
+
$regionId = Mage::getStoreConfig('shipping/origin/region_id');
|
| 12 |
+
$regionCode = Mage::getModel('directory/region')->load($regionId)->getCode();
|
| 13 |
+
$storeZip = Mage::getStoreConfig('shipping/origin/postcode');
|
| 14 |
+
$apiHost = 'http://api.taxjar.com';
|
| 15 |
+
$configJson = $client->getResource(
|
| 16 |
+
$apiKey,
|
| 17 |
+
$apiHost . '/magento/get_configuration/' . $regionCode
|
| 18 |
+
);
|
| 19 |
+
if(!$configJson['allow_update']) {
|
| 20 |
+
return;
|
| 21 |
+
}
|
| 22 |
+
$ratesJson = $client->getResource(
|
| 23 |
+
$apiKey,
|
| 24 |
+
$apiHost . '/magento/get_rates/' . $regionCode . '/' . $storeZip
|
| 25 |
+
);
|
| 26 |
+
$configuration->setTaxBasis($configJson);
|
| 27 |
+
$configuration->setShippingTaxability($configJson);
|
| 28 |
+
$configuration->setDisplaySettings();
|
| 29 |
+
$configuration->setApiSettings($apiKey);
|
| 30 |
+
$this->_purgeExisting();
|
| 31 |
+
$this->_createRates($regionId, $regionCode, $ratesJson);
|
| 32 |
+
$rule->create('Retail Customer-Taxable Goods-Rate 1', 2, 1, $this->newRates);
|
| 33 |
+
if($configJson['freight_taxable']) {
|
| 34 |
+
$rule->create('Retail Customer-Shipping-Rate 1', 4, 2, $this->newRates);
|
| 35 |
+
}
|
| 36 |
+
} else {
|
| 37 |
+
$this->_purgeExisting();
|
| 38 |
+
$this->_setLastUpdateDate(NULL);
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
private function _purgeExisting() {
|
| 45 |
+
$paths = array('tax/calculation', 'tax/calculation_rate', 'tax/calculation_rule');
|
| 46 |
+
foreach($paths as $path){
|
| 47 |
+
$existingRecords = Mage::getModel($path)->getCollection();
|
| 48 |
+
foreach($existingRecords as $record) {
|
| 49 |
+
$record->delete();
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
private function _createRates($regionId, $regionCode, $ratesJson) {
|
| 55 |
+
$rate = Mage::getModel('salestaxautomation/rate');
|
| 56 |
+
foreach($ratesJson as $rateJson) {
|
| 57 |
+
$this->newRates[] = $rate->create($regionId, $regionCode, $rateJson);
|
| 58 |
+
}
|
| 59 |
+
$this->_setLastUpdateDate(date('m-d-Y'));
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
private function _setLastUpdateDate($date) {
|
| 63 |
+
Mage::getModel('core/config')->saveConfig('salestaxautomation/config/last_update', $date);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
}
|
| 69 |
+
?>
|
app/code/community/Taxjar/Salestaxautomation/Model/Rate.php
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Taxjar_Salestaxautomation_Model_Rate {
|
| 3 |
+
|
| 4 |
+
public function create($regionId, $regionCode, $rateJson) {
|
| 5 |
+
$zip = $rateJson['zip'];
|
| 6 |
+
$rate = $rateJson['rate'];
|
| 7 |
+
$rateModel = Mage::getModel('tax/calculation_rate');
|
| 8 |
+
$rateModel->setTaxCountryId('US');
|
| 9 |
+
$rateModel->setTaxRegionId($regionId);
|
| 10 |
+
$rateModel->setTaxPostcode($zip);
|
| 11 |
+
$rateModel->setCode('US-' . $regionCode . '-' . $zip);
|
| 12 |
+
$rateModel->setRate($rate);
|
| 13 |
+
$rateModel->save();
|
| 14 |
+
|
| 15 |
+
return $rateModel->getId();
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
}
|
| 19 |
+
?>
|
app/code/community/Taxjar/Salestaxautomation/Model/Rule.php
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Taxjar_Salestaxautomation_Model_Rule {
|
| 3 |
+
public function create($code, $productClass, $position, $newRates) {
|
| 4 |
+
$ruleModel = Mage::getSingleton('tax/calculation_rule');
|
| 5 |
+
$attributes = array(
|
| 6 |
+
'code' => $code,
|
| 7 |
+
'tax_customer_class' => array(3),
|
| 8 |
+
'tax_product_class' => array($productClass),
|
| 9 |
+
'tax_rate' => $newRates,
|
| 10 |
+
'priority' => 1,
|
| 11 |
+
'position' => $position
|
| 12 |
+
);
|
| 13 |
+
$ruleModel->setData($attributes);
|
| 14 |
+
$ruleModel->setCalculateSubtotal(0);
|
| 15 |
+
$ruleModel->save();
|
| 16 |
+
$ruleModel->saveCalculationData();
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
?>
|
app/code/community/Taxjar/Salestaxautomation/etc/config.xml
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Taxjar_Salestaxautomation><version>0.1.0</version></Taxjar_Salestaxautomation>
|
| 5 |
+
</modules>
|
| 6 |
+
<global>
|
| 7 |
+
<helpers>
|
| 8 |
+
<salestaxautomation>
|
| 9 |
+
<class>Taxjar_Salestaxautomation_Helper</class>
|
| 10 |
+
</salestaxautomation>
|
| 11 |
+
</helpers>
|
| 12 |
+
<models>
|
| 13 |
+
<salestaxautomation>
|
| 14 |
+
<class>Taxjar_Salestaxautomation_Model</class>
|
| 15 |
+
</salestaxautomation>
|
| 16 |
+
</models>
|
| 17 |
+
<blocks>
|
| 18 |
+
<salestaxautomation>
|
| 19 |
+
<class>Taxjar_Salestaxautomation_Block</class>
|
| 20 |
+
</salestaxautomation>
|
| 21 |
+
</blocks>
|
| 22 |
+
<events>
|
| 23 |
+
<admin_system_config_changed_section_salestaxautomation>
|
| 24 |
+
<observers>
|
| 25 |
+
<taxjar_salestaxautomation_model_observer>
|
| 26 |
+
<type>singleton</type>
|
| 27 |
+
<class>Taxjar_Salestaxautomation_Model_Observer</class>
|
| 28 |
+
<method>execute</method>
|
| 29 |
+
</taxjar_salestaxautomation_model_observer>
|
| 30 |
+
</observers>
|
| 31 |
+
</admin_system_config_changed_section_salestaxautomation>
|
| 32 |
+
</events>
|
| 33 |
+
</global>
|
| 34 |
+
<frontend>
|
| 35 |
+
<routers>
|
| 36 |
+
<salestaxautomation>
|
| 37 |
+
<use>standard</use>
|
| 38 |
+
<args>
|
| 39 |
+
<module>Taxjar_Salestaxautomation</module>
|
| 40 |
+
<frontName>salestaxautomation</frontName>
|
| 41 |
+
</args>
|
| 42 |
+
</salestaxautomation>
|
| 43 |
+
</routers>
|
| 44 |
+
</frontend>
|
| 45 |
+
<adminhtml>
|
| 46 |
+
<acl>
|
| 47 |
+
<resources>
|
| 48 |
+
<admin>
|
| 49 |
+
<children>
|
| 50 |
+
<system>
|
| 51 |
+
<children>
|
| 52 |
+
<config>
|
| 53 |
+
<children>
|
| 54 |
+
<salestaxautomation>
|
| 55 |
+
<title>Store Sales Tax Wizard Module Section</title>
|
| 56 |
+
</salestaxautomation>
|
| 57 |
+
</children>
|
| 58 |
+
</config>
|
| 59 |
+
</children>
|
| 60 |
+
</system>
|
| 61 |
+
</children>
|
| 62 |
+
</admin>
|
| 63 |
+
</resources>
|
| 64 |
+
</acl>
|
| 65 |
+
</adminhtml>
|
| 66 |
+
<crontab>
|
| 67 |
+
<jobs>
|
| 68 |
+
<salestaxautomation>
|
| 69 |
+
<schedule><cron_expr>0 8 1 * *</cron_expr></schedule>
|
| 70 |
+
<run><model>salestaxautomation/observer::execute</model></run>
|
| 71 |
+
</salestaxautomation>
|
| 72 |
+
</jobs>
|
| 73 |
+
</crontab>
|
| 74 |
+
|
| 75 |
+
</config>
|
app/code/community/Taxjar/Salestaxautomation/etc/system.xml
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<tabs>
|
| 4 |
+
<salestaxautomation translate="label" module="salestaxautomation">
|
| 5 |
+
<label>TaxJar</label>
|
| 6 |
+
<sort_order>99999</sort_order>
|
| 7 |
+
</salestaxautomation>
|
| 8 |
+
</tabs>
|
| 9 |
+
<sections>
|
| 10 |
+
<salestaxautomation translate="label" module="salestaxautomation">
|
| 11 |
+
<label>Sales Tax Automation</label>
|
| 12 |
+
<tab>salestaxautomation</tab>
|
| 13 |
+
<frontend_type>text</frontend_type>
|
| 14 |
+
<sort_order>1000</sort_order>
|
| 15 |
+
<show_in_default>1</show_in_default>
|
| 16 |
+
<show_in_website>1</show_in_website>
|
| 17 |
+
<show_in_store>1</show_in_store>
|
| 18 |
+
<groups>
|
| 19 |
+
<config translate="label">
|
| 20 |
+
<label>API Token</label>
|
| 21 |
+
<frontend_type>text</frontend_type>
|
| 22 |
+
<sort_order>1</sort_order>
|
| 23 |
+
<show_in_default>1</show_in_default>
|
| 24 |
+
<show_in_website>1</show_in_website>
|
| 25 |
+
<show_in_store>1</show_in_store>
|
| 26 |
+
<fields>
|
| 27 |
+
<salestaxautomation_apikey>
|
| 28 |
+
<label>API Token</label>
|
| 29 |
+
<comment>
|
| 30 |
+
<model>salestaxautomation/comment</model>
|
| 31 |
+
</comment>
|
| 32 |
+
<frontend_type>text</frontend_type>
|
| 33 |
+
<sort_order>1</sort_order>
|
| 34 |
+
<show_in_default>1</show_in_default>
|
| 35 |
+
<show_in_website>1</show_in_website>
|
| 36 |
+
<show_in_store>1</show_in_store>
|
| 37 |
+
</salestaxautomation_apikey>
|
| 38 |
+
</fields>
|
| 39 |
+
</config>
|
| 40 |
+
</groups>
|
| 41 |
+
</salestaxautomation>
|
| 42 |
+
</sections>
|
| 43 |
+
</config>
|
app/etc/modules/Taxjar_Salestaxautomation.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<config>
|
| 2 |
+
<modules>
|
| 3 |
+
<Taxjar_Salestaxautomation>
|
| 4 |
+
<active>true</active>
|
| 5 |
+
<codePool>community</codePool>
|
| 6 |
+
<depends></depends>
|
| 7 |
+
</Taxjar_Salestaxautomation>
|
| 8 |
+
</modules>
|
| 9 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Taxjar_Salestaxautomation</name>
|
| 4 |
+
<version>1.0.0</version>
|
| 5 |
+
<stability>beta</stability>
|
| 6 |
+
<license>MITL</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>Easily collect sales tax without altering your Magento store’s checkout experience or performance. 
|
| 10 |
+
</summary>
|
| 11 |
+
<description>Collect sales tax without changing your Magento Store’s checkout process. 
|
| 12 |
+
TaxJar’s Sales Tax Automation makes collecting sales tax easy by removing complex configuration and 
|
| 13 |
+
providing accurate rates and reporting that eliminate precious hours wasted on filing sales tax returns. 
|
| 14 |
+
Sales Tax Automation Benefits: 
|
| 15 |
+
- Easy first-time install 
|
| 16 |
+
- Automated sales tax configuration 
|
| 17 |
+
- Avoid shopping cart abandonment 
|
| 18 |
+
- Calculations don’t impact store’s performance 
|
| 19 |
+
- Free rates for your state 
|
| 20 |
+
- No setup fee 
|
| 21 |
+
</description>
|
| 22 |
+
<notes>Collect sales tax without changing your Magento Store’s checkout process. 
|
| 23 |
+
TaxJar’s Sales Tax Automation makes collecting sales tax easy by removing complex configuration and 
|
| 24 |
+
providing accurate rates and reporting that eliminate precious hours wasted on filing sales tax returns. 
|
| 25 |
+
Sales Tax Automation Benefits: 
|
| 26 |
+
- Easy first-time install 
|
| 27 |
+
- Automated sales tax configuration 
|
| 28 |
+
- Avoid shopping cart abandonment 
|
| 29 |
+
- Calculations don’t impact store’s performance 
|
| 30 |
+
- Free rates for your state 
|
| 31 |
+
- No setup fee 
|
| 32 |
+
</notes>
|
| 33 |
+
<authors><author><name>Bernd Ustorf</name><user>taxjar</user><email>bernd@taxjar.com</email></author></authors>
|
| 34 |
+
<date>2014-04-18</date>
|
| 35 |
+
<time>22:15:08</time>
|
| 36 |
+
<contents><target name="magecommunity"><dir name="Taxjar"><dir name="Salestaxautomation"><dir name="Helper"><file name="Data.php" hash="96c03874cb66ac342e1ae67bc38f2a7c"/></dir><dir name="Model"><file name="Client.php" hash="07f565045e3c7937e62cca95519f4bb3"/><file name="Comment.php" hash="36c5c9d31dff176eb5e956d3a4edb077"/><file name="Configuration.php" hash="db8cf6bea02ee957c3d1e056349aabed"/><file name="Observer.php" hash="fea56df8ecd51073ce5e65a6d5c44a5c"/><file name="Rate.php" hash="c3056aa1c1097da7ac739653d38fe2c3"/><file name="Rule.php" hash="0b4153d8bc244b4ab585e3d4d3368713"/></dir><dir name="etc"><file name="config.xml" hash="bfdcf1e88dd36890cdee269bb1a59932"/><file name="system.xml" hash="6fbac6eab4308d515c7b4a03ec50c593"/></dir></dir><file name=".DS_Store" hash="13f08486f093ac8c1a2548de0ec42bb6"/></dir></target><target name="mageetc"><dir name="modules"><file name="Taxjar_Salestaxautomation.xml" hash="85eafb00fd56cb0b36130a9dcad1f859"/></dir></target></contents>
|
| 37 |
+
<compatible/>
|
| 38 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.0</min><max>2.0.0</max></package></required></dependencies>
|
| 39 |
+
</package>
|
