Taxjar_Salestaxautomation - Version 1.3.0

Version Notes

* Adds support for zip plus four rate calculations to Magento.
* Rates may now only be installed on one Magento installation at a time.

Download this release

Release Info

Developer TaxJar
Extension Taxjar_Salestaxautomation
Version 1.3.0
Comparing to
See all releases


Code changes from version 1.2.2 to 1.3.0

app/code/community/Taxjar/.DS_Store DELETED
Binary file
app/code/community/Taxjar/SalesTax/Model/Calculation.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * TaxJar Zip+4 Rate Calculation Support for US
5
+ *
6
+ * @author Taxjar (support@taxjar.com)
7
+ */
8
+ class Taxjar_SalesTax_Model_Calculation extends Mage_Tax_Model_Resource_Calculation {
9
+
10
+ /**
11
+ * Returns tax rates for request and when US only uses five digit zip code lookups
12
+ *
13
+ * @param Varien_Object $request
14
+ * @return array
15
+ */
16
+ protected function _getRates( $request ) {
17
+ // Grab each current value
18
+ $countryId = $request->getCountryId();
19
+ $currentPostcode = $request->getPostcode();
20
+ if( $countryId == 'US' ) {
21
+ // Trim whitespace
22
+ $newPostcode = preg_replace('/\s+/', '', $request->getPostcode());
23
+ // Snatch only the first five characters
24
+ $newPostcode = substr($newPostcode, 0, 5);
25
+ // Replace the request's zip code with one that now has 5 digits
26
+ $request->setPostcode($newPostcode);
27
+ // Find rates by the new 5-digit zip
28
+ $rates = parent::_getRates($request);
29
+ // Reset the request's postcode to what it was
30
+ $request->setPostcode($currentPostcode);
31
+ }
32
+ else {
33
+ // Non-US should just work normally
34
+ $rates = parent::_getRates($request);
35
+ }
36
+ return $rates;
37
+ }
38
+
39
+ }
40
+ ?>
app/code/community/Taxjar/SalesTax/Model/Comment.php CHANGED
@@ -72,7 +72,7 @@ class Taxjar_SalesTax_Model_Comment {
72
  * @return $string
73
  */
74
  private function buildInstalledHtml( $statesHtml, $lastUpdate ) {
75
- $htmlString = "<p class='note'><span>TaxJar is installed. Check the Manage Tax Rules section to verify all installed states.</span></p><br/><p>TaxJar has <em>automatically</em> added rates for the following states to your Magento installation:<br/><ul class='messages'>". $statesHtml . "</ul>To manage your TaxJar states <a href='https://app.taxjar.com/account#states' target='_blank'>click here</a>.</p><p>Your sales tax rates were last updated on: <ul class='messages'><li class='info-msg'><ul><li><span style='font-size: 1.4em;'>" . $lastUpdate . "</span></li></ul></li></ul><small>Rates may be automatically or manually updated again once per month. Contact support@taxjar.com with the email address registered to your TaxJar account if you need assistance.</small></p><p><small>If you would like to uninstall TaxJar, remove the API Token from the box above, then save the config. This will remove all tax rates in your Magento store. You can then uninstall in the Magento Connect Manager.<small></p>";
76
  return $htmlString;
77
  }
78
 
@@ -83,7 +83,7 @@ class Taxjar_SalesTax_Model_Comment {
83
  * @return $string
84
  */
85
  private function buildNotYetInstalledHtml( $regionName ) {
86
- $htmlString = "<p class='note'><span>Enter your TaxJar API Token</span></p><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. We will also retrieve all other states from your TaxJar account. 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>";
87
  return $htmlString;
88
  }
89
 
72
  * @return $string
73
  */
74
  private function buildInstalledHtml( $statesHtml, $lastUpdate ) {
75
+ $htmlString = "<p class='note'><span>TaxJar is installed. Check the Manage Tax Rules section to verify all installed states.</span></p><br/><p>TaxJar has <em>automatically</em> added rates for the following states to your Magento installation:<br/><ul class='messages'>". $statesHtml . "</ul>To manage your TaxJar states <a href='https://app.taxjar.com/account#states' target='_blank'>click here</a>.</p><p>Your sales tax rates were last updated on: <ul class='messages'><li class='info-msg'><ul><li><span style='font-size: 1.4em;'>" . $lastUpdate . "</span></li></ul></li></ul><small>Rates may be automatically or manually updated again once per month. Contact support@taxjar.com with the email address registered to your TaxJar account if you need assistance.</small></p><p><small>If you would like to uninstall TaxJar, remove the API Token from the box above, then save the config. This will remove all tax rates in your Magento store. You can then uninstall in the Magento Connect Manager.<small></p><p><strong>Important Notice</strong>: Your API key may be used to install rates on only <em>one</em> Magento installation at a time.</p>";
76
  return $htmlString;
77
  }
78
 
83
  * @return $string
84
  */
85
  private function buildNotYetInstalledHtml( $regionName ) {
86
+ $htmlString = "<p class='note'><span>Enter your TaxJar API Token</span></p><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. We will also retrieve all other states from your TaxJar account. 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><p><small><strong>Important Notice</strong>: Your API key may be used to install rates on only <em>one</em> Magento installation at a time.</small></p>";
87
  return $htmlString;
88
  }
89
 
app/code/community/Taxjar/SalesTax/Model/Debug.php CHANGED
@@ -34,7 +34,7 @@ class Taxjar_SalesTax_Model_Debug {
34
  $states = implode( ',', unserialize( Mage::getStoreConfig('taxjar/config/states') ) );
35
  $apiUser = Mage::getModel('api/user');
36
  $existingUserId = $apiUser->load('taxjar', 'username')->getUserId();
37
- $pluginVersion = '1.2.2';
38
  $phpMemory = @ini_get('memory_limit');
39
  $phpVersion = @phpversion();
40
  $magentoVersion = Mage::getVersion();
34
  $states = implode( ',', unserialize( Mage::getStoreConfig('taxjar/config/states') ) );
35
  $apiUser = Mage::getModel('api/user');
36
  $existingUserId = $apiUser->load('taxjar', 'username')->getUserId();
37
+ $pluginVersion = '1.3.0';
38
  $phpMemory = @ini_get('memory_limit');
39
  $phpVersion = @phpversion();
40
  $magentoVersion = Mage::getVersion();
app/code/community/Taxjar/SalesTax/Model/Observer.php CHANGED
@@ -43,7 +43,7 @@ class Taxjar_SalesTax_Model_Observer {
43
 
44
  if( ! $configJson['allow_update'] ) {
45
  $dateUpdated = Mage::getStoreConfig('taxjar/config/last_update');
46
- Mage::getSingleton('core/session')->addNotice("Your rates are already up to date. Date of last update: " . $dateUpdated);
47
  return;
48
  }
49
 
43
 
44
  if( ! $configJson['allow_update'] ) {
45
  $dateUpdated = Mage::getStoreConfig('taxjar/config/last_update');
46
+ Mage::getSingleton('core/session')->addNotice("Your last rate update was too recent. Please wait at least 5 minutes and try again.");
47
  return;
48
  }
49
 
app/code/community/Taxjar/SalesTax/Model/Rate.php CHANGED
@@ -8,41 +8,48 @@
8
  class Taxjar_SalesTax_Model_Rate {
9
 
10
  /**
11
- * Display Nexus states loaded and API Key setting
12
  *
13
  * @param JSON $string
14
  * @return array
15
  */
16
  public function create( $rateJson ) {
17
- $zip = $rateJson['zip'];
18
- $regionCode = $rateJson['state'];
19
- $rate = $rateJson['rate'];
 
20
 
21
- if ( isset( $rateJson['country'] ) ) {
22
- $countryCode = $rateJson['country'];
23
- }
24
- else {
25
- $countryCode = 'US';
26
- }
27
 
28
- $regionId = Mage::getModel('directory/region')->loadByCode($regionCode, $countryCode)->getId();
29
- $rateModel = Mage::getModel('tax/calculation_rate');
30
 
31
- $rateModel->setTaxCountryId($countryCode);
32
- $rateModel->setTaxRegionId($regionId);
33
- $rateModel->setTaxPostcode($zip);
34
- $rateModel->setCode($countryCode . '-' . $regionCode . '-' . $zip);
35
- $rateModel->setRate($rate);
36
- $rateModel->save();
37
 
38
- if ( $rateJson['freight_taxable'] ) {
39
- $shippingRateId = $rateModel->getId();
 
 
 
 
 
 
40
  }
41
- else {
42
- $shippingRateId = 0;
 
 
43
  }
44
-
45
- return array( $rateModel->getId(), $shippingRateId );
46
  }
47
 
48
  }
8
  class Taxjar_SalesTax_Model_Rate {
9
 
10
  /**
11
+ * Try to create the rate
12
  *
13
  * @param JSON $string
14
  * @return array
15
  */
16
  public function create( $rateJson ) {
17
+ try {
18
+ $zip = $rateJson['zip'];
19
+ $regionCode = $rateJson['state'];
20
+ $rate = $rateJson['rate'];
21
 
22
+ if ( isset( $rateJson['country'] ) ) {
23
+ $countryCode = $rateJson['country'];
24
+ }
25
+ else {
26
+ $countryCode = 'US';
27
+ }
28
 
29
+ $regionId = Mage::getModel('directory/region')->loadByCode($regionCode, $countryCode)->getId();
30
+ $rateModel = Mage::getModel('tax/calculation_rate');
31
 
32
+ $rateModel->setTaxCountryId($countryCode);
33
+ $rateModel->setTaxRegionId($regionId);
34
+ $rateModel->setTaxPostcode($zip);
35
+ $rateModel->setCode($countryCode . '-' . $regionCode . '-' . $zip);
36
+ $rateModel->setRate($rate);
37
+ $rateModel->save();
38
 
39
+ if ( $rateJson['freight_taxable'] ) {
40
+ $shippingRateId = $rateModel->getId();
41
+ }
42
+ else {
43
+ $shippingRateId = 0;
44
+ }
45
+
46
+ return array( $rateModel->getId(), $shippingRateId );
47
  }
48
+ catch ( Exception $e ) {
49
+ Mage::getSingleton('core/session')->addNotice("There was an error encountered while loading rate with code " . $rateModel->getCode() . ". This is most likely due to duplicate codes and can be safely ignored if lots of other rates were loaded. If the error persists, email support@taxjar.com with a screenshot of any Magento errors displayed." );
50
+ unset( $rateModel );
51
+ return;
52
  }
 
 
53
  }
54
 
55
  }
app/code/community/Taxjar/SalesTax/etc/config.xml CHANGED
@@ -6,7 +6,7 @@
6
  -->
7
  <config>
8
  <modules>
9
- <Taxjar_SalesTax><version>1.2.2</version></Taxjar_SalesTax>
10
  </modules>
11
  <global>
12
  <helpers>
@@ -17,7 +17,12 @@
17
  <models>
18
  <taxjar>
19
  <class>Taxjar_SalesTax_Model</class>
20
- </taxjar>
 
 
 
 
 
21
  </models>
22
  <blocks>
23
  <taxjar>
6
  -->
7
  <config>
8
  <modules>
9
+ <Taxjar_SalesTax><version>1.3.0</version></Taxjar_SalesTax>
10
  </modules>
11
  <global>
12
  <helpers>
17
  <models>
18
  <taxjar>
19
  <class>Taxjar_SalesTax_Model</class>
20
+ </taxjar>
21
+ <tax_resource>
22
+ <rewrite>
23
+ <calculation>Taxjar_SalesTax_Model_Calculation</calculation>
24
+ </rewrite>
25
+ </tax_resource>
26
  </models>
27
  <blocks>
28
  <taxjar>
package.xml CHANGED
@@ -1,19 +1,19 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Taxjar_Salestaxautomation</name>
4
- <version>1.2.2</version>
5
  <stability>stable</stability>
6
- <license>MITL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Easily collect sales tax without altering your Magento store&#x2019;s checkout experience or performance.</summary>
10
- <description>Collect sales tax without changing your Magento Store&#x2019;s checkout process. Sales Tax Automation by TaxJar is free to use for 30 days. If you choose to pay for TaxJar, pricing starts at $29.95/month. Pricing is based on the number of transactions your store does per month. We feature both monthly rates and annual plans that offer a 2-month discount if you prepay for the year.</description>
11
- <notes>This release offers the following:&#xD;
12
- * New debug features</notes>
13
  <authors><author><name>TaxJar</name><user>taxjar</user><email>support@taxjar.com</email></author></authors>
14
- <date>2014-11-24</date>
15
- <time>21:31:52</time>
16
- <contents><target name="magecommunity"><dir name="Taxjar"><dir name="SalesTax"><dir name="Helper"><file name="Data.php" hash="565812e7d6927df4c91bfb69b79b1b09"/></dir><dir name="Model"><file name="Client.php" hash="6c3339bcc33670b0d41ded468b72e77b"/><file name="Comment.php" hash="e636422b9cc1ac0f0bb6b3751dcc90c9"/><file name="Configuration.php" hash="1ed6e9467ac8c5ca6e906753071a9161"/><file name="Debug.php" hash="4ce1560ba966e208a70997b753a2233b"/><file name="Observer.php" hash="dae265549f3e99edf406fa7ec9042f70"/><file name="Rate.php" hash="4f1f62e6696f10f34f58d7104936223d"/><file name="Rule.php" hash="ae33149080b3182e62b56607f7b30da4"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4ea028ad6b00688d99531597e8d3c404"/><file name="config.xml" hash="7eafa4838a2bacce9bec14b702df2fbe"/><file name="system.xml" hash="8dc55519eef0349d487f4039eabda164"/></dir></dir><file name=".DS_Store" hash="e385b6a995c1af38f899669fa136a12e"/></dir></target><target name="mageetc"><dir name="modules"><file name="Taxjar_SalesTax.xml" hash="60b211e28d8b9d4cc49d1dd746d4aa46"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Taxjar_Salestaxautomation</name>
4
+ <version>1.3.0</version>
5
  <stability>stable</stability>
6
+ <license>MIT</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Easily collect sales tax without altering your Magento store&#x2019;s checkout experience or performance.</summary>
10
+ <description>TaxJar for Magento allows you to install rates for multiple origin or destination-based states without affecting your store's checkout experience.</description>
11
+ <notes>* Adds support for zip plus four rate calculations to Magento.&#xD;
12
+ * Rates may now only be installed on one Magento installation at a time.</notes>
13
  <authors><author><name>TaxJar</name><user>taxjar</user><email>support@taxjar.com</email></author></authors>
14
+ <date>2015-03-10</date>
15
+ <time>13:48:00</time>
16
+ <contents><target name="magecommunity"><dir name="Taxjar"><dir name="SalesTax"><dir name="Helper"><file name="Data.php" hash="565812e7d6927df4c91bfb69b79b1b09"/></dir><dir name="Model"><file name="Calculation.php" hash="170fd255c7bdf2d3d7cfa258e08dcc91"/><file name="Client.php" hash="6c3339bcc33670b0d41ded468b72e77b"/><file name="Comment.php" hash="b02f877f10934f3596215fbc6a4ce08e"/><file name="Configuration.php" hash="1ed6e9467ac8c5ca6e906753071a9161"/><file name="Debug.php" hash="096b1fb2e45e808845d50f2ad371953a"/><file name="Observer.php" hash="fd0a35937096c2d8b6eb97405eb54460"/><file name="Rate.php" hash="30b07e73624405c5acba6965c0f6b2f6"/><file name="Rule.php" hash="ae33149080b3182e62b56607f7b30da4"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4ea028ad6b00688d99531597e8d3c404"/><file name="config.xml" hash="60802c2569b2a5b7178d527e35d43175"/><file name="system.xml" hash="8dc55519eef0349d487f4039eabda164"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Taxjar_SalesTax.xml" hash="60b211e28d8b9d4cc49d1dd746d4aa46"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>