OnePica_AvaTax - Version 3.0.0

Version Notes

Improved performance
Reduced number of GetTax calls
Fixed error displaying
Fixed logs export
Fixed Customer Tax Code sending for not logged in customer group
Fixed tax calculation if change customer group while place order via admin
Fixed request settings for Multiple Checkout
Fixed buttons "View Shopping Cart" and "Checkout" displaying in the MiniCart if user enters non taxable address during Multiple Checkout
Fixed tax rates in checkout when shipping address changing four times

Download this release

Release Info

Developer Astound Commerce
Extension OnePica_AvaTax
Version 3.0.0
Comparing to
See all releases


Code changes from version 2.6.9 to 3.0.0

Files changed (146) hide show
  1. app/code/community/OnePica/AvaTax/Block/Adminhtml/Notification/Toolbar.php +1 -1
  2. app/code/community/OnePica/AvaTax/Block/Checkout/Onepage/Shipping/Method/Available.php +1 -1
  3. app/code/community/OnePica/AvaTax/Helper/Address.php +286 -0
  4. app/code/community/OnePica/AvaTax/Helper/Calculation.php +307 -0
  5. app/code/community/OnePica/AvaTax/Helper/Config.php +738 -0
  6. app/code/community/OnePica/AvaTax/Helper/Data.php +76 -528
  7. app/code/community/OnePica/AvaTax/Helper/Errors.php +158 -0
  8. app/code/community/OnePica/AvaTax/Helper/GiftWrapping/Data.php +10 -10
  9. app/code/community/OnePica/AvaTax/Helper/Lib.php +62 -0
  10. app/code/community/OnePica/AvaTax/Helper/Tax/Data.php +7 -7
  11. app/code/community/OnePica/AvaTax/Model/Abstract.php +0 -105
  12. app/code/community/OnePica/AvaTax/Model/Action/Abstract.php +96 -0
  13. app/code/community/OnePica/AvaTax/Model/Action/Calculator.php +242 -0
  14. app/code/community/OnePica/AvaTax/Model/Action/Creditmemo.php +65 -0
  15. app/code/community/OnePica/AvaTax/Model/Action/Invoice.php +64 -0
  16. app/code/community/OnePica/AvaTax/Model/Action/Ping.php +34 -0
  17. app/code/community/OnePica/AvaTax/Model/Action/Validator.php +327 -0
  18. app/code/community/OnePica/AvaTax/Model/Adminhtml/Config.php +43 -12
  19. app/code/community/OnePica/AvaTax/Model/Adminhtml/Sales/Order/Create.php +45 -17
  20. app/code/community/OnePica/AvaTax/Model/Avatax/Address.php +0 -351
  21. app/code/community/OnePica/AvaTax/Model/Config.php +0 -224
  22. app/code/community/OnePica/AvaTax/Model/Observer.php +0 -546
  23. app/code/community/OnePica/AvaTax/Model/Observer/Abstract.php +127 -0
  24. app/code/community/OnePica/AvaTax/Model/Observer/AdminSystemConfigChangedSectionTax.php +299 -0
  25. app/code/community/OnePica/AvaTax/Model/Observer/CheckoutSubmitAllAfter.php +38 -0
  26. app/code/community/OnePica/AvaTax/Model/Observer/CheckoutTypeMultishippingCreateOrdersSingle.php +43 -0
  27. app/code/community/OnePica/AvaTax/Model/Observer/CleanLog.php +38 -0
  28. app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPostdispatchCheckoutCartEstimatePost.php +39 -0
  29. app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPostdispatchCheckoutCartEstimateUpdatePost.php +39 -0
  30. app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPostdispatchCheckoutOnepageSaveShippingMethod.php +57 -0
  31. app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPredispatchAdminhtmlSalesOrderCreateLoadBlock.php +41 -0
  32. app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPredispatchCheckoutCartEstimatePost.php +40 -0
  33. app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPredispatchCheckoutCartIndex.php +39 -0
  34. app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPredispatchCheckoutMultishippingIndex.php +40 -0
  35. app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPredispatchCheckoutOnepageIndex.php +40 -0
  36. app/code/community/OnePica/AvaTax/Model/Observer/LoadAvaTaxExternalLib.php +107 -0
  37. app/code/community/OnePica/AvaTax/Model/Observer/MultishippingSetShippingItems.php +65 -0
  38. app/code/community/OnePica/AvaTax/Model/Observer/ProcessQueue.php +37 -0
  39. app/code/community/OnePica/AvaTax/Model/Observer/SalesModelServiceQuoteSubmitAfter.php +38 -0
  40. app/code/community/OnePica/AvaTax/Model/Observer/SalesModelServiceQuoteSubmitBefore.php +41 -0
  41. app/code/community/OnePica/AvaTax/Model/Observer/SalesOrderCreditmemoRefund.php +37 -0
  42. app/code/community/OnePica/AvaTax/Model/Observer/SalesOrderCreditmemoSaveAfter.php +49 -0
  43. app/code/community/OnePica/AvaTax/Model/Observer/SalesOrderInvoicePay.php +37 -0
  44. app/code/community/OnePica/AvaTax/Model/Observer/SalesOrderInvoiceSaveAfter.php +51 -0
  45. app/code/community/OnePica/AvaTax/Model/Observer/SalesQuoteCollectTotalsBefore.php +41 -0
  46. app/code/community/OnePica/AvaTax/Model/Records/Log.php +20 -3
  47. app/code/community/OnePica/AvaTax/Model/Records/Mysql4/Queue.php +2 -2
  48. app/code/community/OnePica/AvaTax/Model/Records/Queue.php +19 -5
  49. app/code/community/OnePica/AvaTax/Model/Records/Queue/Process.php +22 -11
  50. app/code/community/OnePica/AvaTax/Model/Sales/Quote/Address.php +21 -55
  51. app/code/community/OnePica/AvaTax/Model/Sales/Quote/Address/Total/Grand.php +3 -3
  52. app/code/community/OnePica/AvaTax/Model/Sales/Quote/Address/Total/Tax.php +169 -110
  53. app/code/community/OnePica/AvaTax/Model/Service.php +53 -0
  54. app/code/community/OnePica/AvaTax/Model/Service/Abstract.php +224 -0
  55. app/code/community/OnePica/AvaTax/Model/Service/Abstract/Config.php +151 -0
  56. app/code/community/OnePica/AvaTax/Model/Service/Abstract/Tools.php +173 -0
  57. app/code/community/OnePica/AvaTax/Model/Service/Avatax.php +207 -0
  58. app/code/community/OnePica/AvaTax/Model/{Avatax → Service/Avatax}/Abstract.php +124 -280
  59. app/code/community/OnePica/AvaTax/Model/Service/Avatax/Address.php +301 -0
  60. app/code/community/OnePica/AvaTax/Model/Service/Avatax/Config.php +123 -0
  61. app/code/community/OnePica/AvaTax/Model/{Avatax → Service/Avatax}/Estimate.php +82 -136
  62. app/code/community/OnePica/AvaTax/Model/{Avatax → Service/Avatax}/Invoice.php +83 -119
  63. app/code/community/OnePica/AvaTax/Model/{Avatax → Service/Avatax}/Ping.php +5 -5
  64. app/code/community/OnePica/AvaTax/Model/Service/Avatax/Tax.php +66 -0
  65. app/code/community/OnePica/AvaTax/Model/Service/Avatax16.php +200 -0
  66. app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Abstract.php +287 -0
  67. app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Address.php +272 -0
  68. app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Config.php +121 -0
  69. app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Estimate.php +676 -0
  70. app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Invoice.php +550 -0
  71. app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Ping.php +81 -0
  72. app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Tax.php +385 -0
  73. app/code/community/OnePica/AvaTax/Model/{Avatax → Service}/Exception/Address.php +2 -2
  74. app/code/community/OnePica/AvaTax/Model/{Avatax → Service}/Exception/Commitfailure.php +1 -1
  75. app/code/community/OnePica/AvaTax/Model/{Avatax → Service}/Exception/Unbalanced.php +1 -1
  76. app/code/community/OnePica/AvaTax/Model/Service/Result/Address.php +200 -0
  77. app/code/community/OnePica/AvaTax/Model/Service/Result/AddressValidate.php +172 -0
  78. app/code/community/OnePica/AvaTax/Model/Service/Result/Creditmemo.php +142 -0
  79. app/code/community/OnePica/AvaTax/Model/Service/Result/Invoice.php +142 -0
  80. app/code/community/OnePica/AvaTax/Model/Source/Actions.php +10 -19
  81. app/code/community/OnePica/AvaTax/Model/Source/Avatax/Actions.php +54 -0
  82. app/code/community/OnePica/AvaTax/Model/Source/Avatax/Logtype.php +82 -0
  83. app/code/community/OnePica/AvaTax/Model/Source/Avatax/Url.php +55 -0
  84. app/code/community/OnePica/AvaTax/Model/Source/Avatax16/Actions.php +50 -0
  85. app/code/community/OnePica/AvaTax/Model/Source/Avatax16/Buyertype.php +114 -0
  86. app/code/community/OnePica/AvaTax/Model/Source/Avatax16/Logtype.php +91 -0
  87. app/code/community/OnePica/AvaTax/Model/Source/Avatax16/Url.php +46 -0
  88. app/code/community/OnePica/AvaTax/Model/Source/Avatax16/Usetype.php +123 -0
  89. app/code/community/OnePica/AvaTax/Model/Source/Logtype.php +10 -48
  90. app/code/community/OnePica/AvaTax/Model/Source/Regionfilter/List.php +1 -1
  91. app/code/community/OnePica/AvaTax/Model/Source/Regionfilter/Mode.php +3 -3
  92. app/code/community/OnePica/AvaTax/Model/Source/Url.php +45 -0
  93. app/code/community/OnePica/AvaTax/Model/Tax/Config.php +21 -21
  94. app/code/community/OnePica/AvaTax/Model/Total/Quote/Tax/Giftwrapping.php +1 -1
  95. app/code/community/OnePica/AvaTax/etc/adminhtml.xml +2 -0
  96. app/code/community/OnePica/AvaTax/etc/config.xml +120 -25
  97. app/code/community/OnePica/AvaTax/etc/system-avatax16-disabled.xml +39 -0
  98. app/code/community/OnePica/AvaTax/etc/system-avatax16.xml +48 -0
  99. app/code/community/OnePica/AvaTax/etc/system-disabled.xml +1 -1
  100. app/code/community/OnePica/AvaTax/etc/system.xml +51 -7
  101. app/code/community/OnePica/AvaTax/sql/avatax_records_setup/mysql4-upgrade-3.0.0.1-3.0.0.2.php +27 -0
  102. lib/AvaTax/classes/ValidateRequest.class.php +3 -0
  103. lib/OnePica/AvaTax16/AddressResolution.php +55 -0
  104. lib/OnePica/AvaTax16/AddressResolution/PingResponse.php +37 -0
  105. lib/OnePica/AvaTax16/AddressResolution/ResolveSingleAddressResponse.php +83 -0
  106. lib/OnePica/AvaTax16/AddressResolution/TaxAuthority.php +51 -0
  107. lib/OnePica/AvaTax16/Calculation.php +114 -0
  108. lib/OnePica/AvaTax16/Calculation/ListItemResponse.php +72 -0
  109. lib/OnePica/AvaTax16/Calculation/ListItemResponse/CalculatedTaxSummary.php +92 -0
  110. lib/OnePica/AvaTax16/Calculation/ListItemResponse/CalculatedTaxSummary/TaxByType.php +56 -0
  111. lib/OnePica/AvaTax16/Calculation/ListItemResponse/CalculatedTaxSummary/TaxByType/Details.php +52 -0
  112. lib/OnePica/AvaTax16/Calculation/ListItemResponse/Header.php +79 -0
  113. lib/OnePica/AvaTax16/Calculation/ListItemResponse/Line.php +30 -0
  114. lib/OnePica/AvaTax16/Calculation/ListItemResponse/ProcessingInfo.php +79 -0
  115. lib/OnePica/AvaTax16/Calculation/ListResponse.php +62 -0
  116. lib/OnePica/AvaTax16/Config.php +228 -0
  117. lib/OnePica/AvaTax16/Document/Part.php +210 -0
  118. lib/OnePica/AvaTax16/Document/Part/Feedback.php +30 -0
  119. lib/OnePica/AvaTax16/Document/Part/Feedback/LatencyData.php +37 -0
  120. lib/OnePica/AvaTax16/Document/Part/Location.php +128 -0
  121. lib/OnePica/AvaTax16/Document/Part/Location/Address.php +123 -0
  122. lib/OnePica/AvaTax16/Document/Part/Location/LatLong.php +37 -0
  123. lib/OnePica/AvaTax16/Document/Request.php +76 -0
  124. lib/OnePica/AvaTax16/Document/Request/Header.php +199 -0
  125. lib/OnePica/AvaTax16/Document/Request/Line.php +177 -0
  126. lib/OnePica/AvaTax16/Document/Response.php +96 -0
  127. lib/OnePica/AvaTax16/Document/Response/CalculatedTaxSummary.php +78 -0
  128. lib/OnePica/AvaTax16/Document/Response/CalculatedTaxSummary/TaxByType.php +57 -0
  129. lib/OnePica/AvaTax16/Document/Response/CalculatedTaxSummary/TaxByType/Details.php +52 -0
  130. lib/OnePica/AvaTax16/Document/Response/Header.php +183 -0
  131. lib/OnePica/AvaTax16/Document/Response/Line.php +188 -0
  132. lib/OnePica/AvaTax16/Document/Response/Line/CalculatedTax.php +60 -0
  133. lib/OnePica/AvaTax16/Document/Response/Line/CalculatedTax/Details.php +115 -0
  134. lib/OnePica/AvaTax16/Document/Response/Line/CalculatedTax/TaxByType.php +43 -0
  135. lib/OnePica/AvaTax16/Document/Response/ProcessingInfo.php +79 -0
  136. lib/OnePica/AvaTax16/Exception.php +24 -0
  137. lib/OnePica/AvaTax16/IO/CaseInsensitiveArray.php +150 -0
  138. lib/OnePica/AvaTax16/IO/Curl.php +1382 -0
  139. lib/OnePica/AvaTax16/ResourceAbstract.php +135 -0
  140. lib/OnePica/AvaTax16/TaxService.php +254 -0
  141. lib/OnePica/AvaTax16/Transaction.php +227 -0
  142. lib/OnePica/AvaTax16/Transaction/ListItemResponse.php +25 -0
  143. lib/OnePica/AvaTax16/Transaction/ListResponse.php +62 -0
  144. lib/OnePica/AvaTax16/Transaction/TransitionTransactionStateResponse.php +45 -0
  145. lib/OnePica/autoload.php +40 -0
  146. package.xml +13 -5
app/code/community/OnePica/AvaTax/Block/Adminhtml/Notification/Toolbar.php CHANGED
@@ -73,6 +73,6 @@ class OnePica_AvaTax_Block_Adminhtml_Notification_Toolbar extends Mage_Adminhtml
73
  */
74
  public function getQueueAttemptMaxValue()
75
  {
76
- return OnePica_AvaTax_Model_Config::QUEUE_ATTEMPT_MAX;
77
  }
78
  }
73
  */
74
  public function getQueueAttemptMaxValue()
75
  {
76
+ return OnePica_AvaTax_Model_Service_Abstract_Config::QUEUE_ATTEMPT_MAX;
77
  }
78
  }
app/code/community/OnePica/AvaTax/Block/Checkout/Onepage/Shipping/Method/Available.php CHANGED
@@ -93,7 +93,7 @@ class OnePica_AvaTax_Block_Checkout_Onepage_Shipping_Method_Available extends Ma
93
  {
94
  $additional = parent::_toHtml();
95
  if ($this->getAddress()->getAddressNormalized()) {
96
- $notice = Mage::getSingleton('avatax/config')->getConfig('onepage_normalize_message');
97
  if ($notice) {
98
  Mage::getSingleton('core/session')->addNotice($notice);
99
  $additional .= $this->getMessagesBlock()->getGroupedHtml();
93
  {
94
  $additional = parent::_toHtml();
95
  if ($this->getAddress()->getAddressNormalized()) {
96
+ $notice = Mage::helper('avatax/config')->getOnepageNormalizeMessage(Mage::app()->getStore());
97
  if ($notice) {
98
  Mage::getSingleton('core/session')->addNotice($notice);
99
  $additional .= $this->getMessagesBlock()->getGroupedHtml();
app/code/community/OnePica/AvaTax/Helper/Address.php ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The base AvaTax Helper class
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Helper_Address extends Mage_Core_Helper_Abstract
26
+ {
27
+ /**
28
+ * Determines if address normalization is enabled
29
+ *
30
+ * @param Mage_Customer_Model_Address $address
31
+ * @param int $storeId
32
+ *
33
+ * @return bool
34
+ */
35
+ public function isAddressNormalizationOn($address, $storeId)
36
+ {
37
+ if (!$this->isAddressActionable($address, $storeId, OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_ALL, true)) {
38
+ return false;
39
+ }
40
+ return $this->_getConfigData()->getNormalizeAddress($storeId);
41
+ }
42
+
43
+ /**
44
+ * Determines if address validation is enabled
45
+ *
46
+ * @param Mage_Customer_Model_Address $address
47
+ * @param int $storeId
48
+ *
49
+ * @return bool
50
+ */
51
+ public function isAddressValidationOn($address, $storeId)
52
+ {
53
+ if (!$this->isAddressActionable($address, $storeId, OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_ALL, true)) {
54
+ return false;
55
+ }
56
+ return $this->_getConfigData()->getValidateAddress($storeId);
57
+ }
58
+
59
+ /**
60
+ * Get address validation countries
61
+ *
62
+ * @return array
63
+ */
64
+ public function getAddressValidationCountries()
65
+ {
66
+ return explode(',', $this->_getConfigData()->getAddressValidationCountries());
67
+ }
68
+
69
+ /**
70
+ * Determines if the address should be filtered
71
+ *
72
+ * @param Mage_Customer_Model_Address $address
73
+ * @param int $storeId
74
+ * @param int $filterMode
75
+ * @param bool $isAddressValidation
76
+ *
77
+ * @return bool
78
+ */
79
+ public function isAddressActionable($address, $storeId, $filterMode = OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_ALL,
80
+ $isAddressValidation = false
81
+ )
82
+ {
83
+ $filter = false;
84
+
85
+ if ($this->_getConfigData()->getStatusServiceAction($storeId)
86
+ == OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_DISABLE) {
87
+ return false;
88
+ }
89
+
90
+ if ($this->getRegionFilterModByStore($storeId) >= $filterMode) {
91
+ $filter = $this->_getFilterRegion($address, $storeId);
92
+ }
93
+
94
+ if ($isAddressValidation && $filter
95
+ && ((int)$this->getRegionFilterModByStore($storeId) !== OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_ALL)
96
+ ) {
97
+ $filter = false;
98
+ }
99
+
100
+ if (!in_array($address->getCountryId(), $this->getTaxableCountryByStore($storeId))) {
101
+ $filter = 'country';
102
+ }
103
+
104
+ if ($isAddressValidation && !$filter
105
+ && !in_array($address->getCountryId(), $this->getAddressValidationCountries())
106
+ ) {
107
+ $filter = 'country';
108
+ }
109
+
110
+ if ($filter && Mage::helper('avatax')->getLogMode($storeId)) {
111
+ $filterLog = Mage::getSingleton('avatax/session')->getFilterLog();
112
+ if (!is_array($filterLog)) {
113
+ $filterLog = array();
114
+ }
115
+ $key = $address->getCacheHashKey();
116
+
117
+ //did we already log this filtered address?
118
+ if (!in_array($key, $filterLog)) {
119
+ $filterLog[] = $key;
120
+ Mage::getSingleton('avatax/session')->setFilterLog($filterLog);
121
+
122
+ $type = ($filterMode == OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_TAX) ?
123
+ 'tax_calc' : 'tax_calc|address_opts';
124
+ Mage::getModel('avatax_records/log')
125
+ ->setStoreId($storeId)
126
+ ->setLevel('Success')
127
+ ->setType('Filter')
128
+ ->setRequest(print_r($address->debug(), true))
129
+ ->setResult('filter: ' . $filter . ', type: ' . $type)
130
+ ->save();
131
+ }
132
+ }
133
+
134
+ return $filter ? false : true;
135
+ }
136
+
137
+ /**
138
+ * Get region filter mod by store
139
+ *
140
+ * @param null|int $storeId
141
+ *
142
+ * @return int
143
+ * @internal param int $store
144
+ */
145
+ public function getRegionFilterModByStore($storeId = null)
146
+ {
147
+ return $this->_getConfigData()->getRegionFilterMode($storeId);
148
+ }
149
+
150
+ /**
151
+ * Get region filter mode by current scope
152
+ *
153
+ * @throws \Mage_Core_Exception
154
+ * @return int
155
+ */
156
+ public function getRegionFilterModByCurrentScope()
157
+ {
158
+ $websiteId = Mage::app()->getRequest()->get('website');
159
+ $storeId = Mage::app()->getRequest()->get('store');
160
+
161
+ if ($websiteId && !$storeId) {
162
+ return $this->getRegionFilterModByWebsite($websiteId);
163
+ }
164
+
165
+ return $this->getRegionFilterModByStore($storeId);
166
+ }
167
+
168
+ /**
169
+ * Get region filter mod by website
170
+ *
171
+ * @param int $websiteId
172
+ *
173
+ * @return int
174
+ * @throws \Mage_Core_Exception
175
+ */
176
+ public function getRegionFilterModByWebsite($websiteId)
177
+ {
178
+ return $this->_getConfigData()->getConfigRegionFilterModByWebsite($websiteId);
179
+ }
180
+
181
+ /**
182
+ * Get region filter
183
+ *
184
+ * @param Mage_Customer_Model_Address $address
185
+ * @param int $storeId
186
+ *
187
+ * @return string|bool
188
+ */
189
+ protected function _getFilterRegion($address, $storeId)
190
+ {
191
+ $filter = false;
192
+ $regionFilters = explode(',', $this->_getConfigData()->getRegionFilterList($storeId));
193
+ $entityId = $address->getRegionId() ?: $address->getCountryId();
194
+ if (!in_array($entityId, $regionFilters)) {
195
+ $filter = 'region';
196
+ }
197
+ return $filter;
198
+ }
199
+
200
+ /**
201
+ * Get taxable country by store
202
+ *
203
+ * @param int $storeId
204
+ *
205
+ * @return array
206
+ */
207
+ public function getTaxableCountryByStore($storeId = null)
208
+ {
209
+ return explode(',', $this->_getConfigData()->getTaxableCountry($storeId));
210
+ }
211
+
212
+ /**
213
+ * Get taxable country by website
214
+ *
215
+ * @param int $websiteId
216
+ *
217
+ * @return array
218
+ */
219
+ public function getTaxableCountryByWebSite($websiteId)
220
+ {
221
+ return explode(',', Mage::app()
222
+ ->getWebsite($websiteId)
223
+ ->getConfig(OnePica_AvaTax_Helper_Config::XML_PATH_TO_TAX_AVATAX_TAXABLE_COUNTRY)
224
+ );
225
+ }
226
+
227
+ /**
228
+ * Get taxable country by current scope
229
+ *
230
+ * Used in admin panel
231
+ *
232
+ * @return array
233
+ */
234
+ public function getTaxableCountryByCurrentScope()
235
+ {
236
+ $websiteId = Mage::app()->getRequest()->get('website');
237
+ $storeId = Mage::app()->getRequest()->get('store');
238
+ if ($websiteId && !$storeId) {
239
+ return $this->getTaxableCountryByWebSite($websiteId);
240
+ }
241
+ return $this->getTaxableCountryByStore($storeId);
242
+ }
243
+
244
+ /**
245
+ * Determines if the object (quote, invoice, or credit memo) should use AvaTax services
246
+ *
247
+ * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
248
+ * @param Mage_Sales_Model_Quote_Address $shippingAddress
249
+ *
250
+ * @return bool
251
+ */
252
+ public function isObjectActionable($object, $shippingAddress = null)
253
+ {
254
+ $storeId = $object->getStore()->getId();
255
+
256
+ //is action enabled?
257
+ $action = $object->getOrder() ?
258
+ OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC_SUBMIT : OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC;
259
+ if ($this->_getConfigData()->getStatusServiceAction($storeId) < $action) {
260
+ return false;
261
+ }
262
+
263
+ if (!$shippingAddress) {
264
+ $shippingAddress = $object->getShippingAddress();
265
+ }
266
+ if (!$shippingAddress) {
267
+ $shippingAddress = $object->getBillingAddress();
268
+ }
269
+
270
+ //is the region filtered?
271
+ if (!$this->isAddressActionable($shippingAddress, $storeId, OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_TAX)) {
272
+ return false;
273
+ }
274
+
275
+ return true;
276
+ }
277
+
278
+ /**
279
+ * Get config helper
280
+ * @return OnePica_AvaTax_Helper_Config
281
+ */
282
+ private function _getConfigData()
283
+ {
284
+ return Mage::helper('avatax/config');
285
+ }
286
+ }
app/code/community/OnePica/AvaTax/Helper/Calculation.php ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0), a
6
+ * copy of which is available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category OnePica
10
+ * @package OnePica_AvaTax
11
+ * @author OnePica Codemaster <codemaster@onepica.com>
12
+ * @copyright Copyright (c) 2015 One Pica, Inc.
13
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14
+ */
15
+
16
+ /**
17
+ * Class OnePica_AvaTax_Helper_Calculation
18
+ *
19
+ * @category OnePica
20
+ * @package OnePica_AvaTax
21
+ * @author OnePica Codemaster <codemaster@onepica.com>
22
+ */
23
+ class OnePica_AvaTax_Helper_Calculation
24
+ extends Mage_Core_Helper_Abstract
25
+ {
26
+ /**
27
+ * Sets the customer info if available
28
+ *
29
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address|Mage_Sales_Model_Order $object
30
+ * @return $this
31
+ */
32
+ public function getCustomerCode($object)
33
+ {
34
+ /** @var Mage_Customer_Model_Customer $customer */
35
+ $customer = Mage::getModel('customer/customer');
36
+
37
+ if ($object->getCustomerId()) {
38
+ $customer->load($object->getCustomerId());
39
+ }
40
+ // get store id from object or from quote
41
+ $storeId = $this->_getStoreIdFromSalesObject($object);
42
+
43
+ switch ($this->_getConfigHelper()->getCustomerCodeFormat($storeId)) {
44
+ case OnePica_AvaTax_Model_Source_Customercodeformat::LEGACY:
45
+ $customerCode = $this->_getLegacyCustomerCode($object, $customer);
46
+ break;
47
+ case OnePica_AvaTax_Model_Source_Customercodeformat::CUST_EMAIL:
48
+ $customerCode = $this->_getCustomerEmail($object, $customer)
49
+ ?: $this->_getCustomerId($object);
50
+ break;
51
+ case OnePica_AvaTax_Model_Source_Customercodeformat::CUST_ID:
52
+ default:
53
+ $customerCode = $this->_getCustomerId($object);
54
+ break;
55
+ }
56
+
57
+ return $customerCode;
58
+ }
59
+
60
+ /**
61
+ * Get store id from quote address or order object
62
+ *
63
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address|Mage_Sales_Model_Order $object
64
+ * @return int|null
65
+ */
66
+ protected function _getStoreIdFromSalesObject($object)
67
+ {
68
+ $storeId = null;
69
+ if ($object instanceof Mage_Sales_Model_Order) {
70
+ $storeId = $object->getStoreId();
71
+ } elseif ($object instanceof OnePica_AvaTax_Model_Sales_Quote_Address) {
72
+ $storeId = $object->getQuote()->getStoreId();
73
+ }
74
+
75
+ return $storeId;
76
+ }
77
+
78
+ /**
79
+ * Retrieve customer email
80
+ *
81
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address|Mage_Sales_Model_Order $object
82
+ * @param Mage_Customer_Model_Customer $customer
83
+ * @return string
84
+ */
85
+ protected function _getCustomerEmail($object, $customer)
86
+ {
87
+ $email = null;
88
+ if ($object instanceof OnePica_AvaTax_Model_Sales_Quote_Address) {
89
+ $email = $object->getEmail();
90
+ if (!$email) {
91
+ // get email from billing in case the $object is shipping address
92
+ $email = $object->getQuote()->getBillingAddress()
93
+ ? $object->getQuote()->getBillingAddress()->getEmail()
94
+ : null;
95
+ }
96
+ } elseif ($object instanceof Mage_Sales_Model_Order) {
97
+ $email = $object->getCustomerEmail();
98
+ }
99
+
100
+ if (!$email) {
101
+ $email = $customer->getEmail();
102
+ }
103
+
104
+ return $email;
105
+ }
106
+
107
+ /**
108
+ * Retrieve customer id
109
+ *
110
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address|Mage_Sales_Model_Order $object
111
+ * @return string
112
+ */
113
+ protected function _getCustomerId($object)
114
+ {
115
+ return $object->getCustomerId()
116
+ ? $object->getCustomerId()
117
+ : 'guest-' . $object->getId();
118
+ }
119
+
120
+ /**
121
+ * Get legacy customer code
122
+ *
123
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address|Mage_Sales_Model_Order $object
124
+ * @param Mage_Customer_Model_Customer $customer
125
+ * @return string
126
+ */
127
+ protected function _getLegacyCustomerCode($object, $customer)
128
+ {
129
+ if ($customer->getId()) {
130
+ $customerCode = $customer->getName() . ' (' . $customer->getId() . ')';
131
+
132
+ return $customerCode;
133
+ }
134
+
135
+ $address = $object->getBillingAddress() ?: $object;
136
+ $customerCode = $address->getFirstname() . ' ' . $address->getLastname() . ' (Guest)';
137
+
138
+ return $customerCode;
139
+ }
140
+
141
+ /**
142
+ * Get customer usage type
143
+ *
144
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address|Mage_Sales_Model_Order $object
145
+ * @return string
146
+ */
147
+ public function getCustomerOpAvataxCode($object)
148
+ {
149
+ return Mage::getModel('tax/class')->load($this->_getTaxClassId($object))->getOpAvataxCode();
150
+ }
151
+
152
+ /**
153
+ * Get tax class id
154
+ *
155
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address|Mage_Sales_Model_Order $object
156
+ * @return int
157
+ */
158
+ protected function _getTaxClassId($object)
159
+ {
160
+ if ($object instanceof OnePica_AvaTax_Model_Sales_Quote_Address) {
161
+ return $object->getQuote()->getCustomerTaxClassId();
162
+ }
163
+
164
+ return Mage::getSingleton('customer/group')->load($object->getCustomerGroupId())->getTaxClassId();
165
+ }
166
+
167
+ /**
168
+ * Get simple product id from configurable item
169
+ *
170
+ * @param Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Creditmemo_Item|Mage_Sales_Model_Order_Invoice_Item $item
171
+ * @return int
172
+ */
173
+ public function getSimpleProductIdByConfigurable($item)
174
+ {
175
+ if (($item instanceof Mage_Sales_Model_Quote_Item
176
+ || $item instanceof Mage_Sales_Model_Quote_Address_Item)
177
+ && $this->isConfigurable($item)
178
+ ) {
179
+ /** @var Mage_Catalog_Model_Product[] $children */
180
+ $children = $item->getChildren();
181
+ if (isset($children[0]) && $children[0]->getProductId()) {
182
+ return $children[0]->getProductId();
183
+ }
184
+ }
185
+
186
+ if (($item instanceof Mage_Sales_Model_Order_Invoice_Item
187
+ || $item instanceof Mage_Sales_Model_Order_Creditmemo_Item)
188
+ && $this->isConfigurable($item)
189
+ ) {
190
+ $children = $item->getOrderItem()->getChildrenItems();
191
+ if (isset($children[0]) && $children[0]->getProductId()) {
192
+ return $children[0]->getProductId();
193
+ }
194
+ }
195
+
196
+ return 0;
197
+ }
198
+
199
+ /**
200
+ * Checks if item is configurable
201
+ *
202
+ * @param Mage_Sales_Model_Quote_Address_Item|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Creditmemo_Item|Mage_Sales_Model_Order_Invoice_Item $item
203
+ * @return bool
204
+ */
205
+ public function isConfigurable($item)
206
+ {
207
+ if ($item instanceof Mage_Sales_Model_Quote_Item) {
208
+ return $item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
209
+ }
210
+
211
+ if ($item instanceof Mage_Sales_Model_Quote_Address_Item) {
212
+ return $item->getProduct()->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
213
+ }
214
+
215
+ if (($item instanceof Mage_Sales_Model_Order_Invoice_Item
216
+ || $item instanceof Mage_Sales_Model_Order_Creditmemo_Item)
217
+ ) {
218
+ return $item->getOrderItem()->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
219
+ }
220
+
221
+ return false;
222
+ }
223
+
224
+ /**
225
+ * Get item code
226
+ *
227
+ * @param Mage_Catalog_Model_Product $product
228
+ * @param int|Mage_Core_Model_Store $storeId
229
+ * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
230
+ * @return string
231
+ */
232
+ public function getItemCode($product, $storeId, $item = null)
233
+ {
234
+ $itemCode = '';
235
+ if (null !== $product) {
236
+ $itemCode = $this->_getUpcCode($product, $storeId);
237
+ }
238
+
239
+ if (empty($itemCode)) {
240
+ $itemCode = (null !== $item) ? $item->getSku() : $product->getSku();
241
+ }
242
+
243
+ return substr($itemCode, 0, 50);
244
+ }
245
+
246
+ /**
247
+ * Get UPC code from product
248
+ *
249
+ * @param Mage_Catalog_Model_Product $product
250
+ * @param int|Mage_Core_Model_Store $storeId
251
+ * @return string
252
+ */
253
+ protected function _getUpcCode($product, $storeId)
254
+ {
255
+ $upc = $this->getProductAttributeValue(
256
+ $product,
257
+ $this->_getUpcAttributeCode($storeId)
258
+ );
259
+
260
+ return !empty($upc) ? 'UPC:' . $upc : '';
261
+ }
262
+
263
+ /**
264
+ * Get product attribute value
265
+ *
266
+ * @param Mage_Catalog_Model_Product $product
267
+ * @param string $code
268
+ * @return string
269
+ */
270
+ public function getProductAttributeValue($product, $code)
271
+ {
272
+ $value = '';
273
+ if ($code && $product->getResource()->getAttribute($code)) {
274
+ try {
275
+ $value = (string)$product->getResource()
276
+ ->getAttribute($code)
277
+ ->getFrontend()
278
+ ->getValue($product);
279
+ } catch (Exception $e) {
280
+ Mage::logException($e);
281
+ }
282
+ }
283
+
284
+ return $value;
285
+ }
286
+
287
+ /**
288
+ * Get UPC attribute code
289
+ *
290
+ * @param int|Mage_Core_Model_Store $store
291
+ * @return string
292
+ */
293
+ protected function _getUpcAttributeCode($store)
294
+ {
295
+ return $this->_getConfigHelper()->getUpcAttributeCode($store);
296
+ }
297
+
298
+ /**
299
+ * Get data helper
300
+ *
301
+ * @return OnePica_AvaTax_Helper_Config
302
+ */
303
+ protected function _getConfigHelper()
304
+ {
305
+ return Mage::helper('avatax/config');
306
+ }
307
+ }
app/code/community/OnePica/AvaTax/Helper/Config.php ADDED
@@ -0,0 +1,738 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The base AvaTax Helper class
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Helper_Config extends Mage_Core_Helper_Abstract
26
+ {
27
+ /**
28
+ * Path to customer code format
29
+ */
30
+ const PATH_TAX_AVATAX_CUST_CODE_FORMAT = 'tax/avatax/cust_code_format';
31
+
32
+ /**
33
+ * Path to full stop on error
34
+ */
35
+ const XML_PATH_TO_TAX_AVATAX_ERROR_STOP = 'tax/avatax/error_full_stop';
36
+
37
+ /**
38
+ * Path to shipping line item faked sku
39
+ */
40
+ const XML_PATH_TO_TAX_AVATAX_SHIPPING_SKU = 'tax/avatax/shipping_sku';
41
+
42
+ /**
43
+ * Path to giftwraporder line item faked sku
44
+ */
45
+ const XML_PATH_TO_TAX_AVATAX_GW_ORDER_SKU = 'tax/avatax/gw_order_sku';
46
+
47
+ /**
48
+ * Path to giftwrapitems line item faked sku
49
+ */
50
+ const XML_PATH_TO_TAX_AVATAX_GW_ITEMS_SKU = 'tax/avatax/gw_items_sku';
51
+
52
+ /**
53
+ * Path to giftwrapprintedcard line item faked sku
54
+ */
55
+ const XML_PATH_TO_TAX_AVATAX_GW_PRINTED_CARD_SKU = 'tax/avatax/gw_printed_card_sku';
56
+
57
+ /**
58
+ * Path to shipping line item faked sku
59
+ */
60
+ const XML_PATH_TO_TAX_AVATAX_SALES_PERSON_CODE = 'tax/avatax/sales_person_code';
61
+
62
+ /**
63
+ * Path to attribute code for the location code to send to Avalara
64
+ */
65
+ const XML_PATH_TO_TAX_AVATAX_LOCATION_CODE = 'tax/avatax/location_code';
66
+
67
+ /**
68
+ * Path to the positive adjustment identifier to send to Avalara
69
+ */
70
+ const XML_PATH_TO_TAX_AVATAX_ADJUSTMENT_POSITIVE_SKU = 'tax/avatax/adjustment_positive_sku';
71
+
72
+ /**
73
+ * Path to the negative adjustment identifier to send to Avalara
74
+ */
75
+ const XML_PATH_TO_TAX_AVATAX_ADJUSTMENT_NEGATIVE_SKU = 'tax/avatax/adjustment_negative_sku';
76
+
77
+ /**
78
+ * Path to the required field list
79
+ */
80
+ const XML_PATH_TO_TAX_AVATAX_FIELD_REQUIRED_LIST = 'tax/avatax/field_required_list';
81
+
82
+ /**
83
+ * Path to the rules for field
84
+ */
85
+ const XML_PATH_TO_TAX_AVATAX_FIELD_RULE = 'tax/avatax/field_rule';
86
+
87
+ /**
88
+ * Path to the rules for url
89
+ */
90
+ const XML_PATH_TO_TAX_AVATAX_URL = 'tax/avatax/url';
91
+
92
+ /**
93
+ * Path to the rules for url
94
+ */
95
+ const XML_PATH_TO_TAX_AVATAX_ACCOUNT = 'tax/avatax/account';
96
+
97
+ /**
98
+ * Path to the rules for url
99
+ */
100
+ const XML_PATH_TO_TAX_AVATAX_KEY = 'tax/avatax/license';
101
+
102
+ /**
103
+ * Path to the rules for url
104
+ */
105
+ const XML_PATH_TO_TAX_AVATAX_COMPANY_CODE = 'tax/avatax/company_code';
106
+
107
+ /**
108
+ * Path to attribute code for the reference code 1 to send to Avalara
109
+ */
110
+ const XML_PATH_TO_TAX_AVATAX_LINE_REF1_CODE = 'tax/avatax/line_ref1_code';
111
+
112
+ /**
113
+ * Path to attribute code for the reference code 2 to send to Avalara
114
+ */
115
+ const XML_PATH_TO_TAX_AVATAX_LINE_REF2_CODE = 'tax/avatax/line_ref2_code';
116
+
117
+ /**
118
+ * Path to is AvaTax disabled.
119
+ */
120
+ const XML_PATH_TO_TAX_AVATAX_ACTION = 'tax/avatax/action';
121
+
122
+ /**
123
+ * Path to error in backend massage
124
+ */
125
+ const CALCULATE_ERROR_BACKEND_MESSAGE = 'tax/avatax/error_backend_message';
126
+
127
+ /**
128
+ * Path to error frontend message
129
+ */
130
+ const CALCULATE_ERROR_FRONTEND_MESSAGE = 'tax/avatax/error_frontend_message';
131
+
132
+ /**
133
+ * Path to is address normalization on
134
+ */
135
+ const XML_PATH_TO_TAX_AVATAX_NORMALIZE_ADDRESS = 'tax/avatax/normalize_address';
136
+
137
+ /**
138
+ * Path to is address validate
139
+ */
140
+ const XML_PATH_TO_TAX_AVATAX_VALIDATE_ADDRESS = 'tax/avatax/validate_address';
141
+
142
+ /**
143
+ * Path to address validation countries
144
+ */
145
+ const XML_PATH_TO_TAX_AVATAX_ADDRESS_VALIDATION_COUNTRIES = 'tax/avatax/address_validation_countries';
146
+
147
+ /**
148
+ * Xml path to region_filter_mode
149
+ */
150
+ const XML_PATH_TO_TAX_AVATAX_REGION_FILTER_LIST = 'tax/avatax/region_filter_list';
151
+
152
+ /**
153
+ * Xml path to region_filter_mode
154
+ */
155
+ const XML_PATH_TO_TAX_AVATAX_REGION_FILTER_MODE = 'tax/avatax/region_filter_mode';
156
+
157
+ /**
158
+ * Xml path to taxable_country config
159
+ */
160
+ const XML_PATH_TO_TAX_AVATAX_TAXABLE_COUNTRY = 'tax/avatax/taxable_country';
161
+
162
+ /**
163
+ * Path to the logging type
164
+ */
165
+ const XML_PATH_TO_TAX_AVATAX_LOG_TYPE_LIST = 'tax/avatax/log_type_list';
166
+
167
+ /**
168
+ * Path to is AvaTax disabled.
169
+ */
170
+ const XML_PATH_TO_TAX_AVATAX_LOG_STATUS = 'tax/avatax/log_status';
171
+
172
+ /**
173
+ * Path to active avatax service
174
+ */
175
+ const XML_PATH_TO_TAX_AVATAX_ACTIVE_SERVICE = 'tax/avatax/active_service';
176
+
177
+ /**
178
+ * Path to active avatax service
179
+ */
180
+ const XML_PATH_TO_TAX_AVATAX_ONEPAGE_NORMALIZE_MESSAGE = 'tax/avatax/onepage_normalize_message';
181
+
182
+ /**
183
+ * Path to active avatax service
184
+ */
185
+ const XML_PATH_TO_SHIPPING_ORIGIN_COUNTRY_ID = 'shipping/origin/country_id';
186
+
187
+ /**
188
+ * Path to default avalara goods and services type
189
+ */
190
+ const XML_PATH_TO_DEFAULT_AVALARA_GOODS_AND_SERVICES_TYPE = 'tax/avatax/default_avalara_goods_and_services_type';
191
+
192
+ /**
193
+ * Path to default avalara goods and services modifier type
194
+ */
195
+ const XML_PATH_TO_DEFAULT_AVALARA_GOODS_AND_SERVICES_MODIFIER_TYPE =
196
+ 'tax/avatax/default_avalara_goods_and_services_modifier_type';
197
+
198
+ /**
199
+ * Path to default tax payer code
200
+ */
201
+ const XML_PATH_TO_DEFAULT_TAX_PAYER_CODE = 'tax/avatax/default_tax_payer_code';
202
+
203
+ /**
204
+ * Path to default use type
205
+ */
206
+ const XML_PATH_TO_DEFAULT_USE_TYPE = 'tax/avatax/default_use_type';
207
+
208
+ /**
209
+ * Path to default buyer type
210
+ */
211
+ const XML_PATH_TO_DEFAULT_BUYER_TYPE = 'tax/avatax/default_buyer_type';
212
+
213
+ /**
214
+ * Path to upc status
215
+ */
216
+ const XML_PATH_TO_AVATAX_UPC_CHECK_STATUS = 'tax/avatax/upc_check_status';
217
+
218
+ /**
219
+ * Path to upc attribute code
220
+ */
221
+ const PATH_TO_AVATAX_UPC_ATTRIBUTE_CODE = 'tax/avatax/upc_attribute_code';
222
+
223
+ /**
224
+ * Path to avatax16 address validation message
225
+ */
226
+ const PATH_TO_AVATAX16_ADDRESS_VALIDATION_MESSAGE = 'tax/avatax/avatax16_onepage_validate_address_message';
227
+
228
+ /**#@+
229
+ * Service types
230
+ */
231
+ const AVATAX16_SERVICE_TYPE = 'avatax16';
232
+ const AVATAX_SERVICE_TYPE = 'avatax';
233
+ /**#@-*/
234
+
235
+ /**
236
+ * Returns full stop on error
237
+ *
238
+ * @param null|bool|int|Mage_Core_Model_Store $store
239
+ *
240
+ * @return bool
241
+ */
242
+ public function fullStopOnError($store = null)
243
+ {
244
+ return (bool)Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_ERROR_STOP, $store);
245
+ }
246
+
247
+ /**
248
+ * Returns shipping line item faked sku
249
+ *
250
+ * @param null|bool|int|Mage_Core_Model_Store $store
251
+ *
252
+ * @return string
253
+ */
254
+ public function getShippingSku($store = null)
255
+ {
256
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_SHIPPING_SKU, $store);
257
+ }
258
+
259
+ /**
260
+ * Returns service url
261
+ *
262
+ * @param null|bool|int|Mage_Core_Model_Store $store
263
+ *
264
+ * @return string
265
+ */
266
+ public function getServiceUrl($store = null)
267
+ {
268
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_URL, $store);
269
+ }
270
+
271
+ /**
272
+ * Returns service account id
273
+ *
274
+ * @param null|bool|int|Mage_Core_Model_Store $store
275
+ *
276
+ * @return string
277
+ */
278
+ public function getServiceAccountId($store = null)
279
+ {
280
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_ACCOUNT, $store);
281
+ }
282
+
283
+ /**
284
+ * Returns service account id
285
+ *
286
+ * @param null|bool|int|Mage_Core_Model_Store $store
287
+ *
288
+ * @return string
289
+ */
290
+ public function getServiceKey($store = null)
291
+ {
292
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_KEY, $store);
293
+ }
294
+
295
+ /**
296
+ * Returns service account id
297
+ *
298
+ * @param null|bool|int|Mage_Core_Model_Store $store
299
+ *
300
+ * @return string
301
+ */
302
+ public function getCompanyCode($store = null)
303
+ {
304
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_COMPANY_CODE, $store);
305
+ }
306
+
307
+ /**
308
+ * Returns giftwraporder line item faked sku
309
+ *
310
+ * @param null|bool|int|Mage_Core_Model_Store $store
311
+ *
312
+ * @return string
313
+ */
314
+ public function getGwOrderSku($store = null)
315
+ {
316
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_GW_ORDER_SKU, $store);
317
+ }
318
+
319
+ /**
320
+ * Returns giftwrapitems line item faked sku
321
+ *
322
+ * @param null|bool|int|Mage_Core_Model_Store $store
323
+ *
324
+ * @return string
325
+ */
326
+ public function getGwItemsSku($store = null)
327
+ {
328
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_GW_ITEMS_SKU, $store);
329
+ }
330
+
331
+ /**
332
+ * Returns giftwrapprintedcard line item faked sku
333
+ *
334
+ * @param null|bool|int|Mage_Core_Model_Store $store
335
+ *
336
+ * @return string
337
+ */
338
+ public function getGwPrintedCardSku($store = null)
339
+ {
340
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_GW_PRINTED_CARD_SKU, $store);
341
+ }
342
+
343
+ /**
344
+ * Returns shipping line item faked sku
345
+ *
346
+ * @param null|bool|int|Mage_Core_Model_Store $store
347
+ *
348
+ * @return string
349
+ */
350
+ public function getSalesPersonCode($store = null)
351
+ {
352
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_SALES_PERSON_CODE, $store);
353
+ }
354
+
355
+ /**
356
+ * Returns attribute code for the location code to send to Avalara
357
+ *
358
+ * @param null|bool|int|Mage_Core_Model_Store $store
359
+ *
360
+ * @return string
361
+ */
362
+ public function getLocationCode($store = null)
363
+ {
364
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_LOCATION_CODE, $store);
365
+ }
366
+
367
+ /**
368
+ * Returns the positive adjustment identifier to send to Avalara
369
+ *
370
+ * @param null|bool|int|Mage_Core_Model_Store $store
371
+ *
372
+ * @return string
373
+ */
374
+ public function getPositiveAdjustmentSku($store = null)
375
+ {
376
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_ADJUSTMENT_POSITIVE_SKU, $store);
377
+ }
378
+
379
+ /**
380
+ * Returns the negative adjustment identifier to send to Avalara
381
+ *
382
+ * @param null|bool|int|Mage_Core_Model_Store $store
383
+ *
384
+ * @return string
385
+ */
386
+ public function getNegativeAdjustmentSku($store = null)
387
+ {
388
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_ADJUSTMENT_NEGATIVE_SKU, $store);
389
+ }
390
+
391
+ /**
392
+ * Returns the required field list
393
+ *
394
+ * @param null|bool|int|Mage_Core_Model_Store $store
395
+ *
396
+ * @return string
397
+ */
398
+ public function getFieldRequiredList($store = null)
399
+ {
400
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_FIELD_REQUIRED_LIST, $store);
401
+ }
402
+
403
+ /**
404
+ * Returns the rules for field
405
+ *
406
+ * @param null|bool|int|Mage_Core_Model_Store $store
407
+ *
408
+ * @return string
409
+ */
410
+ public function getFieldRule($store = null)
411
+ {
412
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_FIELD_RULE, $store);
413
+ }
414
+
415
+ /**
416
+ * Returns attribute code for the reference code 1 to send to Avalara
417
+ *
418
+ * @param null|bool|int|Mage_Core_Model_Store $store
419
+ *
420
+ * @return string
421
+ */
422
+ public function getRef1AttributeCode($store = null)
423
+ {
424
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_LINE_REF1_CODE, $store);
425
+ }
426
+
427
+ /**
428
+ * Returns attribute code for the reference code 2 to send to Avalara
429
+ *
430
+ * @param null|bool|int|Mage_Core_Model_Store $store
431
+ *
432
+ * @return string
433
+ */
434
+ public function getRef2AttributeCode($store = null)
435
+ {
436
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_LINE_REF2_CODE, $store);
437
+ }
438
+
439
+ /**
440
+ * Get
441
+ */
442
+ public function get()
443
+ {
444
+ }
445
+
446
+ /**
447
+ * Returns the path to the etc directory.
448
+ *
449
+ * @return string
450
+ */
451
+ public function getEtcPath()
452
+ {
453
+ return dirname(dirname(__FILE__)) . DS . 'etc';
454
+ }
455
+
456
+ /**
457
+ * Is AvaTax disabled.
458
+ *
459
+ * @return bool
460
+ * @throws Mage_Core_Exception
461
+ */
462
+ public function isAvaTaxDisabled()
463
+ {
464
+ $websiteId = Mage::app()->getRequest()->get('website');
465
+ $storeId = Mage::app()->getRequest()->get('store');
466
+
467
+ if ($websiteId && !$storeId) {
468
+ return !(bool)Mage::app()->getWebsite($websiteId)->getConfig(self::XML_PATH_TO_TAX_AVATAX_ACTION);
469
+ }
470
+
471
+ return !(bool)Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_ACTION, $storeId);
472
+ }
473
+
474
+ /**
475
+ * Get avatax status
476
+ *
477
+ * @param int|Mage_Core_Model_Store $storeId
478
+ * @return mixed
479
+ */
480
+ public function getStatusServiceAction($storeId = null)
481
+ {
482
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_ACTION, $storeId);
483
+ }
484
+
485
+ /**
486
+ * Get backend message
487
+ *
488
+ * @param int|Mage_Core_Model_Store $storeId
489
+ * @return mixed
490
+ */
491
+ public function getErrorBackendMessage($storeId = null)
492
+ {
493
+ return Mage::getStoreConfig(self::CALCULATE_ERROR_BACKEND_MESSAGE, $storeId);
494
+ }
495
+
496
+ /**
497
+ * Get frontend message
498
+ *
499
+ * @param int|Mage_Core_Model_Store $storeId
500
+ * @return mixed
501
+ */
502
+ public function getErrorFrontendMessage($storeId = null)
503
+ {
504
+ return Mage::getStoreConfig(self::CALCULATE_ERROR_FRONTEND_MESSAGE, $storeId);
505
+ }
506
+
507
+ /**
508
+ * Get normalize address
509
+ *
510
+ * @return mixed
511
+ */
512
+ public function getNormalizeAddress($storeId = null)
513
+ {
514
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_NORMALIZE_ADDRESS, $storeId);
515
+ }
516
+
517
+ /**
518
+ * Get validate address
519
+ *
520
+ * @return mixed
521
+ */
522
+ public function getValidateAddress($storeId = null)
523
+ {
524
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_VALIDATE_ADDRESS, $storeId);
525
+ }
526
+
527
+ /**
528
+ * Get address validation countries
529
+ *
530
+ * @param int|Mage_Core_Model_Store $storeId
531
+ * @return mixed
532
+ */
533
+ public function getAddressValidationCountries($storeId = null)
534
+ {
535
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_ADDRESS_VALIDATION_COUNTRIES, $storeId);
536
+ }
537
+
538
+ /**
539
+ * Get region filter fist
540
+ *
541
+ * @param int|Mage_Core_Model_Store $storeId
542
+ * @return mixed
543
+ */
544
+ public function getRegionFilterList($storeId = null)
545
+ {
546
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_REGION_FILTER_LIST, $storeId);
547
+ }
548
+
549
+ /**
550
+ * Get region filter fist
551
+ *
552
+ * @param int|Mage_Core_Model_Store $storeId
553
+ * @return mixed
554
+ */
555
+ public function getLogTypeList($storeId = null)
556
+ {
557
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_LOG_TYPE_LIST, $storeId);
558
+ }
559
+
560
+ /**
561
+ * Get region filter mode
562
+ *
563
+ * @param int|Mage_Core_Model_Store $storeId
564
+ * @return mixed
565
+ */
566
+ public function getRegionFilterMode($storeId = null)
567
+ {
568
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_REGION_FILTER_MODE, $storeId);
569
+ }
570
+
571
+ /**
572
+ * Get region filter mode
573
+ *
574
+ * @param int|Mage_Core_Model_Store $websiteId
575
+ * @return mixed
576
+ * @throws Mage_Core_Exception
577
+ */
578
+ public function getConfigRegionFilterModByWebsite($websiteId = null)
579
+ {
580
+ return Mage::app()->getWebsite($websiteId)->getConfig(self::XML_PATH_TO_TAX_AVATAX_REGION_FILTER_MODE);
581
+ }
582
+
583
+ /**
584
+ * Get taxable country
585
+ *
586
+ * @param int|Mage_Core_Model_Store $storeId
587
+ * @return mixed
588
+ */
589
+ public function getTaxableCountry($storeId = null)
590
+ {
591
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_TAXABLE_COUNTRY, $storeId);
592
+ }
593
+
594
+ /**
595
+ * Returns the logging level
596
+ *
597
+ * @param null|bool|int|Mage_Core_Model_Store $store
598
+ *
599
+ * @return int
600
+ */
601
+ public function getConfigLogMode($store = null)
602
+ {
603
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_LOG_STATUS, $store);
604
+ }
605
+
606
+ /**
607
+ * Get active avatax service
608
+ *
609
+ * @param null|bool|int|Mage_Core_Model_Store $store
610
+ *
611
+ * @return int
612
+ */
613
+ public function getActiveService($store = null)
614
+ {
615
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_ACTIVE_SERVICE, $store);
616
+ }
617
+
618
+ /**
619
+ * Get shipping origin country_id
620
+ *
621
+ * @param null|bool|int|Mage_Core_Model_Store $store
622
+ *
623
+ * @return int
624
+ */
625
+ public function getShippingOriginCountryId($store = null)
626
+ {
627
+ return Mage::getStoreConfig(self::XML_PATH_TO_SHIPPING_ORIGIN_COUNTRY_ID, $store);
628
+ }
629
+
630
+ /**
631
+ * Get Default Avalara Goods And Services Type
632
+ *
633
+ * @param null|bool|int|Mage_Core_Model_Store $store
634
+ *
635
+ * @return int
636
+ */
637
+ public function getDefaultAvalaraGoodsAndServicesType ($store = null)
638
+ {
639
+ return Mage::getStoreConfig(self::XML_PATH_TO_DEFAULT_AVALARA_GOODS_AND_SERVICES_TYPE, $store);
640
+ }
641
+
642
+ /**
643
+ * Get dDfault Avalara Goods And Services Modifier Type
644
+ *
645
+ * @param null|bool|int|Mage_Core_Model_Store $store
646
+ *
647
+ * @return string
648
+ */
649
+ public function getDefaultAvalaraGoodsAndServicesModifierType($store = null)
650
+ {
651
+ return Mage::getStoreConfig(self::XML_PATH_TO_DEFAULT_AVALARA_GOODS_AND_SERVICES_MODIFIER_TYPE, $store);
652
+ }
653
+
654
+ /**
655
+ * Get Default Tax Payer Code
656
+ *
657
+ * @param null|bool|int|Mage_Core_Model_Store $store
658
+ *
659
+ * @return string
660
+ */
661
+ public function getDefaultTaxPayerCode($store = null)
662
+ {
663
+ return Mage::getStoreConfig(self::XML_PATH_TO_DEFAULT_TAX_PAYER_CODE, $store);
664
+ }
665
+
666
+ /**
667
+ * Get Default Use Type
668
+ *
669
+ * @param null|bool|int|Mage_Core_Model_Store $store
670
+ *
671
+ * @return string
672
+ */
673
+ public function getDefaultUseType($store = null)
674
+ {
675
+ return Mage::getStoreConfig(self::XML_PATH_TO_DEFAULT_USE_TYPE, $store);
676
+ }
677
+
678
+ /**
679
+ * Get Default Buyer Type
680
+ *
681
+ * @param null|bool|int|Mage_Core_Model_Store $store
682
+ *
683
+ * @return string
684
+ */
685
+ public function getDefaultBuyerType($store = null)
686
+ {
687
+ return Mage::getStoreConfig(self::XML_PATH_TO_DEFAULT_BUYER_TYPE, $store);
688
+ }
689
+
690
+ /**
691
+ * Get onepage normalize message
692
+ *
693
+ * @param null|bool|int|Mage_Core_Model_Store $store
694
+ *
695
+ * @return int
696
+ */
697
+ public function getOnepageNormalizeMessage($store = null)
698
+ {
699
+ return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_ONEPAGE_NORMALIZE_MESSAGE, $store);
700
+ }
701
+
702
+ /**
703
+ * Get UPC attributeCode
704
+ *
705
+ * @param int|Mage_Core_Model_Store $storeId
706
+ * @return string
707
+ */
708
+ public function getUpcAttributeCode($storeId = null)
709
+ {
710
+ if (!(bool)Mage::getStoreConfig(self::XML_PATH_TO_AVATAX_UPC_CHECK_STATUS, $storeId)) {
711
+ return '';
712
+ }
713
+
714
+ return (string)Mage::getStoreConfig(self::PATH_TO_AVATAX_UPC_ATTRIBUTE_CODE, $storeId);
715
+ }
716
+
717
+ /**
718
+ * Get customer code format
719
+ *
720
+ * @param int|Mage_Core_Model_Store $store
721
+ * @return string
722
+ */
723
+ public function getCustomerCodeFormat($store)
724
+ {
725
+ return (string)Mage::getStoreConfig(self::PATH_TAX_AVATAX_CUST_CODE_FORMAT, $store);
726
+ }
727
+
728
+ /**
729
+ * Get avatax16 address validation message
730
+ *
731
+ * @param int|Mage_Core_Model_Store $store
732
+ * @return string
733
+ */
734
+ public function getAvatax16AddressValidationMessage($store)
735
+ {
736
+ return (string)Mage::getStoreConfig(self::PATH_TO_AVATAX16_ADDRESS_VALIDATION_MESSAGE, $store);
737
+ }
738
+ }
app/code/community/OnePica/AvaTax/Helper/Data.php CHANGED
@@ -24,97 +24,62 @@
24
  */
25
  class OnePica_AvaTax_Helper_Data extends Mage_Core_Helper_Abstract
26
  {
27
- /**
28
- * Xml path to taxable_country config
29
- */
30
- const XML_PATH_TO_TAX_AVATAX_TAXABLE_COUNTRY = 'tax/avatax/taxable_country';
31
-
32
- /**
33
- * Xml path to region_filter_mode
34
- */
35
- const XML_PATH_TO_TAX_AVATAX_REGION_FILTER_MODE = 'tax/avatax/region_filter_mode';
36
-
37
- /**
38
- * Identifier for error message
39
- */
40
- const CALCULATE_ERROR_MESSAGE_IDENTIFIER = 'avatax_calculate_error';
41
-
42
  /**
43
  * Check if avatax extension is enabled
44
  *
45
  * @param null|bool|int|Mage_Core_Model_Store $store $store
46
  * @return bool
47
  */
48
- public function isAvataxEnabled($store = null)
49
  {
50
- return ($this->_getConfig('action', $store) != OnePica_AvaTax_Model_Config::ACTION_DISABLE);
51
- }
52
-
53
- /**
54
- * Gets the documenation url
55
- *
56
- * @return string
57
- */
58
- public function getDocumentationUrl()
59
- {
60
- return 'http://www.onepica.com/magento-extensions/avatax/';
61
  }
62
 
63
  /**
64
- * Loads a class from the AvaTax library.
65
  *
66
- * @param string $className
67
- * @return OnePica_AvaTax_Helper_Data
68
  */
69
- public function loadClass($className)
70
  {
71
- $classFile = $this->getLibPath() . DS . 'classes' . DS . $className . '.class.php';
72
- require_once $classFile;
73
- return $this;
74
  }
75
 
76
  /**
77
- * Load functions required to work with Avalara API
78
  *
79
- * @return $this
80
  */
81
- public function loadFunctions()
82
  {
83
- $functionsFile = $this->getLibPath() . DS . 'functions.php';
84
- require_once $functionsFile;
85
- return $this;
86
  }
87
 
88
  /**
89
- * Returns the path to the etc directory.
90
  *
91
  * @return string
92
  */
93
- public function getEtcPath ()
94
  {
95
- return dirname(dirname(__FILE__)) . DS . 'etc';
96
  }
97
 
98
  /**
99
- * Returns the path to the AvaTax SDK lib directory.
100
  *
101
- * @return string
 
102
  */
103
- public function getLibPath()
104
  {
105
- return Mage::getBaseDir('lib') . DS . 'AvaTax';
106
- }
107
 
108
- /**
109
- * Returns a config value from the admin.
110
- *
111
- * @param string $path
112
- * @param null|bool|int|Mage_Core_Model_Store $store
113
- * @return string
114
- */
115
- protected function _getConfig ($path, $store = null)
116
- {
117
- return Mage::getSingleton('avatax/config')->getConfig($path, $store);
118
  }
119
 
120
  /**
@@ -125,7 +90,7 @@ class OnePica_AvaTax_Helper_Data extends Mage_Core_Helper_Abstract
125
  */
126
  public function getLogMode($store = null)
127
  {
128
- return $this->_getConfig('log_status', $store);
129
  }
130
 
131
  /**
@@ -136,187 +101,25 @@ class OnePica_AvaTax_Helper_Data extends Mage_Core_Helper_Abstract
136
  */
137
  public function getLogType($store = null)
138
  {
139
- return explode(",", $this->_getConfig('log_type_list', $store));
140
- }
141
-
142
- /**
143
- * Returns shipping line item faked sku
144
- *
145
- * @param null|bool|int|Mage_Core_Model_Store $store
146
- * @return string
147
- */
148
- public function getShippingSku($store = null)
149
- {
150
- return $this->_getConfig('shipping_sku', $store);
151
- }
152
-
153
- /**
154
- * Returns giftwraporder line item faked sku
155
- *
156
- * @param null|bool|int|Mage_Core_Model_Store $store
157
- * @return string
158
- */
159
- public function getGwOrderSku($store = null)
160
- {
161
- return $this->_getConfig('gw_order_sku', $store);
162
- }
163
-
164
- /**
165
- * Returns giftwrapitems line item faked sku
166
- *
167
- * @param null|bool|int|Mage_Core_Model_Store $store
168
- * @return string
169
- */
170
- public function getGwItemsSku($store = null)
171
- {
172
- return $this->_getConfig('gw_items_sku', $store);
173
  }
174
 
175
  /**
176
- * Returns giftwrapprintedcard line item faked sku
177
- *
178
- * @param null|bool|int|Mage_Core_Model_Store $store
179
- * @return string
180
- */
181
- public function getGwPrintedCardSku($store = null)
182
- {
183
- return $this->_getConfig('gw_printed_card_sku', $store);
184
- }
185
-
186
- /**
187
- * Returns shipping line item faked sku
188
- *
189
- * @param null|bool|int|Mage_Core_Model_Store $store
190
- * @return string
191
- */
192
- public function getSalesPersonCode($store = null)
193
- {
194
- return $this->_getConfig('sales_person_code', $store);
195
- }
196
-
197
- /**
198
- * Returns attribute code for the location code to send to Avalara
199
- *
200
- * @param null|bool|int|Mage_Core_Model_Store $store
201
- * @return string
202
- */
203
- public function getLocationCode($store = null)
204
- {
205
- return $this->_getConfig('location_code', $store);
206
- }
207
-
208
- /**
209
- * Returns attribute code for the reference code 1 to send to Avalara
210
- *
211
- * @param null|bool|int|Mage_Core_Model_Store $store
212
- * @return string
213
- */
214
- public function getRef1AttributeCode($store = null)
215
- {
216
- return $this->_getConfig('line_ref1_code', $store);
217
- }
218
-
219
- /**
220
- * Returns attribute code for the reference code 2 to send to Avalara
221
- *
222
- * @param null|bool|int|Mage_Core_Model_Store $store
223
- * @return string
224
- */
225
- public function getRef2AttributeCode($store = null)
226
- {
227
- return $this->_getConfig('line_ref2_code', $store);
228
- }
229
-
230
- /**
231
- * Returns the positive adjustment identifier to send to Avalara
232
- *
233
- * @param null|bool|int|Mage_Core_Model_Store $store
234
- * @return string
235
- */
236
- public function getPositiveAdjustmentSku($store = null)
237
- {
238
- return $this->_getConfig('adjustment_positive_sku', $store);
239
- }
240
-
241
- /**
242
- * Returns the negative adjustment identifier to send to Avalara
243
- *
244
- * @param null|bool|int|Mage_Core_Model_Store $store
245
- * @return string
246
- */
247
- public function getNegativeAdjustmentSku($store = null)
248
- {
249
- return $this->_getConfig('adjustment_negative_sku', $store);
250
- }
251
-
252
- /**
253
- * Returns the required field list
254
- *
255
- * @param null|bool|int|Mage_Core_Model_Store $store
256
- * @return string
257
- */
258
- public function getFieldRequiredList($store = null)
259
- {
260
- return $this->_getConfig('field_required_list', $store);
261
- }
262
-
263
- /**
264
- * Returns the rules for field
265
- *
266
- * @param null|bool|int|Mage_Core_Model_Store $store
267
- * @return string
268
- */
269
- public function getFieldRule($store = null)
270
- {
271
- return $this->_getConfig('field_rule', $store);
272
- }
273
-
274
- /**
275
- * Returns full stop on error
276
  *
277
- * @param null|bool|int|Mage_Core_Model_Store $store
278
  * @return bool
279
  */
280
- public function fullStopOnError($store = null)
281
- {
282
- return (bool)$this->_getConfig('error_full_stop', $store);
283
- }
284
-
285
- /**
286
- * Get address validation countries
287
- *
288
- * @return array
289
- */
290
- public function getAddressValidationCountries()
291
  {
292
- return explode(',', $this->_getConfig('address_validation_countries'));
293
- }
294
 
295
- /**
296
- * Adds error message if there is an error
297
- *
298
- * @param null|bool|int|Mage_Core_Model_Store $store
299
- * @return string
300
- */
301
- public function addErrorMessage($store = null)
302
- {
303
- $message = $this->getErrorMessage($store);
304
- if (Mage::app()->getStore()->isAdmin()) {
305
- /** @var Mage_Adminhtml_Model_Session_Quote $session */
306
- $session = Mage::getSingleton('adminhtml/session_quote');
307
- } else {
308
- /** @var Mage_Checkout_Model_Session $session */
309
- $session = Mage::getSingleton('checkout/session');
310
  }
311
 
312
- $messages = $session->getMessages();
313
- if (!$messages->getMessageByIdentifier(self::CALCULATE_ERROR_MESSAGE_IDENTIFIER)) {
314
- /** @var Mage_Core_Model_Message_Error $error */
315
- $error = Mage::getSingleton('core/message')->error($message);
316
- $error->setIdentifier(self::CALCULATE_ERROR_MESSAGE_IDENTIFIER);
317
- $session->addMessage($error);
318
- }
319
- return $message;
320
  }
321
 
322
  /**
@@ -346,331 +149,76 @@ class OnePica_AvaTax_Helper_Data extends Mage_Core_Helper_Abstract
346
  }
347
 
348
  /**
349
- * Remove error message
350
  *
 
 
351
  * @return $this
352
  */
353
- public function removeErrorMessage()
354
- {
355
- if (Mage::app()->getStore()->isAdmin()) {
356
- /** @var Mage_Adminhtml_Model_Session_Quote $session */
357
- $session = Mage::getSingleton('adminhtml/session_quote');
358
- } else {
359
- /** @var Mage_Checkout_Model_Session $session */
360
- $session = Mage::getSingleton('checkout/session');
361
- }
362
- /** @var Mage_Core_Model_Message_Collection $messages */
363
- $messages = $session->getMessages();
364
- $messages->deleteMessageByIdentifier(self::CALCULATE_ERROR_MESSAGE_IDENTIFIER);
365
- return $this;
366
- }
367
-
368
- /**
369
- * Gets error message
370
- *
371
- * @param null|bool|int|Mage_Core_Model_Store $store
372
- * @return string
373
- */
374
- public function getErrorMessage($store = null)
375
- {
376
- if (Mage::app()->getStore()->isAdmin()) {
377
- return $this->_getConfig('error_backend_message', $store);
378
- } else {
379
- return $this->_getConfig('error_frontend_message', $store);
380
- }
381
- }
382
-
383
- /**
384
- * Is AvaTax disabled.
385
- *
386
- * @return bool
387
- * @throws Mage_Core_Exception
388
- */
389
- public function isAvaTaxDisabled()
390
- {
391
- $websiteId = Mage::app()->getRequest()->get('website');
392
- $storeId = Mage::app()->getRequest()->get('store');
393
-
394
- if ($websiteId && !$storeId) {
395
- return !(bool)Mage::app()->getWebsite($websiteId)->getConfig('tax/avatax/action');
396
- }
397
-
398
- return !(bool)Mage::getStoreConfig('tax/avatax/action', $storeId);
399
- }
400
-
401
- /**
402
- * Does any store have this extension disabled?
403
- *
404
- * @return bool
405
- */
406
- public function isAnyStoreDisabled()
407
- {
408
- $disabled = false;
409
- $storeCollection = Mage::app()->getStores();
410
-
411
- foreach ($storeCollection as $store) {
412
- $disabled |= Mage::getStoreConfig('tax/avatax/action', $store->getId())
413
- == OnePica_AvaTax_Model_Config::ACTION_DISABLE;
414
- }
415
-
416
- return $disabled;
417
- }
418
-
419
- /**
420
- * Determines if address validation is enabled
421
- *
422
- * @param OnePica_AvaTax_Model_Sales_Quote_Address $address
423
- * @param int $storeId
424
- * @return bool
425
- */
426
- public function isAddressValidationOn($address, $storeId)
427
- {
428
- if (!$this->isAddressActionable($address, $storeId, OnePica_AvaTax_Model_Config::REGIONFILTER_ALL, true)) {
429
- return false;
430
- }
431
- return Mage::getStoreConfig('tax/avatax/validate_address', $storeId);
432
- }
433
-
434
- /**
435
- * Determines if address normalization is enabled
436
- *
437
- * @param OnePica_AvaTax_Model_Sales_Quote_Address $address
438
- * @param int $storeId
439
- * @return bool
440
- */
441
- public function isAddressNormalizationOn($address, $storeId)
442
- {
443
- if (!$this->isAddressActionable($address, $storeId, OnePica_AvaTax_Model_Config::REGIONFILTER_ALL, true)) {
444
- return false;
445
- }
446
- return Mage::getStoreConfig('tax/avatax/normalize_address', $storeId);
447
- }
448
-
449
- /**
450
- * Determines if the address should be filtered
451
- *
452
- * @param OnePica_AvaTax_Model_Sales_Quote_Address $address
453
- * @param int $storeId
454
- * @param int $filterMode
455
- * @param bool $isAddressValidation
456
- * @return bool
457
- */
458
- public function isAddressActionable($address, $storeId, $filterMode = OnePica_AvaTax_Model_Config::REGIONFILTER_ALL,
459
- $isAddressValidation = false
460
- ) {
461
- $filter = false;
462
-
463
- if (Mage::getStoreConfig('tax/avatax/action', $storeId) == OnePica_AvaTax_Model_Config::ACTION_DISABLE) {
464
- return false;
465
- }
466
-
467
- if ($this->getRegionFilterModByStore($storeId) >= $filterMode) {
468
- $filter = $this->_getFilterRegion($address, $storeId);
469
- }
470
-
471
- if ($isAddressValidation && $filter
472
- && ((int)$this->getRegionFilterModByStore($storeId) !== OnePica_AvaTax_Model_Config::REGIONFILTER_ALL)
473
- ) {
474
- $filter = false;
475
- }
476
-
477
- if (!in_array($address->getCountryId(), $this->getTaxableCountryByStore($storeId))) {
478
- $filter = 'country';
479
- }
480
-
481
- if ($isAddressValidation && !$filter
482
- && !in_array($address->getCountryId(), $this->getAddressValidationCountries())
483
- ) {
484
- $filter = 'country';
485
- }
486
-
487
- if ($filter && $this->getLogMode($storeId)) {
488
- $filterLog = Mage::getSingleton('avatax/session')->getFilterLog();
489
- if (!is_array($filterLog)) {
490
- $filterLog = array();
491
- }
492
- $key = $address->getCacheHashKey();
493
-
494
- //did we already log this filtered address?
495
- if (!in_array($key, $filterLog)) {
496
- $filterLog[] = $key;
497
- Mage::getSingleton('avatax/session')->setFilterLog($filterLog);
498
-
499
- $type = ($filterMode == OnePica_AvaTax_Model_Config::REGIONFILTER_TAX) ?
500
- 'tax_calc' : 'tax_calc|address_opts';
501
- Mage::getModel('avatax_records/log')
502
- ->setStoreId($storeId)
503
- ->setLevel('Success')
504
- ->setType('Filter')
505
- ->setRequest(print_r($address->debug(), true))
506
- ->setResult('filter: ' . $filter . ', type: ' . $type)
507
- ->save();
508
- }
509
- }
510
-
511
- return $filter ? false : true;
512
- }
513
-
514
- /**
515
- * Get region filter
516
- *
517
- * @param Mage_Customer_Model_Address $address
518
- * @param int $storeId
519
- * @return string|bool
520
- */
521
- protected function _getFilterRegion($address, $storeId)
522
  {
523
- $filter = false;
524
- $regionFilters = explode(',', Mage::getStoreConfig('tax/avatax/region_filter_list', $storeId));
525
- $entityId = $address->getRegionId() ?: $address->getCountryId();
526
- if (!in_array($entityId, $regionFilters)) {
527
- $filter = 'region';
528
  }
529
- return $filter;
530
- }
531
-
532
- /**
533
- * Get taxable country by store
534
- *
535
- * @param int $storeId
536
- * @return array
537
- */
538
- public function getTaxableCountryByStore($storeId = null)
539
- {
540
- return explode(',', Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_TAXABLE_COUNTRY, $storeId));
541
- }
542
-
543
- /**
544
- * Get taxable country by website
545
- *
546
- * @param int $websiteId
547
- * @return array
548
- */
549
- public function getTaxableCountryByWebSite($websiteId)
550
- {
551
- return explode(',', Mage::app()
552
- ->getWebsite($websiteId)
553
- ->getConfig(self::XML_PATH_TO_TAX_AVATAX_TAXABLE_COUNTRY)
554
- );
555
- }
556
 
557
- /**
558
- * Get taxable country by current scope
559
- *
560
- * Used in admin panel
561
- *
562
- * @return array
563
- */
564
- public function getTaxableCountryByCurrentScope()
565
- {
566
- $websiteId = Mage::app()->getRequest()->get('website');
567
- $storeId = Mage::app()->getRequest()->get('store');
568
- if ($websiteId && !$storeId) {
569
- return $this->getTaxableCountryByWebSite($websiteId);
570
- }
571
- return $this->getTaxableCountryByStore($storeId);
572
  }
573
 
574
  /**
575
- * Get region filter mod by store
576
  *
577
- * @param null|int $storeId
578
- * @return int
579
- * @internal param int $store
580
  */
581
- public function getRegionFilterModByStore($storeId = null)
582
  {
583
- return Mage::getStoreConfig(self::XML_PATH_TO_TAX_AVATAX_REGION_FILTER_MODE, $storeId);
584
- }
585
 
586
- /**
587
- * Get region filter mod by website
588
- *
589
- * @param int $websiteId
590
- * @return int
591
- * @throws \Mage_Core_Exception
592
- */
593
- public function getRegionFilterModByWebsite($websiteId)
594
- {
595
- return Mage::app()->getWebsite($websiteId)->getConfig(self::XML_PATH_TO_TAX_AVATAX_REGION_FILTER_MODE);
596
  }
597
 
598
  /**
599
- * Get region filter mode by current scope
600
  *
601
- * @throws \Mage_Core_Exception
602
- * @return int
603
  */
604
- public function getRegionFilterModByCurrentScope()
605
  {
606
- $websiteId = Mage::app()->getRequest()->get('website');
607
- $storeId = Mage::app()->getRequest()->get('store');
608
-
609
- if ($websiteId && !$storeId) {
610
- return $this->getRegionFilterModByWebsite($websiteId);
611
- }
612
-
613
- return $this->getRegionFilterModByStore($storeId);
614
  }
615
 
616
  /**
617
- * Determines if the object (quote, invoice, or credit memo) should use AvaTax services
618
  *
619
- * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
620
- * @param Mage_Sales_Model_Quote_Address $shippingAddress
621
- * @return bool
622
- */
623
- public function isObjectActionable($object, $shippingAddress = null)
624
- {
625
- $storeId = $object->getStore()->getId();
626
-
627
- //is action enabled?
628
- $action = $object->getOrder() ?
629
- OnePica_AvaTax_Model_Config::ACTION_CALC_SUBMIT : OnePica_AvaTax_Model_Config::ACTION_CALC;
630
- if (Mage::getStoreConfig('tax/avatax/action', $storeId) < $action) {
631
- return false;
632
- }
633
-
634
- if (!$shippingAddress) {
635
- $shippingAddress = $object->getShippingAddress();
636
- }
637
- if (!$shippingAddress) {
638
- $shippingAddress = $object->getBillingAddress();
639
- }
640
-
641
- //is the region filtered?
642
- if (!$this->isAddressActionable($shippingAddress, $storeId, OnePica_AvaTax_Model_Config::REGIONFILTER_TAX)) {
643
- return false;
644
- }
645
-
646
- return true;
647
- }
648
-
649
- /**
650
- * Round up
651
  *
652
- * @param float $value
653
- * @param int $precision
654
- * @return float
655
  */
656
- public function roundUp($value, $precision)
657
  {
658
- $fact = pow(10, $precision);
 
659
 
660
- return ceil($fact * $value) / $fact;
661
- }
662
 
663
- /**
664
- * Get UPC attributeCode
665
- *
666
- * @param int $storeId
667
- * @return string
668
- */
669
- public function getUpcAttributeCode($storeId = null)
670
- {
671
- if (!(bool)$this->_getConfig('upc_check_status', $storeId)) {
672
- return '';
673
- }
674
- return (string)$this->_getConfig('upc_attribute_code', $storeId);
675
  }
676
  }
24
  */
25
  class OnePica_AvaTax_Helper_Data extends Mage_Core_Helper_Abstract
26
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  /**
28
  * Check if avatax extension is enabled
29
  *
30
  * @param null|bool|int|Mage_Core_Model_Store $store $store
31
  * @return bool
32
  */
33
+ public function isServiceEnabled($store = null)
34
  {
35
+ return ($this->_getConfigData()->getStatusServiceAction($store)
36
+ != OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_DISABLE);
 
 
 
 
 
 
 
 
 
37
  }
38
 
39
  /**
40
+ * Is avatax 16 service type
41
  *
42
+ * @return bool
 
43
  */
44
+ public function isAvatax16()
45
  {
46
+ return $this->_getConfigData()->getActiveService() === OnePica_AvaTax_Helper_Config::AVATAX16_SERVICE_TYPE;
 
 
47
  }
48
 
49
  /**
50
+ * Is avatax service type
51
  *
52
+ * @return bool
53
  */
54
+ public function isAvatax()
55
  {
56
+ return $this->_getConfigData()->getActiveService() === OnePica_AvaTax_Helper_Config::AVATAX_SERVICE_TYPE;
 
 
57
  }
58
 
59
  /**
60
+ * Gets the documenation url
61
  *
62
  * @return string
63
  */
64
+ public function getDocumentationUrl()
65
  {
66
+ return 'http://www.onepica.com/magento-extensions/avatax/';
67
  }
68
 
69
  /**
70
+ * Is development mod
71
  *
72
+ * @param int $storeId
73
+ * @return bool
74
  */
75
+ public function isDevMod($storeId)
76
  {
77
+ $serviceUrl = $this->_getConfigData()->getServiceUrl($storeId);
 
78
 
79
+ return ($this->isAvatax()
80
+ && ($serviceUrl === OnePica_AvaTax_Model_Source_Avatax_Url::DEVELOPMENT_URL))
81
+ || ($this->isAvatax16()
82
+ && ($serviceUrl === OnePica_AvaTax_Model_Source_Avatax16_Url::DEVELOPMENT_URL));
 
 
 
 
 
 
83
  }
84
 
85
  /**
90
  */
91
  public function getLogMode($store = null)
92
  {
93
+ return $this->_getConfigData()->getConfigLogMode($store);
94
  }
95
 
96
  /**
101
  */
102
  public function getLogType($store = null)
103
  {
104
+ return explode(",", $this->_getConfigData()->getLogTypeList($store));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
106
 
107
  /**
108
+ * Does any store have this extension disabled?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  *
 
110
  * @return bool
111
  */
112
+ public function isAnyStoreDisabled()
 
 
 
 
 
 
 
 
 
 
113
  {
114
+ $disabled = false;
115
+ $storeCollection = Mage::app()->getStores();
116
 
117
+ foreach ($storeCollection as $store) {
118
+ $disabled |= $this->_getConfigData()->getStatusServiceAction($store->getId())
119
+ == OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_DISABLE;
 
 
 
 
 
 
 
 
 
 
 
 
120
  }
121
 
122
+ return $disabled;
 
 
 
 
 
 
 
123
  }
124
 
125
  /**
149
  }
150
 
151
  /**
152
+ * Adds a comment to order history. Method chosen based on Magento version.
153
  *
154
+ * @param Mage_Sales_Model_Order $order
155
+ * @param string $comment
156
  * @return $this
157
  */
158
+ public function addStatusHistoryComment($order, $comment)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  {
160
+ if (method_exists($order, 'addStatusHistoryComment')) {
161
+ $order->addStatusHistoryComment($comment)->save();
162
+ } elseif (method_exists($order, 'addStatusToHistory')) {
163
+ $order->addStatusToHistory($order->getStatus(), $comment, false)->save();
 
164
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
+ return $this;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  }
168
 
169
  /**
170
+ * Round up
171
  *
172
+ * @param float $value
173
+ * @param int $precision
174
+ * @return float
175
  */
176
+ public function roundUp($value, $precision)
177
  {
178
+ $fact = pow(10, $precision);
 
179
 
180
+ return ceil($fact * $value) / $fact;
 
 
 
 
 
 
 
 
 
181
  }
182
 
183
  /**
184
+ * Get config helper
185
  *
186
+ * @return OnePica_AvaTax_Helper_Config
 
187
  */
188
+ private function _getConfigData()
189
  {
190
+ return Mage::helper('avatax/config');
 
 
 
 
 
 
 
191
  }
192
 
193
  /**
194
+ * Generates client name for requests
195
  *
196
+ * Parts:
197
+ * - MyERP: the ERP that this connector is for (not always applicable)
198
+ * - Majver: version info for the ERP (not always applicable)
199
+ * - MinVer: version info for the ERP (not always applicable)
200
+ * - MyConnector: Name of the OEM's connector AND the name of the OEM (company) *required*
201
+ * - Majver: OEM's connector version *required*
202
+ * - MinVer: OEM's connector version *required*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  *
204
+ * @example Magento,1.4,.0.1,OP_AvaTax by One Pica,2,0.1
205
+ * @return string
 
206
  */
207
+ public function getClientName()
208
  {
209
+ $mageVersion = Mage::getVersion();
210
+ $mageVerParts = explode('.', $mageVersion, 2);
211
 
212
+ $opVersion = Mage::getResourceModel('core/resource')->getDbVersion('avatax_records_setup');
213
+ $opVerParts = explode('.', $opVersion, 2);
214
 
215
+ $part = array();
216
+ $part[] = OnePica_AvaTax_Model_Service_Abstract_Config::CONFIG_KEY;
217
+ $part[] = $mageVerParts[0];
218
+ $part[] = $mageVerParts[1];
219
+ $part[] = OnePica_AvaTax_Model_Service_Abstract_Config::APP_NAME;
220
+ $part[] = $opVerParts[0];
221
+ $part[] = $opVerParts[1];
222
+ return implode(',', $part);
 
 
 
 
223
  }
224
  }
app/code/community/OnePica/AvaTax/Helper/Errors.php ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The base AvaTax Helper class
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Helper_Errors extends Mage_Core_Helper_Abstract
26
+ {
27
+ /**
28
+ * Identifier for error message
29
+ */
30
+ const CALCULATE_ERROR_MESSAGE_IDENTIFIER = 'avatax_calculate_error';
31
+
32
+ /**
33
+ * Identifier for validation notice
34
+ */
35
+ const VALIDATION_NOTICE_IDENTIFIER = 'avatax_validation_notice';
36
+
37
+ /**
38
+ * Adds error message if there is an error
39
+ *
40
+ * @param null|bool|int|Mage_Core_Model_Store $store
41
+ *
42
+ * @return string
43
+ */
44
+ public function addErrorMessage($store = null)
45
+ {
46
+ $message = $this->getErrorMessage($store);
47
+ if (Mage::app()->getStore()->isAdmin()) {
48
+ /** @var Mage_Adminhtml_Model_Session_Quote $session */
49
+ $session = Mage::getSingleton('adminhtml/session_quote');
50
+ } else {
51
+ /** @var Mage_Checkout_Model_Session $session */
52
+ $session = Mage::getSingleton('checkout/session');
53
+ }
54
+
55
+ $messages = $session->getMessages();
56
+ if (!$messages->getMessageByIdentifier(self::CALCULATE_ERROR_MESSAGE_IDENTIFIER)) {
57
+ /** @var Mage_Core_Model_Message_Error $error */
58
+ $error = Mage::getSingleton('core/message')->error($message);
59
+ $error->setIdentifier(self::CALCULATE_ERROR_MESSAGE_IDENTIFIER);
60
+ $session->addMessage($error);
61
+ }
62
+ return $message;
63
+ }
64
+
65
+ /**
66
+ * Remove error message
67
+ *
68
+ * @return $this
69
+ */
70
+ public function removeErrorMessage()
71
+ {
72
+ if (Mage::app()->getStore()->isAdmin()) {
73
+ /** @var Mage_Adminhtml_Model_Session_Quote $session */
74
+ $session = Mage::getSingleton('adminhtml/session_quote');
75
+ } else {
76
+ /** @var Mage_Checkout_Model_Session $session */
77
+ $session = Mage::getSingleton('checkout/session');
78
+ }
79
+ /** @var Mage_Core_Model_Message_Collection $messages */
80
+ $messages = $session->getMessages();
81
+ $messages->deleteMessageByIdentifier(self::CALCULATE_ERROR_MESSAGE_IDENTIFIER);
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Gets error message
87
+ *
88
+ * @param null|bool|int|Mage_Core_Model_Store $store
89
+ *
90
+ * @return string
91
+ */
92
+ public function getErrorMessage($store = null)
93
+ {
94
+ if (Mage::app()->getStore()->isAdmin()) {
95
+ return Mage::helper('avatax/config')->getErrorBackendMessage($store);
96
+ } else {
97
+ return Mage::helper('avatax/config')->getErrorFrontendMessage($store);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Get config helper
103
+ *
104
+ * @return OnePica_AvaTax_Helper_Config
105
+ */
106
+ private function _getConfigHelper()
107
+ {
108
+ return Mage::helper('avatax/config');
109
+ }
110
+
111
+ /**
112
+ * Can show estimation errors
113
+ *
114
+ * @param Mage_Sales_Model_Quote $quote
115
+ * @return bool
116
+ */
117
+ public function canShowEstimationError($quote)
118
+ {
119
+ if ($quote->getData('estimate_tax_error') && $this->_getConfigHelper()->fullStopOnError($quote->getStoreId())) {
120
+ return true;
121
+ } else {
122
+ return false;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Returns full stop on error
128
+ *
129
+ * @param Mage_Sales_Model_Quote $quote
130
+ * @return bool
131
+ */
132
+ public function fullStopOnError($quote)
133
+ {
134
+ if ($quote->getData('estimate_tax_error') && $this->_getFullStopOnErrorMode($quote->getStoreId())) {
135
+ return true;
136
+ } else {
137
+ return false;
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Returns full stop on error mode
143
+ *
144
+ * @param null|int $storeId
145
+ * @return bool
146
+ */
147
+ protected function _getFullStopOnErrorMode($storeId = null)
148
+ {
149
+ $validateAddress = $this->_getConfigHelper()->getValidateAddress($storeId);
150
+ $errorFullStop = $this->_getConfigHelper()->fullStopOnError($storeId);
151
+ $enablePreventOrderConst = OnePica_AvaTax_Model_Source_Addressvalidation::ENABLED_PREVENT_ORDER;
152
+ if (!$validateAddress && $errorFullStop || $validateAddress == $enablePreventOrderConst) {
153
+ return true;
154
+ } else {
155
+ return false;
156
+ }
157
+ }
158
+ }
app/code/community/OnePica/AvaTax/Helper/GiftWrapping/Data.php CHANGED
@@ -26,7 +26,7 @@ class OnePica_AvaTax_Helper_GiftWrapping_Data extends Enterprise_GiftWrapping_He
26
  */
27
  public function displayCartWrappingIncludeTaxPrice($store = null)
28
  {
29
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
30
  return false;
31
  }
32
 
@@ -41,7 +41,7 @@ class OnePica_AvaTax_Helper_GiftWrapping_Data extends Enterprise_GiftWrapping_He
41
  */
42
  public function displayCartWrappingExcludeTaxPrice($store = null)
43
  {
44
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
45
  return true;
46
  }
47
 
@@ -56,7 +56,7 @@ class OnePica_AvaTax_Helper_GiftWrapping_Data extends Enterprise_GiftWrapping_He
56
  */
57
  public function displayCartWrappingBothPrices($store = null)
58
  {
59
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
60
  return false;
61
  }
62
 
@@ -71,7 +71,7 @@ class OnePica_AvaTax_Helper_GiftWrapping_Data extends Enterprise_GiftWrapping_He
71
  */
72
  public function displayCartCardIncludeTaxPrice($store = null)
73
  {
74
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
75
  return false;
76
  }
77
 
@@ -86,7 +86,7 @@ class OnePica_AvaTax_Helper_GiftWrapping_Data extends Enterprise_GiftWrapping_He
86
  */
87
  public function displayCartCardBothPrices($store = null)
88
  {
89
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
90
  return false;
91
  }
92
 
@@ -101,7 +101,7 @@ class OnePica_AvaTax_Helper_GiftWrapping_Data extends Enterprise_GiftWrapping_He
101
  */
102
  public function displaySalesWrappingIncludeTaxPrice($store = null)
103
  {
104
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
105
  return false;
106
  }
107
 
@@ -116,7 +116,7 @@ class OnePica_AvaTax_Helper_GiftWrapping_Data extends Enterprise_GiftWrapping_He
116
  */
117
  public function displaySalesWrappingExcludeTaxPrice($store = null)
118
  {
119
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
120
  return true;
121
  }
122
 
@@ -131,7 +131,7 @@ class OnePica_AvaTax_Helper_GiftWrapping_Data extends Enterprise_GiftWrapping_He
131
  */
132
  public function displaySalesWrappingBothPrices($store = null)
133
  {
134
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
135
  return false;
136
  }
137
 
@@ -146,7 +146,7 @@ class OnePica_AvaTax_Helper_GiftWrapping_Data extends Enterprise_GiftWrapping_He
146
  */
147
  public function displaySalesCardIncludeTaxPrice($store = null)
148
  {
149
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
150
  return false;
151
  }
152
 
@@ -161,7 +161,7 @@ class OnePica_AvaTax_Helper_GiftWrapping_Data extends Enterprise_GiftWrapping_He
161
  */
162
  public function displaySalesCardBothPrices($store = null)
163
  {
164
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
165
  return false;
166
  }
167
 
26
  */
27
  public function displayCartWrappingIncludeTaxPrice($store = null)
28
  {
29
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
30
  return false;
31
  }
32
 
41
  */
42
  public function displayCartWrappingExcludeTaxPrice($store = null)
43
  {
44
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
45
  return true;
46
  }
47
 
56
  */
57
  public function displayCartWrappingBothPrices($store = null)
58
  {
59
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
60
  return false;
61
  }
62
 
71
  */
72
  public function displayCartCardIncludeTaxPrice($store = null)
73
  {
74
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
75
  return false;
76
  }
77
 
86
  */
87
  public function displayCartCardBothPrices($store = null)
88
  {
89
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
90
  return false;
91
  }
92
 
101
  */
102
  public function displaySalesWrappingIncludeTaxPrice($store = null)
103
  {
104
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
105
  return false;
106
  }
107
 
116
  */
117
  public function displaySalesWrappingExcludeTaxPrice($store = null)
118
  {
119
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
120
  return true;
121
  }
122
 
131
  */
132
  public function displaySalesWrappingBothPrices($store = null)
133
  {
134
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
135
  return false;
136
  }
137
 
146
  */
147
  public function displaySalesCardIncludeTaxPrice($store = null)
148
  {
149
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
150
  return false;
151
  }
152
 
161
  */
162
  public function displaySalesCardBothPrices($store = null)
163
  {
164
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
165
  return false;
166
  }
167
 
app/code/community/OnePica/AvaTax/Helper/Lib.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The base AvaTax Helper class
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Helper_Lib extends Mage_Core_Helper_Abstract
26
+ {
27
+ /**
28
+ * Returns the path to the AvaTax SDK lib directory.
29
+ *
30
+ * @return string
31
+ */
32
+ public function getLibPath()
33
+ {
34
+ return Mage::getBaseDir('lib') . DS . 'AvaTax';
35
+ }
36
+
37
+ /**
38
+ * Load functions required to work with Avalara API
39
+ *
40
+ * @return $this
41
+ */
42
+ public function loadFunctions()
43
+ {
44
+ $functionsFile = $this->getLibPath() . DS . 'functions.php';
45
+ require_once $functionsFile;
46
+ return $this;
47
+ }
48
+
49
+ /**
50
+ * Loads a class from the AvaTax library.
51
+ *
52
+ * @param string $className
53
+ *
54
+ * @return OnePica_AvaTax_Helper_Data
55
+ */
56
+ public function loadClass($className)
57
+ {
58
+ $classFile = $this->getLibPath() . DS . 'classes' . DS . $className . '.class.php';
59
+ require_once $classFile;
60
+ return $this;
61
+ }
62
+ }
app/code/community/OnePica/AvaTax/Helper/Tax/Data.php CHANGED
@@ -37,7 +37,7 @@ class OnePica_AvaTax_Helper_Tax_Data extends Mage_Tax_Helper_Data
37
  */
38
  public function priceIncludesTax($store = null)
39
  {
40
- if (Mage::helper('avatax')->isAvataxEnabled($store)) {
41
  return false;
42
  }
43
  return parent::priceIncludesTax($store);
@@ -51,7 +51,7 @@ class OnePica_AvaTax_Helper_Tax_Data extends Mage_Tax_Helper_Data
51
  */
52
  public function shippingPriceIncludesTax($store = null)
53
  {
54
- if (Mage::helper('avatax')->isAvataxEnabled($store)) {
55
  return false;
56
  }
57
  return parent::shippingPriceIncludesTax($store);
@@ -65,7 +65,7 @@ class OnePica_AvaTax_Helper_Tax_Data extends Mage_Tax_Helper_Data
65
  */
66
  public function getShippingTaxClass($store)
67
  {
68
- if (Mage::helper('avatax')->isAvataxEnabled($store)) {
69
  return self::AVATAX_SHIPPING_TAX_CLASS;
70
  }
71
  return parent::getShippingTaxClass($store);
@@ -79,7 +79,7 @@ class OnePica_AvaTax_Helper_Tax_Data extends Mage_Tax_Helper_Data
79
  */
80
  public function getTaxBasedOn($store = null)
81
  {
82
- if (Mage::helper('avatax')->isAvataxEnabled($store)) {
83
  return 'shipping';
84
  }
85
  return parent::getTaxBasedOn($store);
@@ -93,7 +93,7 @@ class OnePica_AvaTax_Helper_Tax_Data extends Mage_Tax_Helper_Data
93
  */
94
  public function applyTaxOnCustomPrice($store = null)
95
  {
96
- if (Mage::helper('avatax')->isAvataxEnabled($store)) {
97
  return true;
98
  }
99
  return parent::applyTaxOnCustomPrice($store);
@@ -107,7 +107,7 @@ class OnePica_AvaTax_Helper_Tax_Data extends Mage_Tax_Helper_Data
107
  */
108
  public function applyTaxOnOriginalPrice($store = null)
109
  {
110
- if (Mage::helper('avatax')->isAvataxEnabled($store)) {
111
  return false;
112
  }
113
  return parent::applyTaxOnOriginalPrice($store);
@@ -121,7 +121,7 @@ class OnePica_AvaTax_Helper_Tax_Data extends Mage_Tax_Helper_Data
121
  */
122
  public function applyTaxAfterDiscount($store = null)
123
  {
124
- if (Mage::helper('avatax')->isAvataxEnabled($store)) {
125
  return true;
126
  }
127
  return parent::applyTaxAfterDiscount($store);
37
  */
38
  public function priceIncludesTax($store = null)
39
  {
40
+ if (Mage::helper('avatax')->isServiceEnabled($store)) {
41
  return false;
42
  }
43
  return parent::priceIncludesTax($store);
51
  */
52
  public function shippingPriceIncludesTax($store = null)
53
  {
54
+ if (Mage::helper('avatax')->isServiceEnabled($store)) {
55
  return false;
56
  }
57
  return parent::shippingPriceIncludesTax($store);
65
  */
66
  public function getShippingTaxClass($store)
67
  {
68
+ if (Mage::helper('avatax')->isServiceEnabled($store)) {
69
  return self::AVATAX_SHIPPING_TAX_CLASS;
70
  }
71
  return parent::getShippingTaxClass($store);
79
  */
80
  public function getTaxBasedOn($store = null)
81
  {
82
+ if (Mage::helper('avatax')->isServiceEnabled($store)) {
83
  return 'shipping';
84
  }
85
  return parent::getTaxBasedOn($store);
93
  */
94
  public function applyTaxOnCustomPrice($store = null)
95
  {
96
+ if (Mage::helper('avatax')->isServiceEnabled($store)) {
97
  return true;
98
  }
99
  return parent::applyTaxOnCustomPrice($store);
107
  */
108
  public function applyTaxOnOriginalPrice($store = null)
109
  {
110
+ if (Mage::helper('avatax')->isServiceEnabled($store)) {
111
  return false;
112
  }
113
  return parent::applyTaxOnOriginalPrice($store);
121
  */
122
  public function applyTaxAfterDiscount($store = null)
123
  {
124
+ if (Mage::helper('avatax')->isServiceEnabled($store)) {
125
  return true;
126
  }
127
  return parent::applyTaxAfterDiscount($store);
app/code/community/OnePica/AvaTax/Model/Abstract.php DELETED
@@ -1,105 +0,0 @@
1
- <?php
2
- /**
3
- * OnePica_AvaTax
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0), a
8
- * copy of which is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- *
11
- * @category OnePica
12
- * @package OnePica_AvaTax
13
- * @author OnePica Codemaster <codemaster@onepica.com>
14
- * @copyright Copyright (c) 2009 One Pica, Inc.
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * The abstract base AvaTax model
20
- *
21
- * @category OnePica
22
- * @package OnePica_AvaTax
23
- * @author OnePica Codemaster <codemaster@onepica.com>
24
- */
25
- abstract class OnePica_AvaTax_Model_Abstract extends Varien_Object
26
- {
27
- /**
28
- * The module helper
29
- *
30
- * @var OnePica_AvaTax_Helper_Data
31
- */
32
- protected $_helper = null;
33
-
34
- /**
35
- * Logs a debug message
36
- *
37
- * @param string $type
38
- * @param string $request the request string
39
- * @param string $result the result string
40
- * @param int $storeId id of the store the call is make for
41
- * @param mixed $additional any other info
42
- * @return $this
43
- */
44
- protected function _log($type, $request, $result, $storeId = null, $additional = null)
45
- {
46
- if ($result->getResultCode() == SeverityLevel::$Success) {
47
- switch (Mage::helper('avatax')->getLogMode($storeId)) {
48
- case OnePica_AvaTax_Model_Source_Logmode::ERRORS:
49
- return $this;
50
- break;
51
- case OnePica_AvaTax_Model_Source_Logmode::NORMAL:
52
- $additional = null;
53
- break;
54
- }
55
- }
56
-
57
- if (in_array($type, Mage::helper('avatax')->getLogType($storeId))) {
58
- Mage::getModel('avatax_records/log')
59
- ->setStoreId($storeId)
60
- ->setLevel($result->getResultCode())
61
- ->setType($type)
62
- ->setRequest(print_r($request, true))
63
- ->setResult(print_r($result, true))
64
- ->setAdditional($additional)
65
- ->save();
66
- }
67
- return $this;
68
- }
69
-
70
- /**
71
- * Returns the AvaTax session.
72
- *
73
- * @return OnePica_AvaTax_Model_Session
74
- */
75
- public function getSession ()
76
- {
77
- return Mage::getSingleton('avatax/session');
78
- }
79
-
80
- /**
81
- * Returns the AvaTax helper.
82
- *
83
- * @return OnePica_AvaTax_Helper_Data
84
- */
85
- public function getHelper ()
86
- {
87
- if (!$this->_helper) {
88
- $this->_helper = Mage::helper('avatax');
89
- }
90
- return $this->_helper;
91
- }
92
-
93
- //@startSkipCommitHooks
94
- /**
95
- * Alias to the helper translate method.
96
- *
97
- * @return string
98
- */
99
- public function __()
100
- {
101
- $args = func_get_args();
102
- return call_user_func_array(array($this->getHelper(), '__'), $args);
103
- }
104
- //@finishSkipCommitHooks
105
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/OnePica/AvaTax/Model/Action/Abstract.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ * This source file is subject to the Open Software License (OSL 3.0), a
7
+ * copy of which is available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ *
10
+ * @category OnePica
11
+ * @package OnePica_AvaTax
12
+ * @author OnePica Codemaster <codemaster@onepica.com>
13
+ * @copyright Copyright (c) 2015 One Pica, Inc.
14
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
15
+ */
16
+
17
+ /**
18
+ * Class OnePica_AvaTax_Model_Action_AbstractAction
19
+ *
20
+ * @category OnePica
21
+ * @package OnePica_AvaTax
22
+ * @author OnePica Codemaster <codemaster@onepica.com>
23
+ */
24
+ abstract class OnePica_AvaTax_Model_Action_Abstract
25
+ {
26
+ /**
27
+ * Service
28
+ *
29
+ * @var OnePica_AvaTax_Model_Service_Abstract
30
+ */
31
+ protected $_service;
32
+
33
+ /**
34
+ * Class constructor
35
+ *
36
+ * @param array $params
37
+ * @throws OnePica_AvaTax_Exception
38
+ */
39
+ public function __construct($params = array())
40
+ {
41
+ $activeService = $this->_getConfigHelper()->getActiveService();
42
+ $this->_service = Mage::getSingleton('avatax/service')->factory($activeService, $params);
43
+ }
44
+
45
+ /**
46
+ * Get Service
47
+ * return OnePica_AvaTax_Model_Service_Abstract
48
+ */
49
+ protected function _getService()
50
+ {
51
+ return $this->_service;
52
+ }
53
+
54
+ /**
55
+ * Get config helper
56
+ *
57
+ * @return OnePica_AvaTax_Helper_Config
58
+ */
59
+ protected function _getConfigHelper()
60
+ {
61
+ return Mage::helper('avatax/config');
62
+ }
63
+
64
+ /**
65
+ * Returns the AvaTax helper.
66
+ *
67
+ * @return OnePica_AvaTax_Helper_Config
68
+ */
69
+ protected function _getErrorsHelper()
70
+ {
71
+ return Mage::helper('avatax/errors');
72
+ }
73
+
74
+ /**
75
+ * Returns the AvaTax helper.
76
+ *
77
+ * @return OnePica_AvaTax_Helper_Data
78
+ */
79
+ protected function _getHelper()
80
+ {
81
+ return Mage::helper('avatax');
82
+ }
83
+
84
+ /**
85
+ * Set Store Id
86
+ *
87
+ * @param int $storeId
88
+ * @return $this
89
+ */
90
+ public function setStoreId($storeId)
91
+ {
92
+ $this->_getService()->setStoreId($storeId);
93
+
94
+ return $this;
95
+ }
96
+ }
app/code/community/OnePica/AvaTax/Model/Action/Calculator.php ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Class OnePica_AvaTax_Model_Action_Calculator
20
+ */
21
+ class OnePica_AvaTax_Model_Action_Calculator extends OnePica_AvaTax_Model_Action_Abstract
22
+ {
23
+ /**
24
+ * Address parameter
25
+ */
26
+ const ADDRESS_PARAMETER = 'address';
27
+
28
+ /**
29
+ * Address
30
+ *
31
+ * @var Mage_Sales_Model_Quote_Address
32
+ */
33
+ protected $_address;
34
+
35
+ /**
36
+ * Rates
37
+ *
38
+ * @var array
39
+ */
40
+ protected $_rates = array();
41
+
42
+ /**
43
+ * OnePica_AvaTax_Model_Calculator constructor.
44
+ *
45
+ * @param array $params
46
+ * @throws \OnePica_AvaTax_Exception
47
+ */
48
+ public function __construct($params = array())
49
+ {
50
+ parent::__construct($params);
51
+ $this->_checkAddress($params);
52
+ $this->initRates($params[self::ADDRESS_PARAMETER]);
53
+ }
54
+
55
+ /**
56
+ * Init rates
57
+ *
58
+ * @param Mage_Sales_Model_Quote_Address $address
59
+ * @return $this
60
+ */
61
+ public function initRates($address)
62
+ {
63
+ $this->_address = $address;
64
+ $this->setStoreId($address->getQuote()->getStoreId());
65
+ $this->_rates = $this->_getService()->getRates($address);
66
+
67
+ return $this;
68
+ }
69
+
70
+ /**
71
+ * Get rates from Service
72
+ * Example: $_ratesData = array(
73
+ * 'timestamp' => 1325015952
74
+ * 'summary' => array(
75
+ * array('name'=>'NY STATE TAX', 'rate'=>4, 'amt'=>6),
76
+ * array('name'=>'NY CITY TAX', 'rate'=>4.50, 'amt'=>6.75),
77
+ * array('name'=>'NY SPECIAL TAX', 'rate'=>4.375, 'amt'=>0.56)
78
+ * ),
79
+ * 'items' => array(
80
+ * 5 => array('rate'=>8.875, 'amt'=>13.31),
81
+ * 'Shipping' => array('rate'=>0, 'amt'=>0)
82
+ * ),
83
+ * // if error on get tax
84
+ * 'failure' => true
85
+ * )
86
+ *
87
+ * @return array
88
+ */
89
+ protected function _getRates()
90
+ {
91
+ if (isset($this->_rates['failure']) && ($this->_rates['failure'] === true)) {
92
+ // set error flag for processing estimation errors on upper level
93
+ $this->_address->getQuote()->setData('estimate_tax_error', true);
94
+ }
95
+
96
+ return $this->_rates;
97
+ }
98
+
99
+ /**
100
+ * Estimates tax rate for one item.
101
+ *
102
+ * @param Mage_Sales_Model_Quote_Item $item
103
+ * @return int
104
+ */
105
+ public function getItemRate($item)
106
+ {
107
+ if ($this->isProductCalculated($item)) {
108
+ return 0;
109
+ } else {
110
+ $id = $item->getSku();
111
+ $ratesData = $this->_getRates();
112
+
113
+ return isset($ratesData['items'][$id]['rate']) ? $ratesData['items'][$id]['rate'] : 0;
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Get item tax group
119
+ *
120
+ * @param Mage_Sales_Model_Quote_Item $item
121
+ * @return array
122
+ */
123
+ public function getItemTaxGroup($item)
124
+ {
125
+ if ($this->isProductCalculated($item)) {
126
+ return array();
127
+ }
128
+
129
+ $id = $item->getSku();
130
+ $ratesData = $this->_getRates();
131
+
132
+ $jurisdictionRates = isset($ratesData['items'][$id]['jurisdiction_rates'])
133
+ ? $ratesData['items'][$id]['jurisdiction_rates']
134
+ : array();
135
+
136
+ $taxGroup = array();
137
+ foreach ($jurisdictionRates as $jurisdiction => $rate) {
138
+ $taxGroup[] = array(
139
+ 'rates' => array(
140
+ array(
141
+ 'code' => $jurisdiction,
142
+ 'title' => $jurisdiction,
143
+ 'percent' => $rate,
144
+ 'position' => 0,
145
+ 'priority' => 0,
146
+ 'rule_id' => 0
147
+ )
148
+ ),
149
+ 'percent' => $rate,
150
+ 'id' => $jurisdiction
151
+ );
152
+ }
153
+
154
+ return $taxGroup;
155
+ }
156
+
157
+ /**
158
+ * Get item tax
159
+ *
160
+ * @param Mage_Sales_Model_Quote_Item $item
161
+ * @return int
162
+ */
163
+ public function getItemGiftTax($item)
164
+ {
165
+ if ($item->getParentItemId()) {
166
+ return 0;
167
+ }
168
+ $ratesData = $this->_getRates();
169
+ $id = $item->getSku();
170
+
171
+ return isset($ratesData['gw_items'][$id]['amt']) ? $ratesData['gw_items'][$id]['amt'] : 0;
172
+ }
173
+
174
+ /**
175
+ * Estimates tax amount for one item. Does not trigger a call if the shipping
176
+ * address has no postal code, or if the postal code is set to "-" (OneStepCheckout)
177
+ *
178
+ * @param Mage_Sales_Model_Quote_Item $item
179
+ * @return int
180
+ */
181
+ public function getItemTax($item)
182
+ {
183
+ if ($item->getAddress()->getPostcode() && $item->getAddress()->getPostcode() != '-') {
184
+ if ($this->isProductCalculated($item)) {
185
+ $tax = 0;
186
+ foreach ($item->getChildren() as $child) {
187
+ $child->setAddress($item->getAddress());
188
+ $tax += $this->getItemTax($child);
189
+ }
190
+
191
+ return $tax;
192
+ } else {
193
+ $ratesData = $this->_getRates();;
194
+ $id = $item->getSku();
195
+
196
+ return isset($ratesData['items'][$id]['amt']) ? $ratesData['items'][$id]['amt'] : 0;
197
+ }
198
+ }
199
+
200
+ return 0;
201
+ }
202
+
203
+ /**
204
+ * Get tax detail summary
205
+ *
206
+ * @param Mage_Sales_Model_Quote_Address $address
207
+ * @return array
208
+ */
209
+ public function getSummary($address)
210
+ {
211
+ return $this->_getService()->getSummary($address);
212
+ }
213
+
214
+ /**
215
+ * Test to see if the product carries its own numbers or is calculated based on parent or children
216
+ *
217
+ * @param Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item|mixed $item
218
+ * @return bool
219
+ */
220
+ public function isProductCalculated($item)
221
+ {
222
+ return $this->_getService()->isProductCalculated($item);
223
+ }
224
+
225
+ /**
226
+ * Check address
227
+ *
228
+ * @param array $params
229
+ * @return $this
230
+ * @throws \OnePica_AvaTax_Exception
231
+ */
232
+ protected function _checkAddress(array $params)
233
+ {
234
+ if (!isset($params[self::ADDRESS_PARAMETER])
235
+ || !$params[self::ADDRESS_PARAMETER] instanceof Mage_Sales_Model_Quote_Address
236
+ ) {
237
+ throw new OnePica_AvaTax_Exception($this->_getHelper()->__('Address object is wrong.'));
238
+ }
239
+
240
+ return $this;
241
+ }
242
+ }
app/code/community/OnePica/AvaTax/Model/Action/Creditmemo.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0), a
6
+ * copy of which is available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category OnePica
10
+ * @package OnePica_AvaTax
11
+ * @author OnePica Codemaster <codemaster@onepica.com>
12
+ * @copyright Copyright (c) 2015 One Pica, Inc.
13
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14
+ */
15
+
16
+ /**
17
+ * Class OnePica_AvaTax_Model_Action_Creditmemo
18
+ */
19
+ class OnePica_AvaTax_Model_Action_Creditmemo extends OnePica_AvaTax_Model_Action_Abstract
20
+ {
21
+ /**
22
+ * Save order in AvaTax system
23
+ *
24
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderCreditmemoSaveAfter::execute()
25
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
26
+ * @param OnePica_AvaTax_Model_Records_Queue $queue
27
+ * @return mixed
28
+ * @throws OnePica_AvaTax_Exception
29
+ * @throws OnePica_AvaTax_Model_Service_Exception_Commitfailure
30
+ * @throws OnePica_AvaTax_Model_Service_Exception_Unbalanced
31
+ */
32
+ public function process($creditmemo, $queue)
33
+ {
34
+ $order = $creditmemo->getOrder();
35
+ $storeId = $order->getStoreId();
36
+ $this->setStoreId($storeId);
37
+ $shippingAddress = ($order->getShippingAddress()) ? $order->getShippingAddress() : $order->getBillingAddress();
38
+ if (!$shippingAddress) {
39
+ throw new OnePica_AvaTax_Exception($this->_getHelper()->__('There is no address attached to this order'));
40
+ }
41
+
42
+ /** @var OnePica_AvaTax_Model_Service_Result_Creditmemo $creditmemoResult */
43
+ $creditmemoResult = $this->_getService()->creditmemo($creditmemo, $queue);
44
+
45
+ //if successful
46
+ if (!$creditmemoResult->getHasError()) {
47
+ $message = $this->_getHelper()
48
+ ->__('Credit memo #%s was saved to AvaTax', $creditmemoResult->getDocumentCode());
49
+ $this->_getHelper()->addStatusHistoryComment($order, $message);
50
+
51
+ $totalTax = $creditmemoResult->getTotalTax();
52
+ if ($totalTax != ($creditmemo->getBaseTaxAmount() * -1)) {
53
+ throw new OnePica_AvaTax_Model_Service_Exception_Unbalanced(
54
+ 'Collected: ' . $creditmemo->getTaxAmount() . ', Actual: ' . $totalTax
55
+ );
56
+ }
57
+ //if not successful
58
+ } else {
59
+ $messages = $creditmemoResult->getErrors();
60
+ throw new OnePica_AvaTax_Model_Service_Exception_Commitfailure(implode(' // ', $messages));
61
+ }
62
+
63
+ return true;
64
+ }
65
+ }
app/code/community/OnePica/AvaTax/Model/Action/Invoice.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0), a
6
+ * copy of which is available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category OnePica
10
+ * @package OnePica_AvaTax
11
+ * @author OnePica Codemaster <codemaster@onepica.com>
12
+ * @copyright Copyright (c) 2015 One Pica, Inc.
13
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14
+ */
15
+
16
+ /**
17
+ * Class OnePica_AvaTax_Model_Action_Invoice
18
+ */
19
+ class OnePica_AvaTax_Model_Action_Invoice extends OnePica_AvaTax_Model_Action_Abstract
20
+ {
21
+ /**
22
+ * Save order in AvaTax system
23
+ *
24
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderInvoiceSaveAfter::execute()
25
+ * @param Mage_Sales_Model_Order_Invoice $invoice
26
+ * @param OnePica_AvaTax_Model_Records_Queue $queue
27
+ * @return bool
28
+ * @throws OnePica_AvaTax_Exception
29
+ * @throws OnePica_AvaTax_Model_Service_Exception_Commitfailure
30
+ * @throws OnePica_AvaTax_Model_Service_Exception_Unbalanced
31
+ */
32
+ public function process($invoice, $queue)
33
+ {
34
+ $order = $invoice->getOrder();
35
+ $storeId = $order->getStoreId();
36
+ $this->setStoreId($storeId);
37
+ $shippingAddress = ($order->getShippingAddress()) ? $order->getShippingAddress() : $order->getBillingAddress();
38
+ if (!$shippingAddress) {
39
+ throw new OnePica_AvaTax_Exception($this->_getHelper()->__('There is no address attached to this order'));
40
+ }
41
+
42
+ /** @var OnePica_AvaTax_Model_Service_Result_Invoice $invoiceResult */
43
+ $invoiceResult = $this->_getService()->invoice($invoice, $queue);
44
+
45
+ //if successful
46
+ if (!$invoiceResult->getHasError()) {
47
+ $message = $this->_getHelper()->__('Invoice #%s was saved to AvaTax', $invoiceResult->getDocumentCode());
48
+ $this->_getHelper()->addStatusHistoryComment($order, $message);
49
+
50
+ $totalTax = $invoiceResult->getTotalTax();
51
+ if ($totalTax != $invoice->getBaseTaxAmount()) {
52
+ throw new OnePica_AvaTax_Model_Service_Exception_Unbalanced(
53
+ 'Collected: ' . $invoice->getBaseTaxAmount() . ', Actual: ' . $totalTax
54
+ );
55
+ }
56
+ //if not successful
57
+ } else {
58
+ $messages = $invoiceResult->getErrors();
59
+ throw new OnePica_AvaTax_Model_Service_Exception_Commitfailure(implode(' // ', $messages));
60
+ }
61
+
62
+ return true;
63
+ }
64
+ }
app/code/community/OnePica/AvaTax/Model/Action/Ping.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0), a
6
+ * copy of which is available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category OnePica
10
+ * @package OnePica_AvaTax
11
+ * @author OnePica Codemaster <codemaster@onepica.com>
12
+ * @copyright Copyright (c) 2015 One Pica, Inc.
13
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14
+ */
15
+
16
+ /**
17
+ * Class OnePica_AvaTax_Model_Action_Ping
18
+ */
19
+ class OnePica_AvaTax_Model_Action_Ping extends OnePica_AvaTax_Model_Action_Abstract
20
+ {
21
+ /**
22
+ * Tries to ping AvaTax service with provided credentials
23
+ *
24
+ * @param int|null $storeId
25
+ * @return bool|array
26
+ */
27
+ public function ping($storeId)
28
+ {
29
+ $storeId = Mage::app()->getStore($storeId)->getStoreId();
30
+ $this->setStoreId($storeId);
31
+
32
+ return $this->_getService()->ping($storeId);
33
+ }
34
+ }
app/code/community/OnePica/AvaTax/Model/Action/Validator.php ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Class OnePica_AvaTax_Model_Action_Validator
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Action_Validator extends OnePica_AvaTax_Model_Action_Abstract
26
+ {
27
+ /**
28
+ * The AvaTax Response (Normalized) Address object.
29
+ * This is the normalized Ava address returned by the validation request.
30
+ *
31
+ * @var OnePica_AvaTax16_Document_Part_Location_Address
32
+ */
33
+ protected $_responseAddress = null;
34
+
35
+ /**
36
+ * The Mage Address object
37
+ *
38
+ * @var Mage_Customer_Model_Address_Abstract
39
+ */
40
+ protected $_address = null;
41
+
42
+ /**
43
+ * Set Address
44
+ *
45
+ * @param Mage_Customer_Model_Address_Abstract $address
46
+ * @return $this
47
+ */
48
+ public function setAddress($address)
49
+ {
50
+ $this->_address = $address;
51
+
52
+ return $this;
53
+ }
54
+
55
+ /**
56
+ * Get service address validator
57
+ *
58
+ * @param Mage_Sales_Model_Quote_Address $address
59
+ * @return mixed|OnePica_AvaTax_Model_Service_Avatax_Abstract
60
+ */
61
+ public function validate($address)
62
+ {
63
+ $this->setAddress($address);
64
+ /** @var Mage_Sales_Model_Quote $quote */
65
+ $quote = $address->getQuote();
66
+ $isAddressValidationOn = $this->_getAddressHelper()->isAddressValidationOn($address, $quote->getStoreId());
67
+ $isAddressNormalizationOn = $this->_getAddressHelper()
68
+ ->isAddressNormalizationOn($address, $quote->getStoreId());
69
+ $isAddressActionable = $this->_getAddressHelper()->isAddressActionable(
70
+ $address,
71
+ $quote->getStoreId(),
72
+ OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_ALL,
73
+ true
74
+ );
75
+ //if there is no use cases for AvaTax services, return address as valid without doing a lookup
76
+ if (!$isAddressValidationOn && !$isAddressNormalizationOn && !$isAddressActionable) {
77
+ return true;
78
+ }
79
+ if ($address->getPostcode() && $address->getPostcode() != '-') {
80
+ $checkFieldsResult = $this->_checkFields($quote->getStoreId());
81
+ if ($checkFieldsResult) {
82
+ return $checkFieldsResult;
83
+ }
84
+ $this->setStoreId($quote->getStoreId());
85
+ /** @var OnePica_AvaTax_Model_Service_Result_AddressValidate $result */
86
+ $result = $this->_getService()->validate($address);
87
+ } else {
88
+ $errors = array();
89
+ $errors[] = $this->__('Invalid ZIP/Postal Code.');
90
+
91
+ return $errors;
92
+ }
93
+
94
+ $this->_addressNormalization($isAddressNormalizationOn, $result);
95
+ $addressValidationResult = $this->_addressValidation($isAddressValidationOn, $isAddressActionable, $result);
96
+ if ($addressValidationResult) {
97
+ return $addressValidationResult;
98
+ }
99
+
100
+ return true;
101
+ }
102
+
103
+ /**
104
+ * Address validation
105
+ *
106
+ * @param int $isAddressValidationOn
107
+ * @param int $isAddressActionable
108
+ * @param OnePica_AvaTax_Model_Service_Result_AddressValidate $result
109
+ * @return array|bool|null
110
+ */
111
+ protected function _addressValidation($isAddressValidationOn, $isAddressActionable, $result)
112
+ {
113
+ $errors = array();
114
+ if ($isAddressValidationOn == OnePica_AvaTax_Model_Source_Addressvalidation::ENABLED_PREVENT_ORDER) {
115
+ if (!$result->getHasError() && $result->getResolution()) {
116
+ $this->getAddress()->setAddressValidated(true);
117
+
118
+ return true;
119
+ } else {
120
+ foreach ($result->getErrors() as $message) {
121
+ $errors[] = $this->__($message);
122
+ }
123
+
124
+ return $errors;
125
+ }
126
+ } elseif ($isAddressValidationOn == OnePica_AvaTax_Model_Source_Addressvalidation::ENABLED_ALLOW_ORDER) {
127
+ $this->getAddress()->setAddressValidated(true);
128
+ if (!$result->getHasError() && $result->getResolution()) {
129
+ return true;
130
+ } else {
131
+ if (!$this->getAddress()->getAddressNotified()) {
132
+ $this->getAddress()->setAddressNotified(true);
133
+ foreach ($result->getErrors() as $message) {
134
+ $this->_addValidateNotice($this->__($message));
135
+ }
136
+ }
137
+
138
+ return true;
139
+ }
140
+
141
+ //a valid address isn't required, but Avalara has to say there is
142
+ //enough info to drill down to a tax jurisdiction to calc on
143
+ } elseif (!$isAddressValidationOn && $isAddressActionable) {
144
+ if ($result->isTaxable()) {
145
+ $this->getAddress()->setAddressValidated(true);
146
+
147
+ return true;
148
+ } else {
149
+ foreach ($result->getErrors() as $message) {
150
+ $errors[] = $this->__($message);
151
+ }
152
+
153
+ return $errors;
154
+ }
155
+ }
156
+
157
+ return null;
158
+ }
159
+
160
+ /**
161
+ * Check fields
162
+ *
163
+ * @param int $storeId
164
+ * @return array|null
165
+ */
166
+ protected function _checkFields($storeId = null)
167
+ {
168
+ /** @var Mage_Checkout_Model_Session $session */
169
+ $session = Mage::getSingleton('checkout/session');
170
+ if ($session->getPostType() == 'onepage'
171
+ || $session->getPostType() == 'multishipping'
172
+ || Mage::app()->getStore()->isAdmin()
173
+ ) {
174
+ $requiredFields = explode(",", $this->_getConfigHelper()->getFieldRequiredList($storeId));
175
+ $fieldRules = explode(",", $this->_getConfigHelper()->getFieldRule($storeId));
176
+ foreach ($requiredFields as $field) {
177
+ $requiredFlag = 0;
178
+ foreach ($fieldRules as $rule) {
179
+ if (preg_match("/street\d/", $field)) {
180
+ $field = "street";
181
+ }
182
+
183
+ switch ($field) {
184
+ case 'country':
185
+ $fieldValue = $this->getAddress()->getCountry();
186
+ break;
187
+ case 'region':
188
+ $fieldValue = $this->getAddress()->getRegion();
189
+ break;
190
+ default:
191
+ $fieldValue = $this->getAddress()->getData($field);
192
+ break;
193
+ }
194
+
195
+ if ($fieldValue == $rule || !$fieldValue) {
196
+ $requiredFlag = 1;
197
+ }
198
+ }
199
+ if ($requiredFlag) {
200
+ $errors = array();
201
+ $errors[] = $this->__('Invalid ') . $this->__($field);
202
+
203
+ return $errors;
204
+ }
205
+ }
206
+ }
207
+
208
+ return null;
209
+ }
210
+
211
+ /**
212
+ * Address normalization
213
+ *
214
+ * @param bool $isAddressNormalizationOn
215
+ * @param OnePica_AvaTax_Model_Service_Result_AddressValidate $result
216
+ * @return $this
217
+ * @throws OnePica_AvaTax_Model_Service_Exception_Address
218
+ */
219
+ protected function _addressNormalization(
220
+ $isAddressNormalizationOn,
221
+ OnePica_AvaTax_Model_Service_Result_AddressValidate $result
222
+ ) {
223
+ if ($isAddressNormalizationOn && (!$result->getHasError() && !$result->getErrors())) {
224
+ if ($result->getAddress() instanceof OnePica_AvaTax_Model_Service_Result_Address) {
225
+ $this->setResponseAddress($result->getAddress());
226
+ $this->_convertResponseAddress();
227
+ } else {
228
+ throw new OnePica_AvaTax_Model_Service_Exception_Address($this->__('Invalid response address type.'));
229
+ }
230
+ }
231
+
232
+ return $this;
233
+ }
234
+
235
+ /**
236
+ * Sets attributes from the AvaTax Response address on the Mage address.
237
+ *
238
+ * @return $this
239
+ */
240
+ protected function _convertResponseAddress()
241
+ {
242
+ $street = array($this->getResponseAddress()->getLine1(), $this->getResponseAddress()->getLine2());
243
+ $region = Mage::getModel('directory/region')
244
+ ->loadByCode($this->getResponseAddress()->getState(), $this->getAddress()->getCountryId());
245
+
246
+ $this->getAddress()->setStreet($street)
247
+ ->setCity($this->getResponseAddress()->getCity())
248
+ ->setRegionId($region->getId())
249
+ ->setPostcode($this->getResponseAddress()->getPostalCode())
250
+ ->setCountryId($this->getResponseAddress()->getCountry())
251
+ ->save()
252
+ ->setAddressNormalized(true);
253
+
254
+ return $this;
255
+ }
256
+
257
+ /**
258
+ * Returns the AvaTax helper.
259
+ *
260
+ * @return OnePica_AvaTax_Helper_Address
261
+ */
262
+ protected function _getAddressHelper()
263
+ {
264
+ return Mage::helper('avatax/address');
265
+ }
266
+
267
+ /**
268
+ * Address getter
269
+ *
270
+ * @return Mage_Customer_Model_Address_Abstract
271
+ */
272
+ public function getAddress()
273
+ {
274
+ return $this->_address;
275
+ }
276
+
277
+ /**
278
+ * Get Response Address
279
+ *
280
+ * @return OnePica_AvaTax16_Document_Part_Location_Address
281
+ */
282
+ public function getResponseAddress()
283
+ {
284
+ return $this->_responseAddress;
285
+ }
286
+
287
+ /**
288
+ * Set Response Address
289
+ *
290
+ * @param OnePica_AvaTax16_Document_Part_Location_Address $responseAddress
291
+ * @return $this
292
+ */
293
+ public function setResponseAddress($responseAddress)
294
+ {
295
+ $this->_responseAddress = $responseAddress;
296
+
297
+ return $this;
298
+ }
299
+
300
+ /**
301
+ * Alias to the helper translate method.
302
+ *
303
+ * @return string
304
+ * @skipPublicMethodNaming __
305
+ */
306
+ public function __()
307
+ {
308
+ $args = func_get_args();
309
+
310
+ return call_user_func_array(array(Mage::helper('avatax'), '__'), $args);
311
+ }
312
+
313
+ /**
314
+ * Add validation notice
315
+ *
316
+ * @param string $message
317
+ * @return $this
318
+ */
319
+ protected function _addValidateNotice($message)
320
+ {
321
+ $notice = Mage::getSingleton('core/message')->notice($message);
322
+ $notice->setIdentifier(OnePica_AvaTax_Helper_Errors::VALIDATION_NOTICE_IDENTIFIER);
323
+ Mage::getSingleton('core/session')->addMessage($notice);
324
+
325
+ return $this;
326
+ }
327
+ }
app/code/community/OnePica/AvaTax/Model/Adminhtml/Config.php CHANGED
@@ -32,34 +32,65 @@ class OnePica_AvaTax_Model_Adminhtml_Config extends Mage_Adminhtml_Model_Config
32
  */
33
  protected function _initSectionsAndTabs()
34
  {
35
- if ($this->_getDataHelper()->isAvaTaxDisabled()) {
36
- $config = Mage::getConfig()->loadModulesConfiguration('system.xml')
37
- ->applyExtends();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- Mage::dispatchEvent('adminhtml_init_system_config', array('config' => $config));
40
 
 
41
  //these 4 lines are the only added content
42
- $configFile = $this->_getDataHelper()->getEtcPath() . DS . 'system-disabled.xml';
 
43
  /** @var Mage_Core_Model_Config_Base $mergeModel */
44
  $mergeModel = Mage::getModel('core/config_base');
45
  $mergeModel->loadFile($configFile);
 
46
  $config = $config->extend($mergeModel, true);
47
- $this->_sections = $config->getNode('sections');
48
- $this->_tabs = $config->getNode('tabs');
49
- } else {
50
- parent::_initSectionsAndTabs();
51
  }
52
 
 
 
 
53
  return $this;
54
  }
55
 
56
  /**
57
- * Get data helper
58
  *
59
- * @return \OnePica_AvaTax_Helper_Data
60
  */
61
  protected function _getDataHelper()
62
  {
63
- return Mage::helper('avatax');
 
 
 
 
 
 
 
 
 
 
64
  }
65
  }
32
  */
33
  protected function _initSectionsAndTabs()
34
  {
35
+ if ($this->_getConfigHelper()->isAvaTaxDisabled()) {
36
+ $this->_getDataHelper()->isAvatax16()
37
+ ? $this->_addCustomConfig(array('system-disabled.xml', 'system-avatax16-disabled.xml'))
38
+ : $this->_addCustomConfig(array('system-disabled.xml'));
39
+ } else {
40
+ $this->_getDataHelper()->isAvatax16()
41
+ ? $this->_addCustomConfig(array('system-avatax16.xml'))
42
+ : parent::_initSectionsAndTabs();
43
+ }
44
+
45
+ return $this;
46
+ }
47
+
48
+ /**
49
+ * Added custom config
50
+ *
51
+ * @param array $customConfig
52
+ * @return $this
53
+ */
54
+ protected function _addCustomConfig(array $customConfig)
55
+ {
56
+ $config = Mage::getConfig()->loadModulesConfiguration('system.xml')->applyExtends();
57
 
58
+ Mage::dispatchEvent('adminhtml_init_system_config', array('config' => $config));
59
 
60
+ foreach ($customConfig as $item) {
61
  //these 4 lines are the only added content
62
+ $configFile = $this->_getConfigHelper()->getEtcPath() . DS . $item;
63
+
64
  /** @var Mage_Core_Model_Config_Base $mergeModel */
65
  $mergeModel = Mage::getModel('core/config_base');
66
  $mergeModel->loadFile($configFile);
67
+
68
  $config = $config->extend($mergeModel, true);
 
 
 
 
69
  }
70
 
71
+ $this->_sections = $config->getNode('sections');
72
+ $this->_tabs = $config->getNode('tabs');
73
+
74
  return $this;
75
  }
76
 
77
  /**
78
+ * Get avatax data helper
79
  *
80
+ * @return OnePica_AvaTax_Helper_Data
81
  */
82
  protected function _getDataHelper()
83
  {
84
+ return Mage::helper('avatax/data');
85
+ }
86
+
87
+ /**
88
+ * Get avatax config helper
89
+ *
90
+ * @return \OnePica_AvaTax_Helper_Config
91
+ */
92
+ protected function _getConfigHelper()
93
+ {
94
+ return Mage::helper('avatax/config');
95
  }
96
  }
app/code/community/OnePica/AvaTax/Model/Adminhtml/Sales/Order/Create.php CHANGED
@@ -36,7 +36,6 @@ class OnePica_AvaTax_Model_Adminhtml_Sales_Order_Create extends Mage_Adminhtml_M
36
  *
37
  * @param array $address
38
  * @return $this
39
- * @throws OnePica_AvaTax_Exception
40
  */
41
  public function setShippingAddress($address)
42
  {
@@ -45,24 +44,53 @@ class OnePica_AvaTax_Model_Adminhtml_Sales_Order_Create extends Mage_Adminhtml_M
45
  if ($this->getQuote()->getIsVirtual()) {
46
  return $this;
47
  }
 
 
 
 
 
48
 
49
- if (Mage::helper('avatax')->isAvataxEnabled()) {
50
- if (!Mage::app()->getFrontController()->getRequest()->getParam('isAjax')) {
51
- $result = $this->getShippingAddress()->validate();
52
- if ($result !== true) {
53
- $storeId = $this->_session->getStore()->getId();
54
- if (Mage::helper('avatax')->fullStopOnError($storeId)) {
55
- foreach ($result as $error) {
56
- $this->getSession()->addError($error);
57
- }
58
- throw new OnePica_AvaTax_Exception(implode('<br />', $result));
59
- }
60
- } elseif ($this->getShippingAddress()->getAddressNormalized() && !$this->_messageAdded) {
61
- Mage::getSingleton('avatax/session')->addNotice(Mage::helper('avatax')->__('The shipping address has been modified during the validation process. Please confirm the address below is accurate.'));
62
- $this->_messageAdded = true; // only add the message once
63
- }
64
- }
 
 
 
65
  }
 
66
  return $this;
67
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  }
36
  *
37
  * @param array $address
38
  * @return $this
 
39
  */
40
  public function setShippingAddress($address)
41
  {
44
  if ($this->getQuote()->getIsVirtual()) {
45
  return $this;
46
  }
47
+ if (!$this->_isAjaxRequest()) {
48
+ $this->_validateShippingAddress();
49
+ }
50
+ return $this;
51
+ }
52
 
53
+ /**
54
+ * Validate shipping address
55
+ *
56
+ * @return $this
57
+ * @throws OnePica_AvaTax_Exception
58
+ */
59
+ protected function _validateShippingAddress()
60
+ {
61
+ if (!$this->_getDataHelper()->isServiceEnabled()) {
62
+ return $this;
63
+ }
64
+ $result = $this->getShippingAddress()->validate();
65
+ if ($result !== true) {
66
+ throw new OnePica_AvaTax_Exception(implode('<br />', $result));
67
+ } elseif ($this->getShippingAddress()->getAddressNormalized() && !$this->_messageAdded) {
68
+ Mage::getSingleton('adminhtml/session')->addNotice(
69
+ $this->_getDataHelper()->__('The shipping address has been modified during the validation process. Please confirm the address below is accurate.')
70
+ );
71
+ $this->_messageAdded = true;
72
  }
73
+
74
  return $this;
75
  }
76
+
77
+ /**
78
+ * Is ajax
79
+ *
80
+ * @return bool
81
+ */
82
+ protected function _isAjaxRequest()
83
+ {
84
+ return (bool)Mage::app()->getFrontController()->getRequest()->getParam('isAjax');
85
+ }
86
+
87
+ /**
88
+ * Get data helper
89
+ *
90
+ * @return OnePica_AvaTax_Helper_Data
91
+ */
92
+ protected function _getDataHelper()
93
+ {
94
+ return Mage::helper('avatax');
95
+ }
96
  }
app/code/community/OnePica/AvaTax/Model/Avatax/Address.php DELETED
@@ -1,351 +0,0 @@
1
- <?php
2
- /**
3
- * OnePica_AvaTax
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0), a
8
- * copy of which is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- *
11
- * @category OnePica
12
- * @package OnePica_AvaTax
13
- * @author OnePica Codemaster <codemaster@onepica.com>
14
- * @copyright Copyright (c) 2009 One Pica, Inc.
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * The AvaTax Address Validator model
20
- *
21
- * @category OnePica
22
- * @package OnePica_AvaTax
23
- * @author OnePica Codemaster <codemaster@onepica.com>
24
- */
25
- class OnePica_AvaTax_Model_Avatax_Address extends OnePica_AvaTax_Model_Abstract
26
- {
27
- /**
28
- * An array of previously checked addresses
29
- * Example: $_cache[$key] = serialize($resultObjectFromAvalara)
30
- *
31
- * @var array
32
- */
33
- protected $_cache = array();
34
-
35
- /**
36
- * The Mage Address object
37
- *
38
- * @var OnePica_AvaTax_Model_Sales_Quote_Address
39
- */
40
- protected $_mageAddress = null;
41
-
42
- /**
43
- * The AvaTax Request Address object.
44
- * This is a Ava address copy of the Mage address attributes.
45
- *
46
- * @var Address
47
- */
48
- protected $_requestAddress = null;
49
-
50
- /**
51
- * The AvaTax Response (Normalized) Address object.
52
- * This is the normalized Ava address returned by the validation request.
53
- *
54
- * @var ValidAddress
55
- */
56
- protected $_responseAddress = null;
57
-
58
- /**
59
- * Saves the store id
60
- *
61
- * @var int
62
- */
63
- protected $_storeId = null;
64
-
65
- /**
66
- * Loads any saved addresses in session
67
- */
68
- public function __construct()
69
- {
70
- $addresses = Mage::getSingleton('avatax/session')->getAddresses();
71
- if (is_array($addresses)) {
72
- $this->_cache = $addresses;
73
- }
74
- parent::__construct();
75
- }
76
-
77
- /**
78
- * Saves any current addresses to session
79
- */
80
- public function __destruct()
81
- {
82
- Mage::getSingleton('avatax/session')->setAddresses($this->_cache);
83
-
84
- if (method_exists(get_parent_class(), '__destruct')) {
85
- parent::__destruct();
86
- }
87
- }
88
-
89
- /**
90
- * Sets the Mage address.
91
- *
92
- * @param Mage_Customer_Model_Address_Abstract $address
93
- * @return $this
94
- */
95
- public function setAddress(Mage_Customer_Model_Address_Abstract $address)
96
- {
97
- $this->_storeId = Mage::app()->getStore()->getId();
98
- $this->_mageAddress = $address;
99
- $this->_convertRequestAddress();
100
- return $this;
101
- }
102
-
103
- /**
104
- * Sets attributes from the Mage address on the AvaTax Request address.
105
- *
106
- * @return $this
107
- */
108
- protected function _convertRequestAddress()
109
- {
110
- if (!$this->_requestAddress) {
111
- $this->_requestAddress = new Address();
112
- }
113
- $this->_requestAddress->setLine1($this->_mageAddress->getStreet(1));
114
- $this->_requestAddress->setLine2($this->_mageAddress->getStreet(2));
115
- $this->_requestAddress->setCity($this->_mageAddress->getCity());
116
- $this->_requestAddress->setRegion($this->_mageAddress->getRegionCode());
117
- $this->_requestAddress->setCountry($this->_mageAddress->getCountry());
118
- $this->_requestAddress->setPostalCode($this->_mageAddress->getPostcode());
119
-
120
- return $this;
121
- }
122
-
123
- /**
124
- * Sets attributes from the AvaTax Response address on the Mage address.
125
- *
126
- * @return $this
127
- */
128
- protected function _convertResponseAddress()
129
- {
130
- $street = array($this->_responseAddress->getLine1(), $this->_responseAddress->getLine2());
131
- $region = Mage::getModel('directory/region')
132
- ->loadByCode($this->_responseAddress->getRegion(), $this->_mageAddress->getCountryId());
133
-
134
- $this->_mageAddress->setStreet($street)
135
- ->setCity($this->_responseAddress->getCity())
136
- ->setRegionId($region->getId())
137
- ->setPostcode($this->_responseAddress->getPostalCode())
138
- ->setCountryId($this->_responseAddress->getCountry())
139
- ->save()
140
- ->setAddressNormalized(true);
141
- return $this;
142
- }
143
-
144
- /**
145
- * Validates the address with the AvaTax validation API.
146
- * Returns true on success and an array with an error on failure.
147
- *
148
- * @return array|bool
149
- * @throws OnePica_AvaTax_Model_Avatax_Address_Exception
150
- */
151
- public function validate()
152
- {
153
- if (!$this->_mageAddress) {
154
- throw new OnePica_AvaTax_Model_Avatax_Address_Exception(
155
- $this->__('An address must be set before validation.')
156
- );
157
- }
158
-
159
- /** @var Mage_Sales_Model_Quote $quote */
160
- $quote = $this->_mageAddress->getQuote();
161
- $isAddressValidationOn = $this->_getDataHelper()->isAddressValidationOn($this->_mageAddress, $this->_storeId);
162
- $isAddressNormalizationOn = $this->_getDataHelper()->isAddressNormalizationOn(
163
- $this->_mageAddress, $this->_storeId
164
- );
165
- $isAddressActionable = $this->_getDataHelper()->isAddressActionable(
166
- $this->_mageAddress,
167
- $quote->getStoreId(),
168
- OnePica_AvaTax_Model_Config::REGIONFILTER_ALL,
169
- true
170
- );
171
- //if there is no use cases for AvaTax services, return address as valid without doing a lookup
172
- if (!$isAddressValidationOn && !$isAddressNormalizationOn && !$isAddressActionable) {
173
- return true;
174
- }
175
-
176
- //lookup in AvaTax (with caching)
177
- $key = $this->_mageAddress->getCacheHashKey();
178
-
179
- if (array_key_exists($key, $this->_cache)) {
180
- $result = unserialize($this->_cache[$key]);
181
- } elseif ($this->_mageAddress->getPostcode() && $this->_mageAddress->getPostcode() != '-') {
182
- $checkFieldsResult = $this->_checkFields();
183
- if ($checkFieldsResult) {
184
- return $checkFieldsResult;
185
- }
186
- $result = $this->_sendAddressValidationRequest();
187
- $this->_cache[$key] = serialize($result);
188
- } else {
189
- $errors = array();
190
- $errors[] = $this->__('Invalid ZIP/Postal Code.');
191
-
192
- return $errors;
193
- }
194
-
195
- $this->_addressNormalization($isAddressNormalizationOn, $result);
196
-
197
- $addressValidationResult = $this->_addressValidation($isAddressValidationOn, $isAddressActionable, $result);
198
- if ($addressValidationResult) {
199
- return $addressValidationResult;
200
- }
201
-
202
- return true;
203
- }
204
-
205
- /**
206
- * Address validation
207
- *
208
- * @param int $isAddressValidationOn
209
- * @param int $isAddressActionable
210
- * @param ValidateResult $result
211
- * @return array|bool|null
212
- */
213
- protected function _addressValidation($isAddressValidationOn, $isAddressActionable, $result)
214
- {
215
- if ($isAddressValidationOn == OnePica_AvaTax_Model_Source_Addressvalidation::ENABLED_PREVENT_ORDER) {
216
- if ($result->getResultCode() == SeverityLevel::$Success) {
217
- $this->_mageAddress->setAddressValidated(true);
218
- return true;
219
- } else {
220
- $errors = array();
221
- foreach ($result->getMessages() as $message) {
222
- $errors[] = $this->__($message->getSummary());
223
- }
224
- return $errors;
225
- }
226
- } elseif ($isAddressValidationOn == OnePica_AvaTax_Model_Source_Addressvalidation::ENABLED_ALLOW_ORDER) {
227
- $this->_mageAddress->setAddressValidated(true);
228
- if ($result->getResultCode() == SeverityLevel::$Success) {
229
- return true;
230
- } else {
231
- if (!$this->_mageAddress->getAddressNotified()) {
232
- $this->_mageAddress->setAddressNotified(true);
233
- foreach ($result->getMessages() as $message) {
234
- Mage::getSingleton('core/session')->addNotice($this->__($message->getSummary()));
235
- }
236
- }
237
- return true;
238
- }
239
-
240
- //a valid address isn't required, but Avalara has to say there is
241
- //enough info to drill down to a tax jurisdiction to calc on
242
- } elseif (!$isAddressValidationOn && $isAddressActionable) {
243
- if ($result->isTaxable()) {
244
- $this->_mageAddress->setAddressValidated(true);
245
- return true;
246
- } else {
247
- $errors = array();
248
- foreach ($result->getMessages() as $message) {
249
- $errors[] = $this->__($message->getSummary());
250
- }
251
- return $errors;
252
- }
253
- }
254
-
255
- return null;
256
- }
257
-
258
- /**
259
- * Check fields
260
- *
261
- * @return array|null
262
- */
263
- protected function _checkFields()
264
- {
265
- /** @var Mage_Checkout_Model_Session $session */
266
- $session = Mage::getSingleton('checkout/session');
267
- if ($session->getPostType() == 'onepage') {
268
- $requiredFields = explode(",", $this->getHelper()->getFieldRequiredList());
269
- $fieldRules = explode(",", $this->getHelper()->getFieldRule());
270
- foreach ($requiredFields as $field) {
271
- $requiredFlag = 0;
272
- foreach ($fieldRules as $rule) {
273
- if (preg_match("/street\d/", $field)) {
274
- $field = "street";
275
- }
276
- if ($field == "country") {
277
- $field = "country_id";
278
- }
279
- if ($this->_mageAddress->getData($field) == $rule || !$this->_mageAddress->getData($field)) {
280
- $requiredFlag = 1;
281
- }
282
- }
283
- if ($requiredFlag) {
284
- $errors = array();
285
- $errors[] = $this->__('Invalid ') . $this->__($field);
286
- return $errors;
287
- }
288
- }
289
- }
290
-
291
- return null;
292
- }
293
-
294
- /**
295
- * Get data helper
296
- *
297
- * @return OnePica_AvaTax_Helper_Data
298
- */
299
- protected function _getDataHelper()
300
- {
301
- return Mage::helper('avatax');
302
- }
303
-
304
- /**
305
- * Validate address
306
- *
307
- * @return ValidateResult
308
- */
309
- protected function _sendAddressValidationRequest()
310
- {
311
- /** @var OnePica_AvaTax_Model_Config $config */
312
- $config = Mage::getSingleton('avatax/config')->init($this->_storeId);
313
- $client = $config->getAddressConnection();
314
- $request = new ValidateRequest($this->_requestAddress, TextCase::$Mixed, 0);
315
- $request->setTaxability(true);
316
- $result = $client->Validate($request);
317
- $this->_log(
318
- OnePica_AvaTax_Model_Source_Logtype::VALIDATE,
319
- $request,
320
- $result,
321
- $this->_storeId,
322
- $config->getParams()
323
- );
324
-
325
- return $result;
326
- }
327
-
328
- /**
329
- * Address normalization
330
- *
331
- * @param bool $isAddressNormalizationOn
332
- * @param ValidateResult $result
333
- * @return $this
334
- * @throws \OnePica_AvaTax_Model_Avatax_Address_Exception
335
- */
336
- protected function _addressNormalization($isAddressNormalizationOn, $result)
337
- {
338
- if ($isAddressNormalizationOn && $result->getResultCode() == SeverityLevel::$Success) {
339
- $responseAddress = $result->getValidAddresses();
340
- $responseAddress = array_pop($responseAddress);
341
- if ($responseAddress instanceof ValidAddress) {
342
- $this->_responseAddress = $responseAddress;
343
- $this->_convertResponseAddress();
344
- } else {
345
- throw new OnePica_AvaTax_Model_Avatax_Address_Exception($this->__('Invalid response address type.'));
346
- }
347
- }
348
-
349
- return $this;
350
- }
351
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/OnePica/AvaTax/Model/Config.php DELETED
@@ -1,224 +0,0 @@
1
- <?php
2
- /**
3
- * OnePica_AvaTax
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0), a
8
- * copy of which is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- *
11
- * @category OnePica
12
- * @package OnePica_AvaTax
13
- * @author OnePica Codemaster <codemaster@onepica.com>
14
- * @copyright Copyright (c) 2009 One Pica, Inc.
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * The AvaTax Config Model, which registers config settings with the AvaTax SDK
20
- *
21
- * @category OnePica
22
- * @package OnePica_AvaTax
23
- * @author OnePica Codemaster <codemaster@onepica.com>
24
- */
25
- class OnePica_AvaTax_Model_Config extends Varien_Object
26
- {
27
- /**
28
- * Config key
29
- */
30
- const CONFIG_KEY = 'Magento';
31
-
32
- /**
33
- * App name
34
- */
35
- const APP_NAME = 'OP_AvaTax by One Pica';
36
-
37
- /**
38
- * Disable action
39
- */
40
- const ACTION_DISABLE = 0;
41
-
42
- /**
43
- * Calculate action
44
- */
45
- const ACTION_CALC = 1;
46
-
47
- /**
48
- * Calculate, submit action
49
- */
50
- const ACTION_CALC_SUBMIT = 2;
51
-
52
- /**
53
- * Calculate, submit, commit action
54
- */
55
- const ACTION_CALC_SUBMIT_COMMIT = 3;
56
-
57
- /**
58
- * Region filter disable mode
59
- */
60
- const REGIONFILTER_OFF = 0;
61
-
62
- /**
63
- * Region filter tax mode
64
- */
65
- const REGIONFILTER_TAX = 1;
66
-
67
- /**
68
- * Region filter all mode
69
- */
70
- const REGIONFILTER_ALL = 2;
71
-
72
- /**
73
- * Number of times a queue item will try to send
74
- */
75
- const QUEUE_ATTEMPT_MAX = 5;
76
-
77
- /**
78
- * The AvaTax ATConfig object.
79
- *
80
- * @var ATConfig
81
- */
82
- protected $_config = null;
83
-
84
- /**
85
- * The AvaTax TaxServiceSoap object.
86
- *
87
- * @var TaxServiceSoap
88
- */
89
- protected $_taxConnection;
90
-
91
- /**
92
- * The AvaTax AddressServiceSoap object.
93
- *
94
- * @var AddressServiceSoap
95
- */
96
- protected $_addressConnection;
97
-
98
- /**
99
- * Initializes the AvaTax SDK with connection settings found in the Admin config.
100
- *
101
- * @param int $storeId
102
- * @return OnePica_AvaTax_Model_Config
103
- */
104
- public function init($storeId)
105
- {
106
- if (!$this->_config) {
107
- $this->_config = new ATConfig(
108
- self::CONFIG_KEY,
109
- array(
110
- 'url' => $this->getConfig('url', $storeId),
111
- 'account' => $this->getConfig('account', $storeId),
112
- 'license' => $this->getConfig('license', $storeId),
113
- 'trace' => (Mage::helper('avatax')
114
- ->getLogMode($storeId) == OnePica_AvaTax_Model_Source_Logmode::DEBUG) ? true : false,
115
- 'client' => $this->getClientName()
116
- )
117
- );
118
- }
119
-
120
- return $this;
121
- }
122
-
123
- /**
124
- * Generates client name to pass with communications
125
- *
126
- * Parts:
127
- * - MyERP: the ERP that this connector is for (not always applicable)
128
- * - Majver: version info for the ERP (not always applicable)
129
- * - MinVer: version info for the ERP (not always applicable)
130
- * - MyConnector: Name of the OEM�s connector AND the name of the OEM (company) *required*
131
- * - Majver: OEM�s connector version *required*
132
- * - MinVer: OEM�s connector version *required*
133
- *
134
- * @example Magento,1.4,.0.1,OP_AvaTax by One Pica,2,0.1
135
- * @return string
136
- */
137
- public function getClientName()
138
- {
139
- $mageVersion = Mage::getVersion();
140
- $mageVerParts = explode('.', $mageVersion, 2);
141
-
142
- $opVersion = Mage::getResourceModel('core/resource')->getDbVersion('avatax_records_setup');
143
- $opVerParts = explode('.', $opVersion, 2);
144
-
145
- $part = array();
146
- $part[] = self::CONFIG_KEY;
147
- $part[] = $mageVerParts[0];
148
- $part[] = $mageVerParts[1];
149
- $part[] = self::APP_NAME;
150
- $part[] = $opVerParts[0];
151
- $part[] = $opVerParts[1];
152
- return implode(',', $part);
153
- }
154
-
155
- /**
156
- * Returns the AvaTax Address soap connection client.
157
- *
158
- * @return AddressServiceSoap
159
- */
160
- public function getAddressConnection()
161
- {
162
- if (!$this->_addressConnection) {
163
- $this->_addressConnection = new AddressServiceSoap(self::CONFIG_KEY);
164
- }
165
- return $this->_addressConnection;
166
- }
167
-
168
- /**
169
- * Returns the AvaTax Address soap connection client.
170
- *
171
- * @return AddressServiceSoap
172
- */
173
- public function getTaxConnection()
174
- {
175
- if (!$this->_taxConnection) {
176
- $this->_taxConnection = new TaxServiceSoap(self::CONFIG_KEY);
177
- }
178
- return $this->_taxConnection;
179
- }
180
-
181
- /**
182
- * Returns the AvaTax ATConfig object
183
- *
184
- * @return ATConfig
185
- */
186
- public function getParams()
187
- {
188
- return $this->_config;
189
- }
190
-
191
- /**
192
- * Returns data from the admin system config.
193
- *
194
- * @param string $path
195
- * @param int $store
196
- * @return string
197
- */
198
- public function getConfig($path, $store = null)
199
- {
200
- return Mage::getStoreConfig('tax/avatax/' . $path, $store);
201
- }
202
-
203
- /**
204
- * Returns true if the admin is configured to normalize addresses.
205
- *
206
- * @return boolean
207
- */
208
- public function normalizeAddress()
209
- {
210
- $storeId = Mage::app()->getStore()->getId();
211
- return $this->getConfig('normalize_address', $storeId);
212
- }
213
-
214
- /**
215
- * Returns the company code to use from the AvaTax dashboard
216
- *
217
- * @param null|bool|int|Mage_Core_Model_Store $store
218
- * @return string
219
- */
220
- public function getCompanyCode($store = null)
221
- {
222
- return $this->getConfig('company_code', $store);
223
- }
224
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/OnePica/AvaTax/Model/Observer.php DELETED
@@ -1,546 +0,0 @@
1
- <?php
2
- /**
3
- * OnePica_AvaTax
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0), a
8
- * copy of which is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- *
11
- * @category OnePica
12
- * @package OnePica_AvaTax
13
- * @author OnePica Codemaster <codemaster@onepica.com>
14
- * @copyright Copyright (c) 2009 One Pica, Inc.
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Avatax Observer
20
- *
21
- * @category OnePica
22
- * @package OnePica_AvaTax
23
- * @author OnePica Codemaster <codemaster@onepica.com>
24
- */
25
- class OnePica_AvaTax_Model_Observer extends Mage_Core_Model_Abstract
26
- {
27
- /**
28
- * Avalara lib classes
29
- *
30
- * @var array
31
- */
32
- protected static $_classes = array(
33
- 'TaxRequest',
34
- 'PostTaxRequest',
35
- 'PostTaxResult',
36
- 'CommitTaxRequest',
37
- 'CommitTaxResult',
38
- 'CancelTaxRequest',
39
- 'CancelTaxResult',
40
- 'Enum',
41
- 'CancelCode',
42
- 'ATConfig',
43
- 'ATObject',
44
- 'DynamicSoapClient',
45
- 'AvalaraSoapClient',
46
- 'AddressServiceSoap',
47
- 'Address',
48
- 'Enum',
49
- 'TextCase',
50
- 'Message',
51
- 'SeverityLevel',
52
- 'ValidateRequest',
53
- 'ValidateResult',
54
- 'ValidAddress',
55
- 'TaxServiceSoap',
56
- 'GetTaxRequest',
57
- 'DocumentType',
58
- 'DetailLevel',
59
- 'Line',
60
- 'ServiceMode',
61
- 'GetTaxResult',
62
- 'TaxLine',
63
- 'TaxDetail',
64
- 'PingResult',
65
- 'TaxOverride',
66
- 'TaxOverrideType'
67
- );
68
-
69
- /**
70
- * Sets the collectTotals tax node based on the extensions enabled/disabled status
71
- *
72
- * @param Varien_Event_Observer $observer
73
- * @return $this
74
- */
75
- public function salesQuoteCollectTotalsBefore(Varien_Event_Observer $observer)
76
- {
77
- $storeId = $observer->getEvent()->getQuote()->getStoreId();
78
- if (Mage::getStoreConfig('tax/avatax/action', $storeId) != OnePica_AvaTax_Model_Config::ACTION_DISABLE) {
79
- Mage::getConfig()->setNode('global/sales/quote/totals/tax/class', 'avatax/sales_quote_address_total_tax');
80
- }
81
- return $this;
82
- }
83
-
84
- /**
85
- * Sales order invoice pay event
86
- *
87
- * @param \Varien_Event_Observer $observer
88
- * @return $this
89
- */
90
- public function salesOrderInvoicePay(Varien_Event_Observer $observer)
91
- {
92
- /** @var Mage_Sales_Model_Order_Invoice $invoice */
93
- $invoice = $observer->getEvent()->getInvoice();
94
- $invoice->setData('avatax_can_add_to_queue', true);
95
-
96
- return $this;
97
- }
98
-
99
- /**
100
- * Create a sales invoice record in Avalara
101
- *
102
- * @param Varien_Event_Observer $observer
103
- * @return $this
104
- */
105
- public function salesOrderInvoiceSaveAfter(Varien_Event_Observer $observer)
106
- {
107
- /** @var Mage_Sales_Model_Order_Invoice $invoice */
108
- $invoice = $observer->getEvent()->getInvoice();
109
-
110
- if ($invoice->getData('avatax_can_add_to_queue')
111
- && (int)$invoice->getState() === Mage_Sales_Model_Order_Invoice::STATE_PAID
112
- && Mage::helper('avatax')->isObjectActionable($invoice)
113
- ) {
114
- Mage::getModel('avatax_records/queue')
115
- ->setEntity($invoice)
116
- ->setType(OnePica_AvaTax_Model_Records_Queue::QUEUE_TYPE_INVOICE)
117
- ->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_PENDING)
118
- ->save();
119
- }
120
-
121
- return $this;
122
- }
123
-
124
- /**
125
- * Sales order creditmemo refund event
126
- *
127
- * @param \Varien_Event_Observer $observer
128
- * @return $this
129
- */
130
- public function salesOrderCreditmemoRefund(Varien_Event_Observer $observer)
131
- {
132
- /* @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
133
- $creditmemo = $observer->getEvent()->getCreditmemo();
134
- $creditmemo->setData('avatax_can_add_to_queue', true);
135
-
136
- return $this;
137
- }
138
-
139
- /**
140
- * Create a return invoice record in Avalara
141
- *
142
- * @param Varien_Event_Observer $observer
143
- * @return $this
144
- */
145
- public function salesOrderCreditmemoSaveAfter(Varien_Event_Observer $observer)
146
- {
147
- /* @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
148
- $creditmemo = $observer->getEvent()->getCreditmemo();
149
- if ($creditmemo->getData('avatax_can_add_to_queue')
150
- && (int)$creditmemo->getState() === Mage_Sales_Model_Order_Creditmemo::STATE_REFUNDED
151
- && Mage::helper('avatax')->isObjectActionable($creditmemo)
152
- ) {
153
- Mage::getModel('avatax_records/queue')
154
- ->setEntity($creditmemo)
155
- ->setType(OnePica_AvaTax_Model_Records_Queue::QUEUE_TYPE_CREDITMEMEO)
156
- ->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_PENDING)
157
- ->save();
158
- }
159
- return $this;
160
- }
161
-
162
- /**
163
- * Validate addresses when multishipping checkout on set shipping items
164
- *
165
- * @param Varien_Event_Observer $observer
166
- * @return $this
167
- * @throws OnePica_AvaTax_Exception
168
- */
169
- public function multishippingSetShippingItems(Varien_Event_Observer $observer)
170
- {
171
- /* @var $quote Mage_Sales_Model_Quote */
172
- $quote = $observer->getEvent()->getQuote();
173
- $storeId = $quote->getStoreId();
174
-
175
- $errors = array();
176
- $normalized = false;
177
-
178
- $addresses = $quote->getAllShippingAddresses();
179
- $message = Mage::getStoreConfig('tax/avatax/validate_address_message', $storeId);
180
- foreach ($addresses as $address) {
181
- /* @var $address OnePica_AvaTax_Model_Sales_Quote_Address */
182
- if ($address->validate() !== true) {
183
- $errors[] = sprintf($message, $address->format('oneline'));
184
- }
185
- if ($address->getAddressNormalized()) {
186
- $normalized = true;
187
- }
188
- }
189
-
190
- $session = Mage::getSingleton('checkout/session');
191
- if ($normalized) {
192
- $session->addNotice(Mage::getStoreConfig('tax/avatax/multiaddress_normalize_message', $storeId));
193
- }
194
-
195
- if (!empty($errors)) {
196
- throw new OnePica_AvaTax_Exception(implode('<br />', $errors));
197
- }
198
- return $this;
199
- }
200
-
201
- /**
202
- * Observer push data to Avalara
203
- *
204
- * @return $this;
205
- */
206
- public function processQueue()
207
- {
208
- Mage::getModel('avatax_records/queue_process')->run();
209
- return $this;
210
- }
211
-
212
- /**
213
- * Test for required values when admin config setting related to the this extension are changed
214
- *
215
- * @param Varien_Event_Observer $observer
216
- * @return bool
217
- */
218
- public function adminSystemConfigChangedSectionTax(Varien_Event_Observer $observer)
219
- {
220
- Mage::app()->cleanCache('block_html');
221
- $storeId = $observer->getEvent()->getStore();
222
- $this->_addErrorsToSession($storeId);
223
- $this->_addWarningsToSession($storeId);
224
- }
225
-
226
- /**
227
- * Observer to clean the log every so often so it does not get too big.
228
- *
229
- * @return $this
230
- */
231
- public function cleanLog()
232
- {
233
- $days = floatval(Mage::getStoreConfig('tax/avatax/log_lifetime'));
234
- Mage::getModel('avatax_records/log')->deleteLogsByInterval($days);
235
- return $this;
236
- }
237
-
238
- /**
239
- * This an observer function for the event 'controller_front_init_before' and 'default'
240
- * It prepends our autoloader, so we can load the extra libraries.
241
- *
242
- * @param Varien_Event_Observer $observer
243
- * @return $this
244
- */
245
- public function loadAvaTaxExternalLib(Varien_Event_Observer $observer)
246
- {
247
- spl_autoload_register(array($this, 'loadLib'), true, true);
248
- return $this;
249
- }
250
-
251
- /**
252
- * This function can autoloads classes to work with Avalara API
253
- *
254
- * @param string $class
255
- */
256
- public static function loadLib($class)
257
- {
258
- if (in_array($class, self::$_classes)) {
259
- /** @var OnePica_AvaTax_Helper_Data $helper */
260
- $helper = Mage::helper('avatax');
261
- $helper->loadFunctions();
262
- $helper->loadClass($class);
263
- }
264
- }
265
-
266
- /**
267
- * Set post type for checkout session when 'controller_action_predispatch_checkout_cart_estimatePost' event
268
- *
269
- * @param Varien_Event_Observer $observer
270
- * @return $this
271
- */
272
- public function controllerActionPredispatchCheckoutCartEstimatePost(Varien_Event_Observer $observer)
273
- {
274
- $session = Mage::getSingleton('checkout/session');
275
- $session->setPostType('estimate');
276
- return $this;
277
- }
278
-
279
- /**
280
- * Set post type for checkout session when 'controller_action_predispatch_checkout_onepage_index' event
281
- *
282
- * @param Varien_Event_Observer $observer
283
- * @return $this
284
- */
285
- public function controllerActionPredispatchCheckoutOnepageIndex(Varien_Event_Observer $observer)
286
- {
287
- $session = Mage::getSingleton('checkout/session');
288
- $session->setPostType('onepage');
289
- return $this;
290
- }
291
-
292
- /**
293
- * Prepare warnings array
294
- *
295
- * @param int $storeId
296
- * @return array
297
- */
298
- protected function _prepareWarnings($storeId)
299
- {
300
- $warnings = array();
301
- if (strpos(Mage::getStoreConfig('tax/avatax/url', $storeId), 'development.avalara.net') !== false) {
302
- $warnings[] = Mage::helper('avatax')->__(
303
- 'You are using the AvaTax development connection URL. If you are receiving errors about authentication, please ensure that you have a development account.'
304
- );
305
- }
306
- if (Mage::getStoreConfig('tax/avatax/action', $storeId) == OnePica_AvaTax_Model_Config::ACTION_DISABLE) {
307
- $warnings[] = Mage::helper('avatax')->__('All AvaTax services are disabled');
308
- }
309
- if (Mage::getStoreConfig('tax/avatax/action', $storeId) == OnePica_AvaTax_Model_Config::ACTION_CALC) {
310
- $warnings[] = Mage::helper('avatax')->__('Orders will not be sent to the AvaTax system');
311
- }
312
- if (Mage::getStoreConfig('tax/avatax/action', $storeId) == OnePica_AvaTax_Model_Config::ACTION_CALC_SUBMIT) {
313
- $warnings[] = Mage::helper('avatax')->__('Orders will be sent but never committed to the AvaTax system');
314
- }
315
- if (!Mage::getResourceModel('cron/schedule_collection')->count()) {
316
- $warnings[] = Mage::helper('avatax')->__(
317
- 'It appears that Magento\'s cron scheduler is not running. For more information, see %s.',
318
- '<a href="http://www.magentocommerce.com/wiki/how_to_setup_a_cron_job" target="_black">How to Set Up a Cron Job</a>'
319
- );
320
- }
321
- if ($this->_isRegionFilterAll() && $this->_canNotBeAddressValidated()) {
322
- $warnings[] = Mage::helper('avatax')->__('Please be aware that address validation will not work for addresses outside United States and Canada');
323
- }
324
-
325
- return $warnings;
326
- }
327
-
328
- /**
329
- * Prepare errors array
330
- *
331
- * @param int $storeId
332
- * @return array
333
- */
334
- protected function _prepareErrors($storeId)
335
- {
336
- $errors = array();
337
- $errors = array_merge(
338
- $errors,
339
- $this->_sendPing($storeId),
340
- $this->_checkConnectionFields($storeId),
341
- $this->_checkSkuFields($storeId),
342
- $this->_checkSoapSupport(),
343
- $this->_checkSslSupport()
344
- );
345
-
346
- return $errors;
347
- }
348
-
349
- /**
350
- * Get adminhtml model session
351
- *
352
- * @return \Mage_Adminhtml_Model_Session
353
- */
354
- protected function _getAdminhtmlSession()
355
- {
356
- return Mage::getSingleton('adminhtml/session');
357
- }
358
-
359
- /**
360
- * Add error messages to session
361
- *
362
- * @param int $storeId
363
- * @return $this
364
- */
365
- protected function _addErrorsToSession($storeId)
366
- {
367
- $session = $this->_getAdminhtmlSession();
368
- $errors = $this->_prepareErrors($storeId);
369
- if (count($errors) == 1) {
370
- $session->addError(implode('', $errors));
371
- } elseif (count($errors)) {
372
- $session->addError(
373
- Mage::helper('avatax')->__('Please fix the following issues:') . '<br /> - '
374
- . implode('<br /> - ', $errors)
375
- );
376
- }
377
-
378
- return $this;
379
- }
380
-
381
- /**
382
- * Add warning messages to session
383
- *
384
- * @param int $storeId
385
- * @return $this
386
- */
387
- protected function _addWarningsToSession($storeId)
388
- {
389
- $session = $this->_getAdminhtmlSession();
390
- $warnings = $this->_prepareWarnings($storeId);
391
- if (count($warnings) == 1) {
392
- $session->addWarning(implode('', $warnings));
393
- } elseif (count($warnings)) {
394
- $session->addWarning(
395
- Mage::helper('avatax')->__('Please be aware of the following warnings:')
396
- . '<br /> - '
397
- . implode('<br /> - ', $warnings)
398
- );
399
- }
400
-
401
- return $this;
402
- }
403
-
404
- /**
405
- * Send ping request
406
- *
407
- * @param int $storeId
408
- * @return array
409
- */
410
- protected function _sendPing($storeId)
411
- {
412
- $errors = array();
413
- $ping = Mage::getSingleton('avatax/avatax_ping')->ping($storeId);
414
- if ($ping !== true) {
415
- $errors[] = $ping;
416
- }
417
-
418
- return $errors;
419
- }
420
-
421
- /**
422
- * Check connection fields
423
- *
424
- * @param int $storeId
425
- * @return array
426
- */
427
- protected function _checkConnectionFields($storeId)
428
- {
429
- $errors = array();
430
- if (!Mage::getStoreConfig('tax/avatax/url', $storeId)) {
431
- $errors[] = Mage::helper('avatax')->__('You must enter a connection URL');
432
- }
433
- if (!Mage::getStoreConfig('tax/avatax/account', $storeId)) {
434
- $errors[] = Mage::helper('avatax')->__('You must enter an account number');
435
- }
436
- if (!Mage::getStoreConfig('tax/avatax/license', $storeId)) {
437
- $errors[] = Mage::helper('avatax')->__('You must enter a license key');
438
- }
439
- if (!is_numeric(Mage::getStoreConfig('tax/avatax/log_lifetime'))) {
440
- $errors[] = Mage::helper('avatax')->__('You must enter the number of days to keep log entries');
441
- }
442
- if (!Mage::getStoreConfig('tax/avatax/company_code', $storeId)) {
443
- $errors[] = Mage::helper('avatax')->__('You must enter a company code');
444
- }
445
-
446
- return $errors;
447
- }
448
-
449
- /**
450
- * Check Sku fields
451
- *
452
- * @param int $storeId
453
- * @return array
454
- */
455
- protected function _checkSkuFields($storeId)
456
- {
457
- $errors = array();
458
- if (!Mage::getStoreConfig('tax/avatax/shipping_sku', $storeId)) {
459
- $errors[] = Mage::helper('avatax')->__('You must enter a shipping sku');
460
- }
461
- if (!Mage::getStoreConfig('tax/avatax/adjustment_positive_sku', $storeId)) {
462
- $errors[] = Mage::helper('avatax')->__('You must enter an adjustment refund sku');
463
- }
464
- if (!Mage::getStoreConfig('tax/avatax/adjustment_negative_sku', $storeId)) {
465
- $errors[] = Mage::helper('avatax')->__('You must enter an adjustment fee sku');
466
-
467
- return $errors;
468
- }
469
-
470
- return $errors;
471
- }
472
-
473
- /**
474
- * Check SOAP support
475
- *
476
- * @return array
477
- */
478
- protected function _checkSoapSupport()
479
- {
480
- $errors = array();
481
- if (!class_exists('SoapClient')) {
482
- $errors[] = Mage::helper('avatax')->__(
483
- 'The PHP class SoapClient is missing. It must be enabled to use this extension. See %s for details.',
484
- '<a href="http://www.php.net/manual/en/book.soap.php" target="_blank">http://www.php.net/manual/en/book.soap.php</a>'
485
- );
486
- }
487
-
488
- return $errors;
489
- }
490
-
491
- /**
492
- * Check SSL support
493
- *
494
- * @return array
495
- */
496
- protected function _checkSslSupport()
497
- {
498
- $errors = array();
499
- if (!function_exists('openssl_sign') && count($errors)) {
500
- $key = array_search(Mage::helper('avatax')->__('SSL support is not available in this build'), $errors);
501
- if (isset($errors[$key])) {
502
- unset($errors[$key]);
503
- }
504
- $errors[] = Mage::helper('avatax')->__(
505
- 'SSL must be enabled in PHP to use this extension. Typically, OpenSSL is used but it is not enabled on your server. This may not be a problem if you have some other form of SSL in place. For more information about OpenSSL, see %s.',
506
- '<a href="http://www.php.net/manual/en/book.openssl.php" target="_blank">http://www.php.net/manual/en/book.openssl.php</a>'
507
- );
508
- }
509
-
510
- return $errors;
511
- }
512
-
513
- /**
514
- * Is region filter all mod
515
- *
516
- * @return bool
517
- */
518
- protected function _isRegionFilterAll()
519
- {
520
- return (int)$this->_getDataHelper()->getRegionFilterModByCurrentScope()
521
- === OnePica_AvaTax_Model_Config::REGIONFILTER_ALL;
522
- }
523
-
524
- /**
525
- * Can not be address validated
526
- *
527
- * @return array
528
- */
529
- protected function _canNotBeAddressValidated()
530
- {
531
- return (bool)array_diff(
532
- $this->_getDataHelper()->getTaxableCountryByCurrentScope(),
533
- $this->_getDataHelper()->getAddressValidationCountries()
534
- );
535
- }
536
-
537
- /**
538
- * Get data helper
539
- *
540
- * @return OnePica_AvaTax_Helper_Data
541
- */
542
- protected function _getDataHelper()
543
- {
544
- return Mage::helper('avatax');
545
- }
546
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/OnePica/AvaTax/Model/Observer/Abstract.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Abstract Avatax Observer Model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ abstract class OnePica_AvaTax_Model_Observer_Abstract extends Mage_Core_Model_Abstract
26
+ {
27
+ /**
28
+ * Get adminhtml model session
29
+ *
30
+ * @return \Mage_Adminhtml_Model_Session
31
+ */
32
+ protected function _getAdminhtmlSession()
33
+ {
34
+ return Mage::getSingleton('adminhtml/session');
35
+ }
36
+
37
+ /**
38
+ * Get data helper
39
+ *
40
+ * @return OnePica_AvaTax_Helper_Data
41
+ */
42
+ protected function _getDataHelper()
43
+ {
44
+ return Mage::helper('avatax');
45
+ }
46
+
47
+ /**
48
+ * Get error helper
49
+ *
50
+ * @return OnePica_AvaTax_Helper_Errors
51
+ */
52
+ protected function _getErrorsHelper()
53
+ {
54
+ return Mage::helper('avatax/errors');
55
+ }
56
+
57
+ /**
58
+ * Get quote
59
+ *
60
+ * @return Mage_Sales_Model_Quote
61
+ */
62
+ protected function _getQuote()
63
+ {
64
+ return Mage::getSingleton('checkout/cart')->getQuote();
65
+ }
66
+
67
+ /**
68
+ * Add error message if tax estimation has problems
69
+ *
70
+ * @return $this
71
+ */
72
+ protected function _handleTaxEstimation()
73
+ {
74
+ $quote = $this->_getQuote();
75
+ $quote->collectTotals();
76
+ $this->_addErrorMessage($quote);
77
+
78
+ return $this;
79
+ }
80
+
81
+ /**
82
+ * Add error message if estimation has error
83
+ *
84
+ * @param Mage_Sales_Model_Quote $quote
85
+ * @return $this
86
+ */
87
+ protected function _addErrorMessage($quote)
88
+ {
89
+ if ($quote->getData('estimate_tax_error')) {
90
+ $this->_getErrorsHelper()->addErrorMessage($quote->getStoreId());
91
+ }
92
+
93
+ return $this;
94
+ }
95
+
96
+ /**
97
+ * Stop order creation if tax estimation has problems
98
+ *
99
+ * @param Mage_Sales_Model_Quote $quote
100
+ * @return $this
101
+ * @throws OnePica_AvaTax_Exception
102
+ */
103
+ protected function _handleTaxEstimationOnOrderPlace($quote)
104
+ {
105
+ /** @var OnePica_AvaTax_Helper_Errors $helper */
106
+ $helper = $this->_getErrorsHelper();
107
+ $helper->removeErrorMessage();
108
+ if ($helper->fullStopOnError($quote)) {
109
+ throw new OnePica_AvaTax_Exception($helper->getErrorMessage());
110
+ }
111
+ return $this;
112
+ }
113
+
114
+ /**
115
+ * Delete validation notices
116
+ *
117
+ * @return $this
118
+ */
119
+ protected function _deleteValidateNotices()
120
+ {
121
+ /** @var Mage_Checkout_Model_Session $session */
122
+ $session = Mage::getSingleton('core/session');
123
+ $messages = $session->getMessages();
124
+ $messages->deleteMessageByIdentifier(OnePica_AvaTax_Helper_Errors::VALIDATION_NOTICE_IDENTIFIER);
125
+ return $this;
126
+ }
127
+ }
app/code/community/OnePica/AvaTax/Model/Observer/AdminSystemConfigChangedSectionTax.php ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer AdminSystemConfigChangedSectionTax
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_AdminSystemConfigChangedSectionTax extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Test for required values when admin config setting related to the this extension are changed
29
+ *
30
+ * @param Varien_Event_Observer $observer
31
+ * @return bool
32
+ */
33
+ public function execute(Varien_Event_Observer $observer)
34
+ {
35
+ Mage::app()->cleanCache('block_html');
36
+ $storeId = $observer->getEvent()->getStore();
37
+ $this->_addErrorsToSession($storeId);
38
+ $this->_addWarningsToSession($storeId);
39
+ }
40
+
41
+ /**
42
+ * Add error messages to session
43
+ *
44
+ * @param int $storeId
45
+ * @return $this
46
+ */
47
+ protected function _addErrorsToSession($storeId)
48
+ {
49
+ $session = $this->_getAdminhtmlSession();
50
+ $errors = $this->_prepareErrors($storeId);
51
+ if (count($errors) == 1) {
52
+ $session->addError(implode('', $errors));
53
+ } elseif (count($errors)) {
54
+ $session->addError(
55
+ Mage::helper('avatax')->__('Please fix the following issues:') . '<br /> - '
56
+ . implode('<br /> - ', $errors)
57
+ );
58
+ }
59
+
60
+ return $this;
61
+ }
62
+
63
+ /**
64
+ * Add warning messages to session
65
+ *
66
+ * @param int $storeId
67
+ * @return $this
68
+ */
69
+ protected function _addWarningsToSession($storeId)
70
+ {
71
+ $session = $this->_getAdminhtmlSession();
72
+ $warnings = $this->_prepareWarnings($storeId);
73
+ if (count($warnings) == 1) {
74
+ $session->addWarning(implode('', $warnings));
75
+ } elseif (count($warnings)) {
76
+ $session->addWarning(
77
+ Mage::helper('avatax')->__('Please be aware of the following warnings:')
78
+ . '<br /> - '
79
+ . implode('<br /> - ', $warnings)
80
+ );
81
+ }
82
+
83
+ return $this;
84
+ }
85
+
86
+ /**
87
+ * Prepare errors array
88
+ *
89
+ * @param int $storeId
90
+ * @return array
91
+ */
92
+ protected function _prepareErrors($storeId)
93
+ {
94
+ $errors = array();
95
+ $errors = array_merge(
96
+ $errors,
97
+ $this->_sendPing($storeId),
98
+ $this->_checkConnectionFields($storeId),
99
+ $this->_checkSkuFields($storeId),
100
+ $this->_checkSoapSupport(),
101
+ $this->_checkSslSupport()
102
+ );
103
+
104
+ return $errors;
105
+ }
106
+
107
+ /**
108
+ * Prepare warnings array
109
+ *
110
+ * @param int $storeId
111
+ * @return array
112
+ */
113
+ protected function _prepareWarnings($storeId)
114
+ {
115
+ $warnings = array();
116
+
117
+ if (strpos($this->_getConfigHelper()->getServiceUrl($storeId), 'development.avalara.net') !== false) {
118
+ $warnings[] = Mage::helper('avatax')->__(
119
+ 'You are using the AvaTax development connection URL. If you are receiving errors about authentication, please ensure that you have a development account.'
120
+ );
121
+ }
122
+
123
+ if ($this->_getConfigHelper()->getStatusServiceAction($storeId)
124
+ == OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_DISABLE
125
+ ) {
126
+ $warnings[] = Mage::helper('avatax')->__('All AvaTax services are disabled');
127
+ }
128
+
129
+ if ($this->_getConfigHelper()->getStatusServiceAction($storeId)
130
+ == OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC
131
+ ) {
132
+ $warnings[] = Mage::helper('avatax')->__('Orders will not be sent to the AvaTax system');
133
+ }
134
+
135
+ if ($this->_getDataHelper()->isAvatax() &&
136
+ ($this->_getConfigHelper()->getStatusServiceAction($storeId)
137
+ == OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC_SUBMIT)
138
+ ) {
139
+ $warnings[] = Mage::helper('avatax')->__('Orders will be sent but never committed to the AvaTax system');
140
+ }
141
+
142
+ if (!Mage::getResourceModel('cron/schedule_collection')->count()) {
143
+ $warnings[] = Mage::helper('avatax')->__(
144
+ 'It appears that Magento\'s cron scheduler is not running. For more information, see %s.',
145
+ '<a href="http://www.magentocommerce.com/wiki/how_to_setup_a_cron_job" target="_black">How to Set Up a Cron Job</a>'
146
+ );
147
+ }
148
+
149
+ if ($this->_isRegionFilterAll() && $this->_canNotBeAddressValidated()) {
150
+ $warnings[] = Mage::helper('avatax')
151
+ ->__('Please be aware that address validation will not work for addresses outside United States and Canada');
152
+ }
153
+
154
+ return $warnings;
155
+ }
156
+
157
+ /**
158
+ * Send ping request
159
+ *
160
+ * @param int $storeId
161
+ * @return array
162
+ */
163
+ protected function _sendPing($storeId)
164
+ {
165
+ $errors = array();
166
+ $ping = Mage::getSingleton('avatax/action_ping')->ping($storeId);
167
+ if ($ping !== true) {
168
+ $errors[] = $ping;
169
+ }
170
+
171
+ return $errors;
172
+ }
173
+
174
+ /**
175
+ * Check connection fields
176
+ *
177
+ * @param int $storeId
178
+ * @return array
179
+ */
180
+ protected function _checkConnectionFields($storeId)
181
+ {
182
+ $errors = array();
183
+ if (!Mage::getStoreConfig('tax/avatax/url', $storeId)) {
184
+ $errors[] = Mage::helper('avatax')->__('You must enter a connection URL');
185
+ }
186
+ if (!Mage::getStoreConfig('tax/avatax/account', $storeId)) {
187
+ $errors[] = Mage::helper('avatax')->__('You must enter an account number');
188
+ }
189
+ if (!Mage::getStoreConfig('tax/avatax/license', $storeId)) {
190
+ $errors[] = Mage::helper('avatax')->__('You must enter a license key');
191
+ }
192
+ if (!is_numeric(Mage::getStoreConfig('tax/avatax/log_lifetime'))) {
193
+ $errors[] = Mage::helper('avatax')->__('You must enter the number of days to keep log entries');
194
+ }
195
+ if (!Mage::getStoreConfig('tax/avatax/company_code', $storeId)) {
196
+ $errors[] = Mage::helper('avatax')->__('You must enter a company code');
197
+ }
198
+
199
+ return $errors;
200
+ }
201
+
202
+ /**
203
+ * Check Sku fields
204
+ *
205
+ * @param int $storeId
206
+ * @return array
207
+ */
208
+ protected function _checkSkuFields($storeId)
209
+ {
210
+ $errors = array();
211
+ if (!$this->_getConfigHelper()->getShippingSku($storeId)) {
212
+ $errors[] = Mage::helper('avatax')->__('You must enter a shipping sku');
213
+ }
214
+ if (!$this->_getConfigHelper()->getPositiveAdjustmentSku($storeId)) {
215
+ $errors[] = Mage::helper('avatax')->__('You must enter an adjustment refund sku');
216
+ }
217
+ if (!$this->_getConfigHelper()->getNegativeAdjustmentSku($storeId)) {
218
+ $errors[] = Mage::helper('avatax')->__('You must enter an adjustment fee sku');
219
+
220
+ return $errors;
221
+ }
222
+
223
+ return $errors;
224
+ }
225
+
226
+ /**
227
+ * Check SOAP support
228
+ *
229
+ * @return array
230
+ */
231
+ protected function _checkSoapSupport()
232
+ {
233
+ $errors = array();
234
+ if (!class_exists('SoapClient')) {
235
+ $errors[] = Mage::helper('avatax')->__(
236
+ 'The PHP class SoapClient is missing. It must be enabled to use this extension. See %s for details.',
237
+ '<a href="http://www.php.net/manual/en/book.soap.php" target="_blank">http://www.php.net/manual/en/book.soap.php</a>'
238
+ );
239
+ }
240
+
241
+ return $errors;
242
+ }
243
+
244
+ /**
245
+ * Check SSL support
246
+ *
247
+ * @return array
248
+ */
249
+ protected function _checkSslSupport()
250
+ {
251
+ $errors = array();
252
+ if (!function_exists('openssl_sign') && count($errors)) {
253
+ $key = array_search(Mage::helper('avatax')->__('SSL support is not available in this build'), $errors);
254
+ if (isset($errors[$key])) {
255
+ unset($errors[$key]);
256
+ }
257
+ $errors[] = Mage::helper('avatax')->__(
258
+ 'SSL must be enabled in PHP to use this extension. Typically, OpenSSL is used but it is not enabled on your server. This may not be a problem if you have some other form of SSL in place. For more information about OpenSSL, see %s.',
259
+ '<a href="http://www.php.net/manual/en/book.openssl.php" target="_blank">http://www.php.net/manual/en/book.openssl.php</a>'
260
+ );
261
+ }
262
+
263
+ return $errors;
264
+ }
265
+
266
+ /**
267
+ * Is region filter all mod
268
+ *
269
+ * @return bool
270
+ */
271
+ protected function _isRegionFilterAll()
272
+ {
273
+ return (int)Mage::helper('avatax/address')->getRegionFilterModByCurrentScope()
274
+ === OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_ALL;
275
+ }
276
+
277
+ /**
278
+ * Can not be address validated
279
+ *
280
+ * @return array
281
+ */
282
+ protected function _canNotBeAddressValidated()
283
+ {
284
+ return (bool)array_diff(
285
+ Mage::helper('avatax/address')->getTaxableCountryByCurrentScope(),
286
+ Mage::helper('avatax/address')->getAddressValidationCountries()
287
+ );
288
+ }
289
+
290
+ /**
291
+ * Get config helper
292
+ *
293
+ * @return OnePica_AvaTax_Helper_Config
294
+ */
295
+ protected function _getConfigHelper()
296
+ {
297
+ return Mage::helper('avatax/config');
298
+ }
299
+ }
app/code/community/OnePica/AvaTax/Model/Observer/CheckoutSubmitAllAfter.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer CheckoutSubmitAllAfter
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_CheckoutSubmitAllAfter extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Delete validation notices on successful order place on multiple checkout
29
+ *
30
+ * @param Varien_Event_Observer $observer
31
+ * @return $this
32
+ */
33
+ public function execute(Varien_Event_Observer $observer)
34
+ {
35
+ $this->_deleteValidateNotices();
36
+ return $this;
37
+ }
38
+ }
app/code/community/OnePica/AvaTax/Model/Observer/CheckoutTypeMultishippingCreateOrdersSingle.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer CheckoutTypeMultishippingCreateOrdersSingle
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_CheckoutTypeMultishippingCreateOrdersSingle
26
+ extends OnePica_AvaTax_Model_Observer_Abstract
27
+ {
28
+ /**
29
+ * Stop order creation if tax estimation has problems when multishipping
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ * @throws OnePica_AvaTax_Exception
34
+ */
35
+ public function execute(Varien_Event_Observer $observer)
36
+ {
37
+ /** @var Mage_Sales_Model_Quote_Address $address */
38
+ $address = $observer->getEvent()->getAddress();
39
+ $quote = $address->getQuote();
40
+ $this->_handleTaxEstimationOnOrderPlace($quote);
41
+ return $this;
42
+ }
43
+ }
app/code/community/OnePica/AvaTax/Model/Observer/CleanLog.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer CleanLog
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_CleanLog extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Observer to clean the log every so often so it does not get too big.
29
+ *
30
+ * @return $this
31
+ */
32
+ public function execute()
33
+ {
34
+ $days = floatval(Mage::getStoreConfig('tax/avatax/log_lifetime'));
35
+ Mage::getModel('avatax_records/log')->deleteLogsByInterval($days);
36
+ return $this;
37
+ }
38
+ }
app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPostdispatchCheckoutCartEstimatePost.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer ControllerActionPostdispatchCheckoutCartEstimatePost
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_ControllerActionPostdispatchCheckoutCartEstimatePost
26
+ extends OnePica_AvaTax_Model_Observer_Abstract
27
+ {
28
+ /**
29
+ * Add error message if tax estimation has problems when user estimates post
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ */
34
+ public function execute(Varien_Event_Observer $observer)
35
+ {
36
+ $this->_handleTaxEstimation();
37
+ return $this;
38
+ }
39
+ }
app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPostdispatchCheckoutCartEstimateUpdatePost.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer ControllerActionPostdispatchCheckoutCartEstimateUpdatePost
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_ControllerActionPostdispatchCheckoutCartEstimateUpdatePost
26
+ extends OnePica_AvaTax_Model_Observer_Abstract
27
+ {
28
+ /**
29
+ * Add error message if tax estimation has problems when user updates estimate post
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ */
34
+ public function execute(Varien_Event_Observer $observer)
35
+ {
36
+ $this->_handleTaxEstimation();
37
+ return $this;
38
+ }
39
+ }
app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPostdispatchCheckoutOnepageSaveShippingMethod.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer ControllerActionPostdispatchCheckoutOnepageSaveShippingMethod
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_ControllerActionPostdispatchCheckoutOnepageSaveShippingMethod
26
+ extends OnePica_AvaTax_Model_Observer_Abstract
27
+ {
28
+ /**
29
+ * Stop order creation if tax estimation has problems
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ */
34
+ public function execute(Varien_Event_Observer $observer) {
35
+ if ($this->_getErrorsHelper()->fullStopOnError($this->_getQuote())) {
36
+ Mage::app()
37
+ ->getResponse()
38
+ ->setBody($this->_getResponseErrorMessage());
39
+ }
40
+ return $this;
41
+ }
42
+
43
+ /**
44
+ * Get response error message
45
+ *
46
+ * @return string
47
+ */
48
+ protected function _getResponseErrorMessage()
49
+ {
50
+ return Mage::helper('core')->jsonEncode(
51
+ array(
52
+ 'error' => - 1,
53
+ 'message' => $this->_getErrorsHelper()->getErrorMessage()
54
+ )
55
+ );
56
+ }
57
+ }
app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPredispatchAdminhtmlSalesOrderCreateLoadBlock.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer ControllerActionPredispatchAdminhtmlSalesOrderCreateLoadBlock
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_ControllerActionPredispatchAdminhtmlSalesOrderCreateLoadBlock
26
+ extends OnePica_AvaTax_Model_Observer_Abstract
27
+ {
28
+ /**
29
+ * Add error message if tax estimation has problems when creating order in admin
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ */
34
+ public function execute(Varien_Event_Observer $observer)
35
+ {
36
+ $adminQuote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
37
+ $this->_addErrorMessage($adminQuote);
38
+
39
+ return $this;
40
+ }
41
+ }
app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPredispatchCheckoutCartEstimatePost.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer ControllerActionPredispatchCheckoutCartEstimatePost
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_ControllerActionPredispatchCheckoutCartEstimatePost
26
+ extends OnePica_AvaTax_Model_Observer_Abstract
27
+ {
28
+ /**
29
+ * Set post type for checkout session when 'controller_action_predispatch_checkout_cart_estimatePost' event
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ */
34
+ public function execute(Varien_Event_Observer $observer)
35
+ {
36
+ $session = Mage::getSingleton('checkout/session');
37
+ $session->setPostType('estimate');
38
+ return $this;
39
+ }
40
+ }
app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPredispatchCheckoutCartIndex.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer ControllerActionPredispatchCheckoutCartIndex
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_ControllerActionPredispatchCheckoutCartIndex
26
+ extends OnePica_AvaTax_Model_Observer_Abstract
27
+ {
28
+ /**
29
+ * Add error message if tax estimation has problems when user located at checkout/cart/index
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ */
34
+ public function execute(Varien_Event_Observer $observer)
35
+ {
36
+ $this->_addErrorMessage($this->_getQuote());
37
+ return $this;
38
+ }
39
+ }
app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPredispatchCheckoutMultishippingIndex.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer ControllerActionPredispatchCheckoutMultishippingIndex
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_ControllerActionPredispatchCheckoutMultishippingIndex
26
+ extends OnePica_AvaTax_Model_Observer_Abstract
27
+ {
28
+ /**
29
+ * Set post type for checkout session when 'controller_action_predispatch_checkout_multishipping_index' event
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ */
34
+ public function execute(Varien_Event_Observer $observer)
35
+ {
36
+ $session = Mage::getSingleton('checkout/session');
37
+ $session->setPostType('multishipping');
38
+ return $this;
39
+ }
40
+ }
app/code/community/OnePica/AvaTax/Model/Observer/ControllerActionPredispatchCheckoutOnepageIndex.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer ControllerActionPredispatchCheckoutOnepageIndex
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_ControllerActionPredispatchCheckoutOnepageIndex
26
+ extends OnePica_AvaTax_Model_Observer_Abstract
27
+ {
28
+ /**
29
+ * Set post type for checkout session when 'controller_action_predispatch_checkout_onepage_index' event
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ */
34
+ public function execute(Varien_Event_Observer $observer)
35
+ {
36
+ $session = Mage::getSingleton('checkout/session');
37
+ $session->setPostType('onepage');
38
+ return $this;
39
+ }
40
+ }
app/code/community/OnePica/AvaTax/Model/Observer/LoadAvaTaxExternalLib.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer LoadAvaTaxExternalLib
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_LoadAvaTaxExternalLib extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Avalara lib classes
29
+ *
30
+ * @var array
31
+ */
32
+ protected static $_classes = array(
33
+ 'TaxRequest',
34
+ 'PostTaxRequest',
35
+ 'PostTaxResult',
36
+ 'CommitTaxRequest',
37
+ 'CommitTaxResult',
38
+ 'CancelTaxRequest',
39
+ 'CancelTaxResult',
40
+ 'Enum',
41
+ 'CancelCode',
42
+ 'ATConfig',
43
+ 'ATObject',
44
+ 'DynamicSoapClient',
45
+ 'AvalaraSoapClient',
46
+ 'AddressServiceSoap',
47
+ 'Address',
48
+ 'Enum',
49
+ 'TextCase',
50
+ 'Message',
51
+ 'SeverityLevel',
52
+ 'ValidateRequest',
53
+ 'ValidateResult',
54
+ 'ValidAddress',
55
+ 'TaxServiceSoap',
56
+ 'GetTaxRequest',
57
+ 'DocumentType',
58
+ 'DetailLevel',
59
+ 'Line',
60
+ 'ServiceMode',
61
+ 'GetTaxResult',
62
+ 'TaxLine',
63
+ 'TaxDetail',
64
+ 'PingResult',
65
+ 'TaxOverride',
66
+ 'TaxOverrideType'
67
+ );
68
+
69
+ /**
70
+ * Load AvaTax External Lib
71
+ *
72
+ * @return $this
73
+ */
74
+ public function loadAvaTaxExternalLib()
75
+ {
76
+ spl_autoload_register(array($this, 'loadLib'), true, true);
77
+ return $this;
78
+ }
79
+
80
+ /**
81
+ * This function can autoloads classes to work with Avalara API
82
+ *
83
+ * @param string $class
84
+ */
85
+ public static function loadLib($class)
86
+ {
87
+ if (in_array($class, self::$_classes)) {
88
+ /** @var OnePica_AvaTax_Helper_Data $helper */
89
+ $helper = Mage::helper('avatax/lib');
90
+ $helper->loadFunctions();
91
+ $helper->loadClass($class);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * This an observer function for the event 'controller_front_init_before' and 'default'
97
+ * It prepends our autoloader, so we can load the extra libraries.
98
+ *
99
+ * @param Varien_Event_Observer $observer
100
+ * @return $this
101
+ */
102
+ public function execute(Varien_Event_Observer $observer)
103
+ {
104
+ $this->loadAvaTaxExternalLib();
105
+ return $this;
106
+ }
107
+ }
app/code/community/OnePica/AvaTax/Model/Observer/MultishippingSetShippingItems.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer MultishippingSetShippingItems
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_MultishippingSetShippingItems extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Validate addresses when multishipping checkout on set shipping items
29
+ *
30
+ * @param Varien_Event_Observer $observer
31
+ * @return $this
32
+ * @throws OnePica_AvaTax_Exception
33
+ */
34
+ public function execute(Varien_Event_Observer $observer)
35
+ {
36
+ /* @var $quote Mage_Sales_Model_Quote */
37
+ $quote = $observer->getEvent()->getQuote();
38
+ $storeId = $quote->getStoreId();
39
+
40
+ $errors = array();
41
+ $normalized = false;
42
+
43
+ $addresses = $quote->getAllShippingAddresses();
44
+ $message = Mage::getStoreConfig('tax/avatax/validate_address_message', $storeId);
45
+ foreach ($addresses as $address) {
46
+ /* @var $address OnePica_AvaTax_Model_Sales_Quote_Address */
47
+ if ($address->validate() !== true) {
48
+ $errors[] = sprintf($message, $address->format('oneline'));
49
+ }
50
+ if ($address->getAddressNormalized()) {
51
+ $normalized = true;
52
+ }
53
+ }
54
+
55
+ $session = Mage::getSingleton('checkout/session');
56
+ if ($normalized) {
57
+ $session->addNotice(Mage::getStoreConfig('tax/avatax/multiaddress_normalize_message', $storeId));
58
+ }
59
+
60
+ if (!empty($errors)) {
61
+ throw new OnePica_AvaTax_Exception(implode('<br />', $errors));
62
+ }
63
+ return $this;
64
+ }
65
+ }
app/code/community/OnePica/AvaTax/Model/Observer/ProcessQueue.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer ProcessQueue
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_ProcessQueue extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Observer push data to Avalara
29
+ *
30
+ * @return $this;
31
+ */
32
+ public function execute()
33
+ {
34
+ Mage::getModel('avatax_records/queue_process')->run();
35
+ return $this;
36
+ }
37
+ }
app/code/community/OnePica/AvaTax/Model/Observer/SalesModelServiceQuoteSubmitAfter.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer SalesModelServiceQuoteSubmitAfter
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_SalesModelServiceQuoteSubmitAfter extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Delete validation notices on successful order place
29
+ *
30
+ * @param Varien_Event_Observer $observer
31
+ * @return $this
32
+ */
33
+ public function execute(Varien_Event_Observer $observer)
34
+ {
35
+ $this->_deleteValidateNotices();
36
+ return $this;
37
+ }
38
+ }
app/code/community/OnePica/AvaTax/Model/Observer/SalesModelServiceQuoteSubmitBefore.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer SalesModelServiceQuoteSubmitBefore
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_SalesModelServiceQuoteSubmitBefore extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Stop order creation if tax estimation has problems
29
+ *
30
+ * @param Varien_Event_Observer $observer
31
+ * @return $this
32
+ * @throws OnePica_AvaTax_Exception
33
+ */
34
+ public function execute(Varien_Event_Observer $observer)
35
+ {
36
+ /** @var Mage_Sales_Model_Quote $quote */
37
+ $quote = $observer->getEvent()->getQuote();
38
+ $this->_handleTaxEstimationOnOrderPlace($quote);
39
+ return $this;
40
+ }
41
+ }
app/code/community/OnePica/AvaTax/Model/Observer/SalesOrderCreditmemoRefund.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Class OnePica_AvaTax_Model_Observer_SalesOrderCreditmemoRefund
20
+ */
21
+ class OnePica_AvaTax_Model_Observer_SalesOrderCreditmemoRefund extends OnePica_AvaTax_Model_Observer_Abstract
22
+ {
23
+ /**
24
+ * Set flag, which will be checked in SalesOrderCreditmemoSaveAfter observer
25
+ *
26
+ * @param \Varien_Event_Observer $observer
27
+ * @return $this
28
+ */
29
+ public function execute(Varien_Event_Observer $observer)
30
+ {
31
+ /* @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
32
+ $creditmemo = $observer->getEvent()->getCreditmemo();
33
+ $creditmemo->setData('avatax_can_add_to_queue', true);
34
+
35
+ return $this;
36
+ }
37
+ }
app/code/community/OnePica/AvaTax/Model/Observer/SalesOrderCreditmemoSaveAfter.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer SalesOrderCreditmemoSaveAfter
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_SalesOrderCreditmemoSaveAfter extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Create a return invoice record in Avalara
29
+ *
30
+ * @param Varien_Event_Observer $observer
31
+ * @return $this
32
+ */
33
+ public function execute(Varien_Event_Observer $observer)
34
+ {
35
+ /* @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
36
+ $creditmemo = $observer->getEvent()->getCreditmemo();
37
+ if ($creditmemo->getData('avatax_can_add_to_queue')
38
+ && (int)$creditmemo->getState() === Mage_Sales_Model_Order_Creditmemo::STATE_REFUNDED
39
+ && Mage::helper('avatax/address')->isObjectActionable($creditmemo)
40
+ ) {
41
+ Mage::getModel('avatax_records/queue')
42
+ ->setEntity($creditmemo)
43
+ ->setType(OnePica_AvaTax_Model_Records_Queue::QUEUE_TYPE_CREDITMEMEO)
44
+ ->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_PENDING)
45
+ ->save();
46
+ }
47
+ return $this;
48
+ }
49
+ }
app/code/community/OnePica/AvaTax/Model/Observer/SalesOrderInvoicePay.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Class OnePica_AvaTax_Model_Observer_SalesOrderInvoicePay
20
+ */
21
+ class OnePica_AvaTax_Model_Observer_SalesOrderInvoicePay extends OnePica_AvaTax_Model_Observer_Abstract
22
+ {
23
+ /**
24
+ * Set flag, which will be checked in SalesOrderInvoiceSaveAfter observer
25
+ *
26
+ * @param \Varien_Event_Observer $observer
27
+ * @return $this
28
+ */
29
+ public function execute(Varien_Event_Observer $observer)
30
+ {
31
+ /** @var Mage_Sales_Model_Order_Invoice $invoice */
32
+ $invoice = $observer->getEvent()->getInvoice();
33
+ $invoice->setData('avatax_can_add_to_queue', true);
34
+
35
+ return $this;
36
+ }
37
+ }
app/code/community/OnePica/AvaTax/Model/Observer/SalesOrderInvoiceSaveAfter.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer SalesOrderInvoiceSaveAfter
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_SalesOrderInvoiceSaveAfter extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Create a sales invoice record in Avalara
29
+ *
30
+ * @param Varien_Event_Observer $observer
31
+ * @return $this
32
+ */
33
+ public function execute(Varien_Event_Observer $observer)
34
+ {
35
+ /** @var Mage_Sales_Model_Order_Invoice $invoice */
36
+ $invoice = $observer->getEvent()->getInvoice();
37
+
38
+ if ($invoice->getData('avatax_can_add_to_queue')
39
+ && (int)$invoice->getState() === Mage_Sales_Model_Order_Invoice::STATE_PAID
40
+ && Mage::helper('avatax/address')->isObjectActionable($invoice)
41
+ ) {
42
+ Mage::getModel('avatax_records/queue')
43
+ ->setEntity($invoice)
44
+ ->setType(OnePica_AvaTax_Model_Records_Queue::QUEUE_TYPE_INVOICE)
45
+ ->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_PENDING)
46
+ ->save();
47
+ }
48
+
49
+ return $this;
50
+ }
51
+ }
app/code/community/OnePica/AvaTax/Model/Observer/SalesQuoteCollectTotalsBefore.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax Observer SalesQuoteCollectTotalsBefore
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Observer_SalesQuoteCollectTotalsBefore extends OnePica_AvaTax_Model_Observer_Abstract
26
+ {
27
+ /**
28
+ * Sets the collectTotals tax node based on the extensions enabled/disabled status
29
+ *
30
+ * @param Varien_Event_Observer $observer
31
+ * @return $this
32
+ */
33
+ public function execute(Varien_Event_Observer $observer)
34
+ {
35
+ $storeId = $observer->getEvent()->getQuote()->getStoreId();
36
+ if (Mage::getStoreConfig('tax/avatax/action', $storeId) != OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_DISABLE) {
37
+ Mage::getConfig()->setNode('global/sales/quote/totals/tax/class', 'avatax/sales_quote_address_total_tax');
38
+ }
39
+ return $this;
40
+ }
41
+ }
app/code/community/OnePica/AvaTax/Model/Records/Log.php CHANGED
@@ -18,6 +18,11 @@
18
  /**
19
  * Log model
20
  *
 
 
 
 
 
21
  * @category OnePica
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
@@ -32,7 +37,7 @@ class OnePica_AvaTax_Model_Records_Log extends Mage_Core_Model_Abstract
32
  /**
33
  * Error log level
34
  */
35
- const LOG_LEVEL_ERROR = 'Error';
36
 
37
  /**
38
  * Internal constructor
@@ -53,12 +58,13 @@ class OnePica_AvaTax_Model_Records_Log extends Mage_Core_Model_Abstract
53
  {
54
  if ($value) {
55
  $value = str_replace(
56
- Mage::getStoreConfig('tax/avatax/license'),
57
  '[MASKED::LICENSE_KEY]',
58
  print_r($value, true)
59
  );
60
  }
61
  $this->setData('additional', $value);
 
62
  return $this;
63
  }
64
 
@@ -75,6 +81,7 @@ class OnePica_AvaTax_Model_Records_Log extends Mage_Core_Model_Abstract
75
  foreach ($types as $value) {
76
  $result[$value] = $value;
77
  }
 
78
  return $result;
79
  }
80
 
@@ -87,7 +94,7 @@ class OnePica_AvaTax_Model_Records_Log extends Mage_Core_Model_Abstract
87
  {
88
  return array(
89
  self::LOG_LEVEL_SUCCESS => self::LOG_LEVEL_SUCCESS,
90
- self::LOG_LEVEL_ERROR => self::LOG_LEVEL_ERROR
91
  );
92
  }
93
 
@@ -101,4 +108,14 @@ class OnePica_AvaTax_Model_Records_Log extends Mage_Core_Model_Abstract
101
  {
102
  return $this->getResource()->deleteLogsByInterval($days);
103
  }
 
 
 
 
 
 
 
 
 
 
104
  }
18
  /**
19
  * Log model
20
  *
21
+ * @method int getStoreId()
22
+ * @method $this setStoreId(int $storeId)
23
+ * @method OnePica_AvaTax_Model_Records_Mysql4_Log getResource()
24
+ * @method OnePica_AvaTax_Model_Records_Mysql4_Log_Collection getCollection()
25
+ *
26
  * @category OnePica
27
  * @package OnePica_AvaTax
28
  * @author OnePica Codemaster <codemaster@onepica.com>
37
  /**
38
  * Error log level
39
  */
40
+ const LOG_LEVEL_ERROR = 'Error';
41
 
42
  /**
43
  * Internal constructor
58
  {
59
  if ($value) {
60
  $value = str_replace(
61
+ $this->_getConfigHelper()->getServiceKey($this->getStoreId()),
62
  '[MASKED::LICENSE_KEY]',
63
  print_r($value, true)
64
  );
65
  }
66
  $this->setData('additional', $value);
67
+
68
  return $this;
69
  }
70
 
81
  foreach ($types as $value) {
82
  $result[$value] = $value;
83
  }
84
+
85
  return $result;
86
  }
87
 
94
  {
95
  return array(
96
  self::LOG_LEVEL_SUCCESS => self::LOG_LEVEL_SUCCESS,
97
+ self::LOG_LEVEL_ERROR => self::LOG_LEVEL_ERROR
98
  );
99
  }
100
 
108
  {
109
  return $this->getResource()->deleteLogsByInterval($days);
110
  }
111
+
112
+ /**
113
+ * Get config helper
114
+ *
115
+ * @return OnePica_AvaTax_Helper_Config
116
+ */
117
+ protected function _getConfigHelper()
118
+ {
119
+ return Mage::helper('avatax/config');
120
+ }
121
  }
app/code/community/OnePica/AvaTax/Model/Records/Mysql4/Queue.php CHANGED
@@ -94,11 +94,11 @@ class OnePica_AvaTax_Model_Records_Mysql4_Queue extends Mage_Core_Model_Mysql4_A
94
  $logStatus = Mage::getStoreConfig('tax/avatax/log_status', $storeId);
95
  if ($logStatus) {
96
  $logTypes = Mage::helper('avatax')->getLogType($storeId);
97
- if (in_array(OnePica_AvaTax_Model_Source_Logtype::QUEUE, $logTypes)) {
98
  Mage::getModel('avatax_records/log')
99
  ->setStoreId($object->getStoreId())
100
  ->setLevel(OnePica_AvaTax_Model_Records_Log::LOG_LEVEL_SUCCESS)
101
- ->setType(OnePica_AvaTax_Model_Source_Logtype::QUEUE)
102
  ->setRequest(print_r($object->getData(), true))
103
  ->setResult($result)
104
  ->save();
94
  $logStatus = Mage::getStoreConfig('tax/avatax/log_status', $storeId);
95
  if ($logStatus) {
96
  $logTypes = Mage::helper('avatax')->getLogType($storeId);
97
+ if (in_array(OnePica_AvaTax_Model_Source_Avatax_Logtype::QUEUE, $logTypes)) {
98
  Mage::getModel('avatax_records/log')
99
  ->setStoreId($object->getStoreId())
100
  ->setLevel(OnePica_AvaTax_Model_Records_Log::LOG_LEVEL_SUCCESS)
101
+ ->setType(OnePica_AvaTax_Model_Source_Avatax_Logtype::QUEUE)
102
  ->setRequest(print_r($object->getData(), true))
103
  ->setResult($result)
104
  ->save();
app/code/community/OnePica/AvaTax/Model/Records/Queue.php CHANGED
@@ -20,6 +20,19 @@
20
  /**
21
  * Queue model
22
  *
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  * @category OnePica
24
  * @package OnePica_AvaTax
25
  * @author OnePica Codemaster <codemaster@onepica.com>
@@ -81,6 +94,7 @@ class OnePica_AvaTax_Model_Records_Queue extends Mage_Core_Model_Abstract
81
  $this->setEntityId($object->getId());
82
  $this->setEntityIncrementId($object->getIncrementId());
83
  $this->setStoreId($object->getStoreId());
 
84
  return $this;
85
  }
86
 
@@ -92,7 +106,7 @@ class OnePica_AvaTax_Model_Records_Queue extends Mage_Core_Model_Abstract
92
  public function getTypeOptions()
93
  {
94
  return array(
95
- self::QUEUE_TYPE_INVOICE => self::QUEUE_TYPE_INVOICE,
96
  self::QUEUE_TYPE_CREDITMEMEO => self::QUEUE_TYPE_CREDITMEMEO
97
  );
98
  }
@@ -105,10 +119,10 @@ class OnePica_AvaTax_Model_Records_Queue extends Mage_Core_Model_Abstract
105
  public function getStatusOptions()
106
  {
107
  return array(
108
- self::QUEUE_STATUS_PENDING => self::QUEUE_STATUS_PENDING,
109
- self::QUEUE_STATUS_RETRY => self::QUEUE_STATUS_RETRY,
110
- self::QUEUE_STATUS_FAILED => self::QUEUE_STATUS_FAILED,
111
- self::QUEUE_STATUS_COMPLETE => self::QUEUE_STATUS_COMPLETE,
112
  self::QUEUE_STATUS_UNBALANCED => self::QUEUE_STATUS_UNBALANCED
113
  );
114
  }
20
  /**
21
  * Queue model
22
  *
23
+ * @method int getAttempt()
24
+ * @method $this setAttempt(int $attempt)
25
+ * @method string getStatus()
26
+ * @method $this setStatus(string $status)
27
+ * @method string getMessage()
28
+ * @method $this setMessage(string $message)
29
+ * @method $this setEntityId(int $entityId)
30
+ * @method $this setEntityIncrementId(int $entityIncrementId)
31
+ * @method int getEntityIncrementId()
32
+ * @method $this setStoreId(int $storeId)
33
+ * @method int getStoreId()
34
+ * @method OnePica_AvaTax_Model_Records_Mysql4_Queue _getResource()
35
+ *
36
  * @category OnePica
37
  * @package OnePica_AvaTax
38
  * @author OnePica Codemaster <codemaster@onepica.com>
94
  $this->setEntityId($object->getId());
95
  $this->setEntityIncrementId($object->getIncrementId());
96
  $this->setStoreId($object->getStoreId());
97
+
98
  return $this;
99
  }
100
 
106
  public function getTypeOptions()
107
  {
108
  return array(
109
+ self::QUEUE_TYPE_INVOICE => self::QUEUE_TYPE_INVOICE,
110
  self::QUEUE_TYPE_CREDITMEMEO => self::QUEUE_TYPE_CREDITMEMEO
111
  );
112
  }
119
  public function getStatusOptions()
120
  {
121
  return array(
122
+ self::QUEUE_STATUS_PENDING => self::QUEUE_STATUS_PENDING,
123
+ self::QUEUE_STATUS_RETRY => self::QUEUE_STATUS_RETRY,
124
+ self::QUEUE_STATUS_FAILED => self::QUEUE_STATUS_FAILED,
125
+ self::QUEUE_STATUS_COMPLETE => self::QUEUE_STATUS_COMPLETE,
126
  self::QUEUE_STATUS_UNBALANCED => self::QUEUE_STATUS_UNBALANCED
127
  );
128
  }
app/code/community/OnePica/AvaTax/Model/Records/Queue/Process.php CHANGED
@@ -22,7 +22,7 @@
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
- class OnePica_AvaTax_Model_Records_Queue_Process extends OnePica_AvaTax_Model_Abstract
26
  {
27
  /**
28
  * Remove the Failed process
@@ -64,6 +64,7 @@ class OnePica_AvaTax_Model_Records_Queue_Process extends OnePica_AvaTax_Model_Ab
64
  ->_cleanUnbalanced()
65
  ->_parseInvoices()
66
  ->_parseCreditMemos();
 
67
  return $this;
68
  }
69
 
@@ -153,22 +154,27 @@ class OnePica_AvaTax_Model_Records_Queue_Process extends OnePica_AvaTax_Model_Ab
153
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_FAILED))
154
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_COMPLETE))
155
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_UNBALANCED));
 
 
 
 
156
  foreach ($queue as $item) {
157
  $item->setAttempt($item->getAttempt() + 1);
158
  try {
 
159
  $invoice = Mage::getModel('sales/order_invoice')->load($item->getEntityId());
160
  if ($invoice->getId()) {
161
- Mage::getModel('avatax/avatax_invoice')->invoice($invoice, $item);
162
  }
163
  $item->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_COMPLETE)->setMessage(null)->save();
164
- } catch (OnePica_AvaTax_Model_Avatax_Exception_Unbalanced $e) {
165
  $item->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_UNBALANCED)
166
  ->setMessage($e->getMessage())
167
  ->save();
168
  } catch (Exception $e) {
169
- $status = ($item->getAttempt() >= OnePica_AvaTax_Model_Config::QUEUE_ATTEMPT_MAX) ?
170
- OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_FAILED :
171
- OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_RETRY;
172
  $item->setStatus($status)
173
  ->setMessage($e->getMessage())
174
  ->save();
@@ -191,24 +197,29 @@ class OnePica_AvaTax_Model_Records_Queue_Process extends OnePica_AvaTax_Model_Ab
191
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_FAILED))
192
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_COMPLETE))
193
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_UNBALANCED));
 
 
 
 
194
  foreach ($queue as $item) {
195
  $item->setAttempt($item->getAttempt() + 1);
196
  try {
 
197
  $creditmemo = Mage::getModel('sales/order_creditmemo')->load($item->getEntityId());
198
  if ($creditmemo->getId()) {
199
- Mage::getModel('avatax/avatax_invoice')->creditmemo($creditmemo, $item);
200
  }
201
  $item->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_COMPLETE)
202
  ->setMessage(null)
203
  ->save();
204
- } catch (OnePica_AvaTax_Model_Avatax_Exception_Unbalanced $e) {
205
  $item->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_UNBALANCED)
206
  ->setMessage($e->getMessage())
207
  ->save();
208
  } catch (Exception $e) {
209
- $status = ($item->getAttempt() >= OnePica_AvaTax_Model_Config::QUEUE_ATTEMPT_MAX) ?
210
- OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_FAILED :
211
- OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_RETRY;
212
  $item->setStatus($status)
213
  ->setMessage($e->getMessage())
214
  ->save();
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
+ class OnePica_AvaTax_Model_Records_Queue_Process
26
  {
27
  /**
28
  * Remove the Failed process
64
  ->_cleanUnbalanced()
65
  ->_parseInvoices()
66
  ->_parseCreditMemos();
67
+
68
  return $this;
69
  }
70
 
154
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_FAILED))
155
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_COMPLETE))
156
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_UNBALANCED));
157
+
158
+ /** @var OnePica_AvaTax_Model_Action_Invoice $invoiceAction */
159
+ $invoiceAction = Mage::getModel('avatax/action_invoice');
160
+ /** @var OnePica_AvaTax_Model_Records_Queue $item */
161
  foreach ($queue as $item) {
162
  $item->setAttempt($item->getAttempt() + 1);
163
  try {
164
+ /** @var Mage_Sales_Model_Order_Invoice $invoice */
165
  $invoice = Mage::getModel('sales/order_invoice')->load($item->getEntityId());
166
  if ($invoice->getId()) {
167
+ $invoiceAction->process($invoice, $item);
168
  }
169
  $item->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_COMPLETE)->setMessage(null)->save();
170
+ } catch (OnePica_AvaTax_Model_Service_Exception_Unbalanced $e) {
171
  $item->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_UNBALANCED)
172
  ->setMessage($e->getMessage())
173
  ->save();
174
  } catch (Exception $e) {
175
+ $status = ($item->getAttempt() >= OnePica_AvaTax_Model_Service_Abstract_Config::QUEUE_ATTEMPT_MAX)
176
+ ? OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_FAILED
177
+ : OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_RETRY;
178
  $item->setStatus($status)
179
  ->setMessage($e->getMessage())
180
  ->save();
197
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_FAILED))
198
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_COMPLETE))
199
  ->addFieldToFilter('status', array('neq' => OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_UNBALANCED));
200
+
201
+ /** @var OnePica_AvaTax_Model_Action_Creditmemo $creditmemoAction */
202
+ $creditmemoAction = Mage::getModel('avatax/action_creditmemo');
203
+ /** @var OnePica_AvaTax_Model_Records_Queue $item */
204
  foreach ($queue as $item) {
205
  $item->setAttempt($item->getAttempt() + 1);
206
  try {
207
+ /** @var Mage_Sales_Model_Order_Creditmemo $creditmemo */
208
  $creditmemo = Mage::getModel('sales/order_creditmemo')->load($item->getEntityId());
209
  if ($creditmemo->getId()) {
210
+ $creditmemoAction->process($creditmemo, $item);
211
  }
212
  $item->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_COMPLETE)
213
  ->setMessage(null)
214
  ->save();
215
+ } catch (OnePica_AvaTax_Model_Service_Exception_Unbalanced $e) {
216
  $item->setStatus(OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_UNBALANCED)
217
  ->setMessage($e->getMessage())
218
  ->save();
219
  } catch (Exception $e) {
220
+ $status = ($item->getAttempt() >= OnePica_AvaTax_Model_Service_Abstract_Config::QUEUE_ATTEMPT_MAX)
221
+ ? OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_FAILED
222
+ : OnePica_AvaTax_Model_Records_Queue::QUEUE_STATUS_RETRY;
223
  $item->setStatus($status)
224
  ->setMessage($e->getMessage())
225
  ->save();
app/code/community/OnePica/AvaTax/Model/Sales/Quote/Address.php CHANGED
@@ -24,42 +24,6 @@
24
  */
25
  class OnePica_AvaTax_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Address
26
  {
27
- /**
28
- * Avatax address validator instance
29
- *
30
- * @var OnePica_AvaTax_Model_Avatax_Address
31
- */
32
- protected $_avataxValidator = null;
33
-
34
- /**
35
- * Validation results array (to avoid double valiadation of same address)
36
- *
37
- * @var array
38
- */
39
- static protected $_validationResult = array();
40
-
41
- /**
42
- * Avatax address validator accessor method
43
- *
44
- * @return OnePica_AvaTax_Model_Avatax_Address
45
- */
46
- public function getAvataxValidator()
47
- {
48
- return $this->_avataxValidator;
49
- }
50
-
51
- /**
52
- * Avatax address validator mutator method
53
- *
54
- * @param OnePica_AvaTax_Model_Avatax_Address $object
55
- * @return $this
56
- */
57
- public function setAvataxValidator(OnePica_AvaTax_Model_Avatax_Address $object)
58
- {
59
- $this->_avataxValidator = $object;
60
- return $this;
61
- }
62
-
63
  /**
64
  * Creates a hash key based on only address data for caching
65
  *
@@ -81,7 +45,7 @@ class OnePica_AvaTax_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Ad
81
  */
82
  public function validate()
83
  {
84
- if (!Mage::helper('avatax')->fullStopOnError()) {
85
  return true;
86
  }
87
 
@@ -97,17 +61,9 @@ class OnePica_AvaTax_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Ad
97
  $useForShipping = isset($data['use_for_shipping']) ? (int)$data['use_for_shipping'] : 0;
98
 
99
  if ($this->getAddressType() == self::TYPE_SHIPPING
100
- || $this->getUseForShipping()/* <1.9 */ || $useForShipping/* >=1.9 */) {
101
- if (!isset(self::$_validationResult[$this->getAddressId()])) {
102
- if (!$this->getAvataxValidator()) {
103
- $validator = Mage::getModel('avatax/avatax_address')->setAddress($this);
104
- $this->setAvataxValidator($validator);
105
- }
106
-
107
- self::$_validationResult[$this->getAddressId()] = $this->getAvataxValidator()->validate();
108
- }
109
-
110
- return self::$_validationResult[$this->getAddressId()];
111
  }
112
 
113
  return $result;
@@ -138,7 +94,7 @@ class OnePica_AvaTax_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Ad
138
  */
139
  public function addTotalAmount($code, $amount)
140
  {
141
- $amount = $this->getTotalAmount($code)+$amount;
142
  $this->setTotalAmount($code, $amount);
143
  return $this;
144
  }
@@ -152,7 +108,7 @@ class OnePica_AvaTax_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Ad
152
  */
153
  public function addBaseTotalAmount($code, $amount)
154
  {
155
- $amount = $this->getBaseTotalAmount($code)+$amount;
156
  $this->setBaseTotalAmount($code, $amount);
157
  return $this;
158
  }
@@ -168,7 +124,7 @@ class OnePica_AvaTax_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Ad
168
  {
169
  $this->_totalAmounts[$code] = $amount;
170
  if ($code != 'subtotal') {
171
- $code = $code.'_amount';
172
  }
173
  $this->setData($code, $amount);
174
  return $this;
@@ -185,9 +141,9 @@ class OnePica_AvaTax_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Ad
185
  {
186
  $this->_baseTotalAmounts[$code] = $amount;
187
  if ($code != 'subtotal') {
188
- $code = $code.'_amount';
189
  }
190
- $this->setData('base_'.$code, $amount);
191
  return $this;
192
  }
193
 
@@ -200,7 +156,7 @@ class OnePica_AvaTax_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Ad
200
  public function getTotalAmount($code)
201
  {
202
  if (isset($this->_totalAmounts[$code])) {
203
- return $this->_totalAmounts[$code];
204
  }
205
  return 0;
206
  }
@@ -214,8 +170,18 @@ class OnePica_AvaTax_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Ad
214
  public function getBaseTotalAmount($code)
215
  {
216
  if (isset($this->_baseTotalAmounts[$code])) {
217
- return $this->_baseTotalAmounts[$code];
218
  }
219
  return 0;
220
  }
 
 
 
 
 
 
 
 
 
 
221
  }
24
  */
25
  class OnePica_AvaTax_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Address
26
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  /**
28
  * Creates a hash key based on only address data for caching
29
  *
45
  */
46
  public function validate()
47
  {
48
+ if (!$this->_getConfigHelper()->fullStopOnError($this->getQuote()->getStoreId())) {
49
  return true;
50
  }
51
 
61
  $useForShipping = isset($data['use_for_shipping']) ? (int)$data['use_for_shipping'] : 0;
62
 
63
  if ($this->getAddressType() == self::TYPE_SHIPPING
64
+ || $this->getUseForShipping()/* <1.9 */ || $useForShipping/* >=1.9 */
65
+ ) {
66
+ return Mage::getModel('avatax/action_validator')->validate($this);
 
 
 
 
 
 
 
 
67
  }
68
 
69
  return $result;
94
  */
95
  public function addTotalAmount($code, $amount)
96
  {
97
+ $amount = $this->getTotalAmount($code) + $amount;
98
  $this->setTotalAmount($code, $amount);
99
  return $this;
100
  }
108
  */
109
  public function addBaseTotalAmount($code, $amount)
110
  {
111
+ $amount = $this->getBaseTotalAmount($code) + $amount;
112
  $this->setBaseTotalAmount($code, $amount);
113
  return $this;
114
  }
124
  {
125
  $this->_totalAmounts[$code] = $amount;
126
  if ($code != 'subtotal') {
127
+ $code = $code . '_amount';
128
  }
129
  $this->setData($code, $amount);
130
  return $this;
141
  {
142
  $this->_baseTotalAmounts[$code] = $amount;
143
  if ($code != 'subtotal') {
144
+ $code = $code . '_amount';
145
  }
146
+ $this->setData('base_' . $code, $amount);
147
  return $this;
148
  }
149
 
156
  public function getTotalAmount($code)
157
  {
158
  if (isset($this->_totalAmounts[$code])) {
159
+ return $this->_totalAmounts[$code];
160
  }
161
  return 0;
162
  }
170
  public function getBaseTotalAmount($code)
171
  {
172
  if (isset($this->_baseTotalAmounts[$code])) {
173
+ return $this->_baseTotalAmounts[$code];
174
  }
175
  return 0;
176
  }
177
+
178
+ /**
179
+ * Get avatax config helper
180
+ *
181
+ * @return OnePica_AvaTax_Helper_Config
182
+ */
183
+ protected function _getConfigHelper()
184
+ {
185
+ return Mage::helper('avatax/config');
186
+ }
187
  }
app/code/community/OnePica/AvaTax/Model/Sales/Quote/Address/Total/Grand.php CHANGED
@@ -52,9 +52,9 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Grand extends Mage_Sales_Mo
52
  */
53
  protected function _isAddressActionable($address)
54
  {
55
- /** @var OnePica_AvaTax_Helper_Data $helper */
56
- $helper = Mage::helper('avatax');
57
  $storeId = $address->getQuote()->getStoreId();
58
- return $helper->isAddressActionable($address, $storeId, OnePica_AvaTax_Model_Config::REGIONFILTER_TAX);
59
  }
60
  }
52
  */
53
  protected function _isAddressActionable($address)
54
  {
55
+ /** @var OnePica_AvaTax_Helper_Address $helper */
56
+ $helper = Mage::helper('avatax/address');
57
  $storeId = $address->getQuote()->getStoreId();
58
+ return $helper->isAddressActionable($address, $storeId, OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_TAX);
59
  }
60
  }
app/code/community/OnePica/AvaTax/Model/Sales/Quote/Address/Total/Tax.php CHANGED
@@ -39,7 +39,7 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Tax extends Mage_Sales_Mode
39
  * this could be a problem, but Avatax doesn't support those locations yet.
40
  *
41
  * @param Mage_Sales_Model_Quote_Address $address
42
- * @return Mage_Tax_Model_Sales_Total_Quote
43
  */
44
  public function collect(Mage_Sales_Model_Quote_Address $address)
45
  {
@@ -48,8 +48,6 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Tax extends Mage_Sales_Mode
48
 
49
  if ($address->getPostcode() && $address->getPostcode() != '-') {
50
  $store = $address->getQuote()->getStore();
51
- /** @var OnePica_AvaTax_Model_Avatax_Estimate $calculator */
52
- $calculator = Mage::getModel('avatax/avatax_estimate');
53
 
54
  $address->setTotalAmount($this->getCode(), 0);
55
  $address->setBaseTotalAmount($this->getCode(), 0);
@@ -60,101 +58,144 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Tax extends Mage_Sales_Mode
60
  $address->setBaseShippingTaxAmount(0);
61
 
62
  //Added check for calculating tax for regions filtered in the admin
63
- if ($this->_isAddressActionable($address)) {
64
- /** @var Mage_Sales_Model_Quote_Item $item */
65
- foreach ($address->getAllItems() as $item) {
66
- $item->setAddress($address);
67
- $baseAmount = $calculator->getItemTax($item);
68
-
69
- $giftBaseTaxTotalAmount = $calculator->getItemGiftTax($item);
70
- $giftTaxTotalAmount = $store->convertPrice($giftBaseTaxTotalAmount);
71
- $giftBaseTaxAmount = $this->_getDataHelper()
72
- ->roundUp($giftBaseTaxTotalAmount / $item->getQty(), 2);
73
- $giftTaxAmount = $store->convertPrice($giftBaseTaxAmount);
74
-
75
- $amount = $store->convertPrice($baseAmount);
76
- $percent = $calculator->getItemRate($item);
77
-
78
- $item->setTaxAmount($amount);
79
- $item->setBaseTaxAmount($baseAmount);
80
- $item->setTaxPercent($percent);
81
-
82
- $item->setGwBaseTaxAmount($giftBaseTaxAmount);
83
- $item->setGwTaxAmount($giftTaxAmount);
84
-
85
- $item->setPriceInclTax($item->getPrice() + ($amount / $item->getQty()));
86
- $item->setBasePriceInclTax($item->getBasePrice() + ($baseAmount / $item->getQty()));
87
- $item->setRowTotalInclTax($item->getRowTotal() + $amount);
88
- $item->setBaseRowTotalInclTax($item->getBaseRowTotal() + $baseAmount);
89
-
90
- if (!$calculator->isProductCalculated($item)) {
91
- $this->_addAmount($amount);
92
- $this->_addBaseAmount($baseAmount);
93
- }
94
- $this->_addAmount($giftTaxTotalAmount);
95
- $this->_addBaseAmount($giftBaseTaxTotalAmount);
 
 
 
96
  }
 
 
 
97
 
98
- if ($address->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_SHIPPING
99
- || $address->getUseForShipping()
100
- ) {
101
- $shippingItem = new Varien_Object();
102
- $shippingItem->setSku(Mage::helper('avatax')->getShippingSku($store->getId()));
103
- $shippingItem->setProductId(Mage::helper('avatax')->getShippingSku($store->getId()));
104
- $shippingItem->setAddress($address);
105
- $baseShippingTax = $calculator->getItemTax($shippingItem);
106
- $shippingTax = $store->convertPrice($baseShippingTax);
107
-
108
- $shippingAmt = $address->getTotalAmount('shipping');
109
- $baseShippingAmt = $address->getBaseTotalAmount('shipping');
110
-
111
- $address->setShippingTaxAmount($shippingTax);
112
- $address->setBaseShippingTaxAmount($baseShippingTax);
113
- $address->setShippingInclTax($shippingAmt + $shippingTax);
114
- $address->setBaseShippingInclTax($baseShippingAmt + $baseShippingTax);
115
- $address->setShippingTaxable($shippingTax ? $shippingAmt : 0);
116
- $address->setBaseShippingTaxable($baseShippingTax ? $baseShippingAmt : 0);
117
- $address->setIsShippingInclTax(false);
118
-
119
- $this->_addAmount($shippingTax);
120
- $this->_addBaseAmount($baseShippingTax);
121
- }
122
 
123
- if ($address->getGwPrice() > 0) {
124
- $gwOrderItem = new Varien_Object();
125
- $gwOrderItem->setSku(Mage::helper('avatax')->getGwOrderSku($store->getId()));
126
- $gwOrderItem->setProductId(Mage::helper('avatax')->getGwOrderSku($store->getId()));
127
- $gwOrderItem->setAddress($address);
128
- $baseGwOrderTax = $calculator->getItemTax($gwOrderItem);
129
- $gwOrderTax = $store->convertPrice($baseGwOrderTax);
130
 
131
- $address->setGwBaseTaxAmount($baseGwOrderTax);
132
- $address->setGwTaxAmount($gwOrderTax);
133
 
134
- $this->_addAmount($gwOrderTax);
135
- $this->_addBaseAmount($baseGwOrderTax);
136
- }
137
 
138
- if ($address->getGwAddPrintedCard()) {
139
- $gwPrintedCardItem = new Varien_Object();
140
- $gwPrintedCardItem->setSku(Mage::helper('avatax')->getGwPrintedCardSku($store->getId()));
141
- $gwPrintedCardItem->setProductId(Mage::helper('avatax')->getGwPrintedCardSku($store->getId()));
142
- $gwPrintedCardItem->setAddress($address);
143
- $baseGwPrintedCardTax = $calculator->getItemTax($gwPrintedCardItem);
144
- $gwPrintedCardTax = $store->convertPrice($baseGwPrintedCardTax);
145
 
146
- $address->setGwPrintedCardBaseTaxAmount($baseGwPrintedCardTax);
147
- $address->setGwPrintedCardTaxAmount($gwPrintedCardTax);
148
 
149
- $this->_addAmount($gwPrintedCardTax);
150
- $this->_addBaseAmount($baseGwPrintedCardTax);
151
- }
152
  }
 
 
 
 
153
  }
154
 
155
  return $this;
156
  }
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  /**
159
  * Check if address actionable to calculate tax
160
  *
@@ -164,16 +205,38 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Tax extends Mage_Sales_Mode
164
  protected function _isAddressActionable($address)
165
  {
166
  /** @var OnePica_AvaTax_Helper_Data $helper */
167
- $helper = Mage::helper('avatax');
168
  $storeId = $address->getQuote()->getStoreId();
169
- return $helper->isAddressActionable($address, $storeId, OnePica_AvaTax_Model_Config::REGIONFILTER_TAX);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  }
171
 
172
  /**
173
  * Add tax totals information to address object
174
  *
175
  * @param Mage_Sales_Model_Quote_Address $address
176
- * @return Mage_Tax_Model_Sales_Total_Quote
177
  */
178
  public function fetch(Mage_Sales_Model_Quote_Address $address)
179
  {
@@ -182,34 +245,12 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Tax extends Mage_Sales_Mode
182
  $store = $quote->getStore();
183
  $amount = $address->getTaxAmount();
184
 
185
- $fullInfo = array();
186
- $summary = Mage::getModel('avatax/avatax_estimate')->getSummary($address->getId());
187
-
188
- foreach ($summary as $key => $row) {
189
- $id = 'avatax-' . $key;
190
- $fullInfo[$id] = array(
191
- 'rates' => array(array(
192
- 'code' => $row['name'],
193
- 'title' => $row['name'],
194
- 'percent' => $row['rate'],
195
- 'position' => $key,
196
- 'priority' => $key,
197
- 'rule_id' => 0
198
- )),
199
- 'percent' => $row['rate'],
200
- 'id' => $id,
201
- 'process' => 0,
202
- 'amount' => $row['amt'],
203
- 'base_amount' => $row['amt']
204
- );
205
- }
206
-
207
  if (($amount != 0) || (Mage::helper('tax')->displayZeroTax($store))) {
208
  $address->addTotal(
209
  array(
210
  'code' => $this->getCode(),
211
  'title' => Mage::helper('tax')->__('Tax'),
212
- 'full_info' => $fullInfo,
213
  'value' => $amount,
214
  'area' => null
215
  )
@@ -239,6 +280,20 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Tax extends Mage_Sales_Mode
239
  return $this;
240
  }
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  /* BELOW ARE MAGE CORE PROPERTIES AND METHODS ADDED FOR OLDER VERSION COMPATABILITY */
243
 
244
  /**
@@ -264,6 +319,7 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Tax extends Mage_Sales_Mode
264
  protected function _addAmount($amount)
265
  {
266
  $this->_getAddress()->addTotalAmount($this->getCode(), $amount);
 
267
  return $this;
268
  }
269
 
@@ -276,6 +332,7 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Tax extends Mage_Sales_Mode
276
  protected function _addBaseAmount($baseAmount)
277
  {
278
  $this->_getAddress()->addBaseTotalAmount($this->getCode(), $baseAmount);
 
279
  return $this;
280
  }
281
 
@@ -288,6 +345,7 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Tax extends Mage_Sales_Mode
288
  protected function _setAddress(Mage_Sales_Model_Quote_Address $address)
289
  {
290
  $this->_address = $address;
 
291
  return $this;
292
  }
293
 
@@ -302,6 +360,7 @@ class OnePica_AvaTax_Model_Sales_Quote_Address_Total_Tax extends Mage_Sales_Mode
302
  if ($this->_address === null) {
303
  throw new OnePica_AvaTax_Exception(Mage::helper('sales')->__('Address model is not defined'));
304
  }
 
305
  return $this->_address;
306
  }
307
 
39
  * this could be a problem, but Avatax doesn't support those locations yet.
40
  *
41
  * @param Mage_Sales_Model_Quote_Address $address
42
+ * @return $this
43
  */
44
  public function collect(Mage_Sales_Model_Quote_Address $address)
45
  {
48
 
49
  if ($address->getPostcode() && $address->getPostcode() != '-') {
50
  $store = $address->getQuote()->getStore();
 
 
51
 
52
  $address->setTotalAmount($this->getCode(), 0);
53
  $address->setBaseTotalAmount($this->getCode(), 0);
58
  $address->setBaseShippingTaxAmount(0);
59
 
60
  //Added check for calculating tax for regions filtered in the admin
61
+ if (!$this->_isAddressActionable($address) || !$address->hasItems()) {
62
+ return $this;
63
+ }
64
+ $calculator = $this->_getCalculator($address);
65
+
66
+ $itemTaxGroups = array();
67
+ /** @var Mage_Sales_Model_Quote_Item $item */
68
+ foreach ($address->getAllItems() as $item) {
69
+ $item->setAddress($address);
70
+ $baseAmount = $calculator->getItemTax($item);
71
+
72
+ $giftBaseTaxTotalAmount = $calculator->getItemGiftTax($item);
73
+ $itemTaxGroups[$item->getId()] = $calculator->getItemTaxGroup($item);
74
+ $giftTaxTotalAmount = $store->convertPrice($giftBaseTaxTotalAmount);
75
+ $giftBaseTaxAmount = $this->_getDataHelper()
76
+ ->roundUp($giftBaseTaxTotalAmount / $item->getQty(), 2);
77
+ $giftTaxAmount = $store->convertPrice($giftBaseTaxAmount);
78
+
79
+ $amount = $store->convertPrice($baseAmount);
80
+ $percent = $calculator->getItemRate($item);
81
+
82
+ $item->setTaxAmount($amount);
83
+ $item->setBaseTaxAmount($baseAmount);
84
+ $item->setTaxPercent($percent);
85
+
86
+ $item->setGwBaseTaxAmount($giftBaseTaxAmount);
87
+ $item->setGwTaxAmount($giftTaxAmount);
88
+
89
+ $item->setPriceInclTax($item->getPrice() + ($amount / $item->getQty()));
90
+ $item->setBasePriceInclTax($item->getBasePrice() + ($baseAmount / $item->getQty()));
91
+ $item->setRowTotalInclTax($item->getRowTotal() + $amount);
92
+ $item->setBaseRowTotalInclTax($item->getBaseRowTotal() + $baseAmount);
93
+
94
+ if (!$calculator->isProductCalculated($item)) {
95
+ $this->_addAmount($amount);
96
+ $this->_addBaseAmount($baseAmount);
97
  }
98
+ $this->_addAmount($giftTaxTotalAmount);
99
+ $this->_addBaseAmount($giftBaseTaxTotalAmount);
100
+ }
101
 
102
+ if ($address->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_SHIPPING
103
+ || $address->getUseForShipping()
104
+ ) {
105
+ $shippingItem = new Varien_Object();
106
+ $shippingItem->setSku(Mage::helper('avatax/config')->getShippingSku($store->getId()));
107
+ $shippingItem->setProductId(Mage::helper('avatax/config')->getShippingSku($store->getId()));
108
+ $shippingItem->setAddress($address);
109
+ $baseShippingTax = $calculator->getItemTax($shippingItem);
110
+ $shippingTax = $store->convertPrice($baseShippingTax);
111
+
112
+ $shippingAmt = $address->getTotalAmount('shipping');
113
+ $baseShippingAmt = $address->getBaseTotalAmount('shipping');
114
+
115
+ $address->setShippingTaxAmount($shippingTax);
116
+ $address->setBaseShippingTaxAmount($baseShippingTax);
117
+ $address->setShippingInclTax($shippingAmt + $shippingTax);
118
+ $address->setBaseShippingInclTax($baseShippingAmt + $baseShippingTax);
119
+ $address->setShippingTaxable($shippingTax ? $shippingAmt : 0);
120
+ $address->setBaseShippingTaxable($baseShippingTax ? $baseShippingAmt : 0);
121
+ $address->setIsShippingInclTax(false);
122
+
123
+ $this->_addAmount($shippingTax);
124
+ $this->_addBaseAmount($baseShippingTax);
125
+ }
126
 
127
+ if ($address->getGwPrice() > 0) {
128
+ $gwOrderItem = new Varien_Object();
129
+ $gwOrderItem->setSku(Mage::helper('avatax/config')->getGwOrderSku($store->getId()));
130
+ $gwOrderItem->setProductId(Mage::helper('avatax/config')->getGwOrderSku($store->getId()));
131
+ $gwOrderItem->setAddress($address);
132
+ $baseGwOrderTax = $calculator->getItemTax($gwOrderItem);
133
+ $gwOrderTax = $store->convertPrice($baseGwOrderTax);
134
 
135
+ $address->setGwBaseTaxAmount($baseGwOrderTax);
136
+ $address->setGwTaxAmount($gwOrderTax);
137
 
138
+ $this->_addAmount($gwOrderTax);
139
+ $this->_addBaseAmount($baseGwOrderTax);
140
+ }
141
 
142
+ if ($address->getGwAddPrintedCard()) {
143
+ $gwPrintedCardItem = new Varien_Object();
144
+ $gwPrintedCardItem->setSku(Mage::helper('avatax/config')->getGwPrintedCardSku($store->getId()));
145
+ $gwPrintedCardItem->setProductId(Mage::helper('avatax/config')->getGwPrintedCardSku($store->getId()));
146
+ $gwPrintedCardItem->setAddress($address);
147
+ $baseGwPrintedCardTax = $calculator->getItemTax($gwPrintedCardItem);
148
+ $gwPrintedCardTax = $store->convertPrice($baseGwPrintedCardTax);
149
 
150
+ $address->setGwPrintedCardBaseTaxAmount($baseGwPrintedCardTax);
151
+ $address->setGwPrintedCardTaxAmount($gwPrintedCardTax);
152
 
153
+ $this->_addAmount($gwPrintedCardTax);
154
+ $this->_addBaseAmount($baseGwPrintedCardTax);
 
155
  }
156
+
157
+ $this->_setTaxForItems($address, $itemTaxGroups);
158
+ $summary = $calculator->getSummary($address);
159
+ $this->_saveAppliedTax($address, $summary);
160
  }
161
 
162
  return $this;
163
  }
164
 
165
+ /**
166
+ * Save applied tax
167
+ *
168
+ * @param Mage_Sales_Model_Quote_Address $address
169
+ */
170
+ protected function _saveAppliedTax($address, $summary)
171
+ {
172
+ $fullInfo = array();
173
+ $store = $address->getQuote()->getStore();
174
+
175
+ foreach ($summary as $key => $row) {
176
+ $id = $row['name'];
177
+ $fullInfo[$id] = array(
178
+ 'rates' => array(
179
+ array(
180
+ 'code' => $row['name'],
181
+ 'title' => $row['name'],
182
+ 'percent' => $row['rate'],
183
+ 'position' => $key,
184
+ 'priority' => $key,
185
+ 'rule_id' => 0
186
+ )
187
+ ),
188
+ 'percent' => $row['rate'],
189
+ 'id' => $id,
190
+ 'process' => 0,
191
+ 'amount' => $store->convertPrice($row['amt']),
192
+ 'base_amount' => $row['amt']
193
+ );
194
+ }
195
+
196
+ $address->setAppliedTaxes($fullInfo);
197
+ }
198
+
199
  /**
200
  * Check if address actionable to calculate tax
201
  *
205
  protected function _isAddressActionable($address)
206
  {
207
  /** @var OnePica_AvaTax_Helper_Data $helper */
208
+ $helper = Mage::helper('avatax/address');
209
  $storeId = $address->getQuote()->getStoreId();
210
+
211
+ return $helper->isAddressActionable(
212
+ $address,
213
+ $storeId,
214
+ OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_TAX
215
+ );
216
+ }
217
+
218
+ /**
219
+ * Set tax for items
220
+ *
221
+ * @param \Mage_Sales_Model_Quote_Address $address
222
+ * @param array $itemTaxGroups
223
+ * @return $this
224
+ */
225
+ protected function _setTaxForItems(Mage_Sales_Model_Quote_Address $address, $itemTaxGroups)
226
+ {
227
+ if ($address->getQuote()->getTaxesForItems()) {
228
+ $itemTaxGroups += $address->getQuote()->getTaxesForItems();
229
+ }
230
+ $address->getQuote()->setTaxesForItems($itemTaxGroups);
231
+
232
+ return $this;
233
  }
234
 
235
  /**
236
  * Add tax totals information to address object
237
  *
238
  * @param Mage_Sales_Model_Quote_Address $address
239
+ * @return $this
240
  */
241
  public function fetch(Mage_Sales_Model_Quote_Address $address)
242
  {
245
  $store = $quote->getStore();
246
  $amount = $address->getTaxAmount();
247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  if (($amount != 0) || (Mage::helper('tax')->displayZeroTax($store))) {
249
  $address->addTotal(
250
  array(
251
  'code' => $this->getCode(),
252
  'title' => Mage::helper('tax')->__('Tax'),
253
+ 'full_info' => $address->getAppliedTaxes(),
254
  'value' => $amount,
255
  'area' => null
256
  )
280
  return $this;
281
  }
282
 
283
+ /**
284
+ * Get calculator model
285
+ *
286
+ * @param Mage_Sales_Model_Quote_Address $address
287
+ * @return \OnePica_AvaTax_Model_Action_Calculator
288
+ */
289
+ protected function _getCalculator(Mage_Sales_Model_Quote_Address $address)
290
+ {
291
+ return Mage::getModel(
292
+ 'avatax/action_calculator',
293
+ array(OnePica_AvaTax_Model_Action_Calculator::ADDRESS_PARAMETER => $address)
294
+ );
295
+ }
296
+
297
  /* BELOW ARE MAGE CORE PROPERTIES AND METHODS ADDED FOR OLDER VERSION COMPATABILITY */
298
 
299
  /**
319
  protected function _addAmount($amount)
320
  {
321
  $this->_getAddress()->addTotalAmount($this->getCode(), $amount);
322
+
323
  return $this;
324
  }
325
 
332
  protected function _addBaseAmount($baseAmount)
333
  {
334
  $this->_getAddress()->addBaseTotalAmount($this->getCode(), $baseAmount);
335
+
336
  return $this;
337
  }
338
 
345
  protected function _setAddress(Mage_Sales_Model_Quote_Address $address)
346
  {
347
  $this->_address = $address;
348
+
349
  return $this;
350
  }
351
 
360
  if ($this->_address === null) {
361
  throw new OnePica_AvaTax_Exception(Mage::helper('sales')->__('Address model is not defined'));
362
  }
363
+
364
  return $this->_address;
365
  }
366
 
app/code/community/OnePica/AvaTax/Model/Service.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * OnePica_AvaTax_Model_Service
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0), a
9
+ * copy of which is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category OnePica
13
+ * @package OnePica_AvaTax
14
+ * @author OnePica Codemaster <codemaster@onepica.com>
15
+ * @copyright Copyright (c) 2015 One Pica, Inc.
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * The fabric AvaTax model
21
+ *
22
+ * @category OnePica
23
+ * @package OnePica_AvaTax
24
+ * @author OnePica Codemaster <codemaster@onepica.com>
25
+ */
26
+
27
+ class OnePica_AvaTax_Model_Service extends Mage_Core_Model_Factory
28
+ {
29
+ /**
30
+ * Path to service model
31
+ */
32
+ const XML_PATH_INDEX_INDEX_MODEL = 'avatax/service_';
33
+
34
+ /**
35
+ * Get factory method
36
+ *
37
+ * @param string $service
38
+ * @param array $options
39
+ * @return Mage_Core_Model_Abstract|null|OnePica_AvaTax_Model_Service_Abstract
40
+ * @throws OnePica_AvaTax_Exception
41
+ */
42
+ public function factory($service, array $options = array())
43
+ {
44
+ if (!$service) {
45
+ throw new OnePica_AvaTax_Exception('Service name is not defined.');
46
+ }
47
+ $model = $this->getSingleton(self::XML_PATH_INDEX_INDEX_MODEL . $service, $options);
48
+ if (!$model) {
49
+ throw new OnePica_AvaTax_Exception('Could not found service model ' . $service);
50
+ }
51
+ return $model;
52
+ }
53
+ }
app/code/community/OnePica/AvaTax/Model/Service/Abstract.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Abstract class OnePica_AvaTax_Model_Service_Abstract
20
+ *
21
+ * @class OnePica_AvaTax_Model_Service_Abstract
22
+ * @category OnePica
23
+ * @package OnePica_AvaTax
24
+ * @author OnePica Codemaster <codemaster@onepica.com>
25
+ */
26
+ abstract class OnePica_AvaTax_Model_Service_Abstract extends Varien_Object
27
+ {
28
+ /**
29
+ * Estimate Resource
30
+ *
31
+ * @var mixed
32
+ */
33
+ protected $_estimateResource;
34
+
35
+ /**
36
+ * Invoice Resource
37
+ *
38
+ * @var mixed
39
+ */
40
+ protected $_invoiceResource;
41
+
42
+ /**
43
+ * Ping Resource
44
+ *
45
+ * @var mixed
46
+ */
47
+ protected $_pingResource;
48
+
49
+ /**
50
+ * Address validator resource
51
+ *
52
+ * @var mixed
53
+ */
54
+ protected $_addressValidatorResource;
55
+
56
+ /**
57
+ * Set Store Id
58
+ *
59
+ * @param int $storeId
60
+ * @return $this
61
+ */
62
+ public function setStoreId($storeId)
63
+ {
64
+ $this->setCurrentStoreId($storeId);
65
+ if (!$this->getServiceConfig()) {
66
+ $this->setServiceConfig(
67
+ Mage::getModel($this->_getServiceConfigClassName())->init($this->getCurrentStoreId())
68
+ );
69
+ }
70
+
71
+ // update service config for each resource
72
+ if (null !== $this->_estimateResource) {
73
+ $this->_estimateResource->setServiceConfig($this->getServiceConfig());
74
+ }
75
+
76
+ if (null !== $this->_invoiceResource) {
77
+ $this->_invoiceResource->setServiceConfig($this->getServiceConfig());
78
+ }
79
+
80
+ if (null !== $this->_pingResource) {
81
+ $this->_pingResource->setServiceConfig($this->getServiceConfig());
82
+ }
83
+
84
+ if (null !== $this->_addressValidatorResource) {
85
+ $this->_addressValidatorResource->setServiceConfig($this->getServiceConfig());
86
+ }
87
+
88
+ return $this;
89
+ }
90
+
91
+ /**
92
+ * Get rates from Service
93
+ *
94
+ * @param Mage_Sales_Model_Quote_Address $address
95
+ * @return array
96
+ */
97
+ abstract public function getRates($address);
98
+
99
+ /**
100
+ * Get tax detail summary
101
+ *
102
+ * @param Mage_Sales_Model_Quote_Address $address
103
+ * @return array
104
+ */
105
+ abstract public function getSummary($address);
106
+
107
+ /**
108
+ * Test to see if the product carries its own numbers or is calculated based on parent or children
109
+ *
110
+ * @param Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item|mixed $item
111
+ * @return bool
112
+ */
113
+ abstract public function isProductCalculated($item);
114
+
115
+ /**
116
+ * Save order in AvaTax system
117
+ *
118
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderInvoiceSaveAfter::execute()
119
+ * @param Mage_Sales_Model_Order_Invoice $invoice
120
+ * @param OnePica_AvaTax_Model_Records_Queue $queue
121
+ * @return bool
122
+ */
123
+ abstract public function invoice($invoice, $queue);
124
+
125
+ /**
126
+ * Save order in AvaTax system
127
+ *
128
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderCreditmemoSaveAfter::execute()
129
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
130
+ * @param OnePica_AvaTax_Model_Records_Queue $queue
131
+ * @return bool
132
+ */
133
+ abstract public function creditmemo($creditmemo, $queue);
134
+
135
+ /**
136
+ * Tries to ping AvaTax service with provided credentials
137
+ *
138
+ * @param int $storeId
139
+ * @return bool|array
140
+ */
141
+ abstract public function ping($storeId);
142
+
143
+ /**
144
+ * Get service address validator
145
+ *
146
+ * @param mixed $address
147
+ * @return mixed
148
+ */
149
+ abstract public function validate($address);
150
+
151
+ /**
152
+ * Get service config class name
153
+ *
154
+ * @return string
155
+ */
156
+ abstract protected function _getServiceConfigClassName();
157
+
158
+ /**
159
+ * Service configs for each store
160
+ *
161
+ * @var array|OnePica_AvaTax_Model_Service_Abstract_Config[]
162
+ */
163
+ protected $_configs = array();
164
+
165
+ /**
166
+ * Current store Id
167
+ *
168
+ * @var null|int
169
+ */
170
+ protected $_currentStoreId;
171
+
172
+ /**
173
+ * Get Current Store Id
174
+ *
175
+ * @return null|int
176
+ */
177
+ public function getCurrentStoreId()
178
+ {
179
+ return $this->_currentStoreId;
180
+ }
181
+
182
+ /**
183
+ * Set Current Store Id
184
+ *
185
+ * @param int $storeId
186
+ */
187
+ public function setCurrentStoreId($storeId)
188
+ {
189
+ $this->_currentStoreId = $storeId;
190
+ }
191
+
192
+ /**
193
+ * Get service config.
194
+ *
195
+ * @return null|OnePica_AvaTax_Model_Service_Abstract_Config
196
+ */
197
+ public function getServiceConfig()
198
+ {
199
+ $serviceConfig = isset($this->_configs[$this->getCurrentStoreId()])
200
+ ? $this->_configs[$this->getCurrentStoreId()]
201
+ : null;
202
+ return $serviceConfig;
203
+ }
204
+
205
+ /**
206
+ * Set service config.
207
+ *
208
+ * @param null|OnePica_AvaTax_Model_Service_Abstract_Config $config
209
+ */
210
+ public function setServiceConfig($config)
211
+ {
212
+ $this->_configs[$this->getCurrentStoreId()] = $config;
213
+ }
214
+
215
+ /**
216
+ * Get config helper
217
+ *
218
+ * @return OnePica_AvaTax_Helper_Config
219
+ */
220
+ protected function _getConfigHelper()
221
+ {
222
+ return Mage::helper('avatax/config');
223
+ }
224
+ }
app/code/community/OnePica/AvaTax/Model/Service/Abstract/Config.php ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * @class OnePica_AvaTax_Model_Service_Abstract_Tools
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ abstract class OnePica_AvaTax_Model_Service_Abstract_Config extends Varien_Object
26
+ {
27
+ /**
28
+ * Config key
29
+ */
30
+ const CONFIG_KEY = 'Magento';
31
+
32
+ /**
33
+ * App name
34
+ */
35
+ const APP_NAME = 'OP_AvaTax by One Pica';
36
+
37
+ /**
38
+ * Calculate action
39
+ */
40
+ const ACTION_CALC = 1;
41
+
42
+ /**
43
+ * Calculate, submit action
44
+ */
45
+ const ACTION_CALC_SUBMIT = 2;
46
+
47
+ /**
48
+ * Calculate, submit, commit action
49
+ */
50
+ const ACTION_CALC_SUBMIT_COMMIT = 3;
51
+
52
+ /**
53
+ * Region filter disable mode
54
+ */
55
+ const REGIONFILTER_OFF = 0;
56
+
57
+ /**
58
+ * Region filter tax mode
59
+ */
60
+ const REGIONFILTER_TAX = 1;
61
+
62
+ /**
63
+ * Number of times a queue item will try to send
64
+ */
65
+ const QUEUE_ATTEMPT_MAX = 5;
66
+
67
+ /**
68
+ * Disable action
69
+ */
70
+ const ACTION_DISABLE = 0;
71
+
72
+ /**
73
+ * Region filter all mode
74
+ */
75
+ const REGIONFILTER_ALL = 2;
76
+
77
+ /**
78
+ * Resource connection
79
+ * @var
80
+ */
81
+ protected $_connection = null;
82
+
83
+ /**
84
+ * The lib config object.
85
+ *
86
+ * @var
87
+ */
88
+ protected $_config = null;
89
+
90
+ /**
91
+ * Get resource connection
92
+ * @return mixed
93
+ */
94
+ abstract public function getTaxConnection();
95
+
96
+ /**
97
+ * Init config
98
+ * @param $storeId
99
+ * @return mixed
100
+ */
101
+ abstract public function init($storeId);
102
+
103
+ /**
104
+ *
105
+ * @return mixed
106
+ */
107
+ public function getParams()
108
+ {
109
+ return $this->_config;
110
+ }
111
+
112
+ /**
113
+ * Returns the AvaTax helper.
114
+ *
115
+ * @return OnePica_AvaTax_Helper_Data
116
+ */
117
+ protected function _getHelper()
118
+ {
119
+ return Mage::helper('avatax');
120
+ }
121
+
122
+ /**
123
+ * Returns the AvaTax helper.
124
+ *
125
+ * @return OnePica_AvaTax_Helper_Address
126
+ */
127
+ protected function _getAddressHelper()
128
+ {
129
+ return Mage::helper('avatax/address');
130
+ }
131
+
132
+ /**
133
+ * Returns the AvaTax helper.
134
+ *
135
+ * @return OnePica_AvaTax_Helper_Config
136
+ */
137
+ protected function _getConfigHelper()
138
+ {
139
+ return Mage::helper('avatax/config');
140
+ }
141
+
142
+ /**
143
+ * Returns the AvaTax helper.
144
+ *
145
+ * @return OnePica_AvaTax_Helper_Config
146
+ */
147
+ protected function _getErrorsHelper()
148
+ {
149
+ return Mage::helper('avatax/errors');
150
+ }
151
+ }
app/code/community/OnePica/AvaTax/Model/Service/Abstract/Tools.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * @class OnePica_AvaTax_Model_Service_Abstract_Tools
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Service_Abstract_Tools extends Varien_Object
26
+ {
27
+ /**
28
+ * Length of time in minutes for cached rates
29
+ *
30
+ * @var int
31
+ */
32
+ const CACHE_TTL = 120;
33
+
34
+ //@startSkipCommitHooks
35
+ /**
36
+ * Alias to the helper translate method.
37
+ *
38
+ * @return string
39
+ */
40
+ public function __()
41
+ {
42
+ $args = func_get_args();
43
+ return call_user_func_array(array($this->_getHelper(), '__'), $args);
44
+ }
45
+ //@finishSkipCommitHooks
46
+
47
+ /**
48
+ * Retrieve converted date taking into account the current time zone and store.
49
+ *
50
+ * @param string $gmt
51
+ * @param int $storeId
52
+ * @return string
53
+ */
54
+ protected function _convertGmtDate($gmt, $storeId)
55
+ {
56
+ return $this->_getHelper()
57
+ ->storeDate($storeId, $gmt, false, Varien_Date::DATETIME_INTERNAL_FORMAT)
58
+ ->toString(Varien_Date::DATE_INTERNAL_FORMAT);
59
+ }
60
+
61
+ /**
62
+ * Retrieve application instance
63
+ *
64
+ * @return Mage_Core_Model_App
65
+ */
66
+ protected function _getApp()
67
+ {
68
+ return Mage::app();
69
+ }
70
+
71
+ /**
72
+ * Returns the AvaTax helper.
73
+ *
74
+ * @return OnePica_AvaTax_Helper_Data
75
+ */
76
+ protected function _getHelper()
77
+ {
78
+ return Mage::helper('avatax');
79
+ }
80
+
81
+ /**
82
+ * Returns the AvaTax helper.
83
+ *
84
+ * @return OnePica_AvaTax_Helper_Address
85
+ */
86
+ protected function _getAddressHelper()
87
+ {
88
+ return Mage::helper('avatax/address');
89
+ }
90
+
91
+ /**
92
+ * Returns the AvaTax helper.
93
+ *
94
+ * @return OnePica_AvaTax_Helper_Config
95
+ */
96
+ protected function _getConfigHelper()
97
+ {
98
+ return Mage::helper('avatax/config');
99
+ }
100
+
101
+ /**
102
+ * Returns the AvaTax helper.
103
+ *
104
+ * @return OnePica_AvaTax_Helper_Config
105
+ */
106
+ protected function _getErrorsHelper()
107
+ {
108
+ return Mage::helper('avatax/errors');
109
+ }
110
+
111
+ /**
112
+ * Test to see if the product carries its own numbers or is calculated based on parent or children
113
+ *
114
+ * @param Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item|mixed $item
115
+ * @return bool
116
+ */
117
+ public function isProductCalculated($item)
118
+ {
119
+ // check if item has methods as far as shipping, gift wrapping, printed card item comes as Varien_Object
120
+ if (method_exists($item, 'isChildrenCalculated') && method_exists($item, 'getParentItem')) {
121
+ if ($item->isChildrenCalculated() && !$item->getParentItem()) {
122
+ return true;
123
+ }
124
+ if (!$item->isChildrenCalculated() && $item->getParentItem()) {
125
+ return true;
126
+ }
127
+ }
128
+ return false;
129
+ }
130
+
131
+ /**
132
+ * Retrieve Vat Id
133
+ *
134
+ * @param Mage_Sales_Model_Order|OnePica_AvaTax_Model_Sales_Quote_Address $object
135
+ * @return string
136
+ */
137
+ protected function _getVatId($object)
138
+ {
139
+ if ($object instanceof Mage_Sales_Model_Order) {
140
+ return $this->_getVatIdByOrder($object);
141
+ }
142
+
143
+ return $this->_getVatIdByQuoteAddress($object);
144
+ }
145
+
146
+ /**
147
+ * Retrieve Vat Id from quote address
148
+ *
149
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address $address
150
+ * @return string
151
+ */
152
+ protected function _getVatIdByQuoteAddress($address)
153
+ {
154
+ $vatId = $address->getVatId()
155
+ ?: $address->getQuote()->getBillingAddress()->getVatId();
156
+ return (string)$vatId;
157
+ }
158
+
159
+ /**
160
+ * Retrieve Vat Id from order
161
+ *
162
+ * @param Mage_Sales_Model_Order $order
163
+ * @return string
164
+ */
165
+ protected function _getVatIdByOrder($order)
166
+ {
167
+ $shippingAddress = $order->getShippingAddress();
168
+ if ($shippingAddress && $shippingAddress->getVatId()) {
169
+ return $shippingAddress->getVatId();
170
+ }
171
+ return $order->getBillingAddress()->getVatId();
172
+ }
173
+ }
app/code/community/OnePica/AvaTax/Model/Service/Avatax.php ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Class OnePica_AvaTax_Model_Service_Avatax
20
+ *
21
+ * @property OnePica_AvaTax_Model_Service_Avatax_Invoice _invoiceResource
22
+ * @property OnePica_AvaTax_Model_Service_Avatax_Estimate _estimateResource
23
+ * @property OnePica_AvaTax_Model_Service_Avatax_Ping _pingResource
24
+ * @property OnePica_AvaTax_Model_Service_Avatax_Address
25
+ *
26
+ * @category OnePica
27
+ * @package OnePica_AvaTax
28
+ * @author OnePica Codemaster <codemaster@onepica.com>
29
+ */
30
+ class OnePica_AvaTax_Model_Service_Avatax
31
+ extends OnePica_AvaTax_Model_Service_Abstract
32
+ {
33
+ /**
34
+ * Service config class name
35
+ */
36
+ const AVATAX_SERVICE_CONFIG_CLASS = 'avatax/service_avatax_config';
37
+
38
+ /**
39
+ * OnePica_AvaTax_Model_Service_Avatax constructor.
40
+ *
41
+ * @internal param mixed
42
+ */
43
+ public function __construct()
44
+ {
45
+ $storeId = Mage::app()->getStore()->getStoreId();
46
+ $this->setStoreId($storeId);
47
+ }
48
+
49
+ /**
50
+ * Get estimate resource
51
+ *
52
+ * @return OnePica_AvaTax_Model_Service_Avatax_Estimate
53
+ */
54
+ protected function _getEstimateResource()
55
+ {
56
+ if (null === $this->_estimateResource) {
57
+ $this->_estimateResource = Mage::getModel('avatax/service_avatax_estimate',
58
+ array('service_config' => $this->getServiceConfig()));
59
+ }
60
+
61
+ return $this->_estimateResource;
62
+ }
63
+
64
+ /**
65
+ * Get invoice resource
66
+ *
67
+ * @return OnePica_AvaTax_Model_Service_Avatax_Invoice
68
+ */
69
+ protected function _getInvoiceResource()
70
+ {
71
+ if (null === $this->_invoiceResource) {
72
+ $this->_invoiceResource = Mage::getModel('avatax/service_avatax_invoice',
73
+ array('service_config' => $this->getServiceConfig()));
74
+ }
75
+
76
+ return $this->_invoiceResource;
77
+ }
78
+
79
+ /**
80
+ * Get ping resource
81
+ *
82
+ * @return OnePica_AvaTax_Model_Service_Avatax_Ping
83
+ */
84
+ protected function _getPingResource()
85
+ {
86
+ if (null === $this->_pingResource) {
87
+ $this->_pingResource = Mage::getModel('avatax/service_avatax_ping',
88
+ array('service_config' => $this->getServiceConfig()));
89
+ }
90
+
91
+ return $this->_pingResource;
92
+ }
93
+
94
+ /**
95
+ * Get Address Validator resource
96
+ *
97
+ * @return \OnePica_AvaTax_Model_Service_Avatax_Address
98
+ */
99
+ protected function _getAddressValidatorResource()
100
+ {
101
+ if (null === $this->_addressValidatorResource) {
102
+ return Mage::getModel('avatax/service_avatax_address',
103
+ array('service_config' => $this->getServiceConfig())
104
+ );
105
+ }
106
+
107
+ return $this->_addressValidatorResource;
108
+ }
109
+
110
+ /**
111
+ * Get rates from Avalara
112
+ *
113
+ * @param Mage_Sales_Model_Quote_Address $address
114
+ * @return array
115
+ */
116
+ public function getRates($address)
117
+ {
118
+ return $this->_getEstimateResource()->getRates($address);
119
+ }
120
+
121
+ /**
122
+ * Get tax detail summary
123
+ *
124
+ * @param Mage_Sales_Model_Quote_Address $address
125
+ * @return array
126
+ */
127
+ public function getSummary($address)
128
+ {
129
+ return $this->_getEstimateResource()->getSummary($address);
130
+ }
131
+
132
+ /**
133
+ * Test to see if the product carries its own numbers or is calculated based on parent or children
134
+ *
135
+ * @param Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item|mixed $item
136
+ * @return bool
137
+ */
138
+ public function isProductCalculated($item)
139
+ {
140
+ return $this->_getEstimateResource()->isProductCalculated($item);
141
+ }
142
+
143
+ /**
144
+ * Get avatax address validator
145
+ *
146
+ * @param Mage_Sales_Model_Quote_Address $address
147
+ * @return \OnePica_AvaTax_Model_Service_Avatax_Address
148
+ * @throws \OnePica_AvaTax_Model_Service_Exception_Address
149
+ */
150
+ public function validate($address)
151
+ {
152
+ return $this->_getAddressValidatorResource()->validate($address);
153
+ }
154
+
155
+ /**
156
+ * Save order in AvaTax system
157
+ *
158
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderInvoiceSaveAfter::execute()
159
+ * @param Mage_Sales_Model_Order_Invoice $invoice
160
+ * @param OnePica_AvaTax_Model_Records_Queue $queue
161
+ * @return bool
162
+ * @throws OnePica_AvaTax_Exception
163
+ * @throws OnePica_AvaTax_Model_Service_Exception_Commitfailure
164
+ * @throws OnePica_AvaTax_Model_Service_Exception_Unbalanced
165
+ */
166
+ public function invoice($invoice, $queue)
167
+ {
168
+ return $this->_getInvoiceResource()->invoice($invoice, $queue);
169
+ }
170
+
171
+ /**
172
+ * Save order in AvaTax system
173
+ *
174
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderCreditmemoSaveAfter::execute()
175
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
176
+ * @param OnePica_AvaTax_Model_Records_Queue $queue
177
+ * @return mixed
178
+ * @throws OnePica_AvaTax_Exception
179
+ * @throws OnePica_AvaTax_Model_Service_Exception_Commitfailure
180
+ * @throws OnePica_AvaTax_Model_Service_Exception_Unbalanced
181
+ */
182
+ public function creditmemo($creditmemo, $queue)
183
+ {
184
+ return $this->_getInvoiceResource()->creditmemo($creditmemo, $queue);
185
+ }
186
+
187
+ /**
188
+ * Tries to ping AvaTax service with provided credentials
189
+ *
190
+ * @param int $storeId
191
+ * @return bool|array
192
+ */
193
+ public function ping($storeId)
194
+ {
195
+ return $this->_getPingResource()->ping($storeId);
196
+ }
197
+
198
+ /**
199
+ * Get service config class name
200
+ *
201
+ * @return string
202
+ */
203
+ protected function _getServiceConfigClassName()
204
+ {
205
+ return self::AVATAX_SERVICE_CONFIG_CLASS;
206
+ }
207
+ }
app/code/community/OnePica/AvaTax/Model/{Avatax → Service/Avatax}/Abstract.php RENAMED
@@ -16,14 +16,26 @@
16
  */
17
 
18
  /**
19
- * Avatax abstract model
 
 
20
  *
21
  * @category OnePica
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
- abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model_Abstract
26
  {
 
 
 
 
 
 
 
 
 
 
27
  /**
28
  * Flag that states if there was an error
29
  *
@@ -52,6 +64,92 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
52
  */
53
  protected $_taxClassCollection = null;
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  /**
56
  * Sets the company code on the request
57
  *
@@ -60,7 +158,7 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
60
  */
61
  protected function _setCompanyCode($storeId = null)
62
  {
63
- $config = Mage::getSingleton('avatax/config');
64
  $this->_request->setCompanyCode($config->getCompanyCode($storeId));
65
  return $this;
66
  }
@@ -104,55 +202,6 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
104
  return (int)$this->_getGiftWrappingDataHelper()->getWrappingTaxClass($storeId);
105
  }
106
 
107
- /**
108
- * Sends a request to the Avatax server
109
- *
110
- * @param int $storeId
111
- * @return mixed
112
- */
113
- protected function _send($storeId)
114
- {
115
- /** @var OnePica_AvaTax_Model_Config $config */
116
- $config = Mage::getSingleton('avatax/config')->init($storeId);
117
- $connection = $config->getTaxConnection();
118
- $result = null;
119
- $message = null;
120
-
121
- try {
122
- $result = $connection->getTax($this->_request);
123
- } catch (Exception $exception) {
124
- $message = new Message();
125
- $message->setSummary($exception->getMessage());
126
- }
127
-
128
- if (!isset($result) || !is_object($result) || !$result->getResultCode()) {
129
- $actualResult = $result;
130
- $result = new Varien_Object();
131
- $result->setResultCode(SeverityLevel::$Exception)
132
- ->setActualResult($actualResult)
133
- ->setMessages(array($message));
134
- }
135
-
136
- $this->_log(
137
- OnePica_AvaTax_Model_Source_Logtype::GET_TAX,
138
- $this->_request,
139
- $result,
140
- $storeId,
141
- $config->getParams()
142
- );
143
-
144
- if ($result->getResultCode() != SeverityLevel::$Success) {
145
- self::$_hasError = true;
146
- if (Mage::helper('avatax')->fullStopOnError($storeId)) {
147
- Mage::helper('avatax')->addErrorMessage($storeId);
148
- }
149
- } else {
150
- Mage::helper('avatax')->removeErrorMessage();
151
- }
152
-
153
- return $result;
154
- }
155
-
156
  /**
157
  * Adds additional transaction based data
158
  *
@@ -165,12 +214,12 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
165
  $this->_setCompanyCode($storeId);
166
  $this->_request->setBusinessIdentificationNo($this->_getVatId($object));
167
  $this->_request->setDetailLevel(DetailLevel::$Document);
168
- $this->_request->setDocDate($this->_getDateModel()->date('Y-m-d'));
169
  $this->_request->setExemptionNo('');
170
  $this->_request->setDiscount(0.00); //cannot be used in Magento
171
- $this->_request->setSalespersonCode(Mage::helper('avatax')->getSalesPersonCode($storeId));
172
- $this->_request->setLocationCode(Mage::helper('avatax')->getLocationCode($storeId));
173
- $this->_request->setCountry(Mage::getStoreConfig('shipping/origin/country_id', $storeId));
174
  $this->_request->setCurrencyCode(Mage::app()->getStore($storeId)->getBaseCurrencyCode());
175
  $this->_addCustomer($object);
176
  if ($object instanceof Mage_Sales_Model_Order && $object->getIncrementId()) {
@@ -179,85 +228,17 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
179
  return $this;
180
  }
181
 
182
- /**
183
- * Retrieve Vat Id
184
- *
185
- * @param Mage_Sales_Model_Order|OnePica_AvaTax_Model_Sales_Quote_Address $object
186
- * @return string
187
- */
188
- protected function _getVatId($object)
189
- {
190
- if ($object instanceof Mage_Sales_Model_Order) {
191
- return $this->_getVatIdByOrder($object);
192
- }
193
-
194
- return $this->_getVatIdByQuoteAddress($object);
195
- }
196
-
197
- /**
198
- * Retrieve Vat Id from quote address
199
- *
200
- * @param OnePica_AvaTax_Model_Sales_Quote_Address $address
201
- * @return string
202
- */
203
- protected function _getVatIdByQuoteAddress($address)
204
- {
205
- $vatId = $address->getVatId()
206
- ?: $address->getQuote()->getBillingAddress()->getVatId();
207
- return (string)$vatId;
208
- }
209
-
210
- /**
211
- * Retrieve Vat Id from order
212
- *
213
- * @param Mage_Sales_Model_Order $order
214
- * @return string
215
- */
216
- protected function _getVatIdByOrder($order)
217
- {
218
- $shippingAddress = $order->getShippingAddress();
219
- if ($shippingAddress && $shippingAddress->getVatId()) {
220
- return $shippingAddress->getVatId();
221
- }
222
- return $order->getBillingAddress()->getVatId();
223
- }
224
-
225
  /**
226
  * Sets the customer info if available
227
  *
228
- * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object
229
  * @return $this
230
  */
231
  protected function _addCustomer($object)
232
  {
233
- $format = Mage::getStoreConfig('tax/avatax/cust_code_format', $object->getStoreId());
234
- $customer = Mage::getModel('customer/customer');
235
-
236
- if ($object->getCustomerId()) {
237
- $customer->load($object->getCustomerId());
238
- $taxClass = Mage::getModel('tax/class')->load($customer->getTaxClassId())->getOpAvataxCode();
239
- $this->_request->setCustomerUsageType($taxClass);
240
- }
241
 
242
- switch ($format) {
243
- case OnePica_AvaTax_Model_Source_Customercodeformat::LEGACY:
244
- if ($customer->getId()) {
245
- $customerCode = $customer->getName() . ' (' . $customer->getId() . ')';
246
- } else {
247
- $address = $object->getBillingAddress() ? $object->getBillingAddress() : $object;
248
- $customerCode = $address->getFirstname() . ' ' . $address->getLastname() . ' (Guest)';
249
- }
250
- break;
251
- case OnePica_AvaTax_Model_Source_Customercodeformat::CUST_EMAIL:
252
- $customerCode = $object->getCustomerEmail() ? $object->getCustomerEmail() : $customer->getEmail();
253
- break;
254
- case OnePica_AvaTax_Model_Source_Customercodeformat::CUST_ID:
255
- default:
256
- $customerCode = $object->getCustomerId() ? $object->getCustomerId() : 'guest-'.$object->getId();
257
- break;
258
- }
259
-
260
- $this->_request->setCustomerCode($customerCode);
261
  return $this;
262
  }
263
 
@@ -289,7 +270,7 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
289
  {
290
  $street1 = $address->getStreet(1);
291
  $street2 = $address->getStreet(2);
292
- $city = $address->getCity();
293
  $zip = $address->getPostcode();
294
  $state = Mage::getModel('directory/region')->load($address->getRegionId())->getCode();
295
  $country = $address->getCountry();
@@ -325,43 +306,6 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
325
  return $address;
326
  }
327
 
328
- /**
329
- * Test to see if the product carries its own numbers or is calculated based on parent or children
330
- *
331
- * @param Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item|mixed $item
332
- * @return bool
333
- */
334
- public function isProductCalculated($item)
335
- {
336
- // check if item has methods as far as shipping, gift wrapping, printed card item comes as Varien_Object
337
- if (method_exists($item, 'isChildrenCalculated') && method_exists($item, 'getParentItem')) {
338
- if ($item->isChildrenCalculated() && !$item->getParentItem()) {
339
- return true;
340
- }
341
- if (!$item->isChildrenCalculated() && $item->getParentItem()) {
342
- return true;
343
- }
344
- }
345
- return false;
346
- }
347
-
348
- /**
349
- * Adds a comment to order history. Method choosen based on Magento version.
350
- *
351
- * @param Mage_Sales_Model_Order $order
352
- * @param string $comment
353
- * @return self
354
- */
355
- protected function _addStatusHistoryComment($order, $comment)
356
- {
357
- if (method_exists($order, 'addStatusHistoryComment')) {
358
- $order->addStatusHistoryComment($comment)->save();
359
- } elseif (method_exists($order, 'addStatusToHistory')) {
360
- $order->addStatusToHistory($order->getStatus(), $comment, false)->save();;
361
- }
362
- return $this;
363
- }
364
-
365
  /**
366
  * Init product collection for items to be calculated
367
  *
@@ -374,76 +318,18 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
374
  foreach ($items as $item) {
375
  if (!$this->isProductCalculated($item)) {
376
  $productIds[] = $item->getProductId();
377
- $simpleProductId = $this->_getSimpleProductIdByConfigurable($item);
378
  if ($simpleProductId) {
379
  $productIds[] = $simpleProductId;
380
  }
381
  }
382
  }
383
-
384
  $this->_productCollection = Mage::getModel('catalog/product')->getCollection()
385
  ->addAttributeToSelect('*')
386
  ->addAttributeToFilter('entity_id', array('in' => $productIds));
387
-
388
  return $this;
389
  }
390
 
391
- /**
392
- * Get simple product id from configurable item
393
- *
394
- * @param Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Creditmemo_Item|Mage_Sales_Model_Order_Invoice_Item $item
395
- * @return int
396
- */
397
- protected function _getSimpleProductIdByConfigurable($item)
398
- {
399
- if (($item instanceof Mage_Sales_Model_Quote_Item
400
- || $item instanceof Mage_Sales_Model_Quote_Address_Item)
401
- && $this->_isConfigurable($item)
402
- ) {
403
- $children = $item->getChildren();
404
- if (isset($children[0]) && $children[0]->getProductId()) {
405
- return $children[0]->getProductId();
406
- }
407
- }
408
-
409
- if (($item instanceof Mage_Sales_Model_Order_Invoice_Item
410
- || $item instanceof Mage_Sales_Model_Order_Creditmemo_Item)
411
- && $this->_isConfigurable($item)
412
- ) {
413
- $children = $item->getOrderItem()->getChildrenItems();
414
- if (isset($children[0]) && $children[0]->getProductId()) {
415
- return $children[0]->getProductId();
416
- }
417
- }
418
-
419
- return 0;
420
- }
421
-
422
- /**
423
- * Checks if item is configurable
424
- *
425
- * @param Mage_Sales_Model_Quote_Address_Item|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Creditmemo_Item|Mage_Sales_Model_Order_Invoice_Item $item
426
- * @return bool
427
- */
428
- protected function _isConfigurable($item)
429
- {
430
- if ($item instanceof Mage_Sales_Model_Quote_Item) {
431
- return $item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
432
- }
433
-
434
- if ($item instanceof Mage_Sales_Model_Quote_Address_Item) {
435
- return $item->getProduct()->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
436
- }
437
-
438
- if (($item instanceof Mage_Sales_Model_Order_Invoice_Item
439
- || $item instanceof Mage_Sales_Model_Order_Creditmemo_Item)
440
- ) {
441
- return $item->getOrderItem()->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
442
- }
443
-
444
- return false;
445
- }
446
-
447
  /**
448
  * Init tax class collection for items to be calculated
449
  *
@@ -541,15 +427,16 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
541
  * Get proper ref value for given product
542
  *
543
  * @param Mage_Catalog_Model_Product $product
544
- * @param int $refNumber
545
- * @param int $storeId
546
- * @return string
547
  */
548
  protected function _getRefValueByProductAndNumber($product, $refNumber, $storeId)
549
  {
 
550
  $helperMethod = 'getRef' . $refNumber . 'AttributeCode';
551
- $refCode = Mage::helper('avatax')->{$helperMethod}($storeId);
552
- $value = $this->_getProductAttributeValue($product, $refCode);
553
 
554
  return $value;
555
  }
@@ -574,8 +461,6 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
574
  /**
575
  * Get gift wrapping data helper
576
  *
577
- * Pay Attention! This helper exists only in Magento Enterprise edition
578
- *
579
  * @return \Enterprise_GiftWrapping_Helper_Data
580
  */
581
  protected function _getGiftWrappingDataHelper()
@@ -609,63 +494,22 @@ abstract class OnePica_AvaTax_Model_Avatax_Abstract extends OnePica_AvaTax_Model
609
  }
610
 
611
  /**
612
- * Get product attribute value
613
  *
614
- * @param Mage_Catalog_Model_Product $product
615
- * @param string $code
616
- * @return string
617
- */
618
- protected function _getProductAttributeValue($product, $code)
619
- {
620
- $value = '';
621
- if ($code && $product->getResource()->getAttribute($code)) {
622
- try {
623
- $value = (string)$product->getResource()
624
- ->getAttribute($code)
625
- ->getFrontend()
626
- ->getValue($product);
627
- } catch (Exception $e) {
628
- Mage::logException($e);
629
- }
630
- }
631
- return $value;
632
- }
633
-
634
- /**
635
- * Get UPC code from product
636
- *
637
- * @param Mage_Catalog_Model_Product $product
638
- * @param int|Mage_Core_Model_Store $storeId
639
- * @return string
640
- */
641
- protected function _getUpcCode($product, $storeId)
642
- {
643
- $upc = $this->_getProductAttributeValue(
644
- $product,
645
- $this->_getUpcAttributeCode($storeId)
646
- );
647
-
648
- return !empty($upc) ? 'UPC:' . $upc : '';
649
- }
650
-
651
- /**
652
- * Get UPC attribute code
653
- *
654
- * @param int|Mage_Core_Model_Store $storeId
655
- * @return string
656
  */
657
- protected function _getUpcAttributeCode($storeId)
658
  {
659
- return $this->_getDataHelper()->getUpcAttributeCode($storeId);
660
  }
661
 
662
  /**
663
- * Get data helper
664
  *
665
- * @return OnePica_AvaTax_Helper_Data
666
  */
667
- protected function _getDataHelper()
668
  {
669
- return Mage::helper('avatax');
670
  }
671
  }
16
  */
17
 
18
  /**
19
+ * Avatax service abstract model
20
+ *
21
+ * @method getService() OnePica_AvaTax_Model_Service_Avatax
22
  *
23
  * @category OnePica
24
  * @package OnePica_AvaTax
25
  * @author OnePica Codemaster <codemaster@onepica.com>
26
  */
27
+ abstract class OnePica_AvaTax_Model_Service_Avatax_Abstract extends OnePica_AvaTax_Model_Service_Abstract_Tools
28
  {
29
+ /**
30
+ * Avatax cache tag
31
+ */
32
+ const AVATAX_SERVICE_CACHE_GROUP = 'avatax_cache_tags';
33
+
34
+ /**
35
+ * Avatax cache tag
36
+ */
37
+ const AVATAX_CACHE_GROUP = 'avatax';
38
+
39
  /**
40
  * Flag that states if there was an error
41
  *
64
  */
65
  protected $_taxClassCollection = null;
66
 
67
+ /**
68
+ * The module helper
69
+ *
70
+ * @var OnePica_AvaTax_Helper_Data
71
+ */
72
+ protected $_helper = null;
73
+
74
+ /**
75
+ * The module address helper
76
+ *
77
+ * @var OnePica_AvaTax_Helper_Address
78
+ */
79
+ protected $_getAddressHelper = null;
80
+
81
+ /**
82
+ * The module config helper
83
+ *
84
+ * @var OnePica_AvaTax_Helper_Config
85
+ */
86
+ protected $_getConfigHelper = null;
87
+
88
+ /**
89
+ * The module config helper
90
+ *
91
+ * @var OnePica_AvaTax_Model_Service_Avatax_Invoice
92
+ */
93
+ protected $_errorsHelper = null;
94
+
95
+ /**
96
+ * The module config helper
97
+ *
98
+ * @var OnePica_AvaTax_Model_Service_Avatax_Tax
99
+ */
100
+ protected $_libHelper = null;
101
+
102
+ /**
103
+ * Model cache tag for clear cache in after save and after delete
104
+ */
105
+ protected $_cacheTag = self::AVATAX_SERVICE_CACHE_GROUP;
106
+
107
+ /**
108
+ * Logs a debug message
109
+ *
110
+ * @param string $type
111
+ * @param string $request the request string
112
+ * @param string $result the result string
113
+ * @param int $storeId id of the store the call is make for
114
+ * @param mixed $additional any other info
115
+ * @return $this
116
+ */
117
+ protected function _log($type, $request, $result, $storeId = null, $additional = null)
118
+ {
119
+ if ($result->getResultCode() == SeverityLevel::$Success) {
120
+ switch ($this->_getHelper()->getLogMode($storeId)) {
121
+ case OnePica_AvaTax_Model_Source_Logmode::ERRORS:
122
+ return $this;
123
+ break;
124
+ case OnePica_AvaTax_Model_Source_Logmode::NORMAL:
125
+ $additional = null;
126
+ break;
127
+ }
128
+ }
129
+
130
+ if (in_array($type, $this->_getHelper()->getLogType($storeId))) {
131
+ Mage::getModel('avatax_records/log')
132
+ ->setStoreId($storeId)
133
+ ->setLevel($result->getResultCode())
134
+ ->setType($type)
135
+ ->setRequest(print_r($request, true))
136
+ ->setResult(print_r($result, true))
137
+ ->setAdditional($additional)
138
+ ->save();
139
+ }
140
+ return $this;
141
+ }
142
+
143
+ /**
144
+ * Returns the AvaTax session.
145
+ *
146
+ * @return OnePica_AvaTax_Model_Session
147
+ */
148
+ public function getSession()
149
+ {
150
+ return Mage::getSingleton('avatax/session');
151
+ }
152
+
153
  /**
154
  * Sets the company code on the request
155
  *
158
  */
159
  protected function _setCompanyCode($storeId = null)
160
  {
161
+ $config = Mage::getSingleton('avatax/service_avatax_config');
162
  $this->_request->setCompanyCode($config->getCompanyCode($storeId));
163
  return $this;
164
  }
202
  return (int)$this->_getGiftWrappingDataHelper()->getWrappingTaxClass($storeId);
203
  }
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  /**
206
  * Adds additional transaction based data
207
  *
214
  $this->_setCompanyCode($storeId);
215
  $this->_request->setBusinessIdentificationNo($this->_getVatId($object));
216
  $this->_request->setDetailLevel(DetailLevel::$Document);
217
+ $this->_request->setDocDate($this->_convertGmtDate(Varien_Date::now(), $storeId));
218
  $this->_request->setExemptionNo('');
219
  $this->_request->setDiscount(0.00); //cannot be used in Magento
220
+ $this->_request->setSalespersonCode($this->_getConfigHelper()->getSalesPersonCode($storeId));
221
+ $this->_request->setLocationCode($this->_getConfigHelper()->getLocationCode($storeId));
222
+ $this->_request->setCountry($this->_getConfigHelper()->getShippingOriginCountryId($storeId));
223
  $this->_request->setCurrencyCode(Mage::app()->getStore($storeId)->getBaseCurrencyCode());
224
  $this->_addCustomer($object);
225
  if ($object instanceof Mage_Sales_Model_Order && $object->getIncrementId()) {
228
  return $this;
229
  }
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  /**
232
  * Sets the customer info if available
233
  *
234
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address|Mage_Sales_Model_Order $object
235
  * @return $this
236
  */
237
  protected function _addCustomer($object)
238
  {
239
+ $this->_request->setCustomerUsageType($this->_getCalculationHelper()->getCustomerOpAvataxCode($object));
240
+ $this->_request->setCustomerCode($this->_getCalculationHelper()->getCustomerCode($object));
 
 
 
 
 
 
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  return $this;
243
  }
244
 
270
  {
271
  $street1 = $address->getStreet(1);
272
  $street2 = $address->getStreet(2);
273
+ $city = (string)$address->getCity();
274
  $zip = $address->getPostcode();
275
  $state = Mage::getModel('directory/region')->load($address->getRegionId())->getCode();
276
  $country = $address->getCountry();
306
  return $address;
307
  }
308
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  /**
310
  * Init product collection for items to be calculated
311
  *
318
  foreach ($items as $item) {
319
  if (!$this->isProductCalculated($item)) {
320
  $productIds[] = $item->getProductId();
321
+ $simpleProductId = $this->_getCalculationHelper()->getSimpleProductIdByConfigurable($item);
322
  if ($simpleProductId) {
323
  $productIds[] = $simpleProductId;
324
  }
325
  }
326
  }
 
327
  $this->_productCollection = Mage::getModel('catalog/product')->getCollection()
328
  ->addAttributeToSelect('*')
329
  ->addAttributeToFilter('entity_id', array('in' => $productIds));
 
330
  return $this;
331
  }
332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  /**
334
  * Init tax class collection for items to be calculated
335
  *
427
  * Get proper ref value for given product
428
  *
429
  * @param Mage_Catalog_Model_Product $product
430
+ * @param int $refNumber
431
+ * @param int $storeId
432
+ * @return null|string
433
  */
434
  protected function _getRefValueByProductAndNumber($product, $refNumber, $storeId)
435
  {
436
+ $value = null;
437
  $helperMethod = 'getRef' . $refNumber . 'AttributeCode';
438
+ $code = $this->_getConfigHelper()->{$helperMethod}($storeId);
439
+ $value = $this->_getCalculationHelper()->getProductAttributeValue($product, $code);
440
 
441
  return $value;
442
  }
461
  /**
462
  * Get gift wrapping data helper
463
  *
 
 
464
  * @return \Enterprise_GiftWrapping_Helper_Data
465
  */
466
  protected function _getGiftWrappingDataHelper()
494
  }
495
 
496
  /**
497
+ * Retrieve application instance
498
  *
499
+ * @return Mage_Core_Model_App
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
  */
501
+ protected function _getApp()
502
  {
503
+ return Mage::app();
504
  }
505
 
506
  /**
507
+ * Get calculation helper
508
  *
509
+ * @return \OnePica_AvaTax_Helper_Calculation
510
  */
511
+ protected function _getCalculationHelper()
512
  {
513
+ return Mage::helper('avatax/calculation');
514
  }
515
  }
app/code/community/OnePica/AvaTax/Model/Service/Avatax/Address.php ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Class OnePica_AvaTax_Model_Service_Avatax_Address
20
+ *
21
+ * @method OnePica_AvaTax_Model_Service_Avatax_Config getServiceConfig()
22
+ * @method setServiceConfig(OnePica_AvaTax_Model_Service_Avatax_Config $serviceConfig)
23
+ *
24
+ * @category OnePica
25
+ * @package OnePica_AvaTax
26
+ * @author OnePica Codemaster <codemaster@onepica.com>
27
+ */
28
+ class OnePica_AvaTax_Model_Service_Avatax_Address extends OnePica_AvaTax_Model_Service_Avatax_Abstract
29
+ {
30
+ /**
31
+ * An array of previously checked addresses
32
+ * Example: $_cache[$key] = serialize($resultObjectFromAvalara)
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_cache = array();
37
+
38
+ /**
39
+ * The Mage Address object
40
+ *
41
+ * @var Mage_Customer_Model_Address_Abstract
42
+ */
43
+ protected $_mageAddress = null;
44
+
45
+ /**
46
+ * The AvaTax Request Address object.
47
+ * This is a Ava address copy of the Mage address attributes.
48
+ *
49
+ * @var Address
50
+ */
51
+ protected $_requestAddress = null;
52
+
53
+ /**
54
+ * The AvaTax Response (Normalized) Address object.
55
+ * This is the normalized Ava address returned by the validation request.
56
+ *
57
+ * @var ValidAddress
58
+ */
59
+ protected $_responseAddress = null;
60
+
61
+ /**
62
+ * Saves the store id
63
+ *
64
+ * @var int
65
+ */
66
+ protected $_storeId = null;
67
+
68
+ /**
69
+ * Loads any saved addresses in session
70
+ *
71
+ * @param array $data
72
+ */
73
+ public function __construct($data)
74
+ {
75
+ $addresses = Mage::getSingleton('avatax/session')->getAddresses();
76
+ if (is_array($addresses)) {
77
+ $this->_cache = $addresses;
78
+ }
79
+ if (isset($data['service_config'])) {
80
+ $this->setServiceConfig($data['service_config']);
81
+ }
82
+ parent::_construct();
83
+ }
84
+
85
+ /**
86
+ * Saves any current addresses to session
87
+ */
88
+ public function __destruct()
89
+ {
90
+ Mage::getSingleton('avatax/session')->setAddresses($this->_cache);
91
+
92
+ if (method_exists(get_parent_class(), '__destruct')) {
93
+ parent::__destruct();
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Sets the Mage address.
99
+ *
100
+ * @param Mage_Sales_Model_Quote_Address $address
101
+ * @return $this
102
+ */
103
+ public function setAddress(Mage_Sales_Model_Quote_Address $address)
104
+ {
105
+ $this->_storeId = $address->getQuote()->getStoreId();
106
+ $this->_mageAddress = $address;
107
+ $this->_convertRequestAddress();
108
+
109
+ return $this;
110
+ }
111
+
112
+ /**
113
+ * Get Mage Address
114
+ *
115
+ * @return Mage_Sales_Model_Quote_Address
116
+ */
117
+ public function getMageAddress()
118
+ {
119
+ return $this->_mageAddress;
120
+ }
121
+
122
+ /**
123
+ * Get request address object
124
+ *
125
+ * @return Address
126
+ */
127
+ public function getLocationAddressObject()
128
+ {
129
+ if (null === $this->_requestAddress) {
130
+ $this->_requestAddress = new Address();
131
+ }
132
+
133
+ return $this->_requestAddress;
134
+ }
135
+
136
+ /**
137
+ * Sets attributes from the Mage address on the AvaTax Request address.
138
+ *
139
+ * @return $this
140
+ */
141
+ protected function _convertRequestAddress()
142
+ {
143
+ $this->getLocationAddressObject()->setLine1($this->getMageAddress()->getStreet(1));
144
+ $this->getLocationAddressObject()->setLine2($this->getMageAddress()->getStreet(2));
145
+ $this->getLocationAddressObject()->setCity($this->getMageAddress()->getCity());
146
+ $this->getLocationAddressObject()->setRegion($this->getMageAddress()->getRegionCode());
147
+ $this->getLocationAddressObject()->setCountry($this->getMageAddress()->getCountry());
148
+ $this->getLocationAddressObject()->setPostalCode($this->getMageAddress()->getPostcode());
149
+
150
+ return $this;
151
+ }
152
+
153
+ /**
154
+ * Validates the address with the AvaTax validation API.
155
+ * Returns true on success and an array with an error on failure.
156
+ *
157
+ * @param Mage_Sales_Model_Quote_Address $address
158
+ * @return OnePica_AvaTax_Model_Service_Result_AddressValidate $addressValidationResult
159
+ * @throws OnePica_AvaTax_Model_Service_Exception_Address
160
+ */
161
+ public function validate($address)
162
+ {
163
+ $this->setAddress($address);
164
+ if (!$this->getMageAddress()) {
165
+ throw new OnePica_AvaTax_Model_Service_Exception_Address(
166
+ $this->__('An address must be set before validation.')
167
+ );
168
+ }
169
+
170
+ //lookup in AvaTax (with caching)
171
+ $key = $this->getMageAddress()->getCacheHashKey();
172
+
173
+ if (array_key_exists($key, $this->_cache)) {
174
+ $result = unserialize($this->_cache[$key]);
175
+ } else {
176
+ $result = $this->_sendAddressValidationRequest();
177
+ $this->_cache[$key] = serialize($result);
178
+ }
179
+ /** @var OnePica_AvaTax_Model_Service_Result_AddressValidate $addressValidationResult */
180
+ $addressValidationResult = Mage::getModel('avatax/service_result_addressValidate');
181
+ if ($result instanceof ValidateResult) {
182
+ $hasError = $result->getResultCode() === SeverityLevel::$Error;
183
+ $addressValidationResult->setHasError($hasError);
184
+ if ($hasError) {
185
+ $errors = $result->getMessages();
186
+ if ($addressValidationResult->getHasError() && is_array($errors) && isset($errors[0])) {
187
+ $convertErrors = array();
188
+ foreach ($errors as $element) {
189
+ $convertErrors[] = $element->getSummary();
190
+ }
191
+ $addressValidationResult->setErrors($convertErrors);
192
+ }
193
+ }
194
+ $address = $result->getValidAddresses();
195
+ if (is_array($address) && isset($address[0]) && $address[0]) {
196
+ /** @var ValidAddress $address */
197
+ $address = $address[0];
198
+ /** @var OnePica_AvaTax_Model_Service_Result_Address $resultAddress */
199
+ $resultAddress = Mage::getModel('avatax/service_result_address');
200
+ $resultAddress->setLine1($address->getLine1());
201
+ $resultAddress->setLine2($address->getLine2());
202
+ $resultAddress->setCity($address->getCity());
203
+ $resultAddress->setState($address->getRegion());
204
+ $resultAddress->setPostalCode($address->getPostalCode());
205
+ $resultAddress->setCountry($address->getCountry());
206
+
207
+ $addressValidationResult->setAddress($resultAddress);
208
+ }
209
+ /** Set is success */
210
+ $addressValidationResult->setResolution($result->getResultCode() == SeverityLevel::$Success);
211
+ $addressValidationResult->setIsTaxable($result->isTaxable());
212
+ } else {
213
+ unset($this->_cache[$key]);
214
+ $addressValidationResult->setHasError(true);
215
+ $addressValidationResult->setResolution(false);
216
+ $addressValidationResult->setIsTaxable(false);
217
+ $addressValidationResult->setErrors(
218
+ array(
219
+ $this->_getConfigHelper()->getErrorFrontendMessage($this->_storeId)
220
+ )
221
+ );
222
+ }
223
+
224
+ return $addressValidationResult;
225
+ }
226
+
227
+ /**
228
+ * Validate address
229
+ *
230
+ * @return ValidateResult
231
+ */
232
+ protected function _sendAddressValidationRequest()
233
+ {
234
+ /** @var AddressServiceSoap $client */
235
+ $client = $this->getServiceConfig()->getAddressConnection();
236
+ $request = $this->_getAddressValidationRequest();
237
+ $request->setTaxability(true);
238
+ try {
239
+ $result = $client->Validate($request);
240
+ } catch (Exception $e) {
241
+ $result = $this->_convertExceptionToResult($e);
242
+ }
243
+ $this->_log(
244
+ OnePica_AvaTax_Model_Source_Avatax_Logtype::VALIDATE,
245
+ $request,
246
+ $result,
247
+ $this->_storeId,
248
+ $this->getServiceConfig()->getParams()
249
+ );
250
+
251
+ return $result;
252
+ }
253
+
254
+ /**
255
+ * Get validation request
256
+ *
257
+ * @return ValidateRequest
258
+ */
259
+ private function _getAddressValidationRequest()
260
+ {
261
+ return new ValidateRequest($this->getLocationAddressObject(), TextCase::$Mixed, 0);
262
+ }
263
+
264
+ /**
265
+ * Address normalization
266
+ *
267
+ * @param bool $isAddressNormalizationOn
268
+ * @param ValidateResult $result
269
+ * @return $this
270
+ * @throws OnePica_AvaTax_Model_Service_Exception_Address
271
+ */
272
+ protected function _addressNormalization($isAddressNormalizationOn, $result)
273
+ {
274
+ if ($isAddressNormalizationOn && $result->getResultCode() == SeverityLevel::$Success) {
275
+ $responseAddress = $result->getValidAddresses();
276
+ $responseAddress = array_pop($responseAddress);
277
+ if ($responseAddress instanceof ValidAddress) {
278
+ $this->_responseAddress = $responseAddress;
279
+ $this->_convertResponseAddress();
280
+ } else {
281
+ throw new OnePica_AvaTax_Model_Service_Exception_Address($this->__('Invalid response address type.'));
282
+ }
283
+ }
284
+
285
+ return $this;
286
+ }
287
+
288
+ /**
289
+ * Convert exception to result
290
+ *
291
+ * @param Exception $e
292
+ * @return Varien_Object
293
+ */
294
+ protected function _convertExceptionToResult($e)
295
+ {
296
+ $result = new Varien_Object();
297
+ $result->setResultCode(SeverityLevel::$Exception)->setError($e->getMessage());
298
+
299
+ return $result;
300
+ }
301
+ }
app/code/community/OnePica/AvaTax/Model/Service/Avatax/Config.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The AvaTax Config Model, which registers config settings with the AvaTax SDK
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Service_Avatax_Config extends OnePica_AvaTax_Model_Service_Abstract_Config
26
+ {
27
+ /**
28
+ * The AvaTax TaxServiceSoap object.
29
+ *
30
+ * @var TaxServiceSoap
31
+ */
32
+ protected $_taxConnection = null;
33
+
34
+ /**
35
+ * The AvaTax AddressServiceSoap object.
36
+ *
37
+ * @var AddressServiceSoap
38
+ */
39
+ protected $_addressConnection = null;
40
+
41
+ /**
42
+ * Initializes the AvaTax SDK with connection settings found in the Admin config.
43
+ *
44
+ * @param int $storeId
45
+ * @return OnePica_AvaTax_Model_Config
46
+ */
47
+ public function init($storeId)
48
+ {
49
+ if (null === $this->_config) {
50
+ $this->_config = new ATConfig(
51
+ self::CONFIG_KEY,
52
+ array(
53
+ 'url' => Mage::helper('avatax/config')->getServiceUrl($storeId),
54
+ 'account' => Mage::helper('avatax/config')->getServiceAccountId($storeId),
55
+ 'license' => Mage::helper('avatax/config')->getServiceKey($storeId),
56
+ 'trace' => (Mage::helper('avatax')
57
+ ->getLogMode($storeId) == OnePica_AvaTax_Model_Source_Logmode::DEBUG) ? true : false,
58
+ 'client' => $this->getClientName()
59
+ )
60
+ );
61
+ }
62
+
63
+ return $this;
64
+ }
65
+
66
+ /**
67
+ * Get client name to pass with communications
68
+ *
69
+ * @example Magento,1.4,.0.1,OP_AvaTax by One Pica,2,0.1
70
+ * @return string
71
+ */
72
+ public function getClientName()
73
+ {
74
+ return $this->_getHelper()->getClientName();
75
+ }
76
+
77
+ /**
78
+ * Returns the AvaTax Address soap connection client.
79
+ *
80
+ * @return AddressServiceSoap
81
+ */
82
+ public function getAddressConnection()
83
+ {
84
+ if (null === $this->_addressConnection) {
85
+ $this->_addressConnection = new AddressServiceSoap(self::CONFIG_KEY);
86
+ }
87
+ return $this->_addressConnection;
88
+ }
89
+
90
+ /**
91
+ * Returns the AvaTax Address soap connection client.
92
+ *
93
+ * @return AddressServiceSoap
94
+ */
95
+ public function getTaxConnection()
96
+ {
97
+ if (null === $this->_taxConnection) {
98
+ $this->_taxConnection = new TaxServiceSoap(self::CONFIG_KEY);
99
+ }
100
+ return $this->_taxConnection;
101
+ }
102
+
103
+ /**
104
+ * Returns true if the admin is configured to normalize addresses.
105
+ *
106
+ * @return boolean
107
+ */
108
+ public function normalizeAddress()
109
+ {
110
+ return Mage::helper('avatax/config')->getNormalizeAddress(Mage::app()->getStore());
111
+ }
112
+
113
+ /**
114
+ * Returns the company code to use from the AvaTax dashboard
115
+ *
116
+ * @param null|bool|int|Mage_Core_Model_Store $store
117
+ * @return string
118
+ */
119
+ public function getCompanyCode($store = null)
120
+ {
121
+ return Mage::helper('avatax/config')->getCompanyCode($store);
122
+ }
123
+ }
app/code/community/OnePica/AvaTax/Model/{Avatax → Service/Avatax}/Estimate.php RENAMED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  /**
4
  * OnePica_AvaTax
5
  *
@@ -12,18 +11,19 @@
12
  * @category OnePica
13
  * @package OnePica_AvaTax
14
  * @author OnePica Codemaster <codemaster@onepica.com>
15
- * @copyright Copyright (c) 2009 One Pica, Inc.
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
  /**
20
- * The AvaTax Address Estimate model
21
  *
22
  * @category OnePica
23
  * @package OnePica_AvaTax
24
  * @author OnePica Codemaster <codemaster@onepica.com>
25
  */
26
- class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_Abstract
 
27
  {
28
  /**
29
  * Length of time in minutes for cached rates
@@ -72,6 +72,13 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
72
  */
73
  protected $_productGiftPair = array();
74
 
 
 
 
 
 
 
 
75
  /**
76
  * Loads any saved rates in session
77
  */
@@ -90,106 +97,19 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
90
  }
91
 
92
  /**
93
- * Estimates tax rate for one item.
94
- *
95
- * @param Mage_Sales_Model_Quote_Item $item
96
- * @return int
97
- */
98
- public function getItemRate($item)
99
- {
100
- if ($this->isProductCalculated($item)) {
101
- return 0;
102
- } else {
103
- $key = $this->_getRates($item);
104
- $id = $item->getSku();
105
- return isset($this->_rates[$key]['items'][$id]['rate']) ? $this->_rates[$key]['items'][$id]['rate'] : 0;
106
- }
107
- }
108
-
109
- /**
110
- * Get item tax
111
- *
112
- * @param Mage_Sales_Model_Quote_Item $item
113
- * @return int
114
- */
115
- public function getItemGiftTax($item)
116
- {
117
- if ($item->getParentItemId()) {
118
- return 0;
119
- }
120
- $key = $this->_getRates($item);
121
- $id = $item->getSku();
122
- return isset($this->_rates[$key]['gw_items'][$id]['amt']) ? $this->_rates[$key]['gw_items'][$id]['amt'] : 0;
123
- }
124
-
125
- /**
126
- * Estimates tax amount for one item. Does not trigger a call if the shipping
127
- * address has no postal code, or if the postal code is set to "-" (OneStepCheckout)
128
  *
129
- * @param Mage_Sales_Model_Quote_Item $item
130
- * @return int
131
- */
132
- public function getItemTax($item)
133
- {
134
- if ($item->getAddress()->getPostcode() && $item->getAddress()->getPostcode() != '-') {
135
- if ($this->isProductCalculated($item)) {
136
- $tax = 0;
137
- foreach ($item->getChildren() as $child) {
138
- $child->setAddress($item->getAddress());
139
- $tax += $this->getItemTax($child);
140
- }
141
- return $tax;
142
- } else {
143
- $key = $this->_getRates($item);
144
- $id = $item->getSku();
145
- return isset($this->_rates[$key]['items'][$id]['amt']) ? $this->_rates[$key]['items'][$id]['amt'] : 0;
146
- }
147
- }
148
- return 0;
149
- }
150
-
151
- /**
152
- * Get tax detail summary
153
  *
154
- * @param int|null $addressId
155
  * @return array
156
  */
157
- public function getSummary($addressId = null)
158
- {
159
- $summary = null;
160
-
161
- if ($addressId) {
162
- $timestamp = 0;
163
- foreach ($this->_rates as $row) {
164
- if (isset($row['address_id']) && $row['address_id'] == $addressId && $row['timestamp'] > $timestamp) {
165
- $summary = $row['summary'];
166
- $timestamp = $row['timestamp'];
167
- }
168
- }
169
- }
170
-
171
- if ($summary === null) {
172
- $requestKey = Mage::getSingleton('avatax/session')->getLastRequestKey();
173
- $summary = isset($this->_rates[$requestKey]['summary']) ? $this->_rates[$requestKey]['summary'] : array();
174
- }
175
-
176
- return $summary;
177
- }
178
-
179
- /**
180
- * Get rates from Avalara
181
- *
182
- * @param Mage_Sales_Model_Quote_Item $item
183
- * @return string
184
- */
185
- protected function _getRates($item)
186
  {
187
  if (self::$_hasError) {
188
- return 'error';
189
  }
190
 
191
  /** @var OnePica_AvaTax_Model_Sales_Quote_Address $address */
192
- $address = $item->getAddress();
193
  $this->_lines = array();
194
 
195
  //set up request
@@ -201,7 +121,7 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
201
  $this->_setOriginAddress($quote->getStoreId());
202
  $this->_setDestinationAddress($address);
203
  $this->_request->setDetailLevel(DetailLevel::$Line);
204
- $this->_addItemsInCart($item);
205
  $this->_addShipping($address);
206
  //Added code for calculating tax for giftwrap items
207
  $this->_addGwOrderAmount($address);
@@ -247,19 +167,16 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
247
  'amt' => $row->getTax()
248
  );
249
  }
250
- //failure
251
  } else {
252
  $this->_rates[$requestKey]['failure'] = true;
253
- if (Mage::helper('avatax')->fullStopOnError($address->getStoreId())) {
254
- $address->getQuote()->setHasError(true);
255
- }
256
  }
257
 
258
  Mage::getSingleton('avatax/session')->setRates($this->_rates);
259
  }
260
 
261
- //return $requestKey so it doesn't have to be calculated again
262
- return $requestKey;
263
  }
264
 
265
  /**
@@ -270,10 +187,30 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
270
  protected function _genRequestKey()
271
  {
272
  $hash = sprintf("%u", crc32(serialize($this->_request)));
273
- Mage::getSingleton('avatax/session')->setLastRequestKey($hash);
274
  return $hash;
275
  }
276
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
  /**
278
  * Adds shipping cost to request as item
279
  *
@@ -289,7 +226,7 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
289
 
290
  $line = new Line();
291
  $line->setNo($lineNumber);
292
- $shippingSku = Mage::helper('avatax')->getShippingSku($storeId);
293
  $line->setItemCode($shippingSku ? $shippingSku : 'Shipping');
294
  $line->setDescription('Shipping costs');
295
  $line->setTaxCode($taxClass);
@@ -299,7 +236,7 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
299
 
300
  $this->_lines[$lineNumber] = $line;
301
  $this->_request->setLines($this->_lines);
302
- $this->_lineToLineId[$lineNumber] = Mage::helper('avatax')->getShippingSku($storeId);
303
  return $lineNumber;
304
  }
305
 
@@ -321,7 +258,7 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
321
 
322
  $line = new Line();
323
  $line->setNo($lineNumber);
324
- $gwOrderSku = Mage::helper('avatax')->getGwOrderSku($storeId);
325
  $line->setItemCode($gwOrderSku ? $gwOrderSku : 'GwOrderAmount');
326
  $line->setDescription('Gift Wrap Order Amount');
327
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
@@ -331,7 +268,7 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
331
 
332
  $this->_lines[$lineNumber] = $line;
333
  $this->_request->setLines($this->_lines);
334
- $this->_lineToLineId[$lineNumber] = Mage::helper('avatax')->getGwOrderSku($storeId);
335
  return $lineNumber;
336
  }
337
 
@@ -353,7 +290,7 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
353
 
354
  $line = new Line();
355
  $line->setNo($lineNumber);
356
- $gwItemsSku = Mage::helper('avatax')->getGwItemsSku($storeId);
357
  $line->setItemCode($gwItemsSku ? $gwItemsSku : 'GwItemsAmount');
358
  $line->setDescription('Gift Wrap Items Amount');
359
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
@@ -363,13 +300,13 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
363
 
364
  $this->_lines[$lineNumber] = $line;
365
  $this->_request->setLines($this->_lines);
366
- $this->_lineToLineId[$lineNumber] = Mage::helper('avatax')->getGwItemsSku($storeId);
367
  $this->_productGiftPair[$lineNumber] = $item->getSku();
368
 
369
  return $lineNumber;
370
  }
371
 
372
- /**
373
  * Adds giftwrap printed card cost to request as item
374
  *
375
  * @param Mage_Sales_Model_Quote
@@ -387,7 +324,7 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
387
 
388
  $line = new Line();
389
  $line->setNo($lineNumber);
390
- $gwPrintedCardSku = Mage::helper('avatax')->getGwPrintedCardSku($storeId);
391
  $line->setItemCode($gwPrintedCardSku ? $gwPrintedCardSku : 'GwPrintedCardAmount');
392
  $line->setDescription('Gift Wrap Printed Card Amount');
393
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
@@ -397,29 +334,22 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
397
 
398
  $this->_lines[$lineNumber] = $line;
399
  $this->_request->setLines($this->_lines);
400
- $this->_lineToLineId[$lineNumber] = Mage::helper('avatax')->getGwPrintedCardSku($storeId);
401
  return $lineNumber;
402
  }
403
 
404
  /**
405
  * Adds all items in the cart to the request
406
  *
407
- * @param Mage_Sales_Model_Quote_Item $item
408
  * @return int
409
  */
410
- protected function _addItemsInCart($item)
411
  {
412
- if ($item->getAddress() instanceof Mage_Sales_Model_Quote_Address) {
413
- $items = $item->getAddress()->getAllItems();
414
- } elseif ($item->getQuote() instanceof Mage_Sales_Model_Quote) {
415
- $items = $item->getQuote()->getAllItems();
416
- } else {
417
- $items = array();
418
- }
419
-
420
  if (count($items) > 0) {
421
  $this->_initProductCollection($items);
422
- $this->_initTaxClassCollection($item->getAddress());
423
  foreach ($items as $item) {
424
  /** @var Mage_Sales_Model_Quote_Item $item */
425
  $this->_newLine($item);
@@ -448,11 +378,16 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
448
  $lineNumber = count($this->_lines);
449
  $line = new Line();
450
  $line->setNo($lineNumber);
451
- $line->setItemCode($this->_getItemCode($this->_getProductForItemCode($item), $item->getStoreId()));
452
- $line->setDescription($product->getName());
 
 
 
 
 
453
  $line->setQty($item->getQty());
454
  $line->setAmount($price);
455
- $line->setDiscounted($item->getDiscountAmount() ? true : false);
456
 
457
  if ($taxClass) {
458
  $line->setTaxCode($taxClass);
@@ -476,11 +411,12 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
476
  *
477
  * @param Mage_Sales_Model_Quote_Address_Item|Mage_Sales_Model_Quote_Item $item
478
  * @return null|Mage_Catalog_Model_Product
 
479
  */
480
  protected function _getProductForItemCode($item)
481
  {
482
  $product = $this->_getProductByProductId($item->getProductId());
483
- if (!$this->_isConfigurable($item)) {
484
  return $product;
485
  }
486
 
@@ -518,19 +454,29 @@ class OnePica_AvaTax_Model_Avatax_Estimate extends OnePica_AvaTax_Model_Avatax_A
518
  }
519
 
520
  /**
521
- * Get item code
 
 
 
 
 
522
  *
523
- * @param Mage_Catalog_Model_Product $product
524
- * @param int|Mage_Core_Model_Store $storeId
525
- * @return string
526
  */
527
- protected function _getItemCode($product, $storeId)
528
  {
529
- $itemCode = $this->_getUpcCode($product, $storeId);
530
- if (empty($itemCode)) {
531
- $itemCode = $product->getSku();
 
 
 
 
 
532
  }
533
 
534
- return substr($itemCode, 0, 50);
535
  }
536
  }
1
  <?php
 
2
  /**
3
  * OnePica_AvaTax
4
  *
11
  * @category OnePica
12
  * @package OnePica_AvaTax
13
  * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
  */
17
 
18
  /**
19
+ * Class OnePica_AvaTax_Model_Service_Avatax_Estimate
20
  *
21
  * @category OnePica
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
+ class OnePica_AvaTax_Model_Service_Avatax_Estimate
26
+ extends OnePica_AvaTax_Model_Service_Avatax_Tax
27
  {
28
  /**
29
  * Length of time in minutes for cached rates
72
  */
73
  protected $_productGiftPair = array();
74
 
75
+ /**
76
+ * Last request key
77
+ *
78
+ * @var string
79
+ */
80
+ protected $_lastRequestKey;
81
+
82
  /**
83
  * Loads any saved rates in session
84
  */
97
  }
98
 
99
  /**
100
+ * Get rates from Avalara
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  *
102
+ * @param Mage_Sales_Model_Quote_Address $address
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  *
 
104
  * @return array
105
  */
106
+ public function getRates(Mage_Sales_Model_Quote_Address $address)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  {
108
  if (self::$_hasError) {
109
+ return array('failure' => true);
110
  }
111
 
112
  /** @var OnePica_AvaTax_Model_Sales_Quote_Address $address */
 
113
  $this->_lines = array();
114
 
115
  //set up request
121
  $this->_setOriginAddress($quote->getStoreId());
122
  $this->_setDestinationAddress($address);
123
  $this->_request->setDetailLevel(DetailLevel::$Line);
124
+ $this->_addItemsInCart($address);
125
  $this->_addShipping($address);
126
  //Added code for calculating tax for giftwrap items
127
  $this->_addGwOrderAmount($address);
167
  'amt' => $row->getTax()
168
  );
169
  }
170
+ //failure
171
  } else {
172
  $this->_rates[$requestKey]['failure'] = true;
 
 
 
173
  }
174
 
175
  Mage::getSingleton('avatax/session')->setRates($this->_rates);
176
  }
177
 
178
+ $rates = isset($this->_rates[$requestKey]) ? $this->_rates[$requestKey] : array();
179
+ return $rates;
180
  }
181
 
182
  /**
187
  protected function _genRequestKey()
188
  {
189
  $hash = sprintf("%u", crc32(serialize($this->_request)));
190
+ $this->_setLastRequestKey($hash);
191
  return $hash;
192
  }
193
 
194
+ /**
195
+ * Set last request key
196
+ *
197
+ * @param string $requestKey
198
+ */
199
+ protected function _setLastRequestKey($requestKey)
200
+ {
201
+ $this->_lastRequestKey = $requestKey;
202
+ }
203
+
204
+ /**
205
+ * Get last request key
206
+ *
207
+ * @return string|null
208
+ */
209
+ public function getLastRequestKey()
210
+ {
211
+ return $this->_lastRequestKey;
212
+ }
213
+
214
  /**
215
  * Adds shipping cost to request as item
216
  *
226
 
227
  $line = new Line();
228
  $line->setNo($lineNumber);
229
+ $shippingSku = $this->_getConfigHelper()->getShippingSku($storeId);
230
  $line->setItemCode($shippingSku ? $shippingSku : 'Shipping');
231
  $line->setDescription('Shipping costs');
232
  $line->setTaxCode($taxClass);
236
 
237
  $this->_lines[$lineNumber] = $line;
238
  $this->_request->setLines($this->_lines);
239
+ $this->_lineToLineId[$lineNumber] = $this->_getConfigHelper()->getShippingSku($storeId);
240
  return $lineNumber;
241
  }
242
 
258
 
259
  $line = new Line();
260
  $line->setNo($lineNumber);
261
+ $gwOrderSku = $this->_getConfigHelper()->getGwOrderSku($storeId);
262
  $line->setItemCode($gwOrderSku ? $gwOrderSku : 'GwOrderAmount');
263
  $line->setDescription('Gift Wrap Order Amount');
264
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
268
 
269
  $this->_lines[$lineNumber] = $line;
270
  $this->_request->setLines($this->_lines);
271
+ $this->_lineToLineId[$lineNumber] = $this->_getConfigHelper()->getGwOrderSku($storeId);
272
  return $lineNumber;
273
  }
274
 
290
 
291
  $line = new Line();
292
  $line->setNo($lineNumber);
293
+ $gwItemsSku = $this->_getConfigHelper()->getGwItemsSku($storeId);
294
  $line->setItemCode($gwItemsSku ? $gwItemsSku : 'GwItemsAmount');
295
  $line->setDescription('Gift Wrap Items Amount');
296
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
300
 
301
  $this->_lines[$lineNumber] = $line;
302
  $this->_request->setLines($this->_lines);
303
+ $this->_lineToLineId[$lineNumber] = $this->_getConfigHelper()->getGwItemsSku($storeId);
304
  $this->_productGiftPair[$lineNumber] = $item->getSku();
305
 
306
  return $lineNumber;
307
  }
308
 
309
+ /**
310
  * Adds giftwrap printed card cost to request as item
311
  *
312
  * @param Mage_Sales_Model_Quote
324
 
325
  $line = new Line();
326
  $line->setNo($lineNumber);
327
+ $gwPrintedCardSku = $this->_getConfigHelper()->getGwPrintedCardSku($storeId);
328
  $line->setItemCode($gwPrintedCardSku ? $gwPrintedCardSku : 'GwPrintedCardAmount');
329
  $line->setDescription('Gift Wrap Printed Card Amount');
330
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
334
 
335
  $this->_lines[$lineNumber] = $line;
336
  $this->_request->setLines($this->_lines);
337
+ $this->_lineToLineId[$lineNumber] = $this->_getConfigHelper()->getGwPrintedCardSku($storeId);
338
  return $lineNumber;
339
  }
340
 
341
  /**
342
  * Adds all items in the cart to the request
343
  *
344
+ * @param Mage_Sales_Model_Quote_Address $address
345
  * @return int
346
  */
347
+ protected function _addItemsInCart(Mage_Sales_Model_Quote_Address $address)
348
  {
349
+ $items = $address->getAllItems();
 
 
 
 
 
 
 
350
  if (count($items) > 0) {
351
  $this->_initProductCollection($items);
352
+ $this->_initTaxClassCollection($address);
353
  foreach ($items as $item) {
354
  /** @var Mage_Sales_Model_Quote_Item $item */
355
  $this->_newLine($item);
378
  $lineNumber = count($this->_lines);
379
  $line = new Line();
380
  $line->setNo($lineNumber);
381
+ $line->setItemCode(
382
+ $this->_getCalculationHelper()->getItemCode(
383
+ $this->_getProductForItemCode($item),
384
+ $item->getStoreId()
385
+ )
386
+ );
387
+ $line->setDescription($item->getName());
388
  $line->setQty($item->getQty());
389
  $line->setAmount($price);
390
+ $line->setDiscounted((float)$item->getDiscountAmount() ? true : false);
391
 
392
  if ($taxClass) {
393
  $line->setTaxCode($taxClass);
411
  *
412
  * @param Mage_Sales_Model_Quote_Address_Item|Mage_Sales_Model_Quote_Item $item
413
  * @return null|Mage_Catalog_Model_Product
414
+ * @throws OnePica_AvaTax_Exception
415
  */
416
  protected function _getProductForItemCode($item)
417
  {
418
  $product = $this->_getProductByProductId($item->getProductId());
419
+ if (!$this->_getCalculationHelper()->isConfigurable($item)) {
420
  return $product;
421
  }
422
 
454
  }
455
 
456
  /**
457
+ * Get tax detail summary
458
+ * this method is using last request key,
459
+ * so it returns summary of last made estimation.
460
+ * if you are using two calculation simultaneously,
461
+ * be sure to call getRates method for each calculation
462
+ * before calling getSummary
463
  *
464
+ * @param Mage_Sales_Model_Quote_Address $address
465
+ *
466
+ * @return array
467
  */
468
+ public function getSummary($address)
469
  {
470
+ $lastRequestKey = $this->getLastRequestKey();
471
+
472
+ if (isset($lastRequestKey)) {
473
+ $result = isset($this->_rates[$lastRequestKey]['summary'])
474
+ ? $this->_rates[$lastRequestKey]['summary'] : array();
475
+ } else {
476
+ $rates = $this->getRates($address);
477
+ $result = (isset($rates)) ? $rates['summary'] : null;
478
  }
479
 
480
+ return $result;
481
  }
482
  }
app/code/community/OnePica/AvaTax/Model/{Avatax → Service/Avatax}/Invoice.php RENAMED
@@ -16,13 +16,13 @@
16
  */
17
 
18
  /**
19
- * The AvaTax Address Invoice model
20
  *
21
  * @category OnePica
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
- class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Abstract
26
  {
27
  /**
28
  * An array of line items
@@ -41,16 +41,14 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
41
  /**
42
  * Save order in AvaTax system
43
  *
44
- * @see OnePica_AvaTax_Model_Observer::salesOrderPlaceAfter()
45
- * @param Mage_Sales_Model_Order_Invoice $invoice
46
  * @param OnePica_AvaTax_Model_Records_Queue $queue
47
- * @return bool
48
- * @throws OnePica_AvaTax_Exception
49
- * @throws OnePica_AvaTax_Model_Avatax_Exception_Commitfailure
50
- * @throws OnePica_AvaTax_Model_Avatax_Exception_Unbalanced
51
  */
52
  public function invoice($invoice, $queue)
53
  {
 
54
  $order = $invoice->getOrder();
55
  $storeId = $order->getStoreId();
56
  $invoiceDate = $this->_convertGmtDate($invoice->getCreatedAt(), $storeId);
@@ -58,9 +56,6 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
58
  $statusDate = $this->_convertGmtDate($queue->getUpdatedAt(), $storeId);
59
 
60
  $shippingAddress = ($order->getShippingAddress()) ? $order->getShippingAddress() : $order->getBillingAddress();
61
- if (!$shippingAddress) {
62
- throw new OnePica_AvaTax_Exception($this->__('There is no address attached to this order'));
63
- }
64
 
65
  $this->_request = new GetTaxRequest();
66
  $this->_request->setDocCode($invoice->getIncrementId());
@@ -85,7 +80,7 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
85
  $this->_request->setStatusDate($statusDate);
86
 
87
  $configAction = Mage::getStoreConfig('tax/avatax/action', $order->getStoreId());
88
- $commitAction = OnePica_AvaTax_Model_Config::ACTION_CALC_SUBMIT_COMMIT;
89
  $this->_request->setCommit(($configAction == $commitAction) ? true : false);
90
 
91
  foreach ($items as $item) {
@@ -97,42 +92,41 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
97
  //send to AvaTax
98
  $result = $this->_send($order->getStoreId());
99
 
 
 
 
 
 
100
  //if successful
101
- if ($result->getResultCode() == SeverityLevel::$Success) {
102
- $message = Mage::helper('avatax')->__('Invoice #%s was saved to AvaTax', $result->getDocCode());
103
- $this->_addStatusHistoryComment($order, $message);
104
-
105
- if ($result->getTotalTax() != $invoice->getBaseTaxAmount()) {
106
- throw new OnePica_AvaTax_Model_Avatax_Exception_Unbalanced(
107
- 'Collected: '. $invoice->getBaseTaxAmount() . ', Actual: ' . $result->getTotalTax()
108
- );
109
- }
110
 
111
- //if not successful
112
  } else {
113
  $messages = array();
114
  foreach ($result->getMessages() as $message) {
115
  $messages[] = $message->getSummary();
116
  }
117
- throw new OnePica_AvaTax_Model_Avatax_Exception_Commitfailure(implode(' // ', $messages));
118
  }
119
 
120
- return true;
121
  }
122
 
123
  /**
124
  * Save order in AvaTax system
125
  *
126
- * @see OnePica_AvaTax_Model_Observer::salesOrderPlaceAfter()
127
  * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
128
  * @param OnePica_AvaTax_Model_Records_Queue $queue
129
- * @return mixed
130
- * @throws OnePica_AvaTax_Exception
131
- * @throws OnePica_AvaTax_Model_Avatax_Exception_Commitfailure
132
- * @throws OnePica_AvaTax_Model_Avatax_Exception_Unbalanced
133
  */
134
  public function creditmemo($creditmemo, $queue)
135
  {
 
136
  $order = $creditmemo->getOrder();
137
  $storeId = $order->getStoreId();
138
  $orderDate = $this->_convertGmtDate($order->getCreatedAt(), $storeId);
@@ -140,9 +134,6 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
140
  $creditmemoDate = $this->_convertGmtDate($creditmemo->getCreatedAt(), $storeId);
141
 
142
  $shippingAddress = ($order->getShippingAddress()) ? $order->getShippingAddress() : $order->getBillingAddress();
143
- if (!$shippingAddress) {
144
- throw new OnePica_AvaTax_Exception($this->__('There is no address attached to this order'));
145
- }
146
 
147
  $this->_request = new GetTaxRequest();
148
  $this->_request->setDocCode($creditmemo->getIncrementId());
@@ -160,8 +151,8 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
160
  $this->_addGwPrintedCardAmount($creditmemo, true);
161
 
162
  $this->_addAdjustments(
163
- $creditmemo->getAdjustmentPositive(),
164
- $creditmemo->getAdjustmentNegative(),
165
  $order->getStoreId()
166
  );
167
  $this->_setOriginAddress($order->getStoreId());
@@ -180,7 +171,7 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
180
  $this->_request->setStatusDate($statusDate);
181
 
182
  $configAction = Mage::getStoreConfig('tax/avatax/action', $order->getStoreId());
183
- $commitAction = OnePica_AvaTax_Model_Config::ACTION_CALC_SUBMIT_COMMIT;
184
  $this->_request->setCommit(($configAction == $commitAction) ? true : false);
185
 
186
  foreach ($items as $item) {
@@ -192,26 +183,28 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
192
  //send to AvaTax
193
  $result = $this->_send($order->getStoreId());
194
 
 
 
 
 
 
195
  //if successful
196
- if ($result->getResultCode() == SeverityLevel::$Success) {
197
- $message = Mage::helper('avatax')->__('Credit memo #%s was saved to AvaTax', $result->getDocCode());
198
- $this->_addStatusHistoryComment($order, $message);
199
-
200
- if ($result->getTotalTax() != ($creditmemo->getBaseTaxAmount() * -1)) {
201
- throw new OnePica_AvaTax_Model_Avatax_Exception_Unbalanced(
202
- 'Collected: ' . $creditmemo->getTaxAmount() . ', Actual: ' . $result->getTotalTax()
203
- );
204
- }
205
- //if not successful
206
  } else {
207
  $messages = array();
208
  foreach ($result->getMessages() as $message) {
209
  $messages[] = $message->getSummary();
210
  }
211
- throw new OnePica_AvaTax_Model_Avatax_Exception_Commitfailure(implode(' // ', $messages));
212
  }
213
 
214
- return $result;
215
  }
216
 
217
  /**
@@ -240,7 +233,7 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
240
 
241
  $line = new Line();
242
  $line->setNo($lineNumber);
243
- $line->setItemCode(Mage::helper('avatax')->getShippingSku($storeId));
244
  $line->setDescription('Shipping costs');
245
  $line->setTaxCode($taxClass);
246
  $line->setQty(1);
@@ -277,14 +270,14 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
277
 
278
  $line = new Line();
279
  $line->setNo($lineNumber);
280
- $line->setItemCode(Mage::helper('avatax')->getGwOrderSku($storeId));
281
  $line->setDescription('Gift Wrap Order Amount');
282
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
283
  $line->setQty(1);
284
  $line->setAmount($amount);
285
  $line->setDiscounted(false);
286
 
287
- $this->_lineToItemId[$lineNumber] = Mage::helper('avatax')->getGwOrderSku($storeId);
288
  $this->_lines[$lineNumber] = $line;
289
  $this->_request->setLines($this->_lines);
290
  return $lineNumber;
@@ -315,14 +308,14 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
315
 
316
  $line = new Line();
317
  $line->setNo($lineNumber);
318
- $line->setItemCode(Mage::helper('avatax')->getGwItemsSku($storeId));
319
  $line->setDescription('Gift Wrap Items Amount');
320
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
321
  $line->setQty(1);
322
  $line->setAmount($amount);
323
  $line->setDiscounted(false);
324
 
325
- $this->_lineToItemId[$lineNumber] = Mage::helper('avatax')->getGwItemsSku($storeId);
326
  $this->_lines[$lineNumber] = $line;
327
  $this->_request->setLines($this->_lines);
328
  return $lineNumber;
@@ -353,14 +346,14 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
353
 
354
  $line = new Line();
355
  $line->setNo($lineNumber);
356
- $line->setItemCode(Mage::helper('avatax')->getGwPrintedCardSku($storeId));
357
  $line->setDescription('Gift Wrap Printed Card Amount');
358
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
359
  $line->setQty(1);
360
  $line->setAmount($amount);
361
  $line->setDiscounted(false);
362
 
363
- $this->_lineToItemId[$lineNumber] = Mage::helper('avatax')->getGwPrintedCardSku($storeId);
364
  $this->_lines[$lineNumber] = $line;
365
  $this->_request->setLines($this->_lines);
366
  return $lineNumber;
@@ -378,7 +371,7 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
378
  {
379
  if ($positive != 0) {
380
  $lineNumber = count($this->_lines);
381
- $identifier = Mage::helper('avatax')->getPositiveAdjustmentSku($storeId);
382
 
383
  $line = new Line();
384
  $line->setNo($lineNumber);
@@ -396,7 +389,7 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
396
 
397
  if ($negative != 0) {
398
  $lineNumber = count($this->_lines);
399
- $identifier = Mage::helper('avatax')->getNegativeAdjustmentSku($storeId);
400
 
401
  $line = new Line();
402
  $line->setNo($lineNumber);
@@ -439,7 +432,13 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
439
 
440
  $line = new Line();
441
  $line->setNo(count($this->_lines));
442
- $line->setItemCode($this->_getItemCode($item, $storeId));
 
 
 
 
 
 
443
  $line->setDescription($item->getName());
444
  $line->setQty($item->getQty());
445
  $line->setAmount($price);
@@ -454,16 +453,42 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
454
  $this->_lines[] = $line;
455
  }
456
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
  /**
458
  * Retrieve product for item code
459
  *
460
  * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
461
  * @return null|Mage_Catalog_Model_Product
 
462
  */
463
  protected function _getProductForItemCode($item)
464
  {
465
  $product = $this->_getProductByProductId($item->getProductId());
466
- if (!$this->_isConfigurable($item)) {
467
  return $product;
468
  }
469
 
@@ -493,65 +518,4 @@ class OnePica_AvaTax_Model_Avatax_Invoice extends OnePica_AvaTax_Model_Avatax_Ab
493
 
494
  return $storeId;
495
  }
496
-
497
- /**
498
- * Retrieve converted date taking into account the current time zone and store.
499
- *
500
- * @param string $gmt
501
- * @param int $storeId
502
- * @return string
503
- */
504
- protected function _convertGmtDate($gmt, $storeId)
505
- {
506
- return $this->_getDataHelper()
507
- ->storeDate($storeId, $gmt, false, Varien_Date::DATETIME_INTERNAL_FORMAT)
508
- ->toString(Varien_Date::DATE_INTERNAL_FORMAT);
509
- }
510
-
511
- /**
512
- * Get item code
513
- *
514
- * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
515
- * @param int|Mage_Core_Model_Store $storeId
516
- * @return string
517
- */
518
- protected function _getItemCode($item, $storeId)
519
- {
520
- $product = $this->_getProductForItemCode($item);
521
- $itemCode = '';
522
- if (null !== $product) {
523
- $itemCode = $this->_getUpcCode($product, $storeId);
524
- }
525
-
526
- if (empty($itemCode)) {
527
- $itemCode = $item->getSku();
528
- }
529
-
530
- return substr($itemCode, 0, 50);
531
- }
532
-
533
- /**
534
- * Get line product data
535
- *
536
- * Return a Varien_Object with the following possible methods: getTaxCode, getRef1, getRef2
537
- *
538
- * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
539
- * @param int $storeId
540
- * @return \Varien_Object
541
- */
542
- protected function _getLineProductData($item, $storeId)
543
- {
544
- $lineProductData = new Varien_Object();
545
- $product = $this->_getProductByProductId($item->getProductId());
546
-
547
- if (null === $product) {
548
- return $lineProductData;
549
- }
550
-
551
- $lineProductData->setTaxCode($this->_getTaxClassCodeByProduct($product));
552
- $lineProductData->setRef1($this->_getRefValueByProductAndNumber($product, 1, $storeId));
553
- $lineProductData->setRef2($this->_getRefValueByProductAndNumber($product, 2, $storeId));
554
-
555
- return $lineProductData;
556
- }
557
  }
16
  */
17
 
18
  /**
19
+ * The AvaTax Invoice model
20
  *
21
  * @category OnePica
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
+ class OnePica_AvaTax_Model_Service_Avatax_Invoice extends OnePica_AvaTax_Model_Service_Avatax_Tax
26
  {
27
  /**
28
  * An array of line items
41
  /**
42
  * Save order in AvaTax system
43
  *
44
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderInvoiceSaveAfter::execute()
45
+ * @param Mage_Sales_Model_Order_Invoice $invoice
46
  * @param OnePica_AvaTax_Model_Records_Queue $queue
47
+ * @return OnePica_AvaTax_Model_Service_Result_Invoice
 
 
 
48
  */
49
  public function invoice($invoice, $queue)
50
  {
51
+ $this->_lines = array();
52
  $order = $invoice->getOrder();
53
  $storeId = $order->getStoreId();
54
  $invoiceDate = $this->_convertGmtDate($invoice->getCreatedAt(), $storeId);
56
  $statusDate = $this->_convertGmtDate($queue->getUpdatedAt(), $storeId);
57
 
58
  $shippingAddress = ($order->getShippingAddress()) ? $order->getShippingAddress() : $order->getBillingAddress();
 
 
 
59
 
60
  $this->_request = new GetTaxRequest();
61
  $this->_request->setDocCode($invoice->getIncrementId());
80
  $this->_request->setStatusDate($statusDate);
81
 
82
  $configAction = Mage::getStoreConfig('tax/avatax/action', $order->getStoreId());
83
+ $commitAction = OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC_SUBMIT_COMMIT;
84
  $this->_request->setCommit(($configAction == $commitAction) ? true : false);
85
 
86
  foreach ($items as $item) {
92
  //send to AvaTax
93
  $result = $this->_send($order->getStoreId());
94
 
95
+ /** @var OnePica_AvaTax_Model_Service_Result_Invoice $invoiceResult */
96
+ $invoiceResult = Mage::getModel('avatax/service_result_invoice');
97
+ $resultHasError = $result->getResultCode() != SeverityLevel::$Success;
98
+ $invoiceResult->setHasError($resultHasError);
99
+
100
  //if successful
101
+ if (!$resultHasError) {
102
+ $totalTax = $result->getTotalTax();
103
+ $invoiceResult->setTotalTax($totalTax);
104
+ $documentCode = $result->getDocCode();
105
+ $invoiceResult->setDocumentCode($documentCode);
 
 
 
 
106
 
107
+ //if not successful
108
  } else {
109
  $messages = array();
110
  foreach ($result->getMessages() as $message) {
111
  $messages[] = $message->getSummary();
112
  }
113
+ $invoiceResult->setErrors($messages);
114
  }
115
 
116
+ return $invoiceResult;
117
  }
118
 
119
  /**
120
  * Save order in AvaTax system
121
  *
122
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderCreditmemoSaveAfter::execute()
123
  * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
124
  * @param OnePica_AvaTax_Model_Records_Queue $queue
125
+ * @return OnePica_AvaTax_Model_Service_Result_Creditmemo
 
 
 
126
  */
127
  public function creditmemo($creditmemo, $queue)
128
  {
129
+ $this->_lines = array();
130
  $order = $creditmemo->getOrder();
131
  $storeId = $order->getStoreId();
132
  $orderDate = $this->_convertGmtDate($order->getCreatedAt(), $storeId);
134
  $creditmemoDate = $this->_convertGmtDate($creditmemo->getCreatedAt(), $storeId);
135
 
136
  $shippingAddress = ($order->getShippingAddress()) ? $order->getShippingAddress() : $order->getBillingAddress();
 
 
 
137
 
138
  $this->_request = new GetTaxRequest();
139
  $this->_request->setDocCode($creditmemo->getIncrementId());
151
  $this->_addGwPrintedCardAmount($creditmemo, true);
152
 
153
  $this->_addAdjustments(
154
+ $creditmemo->getBaseAdjustmentPositive(),
155
+ $creditmemo->getBaseAdjustmentNegative(),
156
  $order->getStoreId()
157
  );
158
  $this->_setOriginAddress($order->getStoreId());
171
  $this->_request->setStatusDate($statusDate);
172
 
173
  $configAction = Mage::getStoreConfig('tax/avatax/action', $order->getStoreId());
174
+ $commitAction = OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC_SUBMIT_COMMIT;
175
  $this->_request->setCommit(($configAction == $commitAction) ? true : false);
176
 
177
  foreach ($items as $item) {
183
  //send to AvaTax
184
  $result = $this->_send($order->getStoreId());
185
 
186
+ /** @var OnePica_AvaTax_Model_Service_Result_Creditmemo $creditmemoResult */
187
+ $creditmemoResult = Mage::getModel('avatax/service_result_creditmemo');
188
+ $resultHasError = $result->getResultCode() != SeverityLevel::$Success;
189
+ $creditmemoResult->setHasError($resultHasError);
190
+
191
  //if successful
192
+ if (!$resultHasError) {
193
+ $totalTax = $result->getTotalTax();
194
+ $creditmemoResult->setTotalTax($totalTax);
195
+ $documentCode = $result->getDocCode();
196
+ $creditmemoResult->setDocumentCode($documentCode);
197
+
198
+ //if not successful
 
 
 
199
  } else {
200
  $messages = array();
201
  foreach ($result->getMessages() as $message) {
202
  $messages[] = $message->getSummary();
203
  }
204
+ $creditmemoResult->setErrors($messages);
205
  }
206
 
207
+ return $creditmemoResult;
208
  }
209
 
210
  /**
233
 
234
  $line = new Line();
235
  $line->setNo($lineNumber);
236
+ $line->setItemCode($this->_getConfigHelper()->getShippingSku($storeId));
237
  $line->setDescription('Shipping costs');
238
  $line->setTaxCode($taxClass);
239
  $line->setQty(1);
270
 
271
  $line = new Line();
272
  $line->setNo($lineNumber);
273
+ $line->setItemCode($this->_getConfigHelper()->getGwOrderSku($storeId));
274
  $line->setDescription('Gift Wrap Order Amount');
275
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
276
  $line->setQty(1);
277
  $line->setAmount($amount);
278
  $line->setDiscounted(false);
279
 
280
+ $this->_lineToItemId[$lineNumber] = $this->_getConfigHelper()->getGwOrderSku($storeId);
281
  $this->_lines[$lineNumber] = $line;
282
  $this->_request->setLines($this->_lines);
283
  return $lineNumber;
308
 
309
  $line = new Line();
310
  $line->setNo($lineNumber);
311
+ $line->setItemCode($this->_getConfigHelper()->getGwItemsSku($storeId));
312
  $line->setDescription('Gift Wrap Items Amount');
313
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
314
  $line->setQty(1);
315
  $line->setAmount($amount);
316
  $line->setDiscounted(false);
317
 
318
+ $this->_lineToItemId[$lineNumber] = $this->_getConfigHelper()->getGwItemsSku($storeId);
319
  $this->_lines[$lineNumber] = $line;
320
  $this->_request->setLines($this->_lines);
321
  return $lineNumber;
346
 
347
  $line = new Line();
348
  $line->setNo($lineNumber);
349
+ $line->setItemCode($this->_getConfigHelper()->getGwPrintedCardSku($storeId));
350
  $line->setDescription('Gift Wrap Printed Card Amount');
351
  $line->setTaxCode($this->_getGiftTaxClassCode($storeId));
352
  $line->setQty(1);
353
  $line->setAmount($amount);
354
  $line->setDiscounted(false);
355
 
356
+ $this->_lineToItemId[$lineNumber] = $this->_getConfigHelper()->getGwPrintedCardSku($storeId);
357
  $this->_lines[$lineNumber] = $line;
358
  $this->_request->setLines($this->_lines);
359
  return $lineNumber;
371
  {
372
  if ($positive != 0) {
373
  $lineNumber = count($this->_lines);
374
+ $identifier = $this->_getConfigHelper()->getPositiveAdjustmentSku($storeId);
375
 
376
  $line = new Line();
377
  $line->setNo($lineNumber);
389
 
390
  if ($negative != 0) {
391
  $lineNumber = count($this->_lines);
392
+ $identifier = $this->_getConfigHelper()->getNegativeAdjustmentSku($storeId);
393
 
394
  $line = new Line();
395
  $line->setNo($lineNumber);
432
 
433
  $line = new Line();
434
  $line->setNo(count($this->_lines));
435
+ $line->setItemCode(
436
+ $this->_getCalculationHelper()->getItemCode(
437
+ $this->_getProductForItemCode($item),
438
+ $storeId,
439
+ $item
440
+ )
441
+ );
442
  $line->setDescription($item->getName());
443
  $line->setQty($item->getQty());
444
  $line->setAmount($price);
453
  $this->_lines[] = $line;
454
  }
455
 
456
+ /**
457
+ * Get line product data
458
+ *
459
+ * Return a Varien_Object with the following possible methods: getTaxCode, getRef1, getRef2
460
+ *
461
+ * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
462
+ * @param int $storeId
463
+ * @return \Varien_Object
464
+ */
465
+ protected function _getLineProductData($item, $storeId)
466
+ {
467
+ $lineProductData = new Varien_Object();
468
+ $product = $this->_getProductByProductId($item->getProductId());
469
+
470
+ if (null === $product) {
471
+ return $lineProductData;
472
+ }
473
+
474
+ $lineProductData->setTaxCode($this->_getTaxClassCodeByProduct($product));
475
+ $lineProductData->setRef1($this->_getRefValueByProductAndNumber($product, 1, $storeId));
476
+ $lineProductData->setRef2($this->_getRefValueByProductAndNumber($product, 2, $storeId));
477
+
478
+ return $lineProductData;
479
+ }
480
+
481
  /**
482
  * Retrieve product for item code
483
  *
484
  * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
485
  * @return null|Mage_Catalog_Model_Product
486
+ * @throws OnePica_AvaTax_Exception
487
  */
488
  protected function _getProductForItemCode($item)
489
  {
490
  $product = $this->_getProductByProductId($item->getProductId());
491
+ if (!$this->_getCalculationHelper()->isConfigurable($item)) {
492
  return $product;
493
  }
494
 
518
 
519
  return $storeId;
520
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521
  }
app/code/community/OnePica/AvaTax/Model/{Avatax → Service/Avatax}/Ping.php RENAMED
@@ -11,18 +11,18 @@
11
  * @category OnePica
12
  * @package OnePica_AvaTax
13
  * @author OnePica Codemaster <codemaster@onepica.com>
14
- * @copyright Copyright (c) 2009 One Pica, Inc.
15
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
  */
17
 
18
  /**
19
- * The AvaTax Address Ping model
20
  *
21
  * @category OnePica
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
- class OnePica_AvaTax_Model_Avatax_Ping extends OnePica_AvaTax_Model_Avatax_Abstract
26
  {
27
  /**
28
  * Tries to ping AvaTax service with provided credentials
@@ -33,7 +33,7 @@ class OnePica_AvaTax_Model_Avatax_Ping extends OnePica_AvaTax_Model_Avatax_Abstr
33
  public function ping($storeId = null)
34
  {
35
  /** @var OnePica_AvaTax_Model_Config $config */
36
- $config = Mage::getSingleton('avatax/config')->init($storeId);
37
  $connection = $config->getTaxConnection();
38
  $result = null;
39
  $message = null;
@@ -53,7 +53,7 @@ class OnePica_AvaTax_Model_Avatax_Ping extends OnePica_AvaTax_Model_Avatax_Abstr
53
  }
54
 
55
  $this->_log(
56
- OnePica_AvaTax_Model_Source_Logtype::PING,
57
  new stdClass(),
58
  $result,
59
  $storeId,
11
  * @category OnePica
12
  * @package OnePica_AvaTax
13
  * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
  */
17
 
18
  /**
19
+ * The AvaTax Ping model
20
  *
21
  * @category OnePica
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
+ class OnePica_AvaTax_Model_Service_Avatax_Ping extends OnePica_AvaTax_Model_Service_Avatax_Abstract
26
  {
27
  /**
28
  * Tries to ping AvaTax service with provided credentials
33
  public function ping($storeId = null)
34
  {
35
  /** @var OnePica_AvaTax_Model_Config $config */
36
+ $config = $this->getServiceConfig();
37
  $connection = $config->getTaxConnection();
38
  $result = null;
39
  $message = null;
53
  }
54
 
55
  $this->_log(
56
+ OnePica_AvaTax_Model_Source_Avatax_Logtype::PING,
57
  new stdClass(),
58
  $result,
59
  $storeId,
app/code/community/OnePica/AvaTax/Model/Service/Avatax/Tax.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax service tax model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Service_Avatax_Tax extends OnePica_AvaTax_Model_Service_Avatax_Abstract
26
+ {
27
+ /**
28
+ * Sends a request to the Avatax server
29
+ *
30
+ * @param int $storeId
31
+ * @return mixed
32
+ */
33
+ protected function _send($storeId)
34
+ {
35
+ /** @var OnePica_AvaTax_Model_Config $config */
36
+ $config = $this->getServiceConfig();
37
+ $connection = $config->getTaxConnection();
38
+ $result = null;
39
+ $message = null;
40
+
41
+ try {
42
+ $result = $connection->getTax($this->_request);
43
+ } catch (Exception $exception) {
44
+ $message = new Message();
45
+ $message->setSummary($exception->getMessage());
46
+ }
47
+
48
+ if (!isset($result) || !is_object($result) || !$result->getResultCode()) {
49
+ $actualResult = $result;
50
+ $result = new Varien_Object();
51
+ $result->setResultCode(SeverityLevel::$Exception)
52
+ ->setActualResult($actualResult)
53
+ ->setMessages(array($message));
54
+ }
55
+
56
+ $this->_log(
57
+ OnePica_AvaTax_Model_Source_Avatax_Logtype::GET_TAX,
58
+ $this->_request,
59
+ $result,
60
+ $storeId,
61
+ $config->getParams()
62
+ );
63
+
64
+ return $result;
65
+ }
66
+ }
app/code/community/OnePica/AvaTax/Model/Service/Avatax16.php ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Class OnePica_AvaTax_Model_Service_Avatax16
20
+ *
21
+ * @property OnePica_AvaTax_Model_Service_Avatax16_Invoice _invoiceResource
22
+ * @property OnePica_AvaTax_Model_Service_Avatax16_Estimate _estimateResource
23
+ * @property OnePica_AvaTax_Model_Service_Avatax16_Ping _pingResource
24
+ * @property OnePica_AvaTax_Model_Service_Avatax16_Address _addressValidatorResource
25
+ *
26
+ * @category OnePica
27
+ * @package OnePica_AvaTax
28
+ * @author OnePica Codemaster <codemaster@onepica.com>
29
+ */
30
+ class OnePica_AvaTax_Model_Service_Avatax16
31
+ extends OnePica_AvaTax_Model_Service_Abstract
32
+ {
33
+ /**
34
+ * Service config class name
35
+ */
36
+ const AVATAX16_SERVICE_CONFIG_CLASS = 'avatax/service_avatax16_config';
37
+
38
+ /**
39
+ * OnePica_AvaTax_Model_Service_Avatax16 constructor.
40
+ *
41
+ * @param mixed
42
+ */
43
+ public function __construct()
44
+ {
45
+ $storeId = Mage::app()->getStore()->getStoreId();
46
+ $this->setStoreId($storeId);
47
+ }
48
+
49
+ /**
50
+ * Get estimate resource
51
+ *
52
+ * @return OnePica_AvaTax_Model_Service_Avatax16_Estimate
53
+ */
54
+ protected function _getEstimateResource()
55
+ {
56
+ if (null === $this->_estimateResource) {
57
+ $this->_estimateResource = Mage::getModel('avatax/service_avatax16_estimate',
58
+ array('service_config' => $this->getServiceConfig()));
59
+ }
60
+
61
+ return $this->_estimateResource;
62
+ }
63
+
64
+ /**
65
+ * Get invoice resource
66
+ *
67
+ * @return OnePica_AvaTax_Model_Service_Avatax16_Invoice
68
+ */
69
+ protected function _getInvoiceResource()
70
+ {
71
+ if (null === $this->_invoiceResource) {
72
+ $this->_invoiceResource = Mage::getModel('avatax/service_avatax16_invoice',
73
+ array('service_config' => $this->getServiceConfig()));
74
+ }
75
+
76
+ return $this->_invoiceResource;
77
+ }
78
+
79
+ /**
80
+ * Get ping resource
81
+ *
82
+ * @return OnePica_AvaTax_Model_Service_Avatax16_Ping
83
+ */
84
+ protected function _getPingResource()
85
+ {
86
+ if (null === $this->_pingResource) {
87
+ $this->_pingResource = Mage::getModel('avatax/service_avatax16_ping',
88
+ array('service_config' => $this->getServiceConfig()));
89
+ }
90
+
91
+ return $this->_pingResource;
92
+ }
93
+
94
+ /**
95
+ * Get Address Validator resource
96
+ *
97
+ * @return OnePica_AvaTax_Model_Service_Avatax16_Address
98
+ */
99
+ protected function _getAddressValidatorResource()
100
+ {
101
+ if (null === $this->_addressValidatorResource) {
102
+ return Mage::getModel('avatax/service_avatax16_address',
103
+ array('service_config' => $this->getServiceConfig())
104
+ );
105
+ }
106
+
107
+ return $this->_addressValidatorResource;
108
+ }
109
+
110
+ /**
111
+ * Get rates from Service
112
+ *
113
+ * @param Mage_Sales_Model_Quote_Address $address
114
+ * @return array
115
+ */
116
+ public function getRates($address)
117
+ {
118
+ return $this->_getEstimateResource()->getRates($address);
119
+ }
120
+
121
+ /**
122
+ * Get tax detail summary
123
+ *
124
+ * @param Mage_Sales_Model_Quote_Address $address
125
+ * @return array
126
+ */
127
+ public function getSummary($address)
128
+ {
129
+ return $this->_getEstimateResource()->getSummary($address);
130
+ }
131
+
132
+ /**
133
+ * Test to see if the product carries its own numbers or is calculated based on parent or children
134
+ *
135
+ * @param Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item|mixed $item
136
+ * @return bool
137
+ */
138
+ public function isProductCalculated($item)
139
+ {
140
+ return $this->_getEstimateResource()->isProductCalculated($item);
141
+ }
142
+
143
+ /**
144
+ * Save order in AvaTax system
145
+ *
146
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderInvoiceSaveAfter::execute()
147
+ * @param Mage_Sales_Model_Order_Invoice $invoice
148
+ * @param OnePica_AvaTax_Model_Records_Queue $queue
149
+ * @return bool
150
+ */
151
+ public function invoice($invoice, $queue)
152
+ {
153
+ return $this->_getInvoiceResource()->invoice($invoice, $queue);
154
+ }
155
+
156
+ /**
157
+ * Save order in AvaTax system
158
+ *
159
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderCreditmemoSaveAfter::execute()
160
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
161
+ * @param OnePica_AvaTax_Model_Records_Queue $queue
162
+ * @return bool
163
+ */
164
+ public function creditmemo($creditmemo, $queue)
165
+ {
166
+ return $this->_getInvoiceResource()->creditmemo($creditmemo, $queue);
167
+ }
168
+
169
+ /**
170
+ * Tries to ping AvaTax service with provided credentials
171
+ *
172
+ * @param int $storeId
173
+ * @return bool|array
174
+ */
175
+ public function ping($storeId)
176
+ {
177
+ return $this->_getPingResource()->ping($storeId);
178
+ }
179
+
180
+ /**
181
+ * Get service address validator
182
+ *
183
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address $address
184
+ * @return \OnePica_AvaTax_Model_Service_Avatax16_Address
185
+ */
186
+ public function validate($address)
187
+ {
188
+ return $this->_getAddressValidatorResource()->validate($address);
189
+ }
190
+
191
+ /**
192
+ * Get service config class name
193
+ *
194
+ * @return string
195
+ */
196
+ protected function _getServiceConfigClassName()
197
+ {
198
+ return self::AVATAX16_SERVICE_CONFIG_CLASS;
199
+ }
200
+ }
app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Abstract.php ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax 16 service abstract model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ abstract class OnePica_AvaTax_Model_Service_Avatax16_Abstract extends OnePica_AvaTax_Model_Service_Abstract_Tools
26
+ {
27
+ /**
28
+ * Transaction type sale
29
+ */
30
+ const TRANSACTION_TYPE_SALE = 'Sale';
31
+
32
+ /**
33
+ * Tax location purpose ship from
34
+ */
35
+ const TAX_LOCATION_PURPOSE_SHIP_FROM = 'ShipFrom';
36
+
37
+ /**
38
+ * Tax location purpose ship to
39
+ */
40
+ const TAX_LOCATION_PURPOSE_SHIP_TO = 'ShipTo';
41
+
42
+ /**
43
+ * Default GW items sku
44
+ */
45
+ const DEFAULT_GW_ITEMS_SKU = 'GwItemsAmount';
46
+
47
+ /**
48
+ * Default GW items description
49
+ */
50
+ const DEFAULT_GW_ITEMS_DESCRIPTION = 'Gift Wrap Items Amount';
51
+
52
+ /**
53
+ * Default shipping items sku
54
+ */
55
+ const DEFAULT_SHIPPING_ITEMS_SKU = 'Shipping';
56
+
57
+ /**
58
+ * Default shipping items description
59
+ */
60
+ const DEFAULT_SHIPPING_ITEMS_DESCRIPTION = 'Shipping costs';
61
+
62
+ /**
63
+ * Default GW order sku
64
+ */
65
+ const DEFAULT_GW_ORDER_SKU = 'GwOrderAmount';
66
+
67
+ /**
68
+ * Default GW order description
69
+ */
70
+ const DEFAULT_GW_ORDER_DESCRIPTION = 'Gift Wrap Order Amount';
71
+
72
+ /**
73
+ * Default GW printed card sku
74
+ */
75
+ const DEFAULT_GW_PRINTED_CARD_SKU = 'GwPrintedCardAmount';
76
+
77
+ /**
78
+ * Default GW printed card description
79
+ */
80
+ const DEFAULT_GW_PRINTED_CARD_DESCRIPTION = 'Gift Wrap Printed Card Amount';
81
+
82
+ /**
83
+ * Response result code exception
84
+ */
85
+ const RESPONSE_RESULT_CODE_EXCEPTION = 'Exception';
86
+
87
+ /**
88
+ * Default vendor code
89
+ */
90
+ const DEFAULT_VENDOR_CODE = 'Vendor';
91
+
92
+ /**
93
+ * Service date format
94
+ */
95
+ const SERVICE_DATE_FORMAT = 'Y-MM-dd';
96
+
97
+ /**
98
+ * Default positive adjustment code
99
+ */
100
+ const DEFAULT_POSITIVE_ADJUSTMENT_CODE = 'positive-adjustment';
101
+
102
+ /**
103
+ * Default positive adjustment description
104
+ */
105
+ const DEFAULT_POSITIVE_ADJUSTMENT_DESCRIPTION = 'Adjustment refund';
106
+
107
+ /**
108
+ * Default negative adjustment code
109
+ */
110
+ const DEFAULT_NEGATIVE_ADJUSTMENT_CODE = 'negative-adjustment';
111
+
112
+ /**
113
+ * Default negative adjustment description
114
+ */
115
+ const DEFAULT_NEGATIVE_ADJUSTMENT_DESCRIPTION = 'Adjustment fee';
116
+
117
+ /**
118
+ * Document code invoice prefix
119
+ */
120
+ const DOCUMENT_CODE_INVOICE_PREFIX = 'I';
121
+
122
+ /**
123
+ * Document code creditmemo prefix
124
+ */
125
+ const DOCUMENT_CODE_CREDITMEMO_PREFIX = 'C';
126
+
127
+ /**
128
+ * Returns the AvaTax helper.
129
+ *
130
+ * @return OnePica_AvaTax_Helper_Data
131
+ */
132
+ protected function _getHelper()
133
+ {
134
+ return Mage::helper('avatax');
135
+ }
136
+
137
+ /**
138
+ * Returns the AvaTax helper.
139
+ *
140
+ * @return OnePica_AvaTax_Helper_Address
141
+ */
142
+ protected function _getAddressHelper()
143
+ {
144
+ return Mage::helper('avatax/address');
145
+ }
146
+
147
+ /**
148
+ * Returns the AvaTax helper.
149
+ *
150
+ * @return OnePica_AvaTax_Helper_Config
151
+ */
152
+ protected function _getConfigHelper()
153
+ {
154
+ return Mage::helper('avatax/config');
155
+ }
156
+
157
+ /**
158
+ * Returns the AvaTax helper.
159
+ *
160
+ * @return OnePica_AvaTax_Helper_Config
161
+ */
162
+ protected function _getErrorsHelper()
163
+ {
164
+ return Mage::helper('avatax/errors');
165
+ }
166
+
167
+ /**
168
+ * Get gift wrapping data helper
169
+ *
170
+ * @return \Enterprise_GiftWrapping_Helper_Data
171
+ */
172
+ protected function _getGiftWrappingDataHelper()
173
+ {
174
+ return Mage::helper('enterprise_giftwrapping');
175
+ }
176
+
177
+ /**
178
+ * Logs a debug message
179
+ *
180
+ * @param string $type
181
+ * @param mixed $request the request string
182
+ * @param mixed $result the result string
183
+ * @param int $storeId id of the store the call is make for
184
+ * @param mixed $additional any other info
185
+ * @return $this
186
+ */
187
+ protected function _log($type, $request, $result, $storeId = null, $additional = null)
188
+ {
189
+ if ($result->getHasError() === false) {
190
+ switch ($this->_getHelper()->getLogMode($storeId)) {
191
+ case OnePica_AvaTax_Model_Source_Logmode::ERRORS:
192
+ return $this;
193
+ break;
194
+ case OnePica_AvaTax_Model_Source_Logmode::NORMAL:
195
+ $additional = null;
196
+ break;
197
+ }
198
+ }
199
+ $level = $result->getHasError() ? OnePica_AvaTax_Model_Records_Log::LOG_LEVEL_ERROR
200
+ : OnePica_AvaTax_Model_Records_Log::LOG_LEVEL_SUCCESS;
201
+
202
+ $requestLog = ($request instanceof OnePica_AvaTax16_Document_Part) ? $request->toArray() : $request;
203
+ $resultLog = ($result instanceof OnePica_AvaTax16_Document_Part) ? $result->toArray() : $result;
204
+
205
+ if (in_array($type, $this->_getHelper()->getLogType($storeId))) {
206
+ Mage::getModel('avatax_records/log')
207
+ ->setStoreId($storeId)
208
+ ->setLevel($level)
209
+ ->setType($type)
210
+ ->setRequest(print_r($requestLog, true))
211
+ ->setResult(print_r($resultLog, true))
212
+ ->setAdditional(print_r($additional, true))
213
+ ->save();
214
+ }
215
+ return $this;
216
+ }
217
+
218
+ /**
219
+ * Get date model
220
+ *
221
+ * @return Mage_Core_Model_Date
222
+ */
223
+ protected function _getDateModel()
224
+ {
225
+ return Mage::getSingleton('core/date');
226
+ }
227
+
228
+ /**
229
+ * Get New Document Part Location Address Object
230
+ *
231
+ * @return OnePica_AvaTax16_Document_Part_Location_Address
232
+ */
233
+ protected function _getNewDocumentPartLocationAddressObject()
234
+ {
235
+ return new OnePica_AvaTax16_Document_Part_Location_Address();
236
+ }
237
+
238
+ /**
239
+ * Get New Document Part Location Object
240
+ *
241
+ * @return OnePica_AvaTax16_Document_Part_Location
242
+ */
243
+ protected function _getNewDocumentPartLocationObject()
244
+ {
245
+ return new OnePica_AvaTax16_Document_Part_Location();
246
+ }
247
+
248
+ /**
249
+ * Get New Document Request Header Object
250
+ *
251
+ * @return OnePica_AvaTax16_Document_Request_Header
252
+ */
253
+ protected function _getNewDocumentRequestHeaderObject()
254
+ {
255
+ return new OnePica_AvaTax16_Document_Request_Header();
256
+ }
257
+
258
+ /**
259
+ * Get New Document Request Object
260
+ *
261
+ * @return OnePica_AvaTax16_Document_Request
262
+ */
263
+ protected function _getNewDocumentRequestObject()
264
+ {
265
+ return new OnePica_AvaTax16_Document_Request();
266
+ }
267
+
268
+ /**
269
+ * Get New Document Request Line Object
270
+ *
271
+ * @return OnePica_AvaTax16_Document_Request_Line
272
+ */
273
+ protected function _getNewDocumentRequestLineObject()
274
+ {
275
+ return new OnePica_AvaTax16_Document_Request_Line();
276
+ }
277
+
278
+ /**
279
+ * Get New Service Message Object
280
+ *
281
+ * @return Varien_Object
282
+ */
283
+ protected function _getNewServiceMessageObject()
284
+ {
285
+ return new Varien_Object();
286
+ }
287
+ }
app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Address.php ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Class OnePica_AvaTax_Model_Service_Avatax16_Address
20
+ *
21
+ * @method getService() OnePica_AvaTax_Model_Service_Avatax16
22
+ * @method OnePica_AvaTax_Model_Service_Avatax16_Config getServiceConfig()
23
+ * @method setServiceConfig(OnePica_AvaTax_Model_Service_Avatax16_Config $serviceConfig)
24
+ *
25
+ * @category OnePica
26
+ * @package OnePica_AvaTax
27
+ * @author OnePica Codemaster <codemaster@onepica.com>
28
+ */
29
+ class OnePica_AvaTax_Model_Service_Avatax16_Address extends OnePica_AvaTax_Model_Service_Avatax16_Abstract
30
+ {
31
+ /**
32
+ * Avatax service response
33
+ */
34
+ protected $_successResponse = array('Rooftop');
35
+
36
+ /**
37
+ * The Mage Address object
38
+ *
39
+ * @var Mage_Customer_Model_Address_Abstract
40
+ */
41
+ protected $_address = null;
42
+
43
+ /**
44
+ * The AvaTax16 Request Address object.
45
+ *
46
+ * @var OnePica_AvaTax16_Document_Part_Location_Address
47
+ */
48
+ protected $_locationAddress = null;
49
+
50
+ /**
51
+ * The AvaTax16 Request Address object.
52
+ *
53
+ * @var OnePica_AvaTax16_Document_Part_Location_Address
54
+ */
55
+ protected $_localeObject = null;
56
+
57
+ /**
58
+ * An array of previously checked addresses
59
+ * Example: $_cache[$key] = serialize($resultObjectFromAvalara)
60
+ *
61
+ * @var array
62
+ */
63
+ protected $_cache = array();
64
+
65
+ /**
66
+ * Saves the store id
67
+ *
68
+ * @var int
69
+ */
70
+ protected $_storeId = null;
71
+
72
+ /**
73
+ * OnePica_AvaTax_Model_Service_Avatax16_Address constructor.
74
+ *
75
+ * @param array $data
76
+ * @internal param Mage_Customer_Model_Address_Abstract $_address
77
+ */
78
+ public function __construct($data)
79
+ {
80
+ if (isset($data['service_config'])) {
81
+ $this->setServiceConfig($data['service_config']);
82
+ }
83
+ self::_construct();
84
+ }
85
+
86
+ /**
87
+ * Class pre-constructor
88
+ *
89
+ * @skipPublicMethodNaming _construct
90
+ */
91
+ public function _construct()
92
+ {
93
+ $addresses = Mage::getSingleton('avatax/session')->getAddresses();
94
+ if (is_array($addresses)) {
95
+ $this->_cache = $addresses;
96
+ }
97
+ parent::_construct();
98
+ }
99
+
100
+ /**
101
+ * Saves any current addresses to session
102
+ */
103
+ public function __destruct()
104
+ {
105
+ Mage::getSingleton('avatax/session')->setAddresses($this->_cache);
106
+
107
+ if (method_exists(get_parent_class(), '__destruct')) {
108
+ parent::__destruct();
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Getter for address resolution
114
+ *
115
+ * @return OnePica_AvaTax16_Document_Part_Location_Address
116
+ */
117
+ public function getLocationAddress()
118
+ {
119
+ return $this->_locationAddress;
120
+ }
121
+
122
+ /**
123
+ * Setter for address resolution
124
+ *
125
+ * @param OnePica_AvaTax16_Document_Part_Location_Address $addressResolution
126
+ */
127
+ public function setLocationAddress($addressResolution)
128
+ {
129
+ $this->_locationAddress = $addressResolution;
130
+ }
131
+
132
+ /**
133
+ * Sets the Mage address.
134
+ *
135
+ * @param Mage_Sales_Model_Quote_Address $address
136
+ * @return $this
137
+ */
138
+ public function setAddress(Mage_Sales_Model_Quote_Address $address)
139
+ {
140
+ $this->_storeId = $address->getQuote()->getStoreId();
141
+ $this->_address = $address;
142
+ $this->_initAddressResolution();
143
+
144
+ return $this;
145
+ }
146
+
147
+ /**
148
+ * Address getter
149
+ *
150
+ * @return Mage_Sales_Model_Quote_Address
151
+ */
152
+ public function getAddress()
153
+ {
154
+ return $this->_address;
155
+ }
156
+
157
+ /**
158
+ * Get Location Address Object
159
+ *
160
+ * @return OnePica_AvaTax16_Document_Part_Location_Address
161
+ */
162
+ public function getLocationAddressObject()
163
+ {
164
+ if (null === $this->_localeObject) {
165
+ $this->_localeObject = $this->_getNewDocumentPartLocationAddressObject();
166
+ }
167
+
168
+ return $this->_localeObject;
169
+ }
170
+
171
+ /**
172
+ * Init request address object.
173
+ *
174
+ * @return $this
175
+ */
176
+ protected function _initAddressResolution()
177
+ {
178
+ if (null === $this->getLocationAddress()) {
179
+ $this->setLocationAddress($this->getLocationAddressObject());
180
+ }
181
+ $address = $this->getAddress()->getStreet();
182
+ if (is_array($address) && isset($address[0])) {
183
+ $address = $address[0];
184
+ }
185
+
186
+ $this->getLocationAddress()->setline1($address ? $address : '_');
187
+ $this->getLocationAddress()->setCity($this->getAddress()->getCity());
188
+ $this->getLocationAddress()->setCountry($this->getAddress()->getCountryId());
189
+ $this->getLocationAddress()->setState($this->getAddress()->getRegionCode());
190
+ $this->getLocationAddress()->setZipcode($this->getAddress()->getPostcode());
191
+
192
+ return $this;
193
+ }
194
+
195
+ /**
196
+ * Validates the address with the AvaTax validation API.
197
+ * Returns true on success and an array with an error on failure.
198
+ *
199
+ * @param Mage_Sales_Model_Quote_Address $address
200
+ * @return OnePica_AvaTax_Model_Service_Result_AddressValidate $addressValidationResult
201
+ * @throws OnePica_AvaTax_Model_Service_Exception_Address
202
+ */
203
+ public function validate($address)
204
+ {
205
+ $this->setAddress($address);
206
+ if (!$this->getAddress()->getId()) {
207
+ throw new OnePica_AvaTax_Model_Service_Exception_Address(
208
+ $this->__('An address must be set before validation.')
209
+ );
210
+ }
211
+
212
+ $key = $this->getAddress()->getCacheHashKey();
213
+ if (array_key_exists($key, $this->_cache)) {
214
+ $result = unserialize($this->_cache[$key]);
215
+ } else {
216
+ $result = $this->_sendAddressValidationRequest();
217
+ $this->_cache[$key] = serialize($result);
218
+ }
219
+
220
+ /** @var OnePica_AvaTax_Model_Service_Result_AddressValidate $addressValidationResult */
221
+ $addressValidationResult = Mage::getModel('avatax/service_result_addressValidate');
222
+ $addressValidationResult->setHasError($result->getHasError());
223
+ $addressValidationResult->setErrors($result->getErrors());
224
+ $addressValidationResult->setIsTaxable((bool)$result->getTaxAuthorities());
225
+ if (!$addressValidationResult->getHasError()) {
226
+ /** @var OnePica_AvaTax_Model_Service_Result_Address $resultAddress */
227
+ $resultAddress = Mage::getModel('avatax/service_result_address');
228
+ $address = $result->getAddress();
229
+ $resultAddress->setLine1($address->getLine1());
230
+ $resultAddress->setLine2($address->getLine2());
231
+ $resultAddress->setCity($address->getCity());
232
+ $resultAddress->setState($address->getState());
233
+ $resultAddress->setPostalCode($address->getPostalCode());
234
+ $resultAddress->setCountry($address->getCountry());
235
+
236
+ $addressValidationResult->setAddress($resultAddress);
237
+ }
238
+ $addressValidationResult->setResolution(in_array($result->getResolutionQuality(), $this->_successResponse));
239
+
240
+ // if we have bad resolution we should set error with message
241
+ if (!$addressValidationResult->getResolution()) {
242
+ $errors[] = $this->_getConfigHelper()->getAvatax16AddressValidationMessage(
243
+ $this->getAddress()->getQuote()->getStoreId()
244
+ );
245
+ $addressValidationResult->setErrors($errors);
246
+ }
247
+
248
+ return $addressValidationResult;
249
+ }
250
+
251
+ /**
252
+ * Validate address
253
+ *
254
+ * @return OnePica_AvaTax16_AddressResolution_ResolveSingleAddressResponse
255
+ */
256
+ protected function _sendAddressValidationRequest()
257
+ {
258
+ /** @var OnePica_AvaTax16_AddressResolution_ResolveSingleAddressResponse $resolvedAddress */
259
+ $resolvedAddress = $this->getServiceConfig()->getTaxConnection()
260
+ ->resolveSingleAddress($this->getLocationAddress());
261
+
262
+ $this->_log(
263
+ OnePica_AvaTax_Model_Source_Avatax_Logtype::VALIDATE,
264
+ $this->getLocationAddress(),
265
+ $resolvedAddress,
266
+ $this->_storeId,
267
+ $this->getServiceConfig()->getData()
268
+ );
269
+
270
+ return $resolvedAddress;
271
+ }
272
+ }
app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Config.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * @class OnePica_AvaTax_Model_Service_Avatax16_Config
20
+ * The AvaTax Config Model, which registers config settings with the AvaTax SDK
21
+ *
22
+ * @category OnePica
23
+ * @package OnePica_AvaTax
24
+ * @author OnePica Codemaster <codemaster@onepica.com>
25
+ */
26
+ class OnePica_AvaTax_Model_Service_Avatax16_Config extends OnePica_AvaTax_Model_Service_Abstract_Config
27
+ {
28
+ /**
29
+ * Set AvaTax16 lib Config
30
+ *
31
+ * @param OnePica_AvaTax16_Config $config
32
+ */
33
+ public function setLibConfig($config)
34
+ {
35
+ $this->_config = $config;
36
+ }
37
+
38
+ /**
39
+ * Get Avatax16 lib config
40
+ *
41
+ * @return OnePica_AvaTax16_Config
42
+ */
43
+ public function getLibConfig()
44
+ {
45
+ return $this->_config;
46
+ }
47
+
48
+ /**
49
+ * Initializes the AvaTax16 SDK with connection settings found in the Admin config.
50
+ *
51
+ * @param int $storeId
52
+ * @return OnePica_AvaTax_Model_Service_Avatax16_Config
53
+ */
54
+ public function init($storeId)
55
+ {
56
+ if (null === $this->_config) {
57
+ $this->setLibConfig($this->_getNewServiceConfigObject());
58
+ $this->getLibConfig()->setBaseUrl($this->_getConfigHelper()->getServiceUrl($storeId));
59
+ $this->getLibConfig()->setAccountId($this->_getConfigHelper()->getServiceAccountId($storeId));
60
+ $this->getLibConfig()->setCompanyCode($this->_getConfigHelper()->getCompanyCode($storeId));
61
+ $this->getLibConfig()->setAuthorizationHeader($this->_getConfigHelper()->getServiceKey($storeId));
62
+ $this->getLibConfig()->setUserAgent($this->getClientName());
63
+ }
64
+
65
+ return $this;
66
+ }
67
+
68
+ /**
69
+ * Get New Service Config Object
70
+ *
71
+ * @return OnePica_AvaTax16_Config
72
+ */
73
+ protected function _getNewServiceConfigObject()
74
+ {
75
+ return new OnePica_AvaTax16_Config();
76
+ }
77
+
78
+ /**
79
+ * Get resource connection
80
+ *
81
+ * @return null|OnePica_AvaTax16_TaxService
82
+ */
83
+ public function getTaxConnection()
84
+ {
85
+ if (null === $this->_connection) {
86
+ $this->init(Mage::app()->getStore());
87
+ $this->_connection = $this->_getAvatax16Service();
88
+ }
89
+ return $this->_connection;
90
+ }
91
+
92
+ /**
93
+ * Returns the AvaTax helper.
94
+ *
95
+ * @return OnePica_AvaTax_Helper_Config
96
+ */
97
+ protected function _getConfigHelper()
98
+ {
99
+ return Mage::helper('avatax/config');
100
+ }
101
+
102
+ /**
103
+ * Get object OnePica_AvaTax16_TaxService
104
+ * @return OnePica_AvaTax16_TaxService
105
+ */
106
+ protected function _getAvatax16Service()
107
+ {
108
+ return new OnePica_AvaTax16_TaxService($this->getLibConfig());
109
+ }
110
+
111
+ /**
112
+ * Get client name
113
+ *
114
+ * @example Magento,1.4,.0.1,OP_AvaTax by One Pica,2,0.1
115
+ * @return string
116
+ */
117
+ public function getClientName()
118
+ {
119
+ return $this->_getHelper()->getClientName();
120
+ }
121
+ }
app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Estimate.php ADDED
@@ -0,0 +1,676 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Class OnePica_AvaTax_Model_Service_Avatax16_Estimate
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Service_Avatax16_Estimate extends OnePica_AvaTax_Model_Service_Avatax16_Tax
26
+ {
27
+ /**
28
+ * Length of time in minutes for cached rates
29
+ *
30
+ * @var int
31
+ */
32
+ const CACHE_TTL = 120;
33
+
34
+ /**
35
+ * An array of rates that acts as a cache
36
+ * Example: $_rates[$cachekey] = array(
37
+ * 'timestamp' => 1325015952
38
+ * 'summary' => array(
39
+ * array('name'=>'NY STATE TAX', 'rate'=>4, 'amt'=>6),
40
+ * array('name'=>'NY CITY TAX', 'rate'=>4.50, 'amt'=>6.75),
41
+ * array('name'=>'NY SPECIAL TAX', 'rate'=>4.375, 'amt'=>0.56)
42
+ * ),
43
+ * 'items' => array(
44
+ * 5 => array('rate'=>8.875, 'amt'=>13.31),
45
+ * 'Shipping' => array('rate'=>0, 'amt'=>0)
46
+ * )
47
+ * )
48
+ *
49
+ * @var array
50
+ */
51
+ protected $_rates = array();
52
+
53
+ /**
54
+ * An array of line numbers to quote item ids
55
+ *
56
+ * @var array
57
+ */
58
+ protected $_lineToLineId = array();
59
+
60
+ /**
61
+ * Product gift pair
62
+ *
63
+ * @var array
64
+ */
65
+ protected $_productGiftPair = array();
66
+
67
+ /**
68
+ * Last request key
69
+ *
70
+ * @var string
71
+ */
72
+ protected $_lastRequestKey;
73
+
74
+ /**
75
+ * Loads any saved rates in session
76
+ */
77
+ protected function _construct()
78
+ {
79
+ $rates = Mage::getSingleton('avatax/session')->getAvatax16Rates();
80
+ if (is_array($rates)) {
81
+ foreach ($rates as $key => $rate) {
82
+ if ($rate['timestamp'] < $this->_getDateModel()->timestamp('-' . self::CACHE_TTL . ' minutes')) {
83
+ unset($rates[$key]);
84
+ }
85
+ }
86
+ $this->_rates = $rates;
87
+ }
88
+ return parent::_construct();
89
+ }
90
+
91
+ /**
92
+ * Get rates from Avalara
93
+ *
94
+ * @param Mage_Sales_Model_Quote_Address $address
95
+ * @return array
96
+ */
97
+ public function getRates($address)
98
+ {
99
+ /** @var OnePica_AvaTax_Model_Sales_Quote_Address $address */
100
+ $this->_lines = array();
101
+
102
+ $quote = $address->getQuote();
103
+ $storeId = $quote->getStore()->getId();
104
+ $transactionDate = $this->_convertGmtDate(Varien_Date::now(), $storeId);
105
+
106
+ // Set up document for request
107
+ $this->_request = $this->_getNewDocumentRequestObject();
108
+
109
+ // set up header
110
+ $header = $this->_getRequestHeaderWithMainValues($storeId, $address);
111
+ $header->setDocumentCode('quote-' . $address->getId());
112
+ $header->setTransactionDate($transactionDate);
113
+ $header->setDefaultLocations($this->_getHeaderDefaultLocations($address));
114
+
115
+ $this->_request->setHeader($header);
116
+
117
+ $this->_addItemsInCart($address);
118
+ $this->_addShipping($address);
119
+ //Added code for calculating tax for giftwrap items (order)
120
+ $this->_addGwOrderAmount($address);
121
+ $this->_addGwPrintedCardAmount($address);
122
+
123
+ //check to see if we can/need to make the request to Avalara
124
+ $requestKey = $this->_genRequestKey();
125
+ $makeRequest = empty($this->_rates[$requestKey]['items']);
126
+ //@startSkipCommitHooks
127
+ $makeRequest &= count($this->_lineToLineId) ? true : false;
128
+
129
+ $hasDestinationAddress = false;
130
+ if ($this->_request->getHeader() && $this->_request->getHeader()->getDefaultLocations()) {
131
+ $locations = $this->_request->getHeader()->getDefaultLocations();
132
+ $hasDestinationAddress = isset($locations[self::TAX_LOCATION_PURPOSE_SHIP_TO]) ? true : false;
133
+ }
134
+
135
+ $makeRequest &= $hasDestinationAddress;
136
+ $makeRequest &= $address->getId() ? true : false;
137
+ $makeRequest &= !isset($this->_rates[$requestKey]['failure']);
138
+ //@finishSkipCommitHooks
139
+
140
+ //make request if needed and save results in cache
141
+ if ($makeRequest) {
142
+ /** @var OnePica_AvaTax16_Document_Response $result */
143
+ $result = $this->_send($quote->getStoreId());
144
+ $this->_rates[$requestKey] = array(
145
+ 'timestamp' => $this->_getDateModel()->timestamp(),
146
+ 'address_id' => $address->getId(),
147
+ 'summary' => array(),
148
+ 'items' => array(),
149
+ 'gw_items' => array()
150
+ );
151
+
152
+ //success
153
+ if (!$result->getHasError()) {
154
+ foreach ($result->getLines() as $ctl) {
155
+ /** @var OnePica_AvaTax16_Document_Response_Line $ctl */
156
+ $id = $this->_getItemIdByLine($ctl);
157
+ $code = $this->_getTaxArrayCodeByLine($ctl);
158
+ $this->_rates[$requestKey][$code][$id] = array(
159
+ 'rate' => $this->_getLineRate($ctl),
160
+ 'amt' => $ctl->getCalculatedTax()->getTax(),
161
+ 'jurisdiction_rates' => $this->_getItemJurisdictionRate($ctl)
162
+ );
163
+ }
164
+ $this->_rates[$requestKey]['summary'] = $this->_getSummaryFromResponse($result);
165
+ //failure
166
+ } else {
167
+ $this->_rates[$requestKey]['failure'] = true;
168
+ }
169
+ Mage::getSingleton('avatax/session')->setAvatax16Rates($this->_rates);
170
+ }
171
+
172
+ $rates = isset($this->_rates[$requestKey]) ? $this->_rates[$requestKey] : array();
173
+ return $rates;
174
+ }
175
+
176
+ /**
177
+ * Adds all items in the cart to the request
178
+ *
179
+ * @param Mage_Sales_Model_Quote_Address $address
180
+ * @return int
181
+ */
182
+ protected function _addItemsInCart(Mage_Sales_Model_Quote_Address $address)
183
+ {
184
+ $items = $address->getAllItems();
185
+ if (count($items) > 0) {
186
+ $this->_initProductCollection($items);
187
+ $this->_initTaxClassCollection($address);
188
+ foreach ($items as $item) {
189
+ /** @var Mage_Sales_Model_Quote_Item $item */
190
+ $this->_newLine($item);
191
+ }
192
+ $this->_setLinesToRequest();
193
+ }
194
+
195
+ return count($this->_lines);
196
+ }
197
+
198
+ /**
199
+ * Makes a Line object from a product item object
200
+ *
201
+ * @param Varien_Object|Mage_Sales_Model_Quote_Item $item
202
+ * @return int|bool
203
+ */
204
+ protected function _newLine($item)
205
+ {
206
+ $this->_addGwItemsAmount($item);
207
+ if ($this->isProductCalculated($item)) {
208
+ return false;
209
+ }
210
+ $product = $this->_getProductByProductId($item->getProductId());
211
+ $taxClass = $this->_getTaxClassCodeByProduct($product);
212
+ $price = $item->getBaseRowTotal() - $item->getBaseDiscountAmount();
213
+ $lineNumber = $this->_getNewLineCode();
214
+
215
+ $line = $this->_getNewDocumentRequestLineObject();
216
+ $line->setLineCode($lineNumber);
217
+ $line->setItemCode(
218
+ $this->_getCalculationHelper()->getItemCode(
219
+ $this->_getProductForItemCode($item),
220
+ $item->getStoreId()
221
+ )
222
+ );
223
+ $line->setNumberOfItems($item->getQty());
224
+ $line->setlineAmount($price);
225
+ $line->setItemDescription($item->getName());
226
+ $line->setDiscounted((float)$item->getDiscountAmount() ? 'true' : 'false');
227
+
228
+ if ($taxClass) {
229
+ $line->setAvalaraGoodsAndServicesType($taxClass);
230
+ }
231
+
232
+ $metadata = null;
233
+ $ref1Value = $this->_getRefValueByProductAndNumber($product, 1, $item->getStoreId());
234
+ if ($ref1Value) {
235
+ $metadata['ref1'] = $ref1Value;
236
+ }
237
+ $ref2Value = $this->_getRefValueByProductAndNumber($product, 2, $item->getStoreId());
238
+ if ($ref2Value) {
239
+ $metadata['ref2'] = $ref2Value;
240
+ }
241
+ if ($metadata) {
242
+ $line->setMetadata($metadata);
243
+ }
244
+
245
+ $this->_lines[$lineNumber] = $line;
246
+ $this->_lineToLineId[$lineNumber] = $item->getSku();
247
+ return $lineNumber;
248
+ }
249
+
250
+ /**
251
+ * Retrieve product for item code
252
+ *
253
+ * @param Mage_Sales_Model_Quote_Address_Item|Mage_Sales_Model_Quote_Item $item
254
+ * @return null|Mage_Catalog_Model_Product
255
+ * @throws OnePica_AvaTax_Exception
256
+ */
257
+ protected function _getProductForItemCode($item)
258
+ {
259
+ $product = $this->_getProductByProductId($item->getProductId());
260
+ if (!$this->_getCalculationHelper()->isConfigurable($item)) {
261
+ return $product;
262
+ }
263
+
264
+ $children = $item->getChildren();
265
+
266
+ if (isset($children[0]) && $children[0]->getProductId()) {
267
+ $product = $this->_getProductByProductId($children[0]->getProductId());
268
+ }
269
+
270
+ return $product;
271
+ }
272
+
273
+ /**
274
+ * Adds giftwrapitems cost to request as item
275
+ *
276
+ * @param Mage_Sales_Model_Quote_Item $item
277
+ * @return int|bool
278
+ */
279
+ protected function _addGwItemsAmount($item)
280
+ {
281
+ if (!$item->getGwId()) {
282
+ return false;
283
+ }
284
+ $lineNumber = $this->_getNewLineCode();
285
+ $storeId = $item->getQuote()->getStoreId();
286
+ //Add gift wrapping price(for individual items)
287
+ $gwItemsAmount = $item->getGwBasePrice() * $item->getQty();
288
+
289
+ $line = $this->_getNewDocumentRequestLineObject();
290
+ $line->setLineCode($lineNumber);
291
+ $gwItemsSku = $this->_getConfigHelper()->getGwItemsSku($storeId);
292
+ $line->setItemCode($gwItemsSku ? $gwItemsSku : self::DEFAULT_GW_ITEMS_SKU);
293
+ $line->setItemDescription(self::DEFAULT_GW_ITEMS_DESCRIPTION);
294
+ $line->setAvalaraGoodsAndServicesType($this->_getGiftTaxClassCode($storeId));
295
+ $line->setNumberOfItems($item->getQty());
296
+ $line->setlineAmount($gwItemsAmount);
297
+ $line->setDiscounted('false');
298
+
299
+ $this->_lines[$lineNumber] = $line;
300
+ $this->_setLinesToRequest();
301
+ $this->_lineToLineId[$lineNumber] = $this->_getConfigHelper()->getGwItemsSku($storeId);
302
+ $this->_productGiftPair[$lineNumber] = $item->getSku();
303
+
304
+ return $lineNumber;
305
+ }
306
+
307
+ /**
308
+ * Adds shipping cost to request as item
309
+ *
310
+ * @param Mage_Sales_Model_Quote_Address
311
+ * @return int
312
+ */
313
+ protected function _addShipping($address)
314
+ {
315
+ $lineNumber = $this->_getNewLineCode();
316
+ $storeId = $address->getQuote()->getStore()->getId();
317
+ $taxClass = Mage::helper('tax')->getShippingTaxClass($storeId);
318
+ $shippingAmount = (float) $address->getBaseShippingAmount();
319
+
320
+ $line = $this->_getNewDocumentRequestLineObject();
321
+ $line->setLineCode($lineNumber);
322
+ $shippingSku = $this->_getConfigHelper()->getShippingSku($storeId);
323
+ $line->setItemCode($shippingSku ? $shippingSku : self::DEFAULT_SHIPPING_ITEMS_SKU);
324
+ $line->setItemDescription(self::DEFAULT_SHIPPING_ITEMS_DESCRIPTION);
325
+ $line->setAvalaraGoodsAndServicesType($taxClass);
326
+ $line->setNumberOfItems(1);
327
+ $line->setlineAmount($shippingAmount);
328
+ $line->setDiscounted('false');
329
+
330
+ $this->_lines[$lineNumber] = $line;
331
+ $this->_setLinesToRequest();
332
+ $this->_lineToLineId[$lineNumber] = $shippingSku;
333
+ return $lineNumber;
334
+ }
335
+
336
+ /**
337
+ * Adds giftwraporder cost to request as item (for order)
338
+ *
339
+ * @param Mage_Sales_Model_Quote_Address $address
340
+ * @return int|bool
341
+ */
342
+ protected function _addGwOrderAmount($address)
343
+ {
344
+ if (!$address->getGwPrice()) {
345
+ return false;
346
+ }
347
+ $lineNumber = $this->_getNewLineCode();
348
+ $storeId = $address->getQuote()->getStore()->getId();
349
+ //Add gift wrapping price(for entire order)
350
+ $gwOrderAmount = $address->getGwBasePrice();
351
+
352
+ $line = $this->_getNewDocumentRequestLineObject();
353
+ $line->setLineCode($lineNumber);
354
+ $gwOrderSku = $this->_getConfigHelper()->getGwOrderSku($storeId);
355
+ $line->setItemCode($gwOrderSku ? $gwOrderSku : self::DEFAULT_GW_ORDER_SKU);
356
+ $line->setItemDescription(self::DEFAULT_GW_ORDER_DESCRIPTION);
357
+ $line->setAvalaraGoodsAndServicesType($this->_getGiftTaxClassCode($storeId));
358
+ $line->setNumberOfItems(1);
359
+ $line->setlineAmount($gwOrderAmount);
360
+ $line->setDiscounted('false');
361
+
362
+ $this->_lines[$lineNumber] = $line;
363
+ $this->_setLinesToRequest();
364
+ $this->_lineToLineId[$lineNumber] = $gwOrderSku;
365
+ return $lineNumber;
366
+ }
367
+
368
+ /**
369
+ * Adds giftwrap printed card cost to request as item
370
+ *
371
+ * @param Mage_Sales_Model_Quote
372
+ * @return int|bool
373
+ */
374
+ protected function _addGwPrintedCardAmount($address)
375
+ {
376
+ if (!$address->getGwPrintedCardPrice()) {
377
+ return false;
378
+ }
379
+ $lineNumber = $this->_getNewLineCode();
380
+ $storeId = $address->getQuote()->getStore()->getId();
381
+ //Add printed card price
382
+ $gwPrintedCardAmount = $address->getGwPrintedCardBasePrice();
383
+
384
+ $line = $this->_getNewDocumentRequestLineObject();
385
+ $line->setLineCode($lineNumber);
386
+ $gwPrintedCardSku = $this->_getConfigHelper()->getGwPrintedCardSku($storeId);
387
+ $line->setItemCode($gwPrintedCardSku ? $gwPrintedCardSku : self::DEFAULT_GW_PRINTED_CARD_SKU);
388
+ $line->setItemDescription(self::DEFAULT_GW_PRINTED_CARD_DESCRIPTION);
389
+ $line->setAvalaraGoodsAndServicesType($this->_getGiftTaxClassCode($storeId));
390
+ $line->setNumberOfItems(1);
391
+ $line->setlineAmount($gwPrintedCardAmount);
392
+ $line->setDiscounted('false');
393
+
394
+ $this->_lines[$lineNumber] = $line;
395
+ $this->_setLinesToRequest();
396
+ $this->_lineToLineId[$lineNumber] = $gwPrintedCardSku;
397
+ return $lineNumber;
398
+ }
399
+
400
+ /**
401
+ * Generates a hash key for the exact request
402
+ *
403
+ * @return string
404
+ */
405
+ protected function _genRequestKey()
406
+ {
407
+ $hash = sprintf("%u", crc32(serialize($this->_request)));
408
+ $this->_setLastRequestKey($hash);
409
+ return $hash;
410
+ }
411
+
412
+ /**
413
+ * Set last request key
414
+ *
415
+ * @param string $requestKey
416
+ */
417
+ protected function _setLastRequestKey($requestKey)
418
+ {
419
+ $this->_lastRequestKey = $requestKey;
420
+ }
421
+
422
+ /**
423
+ * Get last request key
424
+ *
425
+ * @return string|null
426
+ */
427
+ public function getLastRequestKey()
428
+ {
429
+ return $this->_lastRequestKey;
430
+ }
431
+
432
+ /**
433
+ * Sends a request to the Avatax16 server
434
+ *
435
+ * @param int $storeId
436
+ * @return mixed
437
+ */
438
+ protected function _send($storeId)
439
+ {
440
+ /** @var OnePica_AvaTax_Model_Service_Avatax16_Config $configModel */
441
+ $configModel = $this->getServiceConfig();
442
+ $config = $configModel->getLibConfig();
443
+ $connection = $configModel->getTaxConnection();
444
+ $result = null;
445
+ $message = null;
446
+
447
+ try {
448
+ $result = $connection->createCalculation($this->_request);
449
+ } catch (Exception $exception) {
450
+ $message = $this->_getNewServiceMessageObject();
451
+ $message->setSummary($exception->getMessage());
452
+ }
453
+
454
+ if (!isset($result) || !is_object($result)) {
455
+ $actualResult = $result;
456
+ $result = new Varien_Object();
457
+ $result->setHasError(true)
458
+ ->setResultCode(self::RESPONSE_RESULT_CODE_EXCEPTION)
459
+ ->setActualResult($actualResult)
460
+ ->setMessages(array($message));
461
+ }
462
+
463
+ $this->_log(
464
+ OnePica_AvaTax_Model_Source_Avatax16_Logtype::CALCULATION,
465
+ $this->_request,
466
+ $result,
467
+ $storeId,
468
+ $config
469
+ );
470
+
471
+ return $result;
472
+ }
473
+
474
+ /**
475
+ * Get item id/code for given line
476
+ *
477
+ * @param OnePica_AvaTax16_Document_Response_Line $line
478
+ * @return string|int
479
+ */
480
+ protected function _getItemIdByLine($line)
481
+ {
482
+ return isset($this->_productGiftPair[$line->getLineCode()])
483
+ ? $this->_productGiftPair[$line->getLineCode()]
484
+ : $this->_lineToLineId[$line->getLineCode()];
485
+ }
486
+
487
+ /**
488
+ * Get tax array code for given line
489
+ *
490
+ * @param OnePica_AvaTax16_Document_Response_Line $line
491
+ * @return string
492
+ */
493
+ protected function _getTaxArrayCodeByLine($line)
494
+ {
495
+ return isset($this->_productGiftPair[$line->getLineCode()]) ? 'gw_items' : 'items';
496
+ }
497
+
498
+ /**
499
+ * Get line rate
500
+ *
501
+ * @param OnePica_AvaTax16_Document_Response_Line $line
502
+ * @return float
503
+ */
504
+ protected function _getLineRate($line)
505
+ {
506
+ $rate = 0;
507
+ if ($line->getCalculatedTax()->getTax()) {
508
+ foreach ($line->getCalculatedTax()->getDetails() as $detail) {
509
+ $rate += $detail->getRate();
510
+ }
511
+ }
512
+ return $rate * 100;
513
+ }
514
+
515
+ /**
516
+ * Get line rate
517
+ *
518
+ * @param OnePica_AvaTax16_Document_Response $response
519
+ * @return array
520
+ */
521
+ protected function _getSummaryFromResponse($response)
522
+ {
523
+ $result = array();
524
+ $rates = $this->_getJurisdictionsRate($response);
525
+ foreach ($response->getCalculatedTaxSummary()->getTaxByType() as $type => $value) {
526
+ foreach ($value->getJurisdictions() as $data) {
527
+ $jurisdiction = $this->_prepareJurisdictionName(
528
+ $type,
529
+ $data->getJurisdictionName(),
530
+ $data->getJurisdictionType()
531
+ );
532
+ $result[] = array(
533
+ 'name' => $jurisdiction,
534
+ 'rate' => isset($rates[$jurisdiction]) ? $rates[$jurisdiction] : 0,
535
+ 'amt' => $data->getTax()
536
+ );
537
+ }
538
+ }
539
+
540
+ return $result;
541
+ }
542
+
543
+ /**
544
+ * Get Jurisdictions rate array
545
+ *
546
+ * @param OnePica_AvaTax16_Document_Response $response
547
+ * @return array
548
+ */
549
+ protected function _getJurisdictionsRate($response)
550
+ {
551
+ $rates = array();
552
+ $fixedRatesData = array();
553
+
554
+ /** @var OnePica_AvaTax16_Document_Response_Line $line */
555
+ foreach ($response->getLines() as $line) {
556
+ if (!$line->getCalculatedTax()->getTax()) {
557
+ continue;
558
+ }
559
+
560
+ foreach ($line->getCalculatedTax()->getDetails() as $detail) {
561
+ $jurisdiction = $this->_prepareJurisdictionName(
562
+ $detail->getTaxType(),
563
+ $detail->getJurisdictionName(),
564
+ $detail->getJurisdictionType()
565
+ );
566
+
567
+ if (!isset($rates[$jurisdiction]) && $detail->getRate()) {
568
+ $rates[$jurisdiction] = $detail->getRate() * 100;
569
+ }
570
+
571
+ if (!$detail->getRate() && $detail->getTax()) {
572
+ if (!isset($fixedRatesData[$jurisdiction]['fixedTax'])) {
573
+ $fixedRatesData[$jurisdiction]['fixedTax'] = 0;
574
+ }
575
+ if (!isset($fixedRatesData[$jurisdiction]['lineAmount'])) {
576
+ $fixedRatesData[$jurisdiction]['lineAmount'] = 0;
577
+ }
578
+ $fixedRatesData[$jurisdiction]['fixedTax'] += $detail->getTax();
579
+ $fixedRatesData[$jurisdiction]['lineAmount'] += $line->getLineAmount();
580
+ }
581
+ }
582
+ }
583
+
584
+ $fixedRates = array();
585
+ foreach ($fixedRatesData as $jurisdiction => $values) {
586
+ $fixedRates[$jurisdiction] = $this->_calculateRate($values['fixedTax'], $values['lineAmount']);
587
+ }
588
+
589
+ return array_merge($rates, $fixedRates);
590
+ }
591
+
592
+ /**
593
+ * Get tax detail summary
594
+ * this method is using last request key,
595
+ * so it returns summary of last made estimation.
596
+ * if you are using two calculation simultaneously,
597
+ * be sure to call getRates method for each calculation
598
+ * before calling getSummary
599
+ *
600
+ * @param Mage_Sales_Model_Quote_Address $address
601
+ *
602
+ * @return array
603
+ */
604
+ public function getSummary($address)
605
+ {
606
+ $lastRequestKey = $this->getLastRequestKey();
607
+
608
+ if (isset($lastRequestKey)) {
609
+ $result = isset($this->_rates[$lastRequestKey]['summary'])
610
+ ? $this->_rates[$lastRequestKey]['summary'] : array();
611
+ } else {
612
+ $rates = $this->getRates($address);
613
+ $result = (isset($rates)) ? $rates['summary'] : null;
614
+ }
615
+
616
+ return $result;
617
+ }
618
+
619
+ /**
620
+ * Get item jurisdiction rate
621
+ *
622
+ * @param OnePica_AvaTax16_Document_Response_Line $line
623
+ * @return array
624
+ */
625
+ protected function _getItemJurisdictionRate($line)
626
+ {
627
+ $rates = array();
628
+ if ($line->getCalculatedTax()->getTax()) {
629
+ foreach ($line->getCalculatedTax()->getDetails() as $detail) {
630
+ $jurisdiction = $this->_prepareJurisdictionName(
631
+ $detail->getTaxType(),
632
+ $detail->getJurisdictionName(),
633
+ $detail->getJurisdictionType()
634
+ );
635
+ $rates[$jurisdiction] = $detail->getRate() * 100;
636
+
637
+ if ($rates[$jurisdiction] === 0 && $detail->getTax()) {
638
+ $rates[$jurisdiction] = $this->_calculateRate($detail->getTax(), $line->getLineAmount());
639
+ }
640
+ }
641
+ }
642
+
643
+ return $rates;
644
+ }
645
+
646
+ /**
647
+ * Prepare Jurisdiction name
648
+ *
649
+ * @param string $taxType
650
+ * @param string $jurisdictionName
651
+ * @param string $jurisdictionType
652
+ * @return string
653
+ */
654
+ protected function _prepareJurisdictionName($taxType, $jurisdictionName, $jurisdictionType)
655
+ {
656
+ $name = preg_replace('/(?<!\ )[A-Z]/', ' $0', $taxType)
657
+ . ': '
658
+ . $jurisdictionName
659
+ . ' '
660
+ . $jurisdictionType;
661
+
662
+ return ucfirst(trim($name));
663
+ }
664
+
665
+ /**
666
+ * Calculate rate
667
+ *
668
+ * @param float $tax
669
+ * @param float $amount
670
+ * @return float
671
+ */
672
+ protected function _calculateRate($tax, $amount)
673
+ {
674
+ return $this->_getHelper()->roundUp(($tax / $amount) * 100, 2);
675
+ }
676
+ }
app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Invoice.php ADDED
@@ -0,0 +1,550 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The AvaTax16 Invoice model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Service_Avatax16_Invoice extends OnePica_AvaTax_Model_Service_Avatax16_Tax
26
+ {
27
+ /**
28
+ * An array of line numbers to product ids
29
+ *
30
+ * @var array
31
+ */
32
+ protected $_lineToItemId = array();
33
+
34
+ /**
35
+ * Save order's invoice in AvaTax system
36
+ *
37
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderInvoiceSaveAfter::execute()
38
+ * @param Mage_Sales_Model_Order_Invoice $invoice
39
+ * @param OnePica_AvaTax_Model_Records_Queue $queue
40
+ * @return OnePica_AvaTax_Model_Service_Result_Invoice
41
+ */
42
+ public function invoice($invoice, $queue)
43
+ {
44
+ $this->_lines = array();
45
+ $order = $invoice->getOrder();
46
+ $storeId = $order->getStoreId();
47
+ $invoiceDate = $this->_convertGmtDate($invoice->getCreatedAt(), $storeId);
48
+ $orderDate = $this->_convertGmtDate($order->getCreatedAt(), $storeId);
49
+
50
+ $shippingAddress = ($order->getShippingAddress()) ? $order->getShippingAddress() : $order->getBillingAddress();
51
+
52
+ // Set up document for request
53
+ $this->_request = $this->_getNewDocumentRequestObject();
54
+
55
+ // set up header
56
+ $header = $this->_getRequestHeaderWithMainValues($storeId, $order);
57
+ $header->setDocumentCode($this->_getInvoiceDocumentCode($invoice));
58
+ $header->setTransactionDate($invoiceDate);
59
+ $header->setTaxCalculationDate($orderDate);
60
+ $header->setDefaultLocations($this->_getHeaderDefaultLocations($shippingAddress));
61
+
62
+ $this->_request->setHeader($header);
63
+
64
+ $this->_addShipping($invoice);
65
+ $items = $invoice->getItemsCollection();
66
+ $this->_initProductCollection($items);
67
+ $this->_initTaxClassCollection($invoice);
68
+ //Added code for calculating tax for giftwrap items
69
+ $this->_addGwOrderAmount($invoice);
70
+ $this->_addGwItemsAmount($invoice);
71
+ $this->_addGwPrintedCardAmount($invoice);
72
+
73
+ foreach ($items as $item) {
74
+ /** @var Mage_Sales_Model_Order_Invoice_Item $item */
75
+ $this->_newLine($item);
76
+ }
77
+ $this->_setLinesToRequest();
78
+
79
+ //send to AvaTax
80
+ $result = $this->_send($order->getStoreId());
81
+
82
+ /** @var OnePica_AvaTax_Model_Service_Result_Invoice $invoiceResult */
83
+ $invoiceResult = Mage::getModel('avatax/service_result_invoice');
84
+ $invoiceResult->setHasError($result->getHasError());
85
+
86
+ //if successful
87
+ if (!$result->getHasError()) {
88
+ $totalTax = $result->getCalculatedTaxSummary()->getTotalTax();
89
+ $invoiceResult->setTotalTax($totalTax);
90
+ $documentCode = $result->getHeader()->getDocumentCode();
91
+ $invoiceResult->setDocumentCode($documentCode);
92
+
93
+ //if not successful
94
+ } else {
95
+ $invoiceResult->setErrors($result->getErrors());
96
+ }
97
+
98
+ return $invoiceResult;
99
+ }
100
+
101
+ /**
102
+ * Save order's creditmemo in AvaTax system
103
+ *
104
+ * @see OnePica_AvaTax_Model_Observer_SalesOrderCreditmemoSaveAfter::execute()
105
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
106
+ * @param OnePica_AvaTax_Model_Records_Queue $queue
107
+ * @return mixed
108
+ * @throws OnePica_AvaTax_Exception
109
+ * @throws OnePica_AvaTax_Model_Service_Exception_Commitfailure
110
+ * @throws OnePica_AvaTax_Model_Service_Exception_Unbalanced
111
+ */
112
+ public function creditmemo($creditmemo, $queue)
113
+ {
114
+ $this->_lines = array();
115
+ $order = $creditmemo->getOrder();
116
+ $storeId = $order->getStoreId();
117
+ $creditmemoDate = $this->_convertGmtDate($creditmemo->getCreatedAt(), $storeId);
118
+ $orderDate = $this->_convertGmtDate($order->getCreatedAt(), $storeId);
119
+
120
+ $shippingAddress = ($order->getShippingAddress()) ? $order->getShippingAddress() : $order->getBillingAddress();
121
+
122
+ // Set up document for request
123
+ $this->_request = $this->_getNewDocumentRequestObject();
124
+
125
+ // set up header
126
+ $header = $this->_getRequestHeaderWithMainValues($storeId, $order);
127
+ $header->setDocumentCode($this->_getCreditmemoDocumentCode($creditmemo));
128
+ $header->setTransactionDate($creditmemoDate);
129
+ $header->setTaxCalculationDate($orderDate);
130
+ $header->setDefaultLocations($this->_getHeaderDefaultLocations($shippingAddress));
131
+
132
+ $this->_request->setHeader($header);
133
+
134
+ $this->_addShipping($creditmemo, true);
135
+ $items = $creditmemo->getAllItems();
136
+ $this->_initProductCollection($items);
137
+ $this->_initTaxClassCollection($creditmemo);
138
+ //Added code for calculating tax for giftwrap items
139
+ $this->_addGwOrderAmount($creditmemo, true);
140
+ $this->_addGwItemsAmount($creditmemo, true);
141
+ $this->_addGwPrintedCardAmount($creditmemo, true);
142
+
143
+ $this->_addAdjustments(
144
+ $creditmemo->getBaseAdjustmentPositive(),
145
+ $creditmemo->getBaseAdjustmentNegative(),
146
+ $order->getStoreId()
147
+ );
148
+
149
+ foreach ($items as $item) {
150
+ /** @var Mage_Sales_Model_Order_Creditmemo_Item $item */
151
+ $this->_newLine($item, true);
152
+ }
153
+ $this->_setLinesToRequest();
154
+
155
+ //send to AvaTax
156
+ $result = $this->_send($order->getStoreId());
157
+
158
+ /** @var OnePica_AvaTax_Model_Service_Result_Creditmemo $creditmemoResult */
159
+ $creditmemoResult = Mage::getModel('avatax/service_result_creditmemo');
160
+ $creditmemoResult->setHasError($result->getHasError());
161
+
162
+ //if successful
163
+ if (!$result->getHasError()) {
164
+ $totalTax = $result->getCalculatedTaxSummary()->getTotalTax();
165
+ $creditmemoResult->setTotalTax($totalTax);
166
+ $documentCode = $result->getHeader()->getDocumentCode();
167
+ $creditmemoResult->setDocumentCode($documentCode);
168
+
169
+ //if not successful
170
+ } else {
171
+ $creditmemoResult->setErrors($result->getErrors());
172
+ }
173
+
174
+ return $creditmemoResult;
175
+ }
176
+
177
+ /**
178
+ * Adds adjustments to request as items
179
+ *
180
+ * @param float $positive
181
+ * @param float $negative
182
+ * @param int $storeId
183
+ * @return array
184
+ */
185
+ protected function _addAdjustments($positive, $negative, $storeId)
186
+ {
187
+ if ($positive != 0) {
188
+ $lineNumber = $this->_getNewLineCode();
189
+ $identifier = $this->_getConfigHelper()->getPositiveAdjustmentSku($storeId);
190
+ $identifier = $identifier ? $identifier : self::DEFAULT_POSITIVE_ADJUSTMENT_CODE;
191
+
192
+ $line = $this->_getNewDocumentRequestLineObject();
193
+ $line->setLineCode($lineNumber);
194
+ $line->setItemCode($identifier);
195
+ $line->setItemDescription(self::DEFAULT_POSITIVE_ADJUSTMENT_DESCRIPTION);
196
+ $line->setAvalaraGoodsAndServicesType($identifier);
197
+ $line->setNumberOfItems(1);
198
+ $line->setlineAmount($positive * -1);
199
+ $line->setDiscounted('false');
200
+ //$line->setTaxIncluded('true');
201
+
202
+ $this->_lineToItemId[$lineNumber] = $identifier;
203
+ $this->_lines[$lineNumber] = $line;
204
+ $this->_setLinesToRequest();
205
+ }
206
+
207
+ if ($negative != 0) {
208
+ $lineNumber = $this->_getNewLineCode();
209
+ $identifier = $this->_getConfigHelper()->getNegativeAdjustmentSku($storeId);
210
+ $identifier = $identifier ? $identifier : self::DEFAULT_NEGATIVE_ADJUSTMENT_CODE;
211
+
212
+ $line = $this->_getNewDocumentRequestLineObject();
213
+ $line->setLineCode($lineNumber);
214
+ $line->setItemCode($identifier);
215
+ $line->setItemDescription(self::DEFAULT_NEGATIVE_ADJUSTMENT_DESCRIPTION);
216
+ $line->setAvalaraGoodsAndServicesType($identifier);
217
+ $line->setNumberOfItems(1);
218
+ $line->setlineAmount($negative);
219
+ $line->setDiscounted('false');
220
+ //$line->setTaxIncluded('true');
221
+
222
+ $this->_lineToItemId[$lineNumber] = $identifier;
223
+ $this->_lines[$lineNumber] = $line;
224
+ $this->_setLinesToRequest();
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Adds shipping cost to request as item
230
+ *
231
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
232
+ * @param bool $credit
233
+ * @return int|bool
234
+ */
235
+ protected function _addShipping($object, $credit = false)
236
+ {
237
+ if ($object->getBaseShippingAmount() == 0) {
238
+ return false;
239
+ }
240
+
241
+ $lineNumber = $this->_getNewLineCode();
242
+ $storeId = $object->getStore()->getId();
243
+ $taxClass = Mage::helper('tax')->getShippingTaxClass($storeId);
244
+
245
+ $amount = $object->getBaseShippingAmount();
246
+ //@startSkipCommitHooks
247
+ $amount = $credit ? (-1 * $amount) : $amount;
248
+ //@finishSkipCommitHooks
249
+
250
+ $line = $this->_getNewDocumentRequestLineObject();
251
+ $line->setLineCode($lineNumber);
252
+ $shippingSku = $this->_getConfigHelper()->getShippingSku($storeId);
253
+ $line->setItemCode($shippingSku ? $shippingSku : self::DEFAULT_SHIPPING_ITEMS_SKU);
254
+ $line->setItemDescription(self::DEFAULT_SHIPPING_ITEMS_DESCRIPTION);
255
+ $line->setAvalaraGoodsAndServicesType($taxClass);
256
+ $line->setNumberOfItems(1);
257
+ $line->setlineAmount($amount);
258
+ $line->setDiscounted('false');
259
+
260
+ $this->_lineToItemId[$lineNumber] = $shippingSku;
261
+ $this->_lines[$lineNumber] = $line;
262
+ $this->_setLinesToRequest();
263
+ return $lineNumber;
264
+ }
265
+
266
+ /**
267
+ * Adds giftwraporder cost to request as item
268
+ *
269
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
270
+ * @param bool $credit
271
+ * @return int|bool
272
+ */
273
+ protected function _addGwOrderAmount($object, $credit = false)
274
+ {
275
+ if ($object->getGwPrice() == 0) {
276
+ return false;
277
+ }
278
+
279
+ $lineNumber = $this->_getNewLineCode();
280
+ $storeId = $object->getStore()->getId();
281
+ $amount = $object->getGwBasePrice();
282
+ //@startSkipCommitHooks
283
+ $amount = $credit ? (-1 * $amount) : $amount;
284
+ //@finishSkipCommitHooks
285
+
286
+ $line = $this->_getNewDocumentRequestLineObject();
287
+ $line->setLineCode($lineNumber);
288
+ $gwOrderSku = $this->_getConfigHelper()->getGwOrderSku($storeId);
289
+ $line->setItemCode($gwOrderSku ? $gwOrderSku : self::DEFAULT_GW_ORDER_SKU);
290
+ $line->setItemDescription(self::DEFAULT_GW_ORDER_DESCRIPTION);
291
+ $line->setAvalaraGoodsAndServicesType($this->_getGiftTaxClassCode($storeId));
292
+ $line->setNumberOfItems(1);
293
+ $line->setlineAmount($amount);
294
+ $line->setDiscounted('false');
295
+
296
+ $this->_lineToItemId[$lineNumber] = $gwOrderSku;
297
+ $this->_lines[$lineNumber] = $line;
298
+ $this->_setLinesToRequest();
299
+ return $lineNumber;
300
+ }
301
+
302
+ /**
303
+ * Adds giftwrapitems cost to request as item
304
+ *
305
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
306
+ * @param bool $credit
307
+ * @return int|bool
308
+ */
309
+ protected function _addGwItemsAmount($object, $credit = false)
310
+ {
311
+ if ($object->getGwItemsPrice() == 0) {
312
+ return false;
313
+ }
314
+
315
+ $lineNumber = $this->_getNewLineCode();
316
+ $storeId = $object->getStore()->getId();
317
+
318
+ $amount = $object->getGwItemsBasePrice();
319
+ //@startSkipCommitHooks
320
+ $amount = $credit ? (-1 * $amount) : $amount;
321
+ //@finishSkipCommitHooks
322
+
323
+ $line = $this->_getNewDocumentRequestLineObject();
324
+ $line->setLineCode($lineNumber);
325
+ $gwItemsSku = $this->_getConfigHelper()->getGwItemsSku($storeId);
326
+ $line->setItemCode($gwItemsSku ? $gwItemsSku : self::DEFAULT_GW_ITEMS_SKU);
327
+ $line->setItemDescription(self::DEFAULT_GW_ITEMS_DESCRIPTION);
328
+ $line->setAvalaraGoodsAndServicesType($this->_getGiftTaxClassCode($storeId));
329
+ $line->setNumberOfItems(1);
330
+ $line->setlineAmount($amount);
331
+ $line->setDiscounted('false');
332
+
333
+ $this->_lineToItemId[$lineNumber] = $gwItemsSku;
334
+ $this->_lines[$lineNumber] = $line;
335
+ $this->_setLinesToRequest();
336
+ return $lineNumber;
337
+ }
338
+
339
+ /**
340
+ * Adds giftwrap printed card cost to request as item
341
+ *
342
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
343
+ * @param bool $credit
344
+ * @return int|bool
345
+ */
346
+ protected function _addGwPrintedCardAmount($object, $credit = false)
347
+ {
348
+ if (!$object->getGwPrintedCardBasePrice()) {
349
+ return false;
350
+ }
351
+
352
+ $lineNumber = $this->_getNewLineCode();
353
+ $storeId = $object->getStore()->getId();
354
+
355
+ $amount = $object->getGwPrintedCardBasePrice();
356
+ //@startSkipCommitHooks
357
+ $amount = $credit ? (-1 * $amount) : $amount;
358
+ //@finishSkipCommitHooks
359
+
360
+ $line = $this->_getNewDocumentRequestLineObject();
361
+ $line->setLineCode($lineNumber);
362
+ $gwPrintedCardSku = $this->_getConfigHelper()->getGwPrintedCardSku($storeId);
363
+ $line->setItemCode($gwPrintedCardSku ? $gwPrintedCardSku : self::DEFAULT_GW_PRINTED_CARD_SKU);
364
+ $line->setItemDescription(self::DEFAULT_GW_PRINTED_CARD_DESCRIPTION);
365
+ $line->setAvalaraGoodsAndServicesType($this->_getGiftTaxClassCode($storeId));
366
+ $line->setNumberOfItems(1);
367
+ $line->setlineAmount($amount);
368
+ $line->setDiscounted('false');
369
+
370
+ $this->_lineToItemId[$lineNumber] = $gwPrintedCardSku;
371
+ $this->_lines[$lineNumber] = $line;
372
+ $this->_setLinesToRequest();
373
+ return $lineNumber;
374
+ }
375
+
376
+ /**
377
+ * Makes a Line object from a product item object
378
+ *
379
+ * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
380
+ * @param bool $credit
381
+ * @return null|bool
382
+ */
383
+ protected function _newLine($item, $credit = false)
384
+ {
385
+ if ($this->isProductCalculated($item->getOrderItem())) {
386
+ return false;
387
+ }
388
+ if ($item->getQty() == 0) {
389
+ return false;
390
+ }
391
+
392
+ $lineNumber = $this->_getNewLineCode();
393
+ $storeId = $this->_retrieveStoreIdFromItem($item);
394
+
395
+ $price = $item->getBaseRowTotal() - $item->getBaseDiscountAmount();
396
+ //@startSkipCommitHooks
397
+ $price = $credit ? (-1 * $price) : $price;
398
+ //@finishSkipCommitHooks
399
+
400
+ $line = $this->_getNewDocumentRequestLineObject();
401
+ $line->setLineCode($lineNumber);
402
+ $line->setItemCode($this->_getCalculationHelper()
403
+ ->getItemCode($this->_getProductForItemCode($item), $storeId, $item));
404
+ $line->setItemDescription($item->getName());
405
+ $line->setNumberOfItems($item->getQty());
406
+ $line->setlineAmount($price);
407
+ $line->setDiscounted($item->getBaseDiscountAmount() ? 'true' : 'false');
408
+
409
+ $productData = $this->_getLineProductData($item, $storeId);
410
+ $line->setAvalaraGoodsAndServicesType($productData->getTaxCode());
411
+ $line->setMetadata($productData->getMetaData());
412
+
413
+ $this->_lineToItemId[$lineNumber] = $item->getOrderItemId();
414
+ $this->_lines[$lineNumber] = $line;
415
+ }
416
+
417
+ /**
418
+ * Retrieve product for item code
419
+ *
420
+ * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
421
+ * @return null|Mage_Catalog_Model_Product
422
+ * @throws OnePica_AvaTax_Exception
423
+ */
424
+ protected function _getProductForItemCode($item)
425
+ {
426
+ $product = $this->_getProductByProductId($item->getProductId());
427
+ if (!$this->_getCalculationHelper()->isConfigurable($item)) {
428
+ return $product;
429
+ }
430
+
431
+ $children = $item->getOrderItem()->getChildrenItems();
432
+
433
+ if (isset($children[0]) && $children[0]->getProductId()) {
434
+ $product = $this->_getProductByProductId($children[0]->getProductId());
435
+ }
436
+
437
+ return $product;
438
+ }
439
+
440
+ /**
441
+ * Retrieve store id from item
442
+ *
443
+ * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
444
+ * @return int
445
+ */
446
+ protected function _retrieveStoreIdFromItem($item)
447
+ {
448
+ $storeId = null;
449
+ if ($item instanceof Mage_Sales_Model_Order_Invoice_Item) {
450
+ $storeId = $item->getInvoice()->getStoreId();
451
+ } else {
452
+ $storeId = $item->getCreditmemo()->getStoreId();
453
+ }
454
+
455
+ return $storeId;
456
+ }
457
+
458
+ /**
459
+ * Sends a request to the Avatax16 server
460
+ *
461
+ * @param int $storeId
462
+ * @return mixed
463
+ */
464
+ protected function _send($storeId)
465
+ {
466
+ /** @var OnePica_AvaTax_Model_Service_Avatax16_Config $configModel */
467
+ $configModel = $this->getServiceConfig();
468
+ $config = $configModel->getLibConfig();
469
+ $connection = $configModel->getTaxConnection();
470
+ $result = null;
471
+ $message = null;
472
+
473
+ try {
474
+ $result = $connection->createTransaction($this->_request);
475
+ } catch (Exception $exception) {
476
+ $message = $this->_getNewServiceMessageObject();
477
+ $message->setSummary($exception->getMessage());
478
+ }
479
+
480
+ if (!isset($result) || !is_object($result)) {
481
+ $actualResult = $result;
482
+ $result = new Varien_Object();
483
+ $result->setHasError(true)
484
+ ->setResultCode(self::RESPONSE_RESULT_CODE_EXCEPTION)
485
+ ->setActualResult($actualResult)
486
+ ->setMessages(array($message));
487
+ }
488
+
489
+ $this->_log(
490
+ OnePica_AvaTax_Model_Source_Avatax16_Logtype::TRANSACTION,
491
+ $this->_request,
492
+ $result,
493
+ $storeId,
494
+ $config
495
+ );
496
+
497
+ return $result;
498
+ }
499
+
500
+ /**
501
+ * Get document code for invoice
502
+ *
503
+ * @param Mage_Sales_Model_Order_Invoice $invoice
504
+ * @return string
505
+ */
506
+ protected function _getInvoiceDocumentCode($invoice)
507
+ {
508
+ return self::DOCUMENT_CODE_INVOICE_PREFIX . $invoice->getIncrementId();
509
+ }
510
+
511
+ /**
512
+ * Get document code for creditmemo
513
+ *
514
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
515
+ * @return string
516
+ */
517
+ protected function _getCreditmemoDocumentCode($creditmemo)
518
+ {
519
+ return self::DOCUMENT_CODE_CREDITMEMO_PREFIX . $creditmemo->getIncrementId();
520
+ }
521
+
522
+ /**
523
+ * Get line product data
524
+ *
525
+ * Return a Varien_Object with the following possible methods: getTaxCode, getMetaData
526
+ *
527
+ * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
528
+ * @param int $storeId
529
+ * @return \Varien_Object
530
+ */
531
+ protected function _getLineProductData($item, $storeId)
532
+ {
533
+ $lineProductData = new Varien_Object();
534
+ $product = $this->_getProductByProductId($item->getProductId());
535
+
536
+ if (null === $product) {
537
+ return $lineProductData;
538
+ }
539
+
540
+ $lineProductData->setTaxCode($this->_getTaxClassCodeByProduct($product));
541
+ $metaData = array(
542
+ 'ref1' => $this->_getRefValueByProductAndNumber($product, 1, $storeId),
543
+ 'ref2' => $this->_getRefValueByProductAndNumber($product, 2, $storeId)
544
+ );
545
+
546
+ $lineProductData->setMetaData($metaData);
547
+
548
+ return $lineProductData;
549
+ }
550
+ }
app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Ping.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The AvaTax Ping model
20
+ *
21
+ * @class OnePica_AvaTax_Model_Service_Avatax16_Ping
22
+ * @category OnePica
23
+ * @package OnePica_AvaTax
24
+ * @author OnePica Codemaster <codemaster@onepica.com>
25
+ */
26
+ class OnePica_AvaTax_Model_Service_Avatax16_Ping extends OnePica_AvaTax_Model_Service_Avatax16_Abstract
27
+ {
28
+ /**
29
+ * Tries to ping AvaTax service with provided credentials
30
+ *
31
+ * @param int $storeId
32
+ * @return bool|array
33
+ */
34
+ public function ping($storeId = null)
35
+ {
36
+ /** @var OnePica_AvaTax_Model_Service_Avatax16_Config $config */
37
+ $config = $this->getServiceConfig();
38
+ $connection = $config->getTaxConnection();
39
+ $result = null;
40
+ $message = '';
41
+
42
+ try {
43
+ /** @var OnePica_AvaTax16_AddressResolution_PingResponse $result */
44
+ $result = $connection->ping();
45
+ } catch (Exception $exception) {
46
+ $message = $exception->getMessage();
47
+ }
48
+
49
+ if (!isset($result) || !is_object($result) || !$result->getHasError()) {
50
+ $actualResult = $result;
51
+ $result = new Varien_Object();
52
+ $result->setHasError($result->getHasError());
53
+ $result->setActualResult($actualResult);
54
+ $result->setMessage($message);
55
+ }
56
+
57
+ $this->_log(
58
+ OnePica_AvaTax_Model_Source_Avatax_Logtype::PING,
59
+ new stdClass(),
60
+ $result,
61
+ $storeId,
62
+ $config->getParams()
63
+ );
64
+
65
+ if ($result->getHasError()) {
66
+ if (is_array($result->getErrors())) {
67
+ $messages = array();
68
+ foreach ($result->getErrors() as $messageItem) {
69
+ $messages[] = $this->__($messageItem);
70
+ }
71
+ $message .= implode(' ', $messages);
72
+ }
73
+ }
74
+
75
+ if (!$message) {
76
+ $message = $this->__('The user or account could not be authenticated.');
77
+ }
78
+
79
+ return (!$result->getHasError()) ? true : $message;
80
+ }
81
+ }
app/code/community/OnePica/AvaTax/Model/Service/Avatax16/Tax.php ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Avatax16 service tax model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Service_Avatax16_Tax extends OnePica_AvaTax_Model_Service_Avatax16_Abstract
26
+ {
27
+ /**
28
+ * The document request data object
29
+ *
30
+ * @var OnePica_AvaTax16_Document_Request
31
+ */
32
+ protected $_request = null;
33
+
34
+ /**
35
+ * An array of line items
36
+ *
37
+ * @var array
38
+ */
39
+ protected $_lines = array();
40
+
41
+ /**
42
+ * Product collection for items to be calculated
43
+ *
44
+ * @var Mage_Catalog_Model_Resource_Product_Collection
45
+ */
46
+ protected $_productCollection = null;
47
+
48
+ /**
49
+ * Tax class collection for items to be calculated
50
+ *
51
+ * @var Mage_Tax_Model_Resource_Class_Collection
52
+ */
53
+ protected $_taxClassCollection = null;
54
+
55
+ /**
56
+ * Get the orgin address for the request
57
+ *
58
+ * @param null|bool|int|Mage_Core_Model_Store $store
59
+ * @return OnePica_AvaTax16_Document_Part_Location_Address
60
+ */
61
+ protected function _getOriginAddress($store = null)
62
+ {
63
+ $country = Mage::getStoreConfig('shipping/origin/country_id', $store);
64
+ $zip = Mage::getStoreConfig('shipping/origin/postcode', $store);
65
+ $regionId = Mage::getStoreConfig('shipping/origin/region_id', $store);
66
+ $state = Mage::getModel('directory/region')->load($regionId)->getCode();
67
+ $city = Mage::getStoreConfig('shipping/origin/city', $store);
68
+ $street = Mage::getStoreConfig('shipping/origin/street', $store);
69
+ $address = $this->_newAddress($street, '', $city, $state, $zip, $country);
70
+ return $address;
71
+ }
72
+
73
+ /**
74
+ * Get the shipping address for the request
75
+ *
76
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address $address
77
+ * @return OnePica_AvaTax16_Document_Part_Location_Address
78
+ */
79
+ protected function _getDestinationAddress($address)
80
+ {
81
+ $street1 = $address->getStreet(1);
82
+ $street2 = $address->getStreet(2);
83
+ $city = (string)$address->getCity();
84
+ $zip = $address->getPostcode();
85
+ $state = Mage::getModel('directory/region')->load($address->getRegionId())->getCode();
86
+ $country = $address->getCountry();
87
+ $address = $this->_newAddress($street1, $street2, $city, $state, $zip, $country);
88
+
89
+ return $address;
90
+ }
91
+
92
+ /**
93
+ * Generic address maker
94
+ *
95
+ * @param string $line1
96
+ * @param string $line2
97
+ * @param string $city
98
+ * @param string $state
99
+ * @param string $zip
100
+ * @param string $country
101
+ * @return OnePica_AvaTax16_Document_Part_Location_Address
102
+ */
103
+ protected function _newAddress($line1, $line2, $city, $state, $zip, $country = 'USA')
104
+ {
105
+ $address = $this->_getNewDocumentPartLocationAddressObject();
106
+ // set required field line1 if it is empty
107
+ $line1 = ($line1) ? $line1 : '_';
108
+ $address->setLine1($line1);
109
+ $address->setLine2($line2);
110
+ $address->setCity($city);
111
+ $address->setState($state);
112
+ $address->setZipcode($zip);
113
+ $address->setCountry($country);
114
+ return $address;
115
+ }
116
+
117
+ /**
118
+ * Get default locations
119
+ *
120
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address
121
+ * @return array
122
+ */
123
+ protected function _getHeaderDefaultLocations($address)
124
+ {
125
+ $entity = $address->getQuote() ? $address->getQuote() : $address->getOrder();
126
+ $storeId = $entity->getStoreId();
127
+
128
+ $locationFrom = $this->_getNewDocumentPartLocationObject();
129
+ $locationFrom->setTaxLocationPurpose(self::TAX_LOCATION_PURPOSE_SHIP_FROM);
130
+ $locationFrom->setAddress($this->_getOriginAddress($storeId));
131
+
132
+ $locationTo = $this->_getNewDocumentPartLocationObject();
133
+ $locationTo->setTaxLocationPurpose(self::TAX_LOCATION_PURPOSE_SHIP_TO);
134
+ $locationTo->setAddress($this->_getDestinationAddress($address));
135
+
136
+ $defaultLocations = array(
137
+ self::TAX_LOCATION_PURPOSE_SHIP_FROM => $locationFrom,
138
+ self::TAX_LOCATION_PURPOSE_SHIP_TO => $locationTo
139
+ );
140
+
141
+ return $defaultLocations;
142
+ }
143
+
144
+ /**
145
+ * Init product collection for items to be calculated
146
+ *
147
+ * @param Mage_Sales_Model_Mysql4_Order_Invoice_Item_Collection|array $items
148
+ * @return $this
149
+ */
150
+ protected function _initProductCollection($items)
151
+ {
152
+ $productIds = array();
153
+ foreach ($items as $item) {
154
+ if (!$this->isProductCalculated($item)) {
155
+ $productIds[] = $item->getProductId();
156
+ $simpleProductId = $this->_getCalculationHelper()->getSimpleProductIdByConfigurable($item);
157
+ if ($simpleProductId) {
158
+ $productIds[] = $simpleProductId;
159
+ }
160
+ }
161
+ }
162
+ $this->_productCollection = Mage::getModel('catalog/product')->getCollection()
163
+ ->addAttributeToSelect('*')
164
+ ->addAttributeToFilter('entity_id', array('in' => $productIds));
165
+
166
+ return $this;
167
+ }
168
+
169
+ /**
170
+ * Init tax class collection for items to be calculated
171
+ *
172
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo|Mage_Sales_Model_Quote_Address $object
173
+ * @return $this
174
+ * @throws OnePica_AvaTax_Exception
175
+ */
176
+ protected function _initTaxClassCollection($object)
177
+ {
178
+ $taxClassIds = array();
179
+ foreach ($this->_getProductCollection() as $product) {
180
+ if (!in_array($product->getTaxClassId(), $taxClassIds)) {
181
+ $taxClassIds[] = $product->getTaxClassId();
182
+ }
183
+ }
184
+ $gwTaxClassId = $this->_getGwTaxClassId($object);
185
+
186
+ if (0 !== $gwTaxClassId) {
187
+ $taxClassIds[] = $gwTaxClassId;
188
+ }
189
+ $this->_taxClassCollection = Mage::getModel('tax/class')->getCollection()
190
+ ->addFieldToFilter('class_id', array('in' => $taxClassIds));
191
+
192
+ return $this;
193
+ }
194
+
195
+ /**
196
+ * Get product collection for items to be calculated
197
+ *
198
+ * @return Mage_Catalog_Model_Resource_Product_Collection
199
+ * @throws OnePica_AvaTax_Exception
200
+ */
201
+ protected function _getProductCollection()
202
+ {
203
+ if (!$this->_productCollection) {
204
+ throw new OnePica_AvaTax_Exception('Product collection should be set before usage');
205
+ }
206
+
207
+ return $this->_productCollection;
208
+ }
209
+
210
+ /**
211
+ * Get tax class collection for items to be calculated
212
+ *
213
+ * @return Mage_Tax_Model_Resource_Class_Collection
214
+ * @throws OnePica_AvaTax_Exception
215
+ */
216
+ protected function _getTaxClassCollection()
217
+ {
218
+ if (!$this->_taxClassCollection) {
219
+ throw new OnePica_AvaTax_Exception('Tax class collection should be set before usage');
220
+ }
221
+
222
+ return $this->_taxClassCollection;
223
+ }
224
+
225
+ /**
226
+ * Get gift wrapping tax class id
227
+ *
228
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo|Mage_Sales_Model_Quote_Address $object
229
+ * @return int
230
+ */
231
+ protected function _getGwTaxClassId($object)
232
+ {
233
+ if (Mage::getEdition() !== Mage::EDITION_ENTERPRISE) {
234
+ return 0;
235
+ }
236
+ if (!$object->getGwPrice()
237
+ && !$object->getGwItemsPrice()
238
+ && !$object->getGwPrintedCardPrice()
239
+ ) {
240
+ return 0;
241
+ }
242
+
243
+ if ($object instanceof Mage_Sales_Model_Quote_Address) {
244
+ $storeId = $object->getQuote()->getStoreId();
245
+ } else {
246
+ $storeId = $object->getStoreId();
247
+ }
248
+
249
+ return $this->_getWrappingTaxClass($storeId);
250
+ }
251
+
252
+ /**
253
+ * Get gift wrapping tax class config value
254
+ *
255
+ * @param int $storeId
256
+ * @return int
257
+ */
258
+ protected function _getWrappingTaxClass($storeId)
259
+ {
260
+ return (int)$this->_getGiftWrappingDataHelper()->getWrappingTaxClass($storeId);
261
+ }
262
+
263
+ /**
264
+ * Get product from collection by given product id
265
+ *
266
+ * @param int $productId
267
+ * @return Mage_Catalog_Model_Product
268
+ * @throws OnePica_AvaTax_Exception
269
+ */
270
+ protected function _getProductByProductId($productId)
271
+ {
272
+ return $this->_getProductCollection()->getItemById($productId);
273
+ }
274
+
275
+ /**
276
+ * Get Avatax tax code for given product
277
+ *
278
+ * @param Mage_Catalog_Model_Product $product
279
+ * @return string
280
+ */
281
+ protected function _getTaxClassCodeByProduct($product)
282
+ {
283
+ $taxClass = $this->_getTaxClassCollection()->getItemById($product->getTaxClassId());
284
+ return $taxClass ? $taxClass->getOpAvataxCode() : '';
285
+ }
286
+
287
+ /**
288
+ * Get gift Avatax tax class code
289
+ *
290
+ * @param int $storeId
291
+ * @return string
292
+ */
293
+ protected function _getGiftTaxClassCode($storeId)
294
+ {
295
+ $taxClassId = $this->_getWrappingTaxClass($storeId);
296
+ $taxClass = $this->_getTaxClassCollection()->getItemById($taxClassId);
297
+ return $taxClass ? $taxClass->getOpAvataxCode() : '';
298
+ }
299
+
300
+ /**
301
+ * Get proper ref value for given product
302
+ *
303
+ * @param Mage_Catalog_Model_Product $product
304
+ * @param int $refNumber
305
+ * @param int $storeId
306
+ * @return null|string
307
+ */
308
+ protected function _getRefValueByProductAndNumber($product, $refNumber, $storeId)
309
+ {
310
+ $value = null;
311
+ $helperMethod = 'getRef' . $refNumber . 'AttributeCode';
312
+ $code = $this->_getConfigHelper()->{$helperMethod}($storeId);
313
+ $value = $this->_getCalculationHelper()->getProductAttributeValue($product, $code);
314
+
315
+ return $value;
316
+ }
317
+
318
+ /**
319
+ * Get new line code
320
+ *
321
+ * @return string
322
+ */
323
+ protected function _getNewLineCode()
324
+ {
325
+ return count($this->_lines) + 1;
326
+ }
327
+
328
+ /**
329
+ * Set lines to request object
330
+ * Avalara should receive lines as numeric array starting from 0
331
+ *
332
+ * @return $this
333
+ */
334
+ protected function _setLinesToRequest()
335
+ {
336
+ $this->_request->setLines(array_values($this->_lines));
337
+ }
338
+
339
+ /**
340
+ * Get Request Header With Main Values
341
+ *
342
+ * @param int $storeId
343
+ * @param OnePica_AvaTax_Model_Sales_Quote_Address|Mage_Sales_Model_Order $object
344
+ * @return \OnePica_AvaTax16_Document_Request_Header
345
+ */
346
+ protected function _getRequestHeaderWithMainValues($storeId, $object)
347
+ {
348
+ $configModel = $this->getServiceConfig()->init($storeId);
349
+ $config = $configModel->getLibConfig();
350
+ // header generation
351
+ $header = $this->_getNewDocumentRequestHeaderObject();
352
+ $header->setAccountId($config->getAccountId());
353
+ $header->setCompanyCode($config->getCompanyCode());
354
+ $header->setTransactionType(self::TRANSACTION_TYPE_SALE);
355
+ $header->setCustomerCode($this->_getCalculationHelper()->getCustomerCode($object));
356
+ $header->setDefaultTaxPayerCode($this->_getVatId($object));
357
+ $metadata = array('salesPersonCode' => $this->_getConfigHelper()->getSalesPersonCode($storeId));
358
+ $header->setMetadata($metadata);
359
+ /** @todo: Remove this code if this field is not required by extesion and Avalara
360
+ $header->setVendorCode(self::DEFAULT_VENDOR_CODE); */
361
+ $header->setCurrency(Mage::app()->getStore($storeId)->getBaseCurrencyCode());
362
+ $header->setDefaultBuyerType($this->_getCalculationHelper()->getCustomerOpAvataxCode($object));
363
+ /** @todo: Remove this code if we will not use those properties
364
+ $header->setDefaultAvalaraGoodsAndServicesType($this->_getConfigHelper()
365
+ ->getDefaultAvalaraGoodsAndServicesType($storeId));
366
+ $header->setDefaultAvalaraGoodsAndServicesModifierType($this->_getConfigHelper()
367
+ ->getDefaultAvalaraGoodsAndServicesModifierType($storeId));
368
+ $header->setDefaultTaxPayerCode($this->_getConfigHelper()->getDefaultTaxPayerCode($storeId));
369
+ $header->setDefaultUseType($this->_getConfigHelper()->getDefaultUseType($storeId));
370
+ $header->setDefaultBuyerType($this->_getConfigHelper()->getDefaultBuyerType($storeId));
371
+ */
372
+
373
+ return $header;
374
+ }
375
+
376
+ /**
377
+ * Get calculation helper
378
+ *
379
+ * @return \OnePica_AvaTax_Helper_Calculation
380
+ */
381
+ protected function _getCalculationHelper()
382
+ {
383
+ return Mage::helper('avatax/calculation');
384
+ }
385
+ }
app/code/community/OnePica/AvaTax/Model/{Avatax → Service}/Exception/Address.php RENAMED
@@ -16,12 +16,12 @@
16
  */
17
 
18
  /**
19
- * The AvaTax Validation Exception class
20
  *
21
  * @category OnePica
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
- class OnePica_AvaTax_Model_Avatax_Address_Exception extends Exception
26
  {
27
  }
16
  */
17
 
18
  /**
19
+ * The Address Validation Exception class
20
  *
21
  * @category OnePica
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
+ class OnePica_AvaTax_Model_Service_Exception_Address extends Exception
26
  {
27
  }
app/code/community/OnePica/AvaTax/Model/{Avatax → Service}/Exception/Commitfailure.php RENAMED
@@ -22,6 +22,6 @@
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
- class OnePica_AvaTax_Model_Avatax_Exception_Commitfailure extends Exception
26
  {
27
  }
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
+ class OnePica_AvaTax_Model_Service_Exception_Commitfailure extends Exception
26
  {
27
  }
app/code/community/OnePica/AvaTax/Model/{Avatax → Service}/Exception/Unbalanced.php RENAMED
@@ -22,6 +22,6 @@
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
- class OnePica_AvaTax_Model_Avatax_Exception_Unbalanced extends Exception
26
  {
27
  }
22
  * @package OnePica_AvaTax
23
  * @author OnePica Codemaster <codemaster@onepica.com>
24
  */
25
+ class OnePica_AvaTax_Model_Service_Exception_Unbalanced extends Exception
26
  {
27
  }
app/code/community/OnePica/AvaTax/Model/Service/Result/Address.php ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The AvaTax Service Result Address model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Service_Result_Address
26
+ {
27
+ /**
28
+ * Line 1
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_line1;
33
+
34
+ /**
35
+ * Line 2
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_line2;
40
+
41
+ /**
42
+ * City
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_city;
47
+
48
+ /**
49
+ * State
50
+ *
51
+ * @var string
52
+ */
53
+ protected $_state;
54
+
55
+ /**
56
+ * Country
57
+ *
58
+ * @var string
59
+ */
60
+ protected $_country;
61
+
62
+ /**
63
+ * Postal Code
64
+ *
65
+ * @var string
66
+ */
67
+ protected $_postalCode;
68
+
69
+ /**
70
+ * Get line 1
71
+ *
72
+ * @return string|null
73
+ */
74
+ public function getLine1()
75
+ {
76
+ return $this->_line1;
77
+ }
78
+
79
+ /**
80
+ * Set line 1
81
+ *
82
+ * @param string $value
83
+ * @return $this
84
+ */
85
+ public function setLine1($value)
86
+ {
87
+ $this->_line1 = $value;
88
+ return $this;
89
+ }
90
+
91
+ /**
92
+ * Get line 2
93
+ *
94
+ * @return string|null
95
+ */
96
+ public function getLine2()
97
+ {
98
+ return $this->_line2;
99
+ }
100
+
101
+ /**
102
+ * Set line 2
103
+ *
104
+ * @param string $value
105
+ * @return $this
106
+ */
107
+ public function setLine2($value)
108
+ {
109
+ $this->_line2 = $value;
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * Get City
115
+ *
116
+ * @return string|null
117
+ */
118
+ public function getCity()
119
+ {
120
+ return $this->_city;
121
+ }
122
+
123
+ /**
124
+ * Set City
125
+ *
126
+ * @param string $value
127
+ * @return $this
128
+ */
129
+ public function setCity($value)
130
+ {
131
+ $this->_city = $value;
132
+ return $this;
133
+ }
134
+
135
+ /**
136
+ * Get State
137
+ *
138
+ * @return string|null
139
+ */
140
+ public function getState()
141
+ {
142
+ return $this->_state;
143
+ }
144
+
145
+ /**
146
+ * Set State
147
+ *
148
+ * @param string $value
149
+ * @return $this
150
+ */
151
+ public function setState($value)
152
+ {
153
+ $this->_state = $value;
154
+ return $this;
155
+ }
156
+
157
+ /**
158
+ * Get Country
159
+ *
160
+ * @return string|null
161
+ */
162
+ public function getCountry()
163
+ {
164
+ return $this->_country;
165
+ }
166
+
167
+ /**
168
+ * Set Country
169
+ *
170
+ * @param string $value
171
+ * @return $this
172
+ */
173
+ public function setCountry($value)
174
+ {
175
+ $this->_country = $value;
176
+ return $this;
177
+ }
178
+
179
+ /**
180
+ * Get Postal Code
181
+ *
182
+ * @return string|null
183
+ */
184
+ public function getPostalCode()
185
+ {
186
+ return $this->_postalCode;
187
+ }
188
+
189
+ /**
190
+ * Set Postal Code
191
+ *
192
+ * @param string $value
193
+ * @return $this
194
+ */
195
+ public function setPostalCode($value)
196
+ {
197
+ $this->_postalCode = $value;
198
+ return $this;
199
+ }
200
+ }
app/code/community/OnePica/AvaTax/Model/Service/Result/AddressValidate.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The AvaTax Service Result Address Validate model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Service_Result_AddressValidate
26
+ {
27
+ /**
28
+ * Has error
29
+ *
30
+ * @var bool
31
+ */
32
+ protected $_hasError = false;
33
+
34
+ /**
35
+ * Errors
36
+ *
37
+ * @var array
38
+ */
39
+ protected $_errors;
40
+
41
+ /**
42
+ * Resolution
43
+ *
44
+ * @var bool
45
+ */
46
+ protected $_resolution = false;
47
+
48
+ /**
49
+ * Address
50
+ *
51
+ * @var OnePica_AvaTax_Model_Service_Result_Address
52
+ */
53
+ protected $_address;
54
+
55
+ /**
56
+ * Is taxable
57
+ *
58
+ * @var bool
59
+ */
60
+ protected $_isTaxable = false;
61
+
62
+ /**
63
+ * Get Has Error
64
+ *
65
+ * @return bool
66
+ */
67
+ public function getHasError()
68
+ {
69
+ return $this->_hasError;
70
+ }
71
+
72
+ /**
73
+ * Set Has Error
74
+ *
75
+ * @param bool $value
76
+ * @return $this
77
+ */
78
+ public function setHasError($value)
79
+ {
80
+ $this->_hasError = $value;
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * Get Errors
86
+ *
87
+ * @return array
88
+ */
89
+ public function getErrors()
90
+ {
91
+ return $this->_errors;
92
+ }
93
+
94
+ /**
95
+ * Set Errors
96
+ *
97
+ * @param array $value
98
+ * @return $this
99
+ */
100
+ public function setErrors($value)
101
+ {
102
+ $this->_errors = $value;
103
+ return $this;
104
+ }
105
+
106
+ /**
107
+ * Get Resolution
108
+ *
109
+ * @return bool
110
+ */
111
+ public function getResolution()
112
+ {
113
+ return $this->_resolution;
114
+ }
115
+
116
+ /**
117
+ * Set Resolution
118
+ *
119
+ * @param bool $value
120
+ * @return $this
121
+ */
122
+ public function setResolution($value)
123
+ {
124
+ $this->_resolution = $value;
125
+ return $this;
126
+ }
127
+
128
+ /**
129
+ * Get Address
130
+ *
131
+ * @return OnePica_AvaTax_Model_Service_Result_Address
132
+ */
133
+ public function getAddress()
134
+ {
135
+ return $this->_address;
136
+ }
137
+
138
+ /**
139
+ * Set Address
140
+ *
141
+ * @param OnePica_AvaTax_Model_Service_Result_Address $address
142
+ * @return $this
143
+ */
144
+ public function setAddress($address)
145
+ {
146
+ $this->_address = $address;
147
+ return $this;
148
+ }
149
+
150
+ /**
151
+ * Is taxable
152
+ *
153
+ * @return bool
154
+ */
155
+ public function isTaxable()
156
+ {
157
+ return $this->_isTaxable;
158
+ }
159
+
160
+ /**
161
+ * Set isTaxable
162
+ *
163
+ * @param bool $isTaxable
164
+ * @return $this
165
+ */
166
+ public function setIsTaxable($isTaxable)
167
+ {
168
+ $this->_isTaxable = $isTaxable;
169
+
170
+ return $this;
171
+ }
172
+ }
app/code/community/OnePica/AvaTax/Model/Service/Result/Creditmemo.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The AvaTax Service Result Creditmemo model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Service_Result_Creditmemo
26
+ {
27
+ /**
28
+ * Has error
29
+ *
30
+ * @var bool
31
+ */
32
+ protected $_hasError = false;
33
+
34
+ /**
35
+ * Errors
36
+ *
37
+ * @var array
38
+ */
39
+ protected $_errors;
40
+
41
+ /**
42
+ * Document Code
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_documentCode;
47
+
48
+ /**
49
+ * Total tax
50
+ *
51
+ * @var float
52
+ */
53
+ protected $_totalTax;
54
+
55
+ /**
56
+ * Get has error
57
+ *
58
+ * @return bool
59
+ */
60
+ public function getHasError()
61
+ {
62
+ return $this->_hasError;
63
+ }
64
+
65
+ /**
66
+ * Set has error
67
+ *
68
+ * @param bool $value
69
+ * @return $this
70
+ */
71
+ public function setHasError($value)
72
+ {
73
+ $this->_hasError = $value;
74
+ return $this;
75
+ }
76
+
77
+ /**
78
+ * Get errors
79
+ *
80
+ * @return array|null
81
+ */
82
+ public function getErrors()
83
+ {
84
+ return $this->_errors;
85
+ }
86
+
87
+ /**
88
+ * Set errors
89
+ *
90
+ * @param array $value
91
+ * @return $this
92
+ */
93
+ public function setErrors($value)
94
+ {
95
+ $this->_errors = $value;
96
+ return $this;
97
+ }
98
+
99
+ /**
100
+ * Get Document Code
101
+ *
102
+ * @return string|null
103
+ */
104
+ public function getDocumentCode()
105
+ {
106
+ return $this->_documentCode;
107
+ }
108
+
109
+ /**
110
+ * Set Document Code
111
+ *
112
+ * @param string $value
113
+ * @return $this
114
+ */
115
+ public function setDocumentCode($value)
116
+ {
117
+ $this->_documentCode = $value;
118
+ return $this;
119
+ }
120
+
121
+ /**
122
+ * Get Total Tax
123
+ *
124
+ * @return float|null
125
+ */
126
+ public function getTotalTax()
127
+ {
128
+ return $this->_totalTax;
129
+ }
130
+
131
+ /**
132
+ * Set Total Tax
133
+ *
134
+ * @param float $value
135
+ * @return $this
136
+ */
137
+ public function setTotalTax($value)
138
+ {
139
+ $this->_totalTax = $value;
140
+ return $this;
141
+ }
142
+ }
app/code/community/OnePica/AvaTax/Model/Service/Result/Invoice.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * The AvaTax Service Result Invoice model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Service_Result_Invoice
26
+ {
27
+ /**
28
+ * Has error
29
+ *
30
+ * @var bool
31
+ */
32
+ protected $_hasError = false;
33
+
34
+ /**
35
+ * Errors
36
+ *
37
+ * @var array
38
+ */
39
+ protected $_errors;
40
+
41
+ /**
42
+ * Document Code
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_documentCode;
47
+
48
+ /**
49
+ * Total tax
50
+ *
51
+ * @var float
52
+ */
53
+ protected $_totalTax;
54
+
55
+ /**
56
+ * Get has error
57
+ *
58
+ * @return bool
59
+ */
60
+ public function getHasError()
61
+ {
62
+ return $this->_hasError;
63
+ }
64
+
65
+ /**
66
+ * Set has error
67
+ *
68
+ * @param bool $value
69
+ * @return $this
70
+ */
71
+ public function setHasError($value)
72
+ {
73
+ $this->_hasError = $value;
74
+ return $this;
75
+ }
76
+
77
+ /**
78
+ * Get errors
79
+ *
80
+ * @return array|null
81
+ */
82
+ public function getErrors()
83
+ {
84
+ return $this->_errors;
85
+ }
86
+
87
+ /**
88
+ * Set errors
89
+ *
90
+ * @param array $value
91
+ * @return $this
92
+ */
93
+ public function setErrors($value)
94
+ {
95
+ $this->_errors = $value;
96
+ return $this;
97
+ }
98
+
99
+ /**
100
+ * Get Document Code
101
+ *
102
+ * @return string|null
103
+ */
104
+ public function getDocumentCode()
105
+ {
106
+ return $this->_documentCode;
107
+ }
108
+
109
+ /**
110
+ * Set Document Code
111
+ *
112
+ * @param string $value
113
+ * @return $this
114
+ */
115
+ public function setDocumentCode($value)
116
+ {
117
+ $this->_documentCode = $value;
118
+ return $this;
119
+ }
120
+
121
+ /**
122
+ * Get Total Tax
123
+ *
124
+ * @return float|null
125
+ */
126
+ public function getTotalTax()
127
+ {
128
+ return $this->_totalTax;
129
+ }
130
+
131
+ /**
132
+ * Set Total Tax
133
+ *
134
+ * @param float $value
135
+ * @return $this
136
+ */
137
+ public function setTotalTax($value)
138
+ {
139
+ $this->_totalTax = $value;
140
+ return $this;
141
+ }
142
+ }
app/code/community/OnePica/AvaTax/Model/Source/Actions.php CHANGED
@@ -26,28 +26,19 @@ class OnePica_AvaTax_Model_Source_Actions
26
  {
27
  /**
28
  * Gets the list of cache methods for the admin config dropdown
29
- *
30
  * @return array
 
31
  */
32
  public function toOptionArray()
33
  {
34
- return array(
35
- array(
36
- 'value' => OnePica_AvaTax_Model_Config::ACTION_DISABLE,
37
- 'label' => Mage::helper('avatax')->__('Disable')
38
- ),
39
- array(
40
- 'value' => OnePica_AvaTax_Model_Config::ACTION_CALC,
41
- 'label' => Mage::helper('avatax')->__('Enable: calculate tax')
42
- ),
43
- array(
44
- 'value' => OnePica_AvaTax_Model_Config::ACTION_CALC_SUBMIT,
45
- 'label' => Mage::helper('avatax')->__('Enable: calculate tax, submit data')
46
- ),
47
- array(
48
- 'value' => OnePica_AvaTax_Model_Config::ACTION_CALC_SUBMIT_COMMIT,
49
- 'label' => Mage::helper('avatax')->__('Enable: calculate tax, submit data, and commit')
50
- )
51
- );
52
  }
53
  }
26
  {
27
  /**
28
  * Gets the list of cache methods for the admin config dropdown
 
29
  * @return array
30
+ * @throws OnePica_AvaTax_Exception
31
  */
32
  public function toOptionArray()
33
  {
34
+ $activeService = Mage::helper('avatax/config')->getActiveService(Mage::app()->getStore());
35
+ if (!$activeService) {
36
+ throw new OnePica_AvaTax_Exception('Service source model is not defined.');
37
+ }
38
+ $model = Mage::getModel('avatax/source_' . $activeService . '_actions');
39
+ if (!$model) {
40
+ throw new OnePica_AvaTax_Exception('Could not found source model ' . $activeService);
41
+ }
42
+ return $model->toArray();
 
 
 
 
 
 
 
 
 
43
  }
44
  }
app/code/community/OnePica/AvaTax/Model/Source/Avatax/Actions.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * @class OnePica_AvaTax_Model_Source_Avatax_Actions
20
+ * Actions source model
21
+ *
22
+ * @category OnePica
23
+ * @package OnePica_AvaTax
24
+ * @author OnePica Codemaster <codemaster@onepica.com>
25
+ */
26
+ class OnePica_AvaTax_Model_Source_Avatax_Actions
27
+ {
28
+ /**
29
+ * Gets the list of cache methods for the admin config dropdown
30
+ *
31
+ * @return array
32
+ */
33
+ public function toArray()
34
+ {
35
+ return array(
36
+ array(
37
+ 'value' => OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_DISABLE,
38
+ 'label' => Mage::helper('avatax')->__('Disable')
39
+ ),
40
+ array(
41
+ 'value' => OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC,
42
+ 'label' => Mage::helper('avatax')->__('Enable: calculate tax')
43
+ ),
44
+ array(
45
+ 'value' => OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC_SUBMIT,
46
+ 'label' => Mage::helper('avatax')->__('Enable: calculate tax, submit data')
47
+ ),
48
+ array(
49
+ 'value' => OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC_SUBMIT_COMMIT,
50
+ 'label' => Mage::helper('avatax')->__('Enable: calculate tax, submit data, and commit')
51
+ )
52
+ );
53
+ }
54
+ }
app/code/community/OnePica/AvaTax/Model/Source/Avatax/Logtype.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Log type source model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Source_Avatax_Logtype
26
+ {
27
+ /**
28
+ * Ping type
29
+ */
30
+ const PING = 'Ping';
31
+
32
+ /**
33
+ * Get tax type
34
+ */
35
+ const GET_TAX = 'GetTax';
36
+
37
+ /**
38
+ * Filter type
39
+ */
40
+ const FILTER = 'Filter';
41
+
42
+ /**
43
+ * Validate type
44
+ */
45
+ const VALIDATE = 'Validate';
46
+
47
+ /**
48
+ * Queue type
49
+ */
50
+ const QUEUE = 'Queue';
51
+
52
+ /**
53
+ * Gets the list of type for the admin config dropdown
54
+ *
55
+ * @return array
56
+ */
57
+ public function toArray()
58
+ {
59
+ return array(
60
+ array(
61
+ 'value' => self::PING,
62
+ 'label' => Mage::helper('avatax')->__('Ping')
63
+ ),
64
+ array(
65
+ 'value' => self::GET_TAX,
66
+ 'label' => Mage::helper('avatax')->__('GetTax')
67
+ ),
68
+ array(
69
+ 'value' => self::FILTER,
70
+ 'label' => Mage::helper('avatax')->__('Filter')
71
+ ),
72
+ array(
73
+ 'value' => self::VALIDATE,
74
+ 'label' => Mage::helper('avatax')->__('Validate')
75
+ ),
76
+ array(
77
+ 'value' => self::QUEUE,
78
+ 'label' => Mage::helper('avatax')->__('Queue')
79
+ )
80
+ );
81
+ }
82
+ }
app/code/community/OnePica/AvaTax/Model/Source/Avatax/Url.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Url source model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Source_Avatax_Url
26
+ {
27
+ /**
28
+ * Url for production
29
+ */
30
+ const PRODUCTION_URL = 'https://avatax.avalara.net/';
31
+
32
+ /**
33
+ * Url for development
34
+ */
35
+ const DEVELOPMENT_URL = 'https://development.avalara.net';
36
+
37
+ /**
38
+ * Gets the list of urls for the admin config dropdown
39
+ *
40
+ * @return array
41
+ */
42
+ public function toArray()
43
+ {
44
+ return array(
45
+ array(
46
+ 'value' => self::PRODUCTION_URL,
47
+ 'label' => Mage::helper('avatax')->__('Production' . ' (' . self::PRODUCTION_URL . ')')
48
+ ),
49
+ array(
50
+ 'value' => self::DEVELOPMENT_URL,
51
+ 'label' => Mage::helper('avatax')->__('Development' . ' (' . self::DEVELOPMENT_URL . ')')
52
+ ),
53
+ );
54
+ }
55
+ }
app/code/community/OnePica/AvaTax/Model/Source/Avatax16/Actions.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * @class OnePica_AvaTax_Model_Source_Avatax16_Actions
20
+ * Actions source model
21
+ *
22
+ * @category OnePica
23
+ * @package OnePica_AvaTax
24
+ * @author OnePica Codemaster <codemaster@onepica.com>
25
+ */
26
+ class OnePica_AvaTax_Model_Source_Avatax16_Actions
27
+ {
28
+ /**
29
+ * Gets the list of cache methods for the admin config dropdown
30
+ *
31
+ * @return array
32
+ */
33
+ public function toArray()
34
+ {
35
+ return array(
36
+ array(
37
+ 'value' => OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_DISABLE,
38
+ 'label' => Mage::helper('avatax')->__('Disable')
39
+ ),
40
+ array(
41
+ 'value' => OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC,
42
+ 'label' => Mage::helper('avatax')->__('Enable: calculate tax')
43
+ ),
44
+ array(
45
+ 'value' => OnePica_AvaTax_Model_Service_Abstract_Config::ACTION_CALC_SUBMIT,
46
+ 'label' => Mage::helper('avatax')->__('Enable: calculate tax, submit data')
47
+ )
48
+ );
49
+ }
50
+ }
app/code/community/OnePica/AvaTax/Model/Source/Avatax16/Buyertype.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Buyer type source model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ * @todo Remove this class if we will not use those properties
25
+ */
26
+ class OnePica_AvaTax_Model_Source_Avatax16_Buyertype
27
+ {
28
+ /**
29
+ * Resale
30
+ */
31
+ const RESALE = 'G';
32
+
33
+ /**
34
+ * Agricultural Production
35
+ */
36
+ const AGRICULTURAL_PRODUCTION = 'H';
37
+
38
+ /**
39
+ * Industrial Prod/Mfg.
40
+ */
41
+ const INDUSTRIAL_PROD_MFG = 'I';
42
+
43
+ /**
44
+ * Direct Pay Permit
45
+ */
46
+ const DIRECT_PAY_PERMIT = 'J';
47
+
48
+ /**
49
+ * Direct Mail
50
+ */
51
+ const DIRECT_MAIL = 'K';
52
+
53
+ /**
54
+ * Other
55
+ */
56
+ const OTHER = 'L';
57
+
58
+ /**
59
+ * Commercial Aquaculture (Canada)
60
+ */
61
+ const COMMERCIAL_AQUACULTURE = 'P';
62
+
63
+ /**
64
+ * Commercial Fishery (Canada)
65
+ */
66
+ const COMMERCIAL_FISHERY = 'Q';
67
+
68
+ /**
69
+ * Gets the list of type for the admin config dropdown
70
+ *
71
+ * @return array
72
+ */
73
+ public function toOptionArray()
74
+ {
75
+ return array(
76
+ array(
77
+ 'value' => '',
78
+ 'label' => ''
79
+ ),
80
+ array(
81
+ 'value' => self::RESALE,
82
+ 'label' => Mage::helper('avatax')->__('G - Resale')
83
+ ),
84
+ array(
85
+ 'value' => self::AGRICULTURAL_PRODUCTION,
86
+ 'label' => Mage::helper('avatax')->__('H - Agricultural Production')
87
+ ),
88
+ array(
89
+ 'value' => self::INDUSTRIAL_PROD_MFG,
90
+ 'label' => Mage::helper('avatax')->__('I - Industrial Prod/Mfg.')
91
+ ),
92
+ array(
93
+ 'value' => self::DIRECT_PAY_PERMIT,
94
+ 'label' => Mage::helper('avatax')->__('J - Direct Pay Permit')
95
+ ),
96
+ array(
97
+ 'value' => self::DIRECT_MAIL,
98
+ 'label' => Mage::helper('avatax')->__('K - Direct Mail')
99
+ ),
100
+ array(
101
+ 'value' => self::OTHER,
102
+ 'label' => Mage::helper('avatax')->__('L - Other')
103
+ ),
104
+ array(
105
+ 'value' => self::COMMERCIAL_AQUACULTURE,
106
+ 'label' => Mage::helper('avatax')->__('P - Commercial Aquaculture (Canada)')
107
+ ),
108
+ array(
109
+ 'value' => self::COMMERCIAL_FISHERY,
110
+ 'label' => Mage::helper('avatax')->__('Q - Commercial Fishery (Canada)')
111
+ )
112
+ );
113
+ }
114
+ }
app/code/community/OnePica/AvaTax/Model/Source/Avatax16/Logtype.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2009 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Log type source model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Source_Avatax16_Logtype
26
+ {
27
+ /**
28
+ * Ping type
29
+ */
30
+ const PING = 'Ping';
31
+
32
+ /**
33
+ * Get Calculation type
34
+ */
35
+ const CALCULATION = 'Calculation';
36
+
37
+ /**
38
+ * Get Transaction type
39
+ */
40
+ const TRANSACTION = 'Transaction';
41
+
42
+ /**
43
+ * Filter type
44
+ */
45
+ const FILTER = 'Filter';
46
+
47
+ /**
48
+ * Validate type
49
+ */
50
+ const VALIDATE = 'Validate';
51
+
52
+ /**
53
+ * Queue type
54
+ */
55
+ const QUEUE = 'Queue';
56
+
57
+ /**
58
+ * Gets the list of type for the admin config dropdown
59
+ *
60
+ * @return array
61
+ */
62
+ public function toArray()
63
+ {
64
+ return array(
65
+ array(
66
+ 'value' => self::PING,
67
+ 'label' => Mage::helper('avatax')->__('Ping')
68
+ ),
69
+ array(
70
+ 'value' => self::CALCULATION,
71
+ 'label' => Mage::helper('avatax')->__('Calculation')
72
+ ),
73
+ array(
74
+ 'value' => self::TRANSACTION,
75
+ 'label' => Mage::helper('avatax')->__('Transaction')
76
+ ),
77
+ array(
78
+ 'value' => self::FILTER,
79
+ 'label' => Mage::helper('avatax')->__('Filter')
80
+ ),
81
+ array(
82
+ 'value' => self::VALIDATE,
83
+ 'label' => Mage::helper('avatax')->__('Validate')
84
+ ),
85
+ array(
86
+ 'value' => self::QUEUE,
87
+ 'label' => Mage::helper('avatax')->__('Queue')
88
+ )
89
+ );
90
+ }
91
+ }
app/code/community/OnePica/AvaTax/Model/Source/Avatax16/Url.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Url source model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Source_Avatax16_Url
26
+ {
27
+ /**
28
+ * Url for development
29
+ */
30
+ const DEVELOPMENT_URL = 'https://tax-qa.avlr.sh/';
31
+
32
+ /**
33
+ * Gets the list of urls for the admin config dropdown
34
+ *
35
+ * @return array
36
+ */
37
+ public function toArray()
38
+ {
39
+ return array(
40
+ array(
41
+ 'value' => self::DEVELOPMENT_URL,
42
+ 'label' => Mage::helper('avatax')->__('Development' . ' (' . self::DEVELOPMENT_URL . ')')
43
+ )
44
+ );
45
+ }
46
+ }
app/code/community/OnePica/AvaTax/Model/Source/Avatax16/Usetype.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Use type source model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ * @todo Remove this class if we will not use those properties
25
+ */
26
+ class OnePica_AvaTax_Model_Source_Avatax16_Usetype
27
+ {
28
+ /**
29
+ * Federal Government
30
+ */
31
+ const FEDERAL_GOVERNMENT = 'A';
32
+
33
+ /**
34
+ * State/Local Govt.
35
+ */
36
+ const STATE_LOCAL_GOVT = 'B';
37
+
38
+ /**
39
+ * Tribal Government
40
+ */
41
+ const TRIBAL_GOVERNMENT = 'C';
42
+
43
+ /**
44
+ * Foreign Diplomat
45
+ */
46
+ const FOREIGN_DIPLOMAT = 'D';
47
+
48
+ /**
49
+ * Charitable Organization
50
+ */
51
+ const CHARITABLE_ORGANIZATION = 'E';
52
+
53
+ /**
54
+ * Religious/Education
55
+ */
56
+ const RELIGIOUS_EDUCATION = 'F';
57
+
58
+ /**
59
+ * Other
60
+ */
61
+ const OTHER = 'L';
62
+
63
+ /**
64
+ * Local Government
65
+ */
66
+ const LOCAL_GOVERNMENT = 'N';
67
+
68
+ /**
69
+ * Non-resident (Canada)
70
+ */
71
+ const NON_RESIDENT = 'R';
72
+
73
+ /**
74
+ * Gets the list of type for the admin config dropdown
75
+ *
76
+ * @return array
77
+ */
78
+ public function toOptionArray()
79
+ {
80
+ return array(
81
+ array(
82
+ 'value' => '',
83
+ 'label' => ''
84
+ ),
85
+ array(
86
+ 'value' => self::FEDERAL_GOVERNMENT,
87
+ 'label' => Mage::helper('avatax')->__('A - Federal Government')
88
+ ),
89
+ array(
90
+ 'value' => self::STATE_LOCAL_GOVT,
91
+ 'label' => Mage::helper('avatax')->__('B - State/Local Govt.')
92
+ ),
93
+ array(
94
+ 'value' => self::TRIBAL_GOVERNMENT,
95
+ 'label' => Mage::helper('avatax')->__('C - Tribal Government')
96
+ ),
97
+ array(
98
+ 'value' => self::FOREIGN_DIPLOMAT,
99
+ 'label' => Mage::helper('avatax')->__('D - Foreign Diplomat')
100
+ ),
101
+ array(
102
+ 'value' => self::CHARITABLE_ORGANIZATION,
103
+ 'label' => Mage::helper('avatax')->__('E - Charitable Organization')
104
+ ),
105
+ array(
106
+ 'value' => self::RELIGIOUS_EDUCATION,
107
+ 'label' => Mage::helper('avatax')->__('F - Religious/Education')
108
+ ),
109
+ array(
110
+ 'value' => self::OTHER,
111
+ 'label' => Mage::helper('avatax')->__('L - Other')
112
+ ),
113
+ array(
114
+ 'value' => self::LOCAL_GOVERNMENT,
115
+ 'label' => Mage::helper('avatax')->__('N - Local Government')
116
+ ),
117
+ array(
118
+ 'value' => self::NON_RESIDENT,
119
+ 'label' => Mage::helper('avatax')->__('R - Non-resident (Canada)')
120
+ )
121
+ );
122
+ }
123
+ }
app/code/community/OnePica/AvaTax/Model/Source/Logtype.php CHANGED
@@ -24,59 +24,21 @@
24
  */
25
  class OnePica_AvaTax_Model_Source_Logtype
26
  {
27
- /**
28
- * Ping type
29
- */
30
- const PING = 'Ping';
31
-
32
- /**
33
- * Get tax type
34
- */
35
- const GET_TAX = 'GetTax';
36
-
37
- /**
38
- * Filter type
39
- */
40
- const FILTER = 'Filter';
41
-
42
- /**
43
- * Validate type
44
- */
45
- const VALIDATE = 'Validate';
46
-
47
- /**
48
- * Queue type
49
- */
50
- const QUEUE = 'Queue';
51
-
52
  /**
53
  * Gets the list of type for the admin config dropdown
54
- *
55
  * @return array
 
56
  */
57
  public function toOptionArray()
58
  {
59
- return array(
60
- array(
61
- 'value' => self::PING,
62
- 'label' => Mage::helper('avatax')->__('Ping')
63
- ),
64
- array(
65
- 'value' => self::GET_TAX,
66
- 'label' => Mage::helper('avatax')->__('Get Tax')
67
- ),
68
- array(
69
- 'value' => self::FILTER,
70
- 'label' => Mage::helper('avatax')->__('Filter')
71
- ),
72
- array(
73
- 'value' => self::VALIDATE,
74
- 'label' => Mage::helper('avatax')->__('Validate')
75
- ),
76
- array(
77
- 'value' => self::QUEUE,
78
- 'label' => Mage::helper('avatax')->__('Queue')
79
- )
80
- );
81
  }
82
  }
24
  */
25
  class OnePica_AvaTax_Model_Source_Logtype
26
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  /**
28
  * Gets the list of type for the admin config dropdown
 
29
  * @return array
30
+ * @throws OnePica_AvaTax_Exception
31
  */
32
  public function toOptionArray()
33
  {
34
+ $activeService = Mage::helper('avatax/config')->getActiveService(Mage::app()->getStore());
35
+ if (!$activeService) {
36
+ throw new OnePica_AvaTax_Exception('Service source model is not defined.');
37
+ }
38
+ $model = Mage::getModel('avatax/source_' . $activeService . '_logtype');
39
+ if (!$model) {
40
+ throw new OnePica_AvaTax_Exception('Could not found source model ' . $activeService);
41
+ }
42
+ return $model->toArray();
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
44
  }
app/code/community/OnePica/AvaTax/Model/Source/Regionfilter/List.php CHANGED
@@ -120,7 +120,7 @@ class OnePica_AvaTax_Model_Source_Regionfilter_List
120
  */
121
  protected function _getCountryList()
122
  {
123
- return $this->_getDataHelper()->getTaxableCountryByCurrentScope();
124
  }
125
 
126
  /**
120
  */
121
  protected function _getCountryList()
122
  {
123
+ return Mage::helper('avatax/address')->getTaxableCountryByCurrentScope();
124
  }
125
 
126
  /**
app/code/community/OnePica/AvaTax/Model/Source/Regionfilter/Mode.php CHANGED
@@ -33,15 +33,15 @@ class OnePica_AvaTax_Model_Source_Regionfilter_Mode
33
  {
34
  return array(
35
  array(
36
- 'value' => OnePica_AvaTax_Model_Config::REGIONFILTER_OFF,
37
  'label' => Mage::helper('avatax')->__('None')
38
  ),
39
  array(
40
- 'value' => OnePica_AvaTax_Model_Config::REGIONFILTER_TAX,
41
  'label' => Mage::helper('avatax')->__('Filter tax calculations')
42
  ),
43
  array(
44
- 'value' => OnePica_AvaTax_Model_Config::REGIONFILTER_ALL,
45
  'label' => Mage::helper('avatax')->__('Filter tax calculations & address options')
46
  )
47
  );
33
  {
34
  return array(
35
  array(
36
+ 'value' => OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_OFF,
37
  'label' => Mage::helper('avatax')->__('None')
38
  ),
39
  array(
40
+ 'value' => OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_TAX,
41
  'label' => Mage::helper('avatax')->__('Filter tax calculations')
42
  ),
43
  array(
44
+ 'value' => OnePica_AvaTax_Model_Service_Abstract_Config::REGIONFILTER_ALL,
45
  'label' => Mage::helper('avatax')->__('Filter tax calculations & address options')
46
  )
47
  );
app/code/community/OnePica/AvaTax/Model/Source/Url.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Service Url source model
20
+ *
21
+ * @category OnePica
22
+ * @package OnePica_AvaTax
23
+ * @author OnePica Codemaster <codemaster@onepica.com>
24
+ */
25
+ class OnePica_AvaTax_Model_Source_Url
26
+ {
27
+ /**
28
+ * Gets the list of service urls for the admin config dropdown
29
+ *
30
+ * @return array
31
+ * @throws OnePica_AvaTax_Exception
32
+ */
33
+ public function toOptionArray()
34
+ {
35
+ $activeService = Mage::helper('avatax/config')->getActiveService(Mage::app()->getStore());
36
+ if (!$activeService) {
37
+ throw new OnePica_AvaTax_Exception('Service source model is not defined.');
38
+ }
39
+ $model = Mage::getModel('avatax/source_' . $activeService . '_url');
40
+ if (!$model) {
41
+ throw new OnePica_AvaTax_Exception('Could not found source model ' . $activeService);
42
+ }
43
+ return $model->toArray();
44
+ }
45
+ }
app/code/community/OnePica/AvaTax/Model/Tax/Config.php CHANGED
@@ -33,7 +33,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
33
  */
34
  public function discountTax($store = null)
35
  {
36
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
37
  return false;
38
  }
39
 
@@ -48,7 +48,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
48
  */
49
  public function priceIncludesTax($store = null)
50
  {
51
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
52
  return false;
53
  }
54
 
@@ -63,7 +63,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
63
  */
64
  public function shippingPriceIncludesTax($store = null)
65
  {
66
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
67
  return false;
68
  }
69
 
@@ -78,7 +78,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
78
  */
79
  public function displayCartPricesInclTax($store = null)
80
  {
81
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
82
  return false;
83
  }
84
 
@@ -93,7 +93,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
93
  */
94
  public function displayCartPricesExclTax($store = null)
95
  {
96
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
97
  return true;
98
  }
99
 
@@ -108,7 +108,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
108
  */
109
  public function displayCartPricesBoth($store = null)
110
  {
111
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
112
  return false;
113
  }
114
 
@@ -123,7 +123,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
123
  */
124
  public function displayCartSubtotalInclTax($store = null)
125
  {
126
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
127
  return false;
128
  }
129
 
@@ -138,7 +138,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
138
  */
139
  public function displayCartSubtotalExclTax($store = null)
140
  {
141
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
142
  return true;
143
  }
144
 
@@ -153,7 +153,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
153
  */
154
  public function displayCartSubtotalBoth($store = null)
155
  {
156
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
157
  return false;
158
  }
159
 
@@ -168,7 +168,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
168
  */
169
  public function displayCartShippingInclTax($store = null)
170
  {
171
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
172
  return false;
173
  }
174
 
@@ -183,7 +183,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
183
  */
184
  public function displayCartShippingExclTax($store = null)
185
  {
186
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
187
  return true;
188
  }
189
 
@@ -198,7 +198,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
198
  */
199
  public function displayCartShippingBoth($store = null)
200
  {
201
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
202
  return false;
203
  }
204
 
@@ -213,7 +213,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
213
  */
214
  public function displaySalesPricesInclTax($store = null)
215
  {
216
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
217
  return false;
218
  }
219
 
@@ -228,7 +228,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
228
  */
229
  public function displaySalesPricesExclTax($store = null)
230
  {
231
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
232
  return true;
233
  }
234
 
@@ -243,7 +243,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
243
  */
244
  public function displaySalesPricesBoth($store = null)
245
  {
246
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
247
  return false;
248
  }
249
 
@@ -258,7 +258,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
258
  */
259
  public function displaySalesSubtotalInclTax($store = null)
260
  {
261
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
262
  return false;
263
  }
264
 
@@ -273,7 +273,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
273
  */
274
  public function displaySalesSubtotalExclTax($store = null)
275
  {
276
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
277
  return true;
278
  }
279
 
@@ -288,7 +288,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
288
  */
289
  public function displaySalesSubtotalBoth($store = null)
290
  {
291
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
292
  return false;
293
  }
294
 
@@ -303,7 +303,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
303
  */
304
  public function displaySalesShippingInclTax($store = null)
305
  {
306
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
307
  return false;
308
  }
309
 
@@ -318,7 +318,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
318
  */
319
  public function displaySalesShippingExclTax($store = null)
320
  {
321
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
322
  return true;
323
  }
324
 
@@ -333,7 +333,7 @@ class OnePica_AvaTax_Model_Tax_Config extends Mage_Tax_Model_Config
333
  */
334
  public function displaySalesShippingBoth($store = null)
335
  {
336
- if ($this->_getDataHelper()->isAvataxEnabled($store)) {
337
  return false;
338
  }
339
 
33
  */
34
  public function discountTax($store = null)
35
  {
36
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
37
  return false;
38
  }
39
 
48
  */
49
  public function priceIncludesTax($store = null)
50
  {
51
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
52
  return false;
53
  }
54
 
63
  */
64
  public function shippingPriceIncludesTax($store = null)
65
  {
66
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
67
  return false;
68
  }
69
 
78
  */
79
  public function displayCartPricesInclTax($store = null)
80
  {
81
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
82
  return false;
83
  }
84
 
93
  */
94
  public function displayCartPricesExclTax($store = null)
95
  {
96
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
97
  return true;
98
  }
99
 
108
  */
109
  public function displayCartPricesBoth($store = null)
110
  {
111
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
112
  return false;
113
  }
114
 
123
  */
124
  public function displayCartSubtotalInclTax($store = null)
125
  {
126
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
127
  return false;
128
  }
129
 
138
  */
139
  public function displayCartSubtotalExclTax($store = null)
140
  {
141
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
142
  return true;
143
  }
144
 
153
  */
154
  public function displayCartSubtotalBoth($store = null)
155
  {
156
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
157
  return false;
158
  }
159
 
168
  */
169
  public function displayCartShippingInclTax($store = null)
170
  {
171
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
172
  return false;
173
  }
174
 
183
  */
184
  public function displayCartShippingExclTax($store = null)
185
  {
186
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
187
  return true;
188
  }
189
 
198
  */
199
  public function displayCartShippingBoth($store = null)
200
  {
201
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
202
  return false;
203
  }
204
 
213
  */
214
  public function displaySalesPricesInclTax($store = null)
215
  {
216
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
217
  return false;
218
  }
219
 
228
  */
229
  public function displaySalesPricesExclTax($store = null)
230
  {
231
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
232
  return true;
233
  }
234
 
243
  */
244
  public function displaySalesPricesBoth($store = null)
245
  {
246
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
247
  return false;
248
  }
249
 
258
  */
259
  public function displaySalesSubtotalInclTax($store = null)
260
  {
261
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
262
  return false;
263
  }
264
 
273
  */
274
  public function displaySalesSubtotalExclTax($store = null)
275
  {
276
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
277
  return true;
278
  }
279
 
288
  */
289
  public function displaySalesSubtotalBoth($store = null)
290
  {
291
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
292
  return false;
293
  }
294
 
303
  */
304
  public function displaySalesShippingInclTax($store = null)
305
  {
306
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
307
  return false;
308
  }
309
 
318
  */
319
  public function displaySalesShippingExclTax($store = null)
320
  {
321
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
322
  return true;
323
  }
324
 
333
  */
334
  public function displaySalesShippingBoth($store = null)
335
  {
336
+ if ($this->_getDataHelper()->isServiceEnabled($store)) {
337
  return false;
338
  }
339
 
app/code/community/OnePica/AvaTax/Model/Total/Quote/Tax/Giftwrapping.php CHANGED
@@ -30,7 +30,7 @@ class OnePica_AvaTax_Model_Total_Quote_Tax_Giftwrapping
30
  public function collect(Mage_Sales_Model_Quote_Address $address)
31
  {
32
  $storeId = $address->getQuote()->getStore()->getId();
33
- if ($this->_getAvaTaxDataHelper()->isAvataxEnabled($storeId)) {
34
  return $this;
35
  }
36
 
30
  public function collect(Mage_Sales_Model_Quote_Address $address)
31
  {
32
  $storeId = $address->getQuote()->getStore()->getId();
33
+ if ($this->_getAvaTaxDataHelper()->isServiceEnabled($storeId)) {
34
  return $this;
35
  }
36
 
app/code/community/OnePica/AvaTax/etc/adminhtml.xml CHANGED
@@ -43,10 +43,12 @@
43
  <avatax_queue translate="title" module="avatax">
44
  <title>AvaTax Order Sync Queue</title>
45
  <action>adminhtml/avaTax_grid/queue</action>
 
46
  </avatax_queue>
47
  <avatax_log translate="title" module="avatax">
48
  <title>AvaTax Log</title>
49
  <action>adminhtml/avaTax_grid/log</action>
 
50
  </avatax_log>
51
  </children>
52
  </tax>
43
  <avatax_queue translate="title" module="avatax">
44
  <title>AvaTax Order Sync Queue</title>
45
  <action>adminhtml/avaTax_grid/queue</action>
46
+ <resource>avatax</resource>
47
  </avatax_queue>
48
  <avatax_log translate="title" module="avatax">
49
  <title>AvaTax Log</title>
50
  <action>adminhtml/avaTax_grid/log</action>
51
+ <resource>avatax</resource>
52
  </avatax_log>
53
  </children>
54
  </tax>
app/code/community/OnePica/AvaTax/etc/config.xml CHANGED
@@ -19,7 +19,7 @@
19
  <config>
20
  <modules>
21
  <OnePica_AvaTax>
22
- <version>2.6.9.0</version>
23
  </OnePica_AvaTax>
24
  </modules>
25
  <global>
@@ -121,8 +121,8 @@
121
  <observers>
122
  <avatax>
123
  <type>singleton</type>
124
- <class>avatax/observer</class>
125
- <method>salesOrderInvoicePay</method>
126
  </avatax>
127
  </observers>
128
  </sales_order_invoice_pay>
@@ -130,8 +130,8 @@
130
  <observers>
131
  <avatax>
132
  <type>singleton</type>
133
- <class>avatax/observer</class>
134
- <method>salesOrderCreditmemoRefund</method>
135
  </avatax>
136
  </observers>
137
  </sales_order_creditmemo_refund>
@@ -139,8 +139,8 @@
139
  <observers>
140
  <avatax>
141
  <type>singleton</type>
142
- <class>avatax/observer</class>
143
- <method>salesQuoteCollectTotalsBefore</method>
144
  </avatax>
145
  </observers>
146
  </sales_quote_collect_totals_before>
@@ -148,8 +148,8 @@
148
  <observers>
149
  <avatax>
150
  <type>singleton</type>
151
- <class>avatax/observer</class>
152
- <method>salesOrderInvoiceSaveAfter</method>
153
  </avatax>
154
  </observers>
155
  </sales_order_invoice_save_after>
@@ -157,8 +157,8 @@
157
  <observers>
158
  <avatax>
159
  <type>singleton</type>
160
- <class>avatax/observer</class>
161
- <method>salesOrderCreditmemoSaveAfter</method>
162
  </avatax>
163
  </observers>
164
  </sales_order_creditmemo_save_after>
@@ -166,8 +166,8 @@
166
  <observers>
167
  <avatax>
168
  <type>singleton</type>
169
- <class>avatax/observer</class>
170
- <method>adminSystemConfigChangedSectionTax</method>
171
  </avatax>
172
  </observers>
173
  </admin_system_config_changed_section_tax>
@@ -175,8 +175,8 @@
175
  <observers>
176
  <avatax>
177
  <type>singleton</type>
178
- <class>avatax/observer</class>
179
- <method>multishippingSetShippingItems</method>
180
  </avatax>
181
  </observers>
182
  </checkout_type_multishipping_set_shipping_items>
@@ -184,8 +184,8 @@
184
  <observers>
185
  <avatax>
186
  <type>singleton</type>
187
- <class>avatax/observer</class>
188
- <method>loadAvaTaxExternalLib</method>
189
  </avatax>
190
  </observers>
191
  </controller_front_init_before>
@@ -193,8 +193,8 @@
193
  <observers>
194
  <avatax>
195
  <type>singleton</type>
196
- <class>avatax/observer</class>
197
- <method>loadAvaTaxExternalLib</method>
198
  </avatax>
199
  </observers>
200
  </default>
@@ -202,8 +202,8 @@
202
  <observers>
203
  <avatax>
204
  <type>singleton</type>
205
- <class>avatax/observer</class>
206
- <method>controllerActionPredispatchCheckoutCartEstimatePost</method>
207
  </avatax>
208
  </observers>
209
  </controller_action_predispatch_checkout_cart_estimatePost>
@@ -211,11 +211,101 @@
211
  <observers>
212
  <avatax>
213
  <type>singleton</type>
214
- <class>avatax/observer</class>
215
- <method>controllerActionPredispatchCheckoutOnepageIndex</method>
216
  </avatax>
217
  </observers>
218
  </controller_action_predispatch_checkout_onepage_index>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  </events>
220
  </global>
221
  <frontend>
@@ -283,10 +373,12 @@
283
  <avatax_queue translate="title" module="avatax">
284
  <title>AvaTax Order Sync Queue</title>
285
  <action>adminhtml/avaTax_grid/queue</action>
 
286
  </avatax_queue>
287
  <avatax_log translate="title" module="avatax">
288
  <title>AvaTax Log</title>
289
  <action>adminhtml/avaTax_grid/log</action>
 
290
  </avatax_log>
291
  </children>
292
  </tax>
@@ -309,6 +401,8 @@
309
  <default>
310
  <tax>
311
  <avatax>
 
 
312
  <action>0</action>
313
  <url>https://avatax.avalara.net/</url>
314
  <region_filter_mode>0</region_filter_mode>
@@ -335,6 +429,7 @@
335
  <onepage_normalize_message>Your shipping address has been modified during our validation process. Please confirm the address to the right is accurate.</onepage_normalize_message>
336
  <multiaddress_normalize_message>Your shipping addresses have been modified during our validation process. Please confirm they are still correct.</multiaddress_normalize_message>
337
  <validate_address_message>The address '%s' appears invalid. Please correct it or select another address.</validate_address_message>
 
338
  </avatax>
339
  <calculation>
340
  <based_on>shipping</based_on>
@@ -355,13 +450,13 @@
355
  <avatax_processqueue>
356
  <schedule><cron_expr>0 * * * *</cron_expr></schedule>
357
  <run>
358
- <model>avatax/observer::processQueue</model>
359
  </run>
360
  </avatax_processqueue>
361
  <avatax_cleanlog>
362
  <schedule><cron_expr>0 0 * * *</cron_expr></schedule>
363
  <run>
364
- <model>avatax/observer::cleanLog</model>
365
  </run>
366
  </avatax_cleanlog>
367
  </jobs>
19
  <config>
20
  <modules>
21
  <OnePica_AvaTax>
22
+ <version>3.0.0.18</version>
23
  </OnePica_AvaTax>
24
  </modules>
25
  <global>
121
  <observers>
122
  <avatax>
123
  <type>singleton</type>
124
+ <class>avatax/observer_salesOrderInvoicePay</class>
125
+ <method>execute</method>
126
  </avatax>
127
  </observers>
128
  </sales_order_invoice_pay>
130
  <observers>
131
  <avatax>
132
  <type>singleton</type>
133
+ <class>avatax/observer_salesOrderCreditmemoRefund</class>
134
+ <method>execute</method>
135
  </avatax>
136
  </observers>
137
  </sales_order_creditmemo_refund>
139
  <observers>
140
  <avatax>
141
  <type>singleton</type>
142
+ <class>avatax/observer_salesQuoteCollectTotalsBefore</class>
143
+ <method>execute</method>
144
  </avatax>
145
  </observers>
146
  </sales_quote_collect_totals_before>
148
  <observers>
149
  <avatax>
150
  <type>singleton</type>
151
+ <class>avatax/observer_salesOrderInvoiceSaveAfter</class>
152
+ <method>execute</method>
153
  </avatax>
154
  </observers>
155
  </sales_order_invoice_save_after>
157
  <observers>
158
  <avatax>
159
  <type>singleton</type>
160
+ <class>avatax/observer_salesOrderCreditmemoSaveAfter</class>
161
+ <method>execute</method>
162
  </avatax>
163
  </observers>
164
  </sales_order_creditmemo_save_after>
166
  <observers>
167
  <avatax>
168
  <type>singleton</type>
169
+ <class>avatax/observer_adminSystemConfigChangedSectionTax</class>
170
+ <method>execute</method>
171
  </avatax>
172
  </observers>
173
  </admin_system_config_changed_section_tax>
175
  <observers>
176
  <avatax>
177
  <type>singleton</type>
178
+ <class>avatax/observer_multishippingSetShippingItems</class>
179
+ <method>execute</method>
180
  </avatax>
181
  </observers>
182
  </checkout_type_multishipping_set_shipping_items>
184
  <observers>
185
  <avatax>
186
  <type>singleton</type>
187
+ <class>avatax/observer_loadAvaTaxExternalLib</class>
188
+ <method>execute</method>
189
  </avatax>
190
  </observers>
191
  </controller_front_init_before>
193
  <observers>
194
  <avatax>
195
  <type>singleton</type>
196
+ <class>avatax/observer_loadAvaTaxExternalLib</class>
197
+ <method>execute</method>
198
  </avatax>
199
  </observers>
200
  </default>
202
  <observers>
203
  <avatax>
204
  <type>singleton</type>
205
+ <class>avatax/observer_controllerActionPredispatchCheckoutCartEstimatePost</class>
206
+ <method>execute</method>
207
  </avatax>
208
  </observers>
209
  </controller_action_predispatch_checkout_cart_estimatePost>
211
  <observers>
212
  <avatax>
213
  <type>singleton</type>
214
+ <class>avatax/observer_controllerActionPredispatchCheckoutOnepageIndex</class>
215
+ <method>execute</method>
216
  </avatax>
217
  </observers>
218
  </controller_action_predispatch_checkout_onepage_index>
219
+ <controller_action_predispatch_checkout_multishipping_index>
220
+ <observers>
221
+ <avatax>
222
+ <type>singleton</type>
223
+ <class>avatax/observer_controllerActionPredispatchCheckoutMultishippingIndex</class>
224
+ <method>execute</method>
225
+ </avatax>
226
+ </observers>
227
+ </controller_action_predispatch_checkout_multishipping_index>
228
+ <controller_action_predispatch_checkout_cart_index>
229
+ <observers>
230
+ <avatax>
231
+ <type>singleton</type>
232
+ <class>avatax/observer_controllerActionPredispatchCheckoutCartIndex</class>
233
+ <method>execute</method>
234
+ </avatax>
235
+ </observers>
236
+ </controller_action_predispatch_checkout_cart_index>
237
+ <controller_action_postdispatch_checkout_cart_estimatePost>
238
+ <observers>
239
+ <avatax>
240
+ <type>singleton</type>
241
+ <class>avatax/observer_controllerActionPostdispatchCheckoutCartEstimatePost</class>
242
+ <method>execute</method>
243
+ </avatax>
244
+ </observers>
245
+ </controller_action_postdispatch_checkout_cart_estimatePost>
246
+ <controller_action_postdispatch_checkout_cart_estimateUpdatePost>
247
+ <observers>
248
+ <avatax>
249
+ <type>singleton</type>
250
+ <class>avatax/observer_controllerActionPostdispatchCheckoutCartEstimateUpdatePost</class>
251
+ <method>execute</method>
252
+ </avatax>
253
+ </observers>
254
+ </controller_action_postdispatch_checkout_cart_estimateUpdatePost>
255
+ <sales_model_service_quote_submit_before>
256
+ <observers>
257
+ <avatax>
258
+ <type>singleton</type>
259
+ <class>avatax/observer_salesModelServiceQuoteSubmitBefore</class>
260
+ <method>execute</method>
261
+ </avatax>
262
+ </observers>
263
+ </sales_model_service_quote_submit_before>
264
+ <controller_action_postdispatch_checkout_onepage_saveShippingMethod>
265
+ <observers>
266
+ <avatax>
267
+ <type>singleton</type>
268
+ <class>avatax/observer_controllerActionPostdispatchCheckoutOnepageSaveShippingMethod</class>
269
+ <method>execute</method>
270
+ </avatax>
271
+ </observers>
272
+ </controller_action_postdispatch_checkout_onepage_saveShippingMethod>
273
+ <checkout_type_multishipping_create_orders_single>
274
+ <observers>
275
+ <avatax>
276
+ <type>singleton</type>
277
+ <class>avatax/observer_checkoutTypeMultishippingCreateOrdersSingle</class>
278
+ <method>execute</method>
279
+ </avatax>
280
+ </observers>
281
+ </checkout_type_multishipping_create_orders_single>
282
+ <sales_model_service_quote_submit_after>
283
+ <observers>
284
+ <avatax>
285
+ <type>singleton</type>
286
+ <class>avatax/observer_salesModelServiceQuoteSubmitAfter</class>
287
+ <method>execute</method>
288
+ </avatax>
289
+ </observers>
290
+ </sales_model_service_quote_submit_after>
291
+ <checkout_submit_all_after>
292
+ <observers>
293
+ <avatax>
294
+ <type>singleton</type>
295
+ <class>avatax/observer_checkoutSubmitAllAfter</class>
296
+ <method>execute</method>
297
+ </avatax>
298
+ </observers>
299
+ </checkout_submit_all_after>
300
+ <controller_action_postdispatch_adminhtml_sales_order_create_loadBlock>
301
+ <observers>
302
+ <avatax>
303
+ <type>singleton</type>
304
+ <class>avatax/observer_controllerActionPredispatchAdminhtmlSalesOrderCreateLoadBlock</class>
305
+ <method>execute</method>
306
+ </avatax>
307
+ </observers>
308
+ </controller_action_postdispatch_adminhtml_sales_order_create_loadBlock>
309
  </events>
310
  </global>
311
  <frontend>
373
  <avatax_queue translate="title" module="avatax">
374
  <title>AvaTax Order Sync Queue</title>
375
  <action>adminhtml/avaTax_grid/queue</action>
376
+ <resource>avatax</resource>
377
  </avatax_queue>
378
  <avatax_log translate="title" module="avatax">
379
  <title>AvaTax Log</title>
380
  <action>adminhtml/avaTax_grid/log</action>
381
+ <resource>avatax</resource>
382
  </avatax_log>
383
  </children>
384
  </tax>
401
  <default>
402
  <tax>
403
  <avatax>
404
+ <validate_address>1</validate_address>
405
+ <active_service>avatax</active_service>
406
  <action>0</action>
407
  <url>https://avatax.avalara.net/</url>
408
  <region_filter_mode>0</region_filter_mode>
429
  <onepage_normalize_message>Your shipping address has been modified during our validation process. Please confirm the address to the right is accurate.</onepage_normalize_message>
430
  <multiaddress_normalize_message>Your shipping addresses have been modified during our validation process. Please confirm they are still correct.</multiaddress_normalize_message>
431
  <validate_address_message>The address '%s' appears invalid. Please correct it or select another address.</validate_address_message>
432
+ <avatax16_onepage_validate_address_message>Unable to validate address.</avatax16_onepage_validate_address_message>
433
  </avatax>
434
  <calculation>
435
  <based_on>shipping</based_on>
450
  <avatax_processqueue>
451
  <schedule><cron_expr>0 * * * *</cron_expr></schedule>
452
  <run>
453
+ <model>avatax/observer_processQueue::execute</model>
454
  </run>
455
  </avatax_processqueue>
456
  <avatax_cleanlog>
457
  <schedule><cron_expr>0 0 * * *</cron_expr></schedule>
458
  <run>
459
+ <model>avatax/observer_cleanLog::execute</model>
460
  </run>
461
  </avatax_cleanlog>
462
  </jobs>
app/code/community/OnePica/AvaTax/etc/system-avatax16-disabled.xml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * OnePica_AvaTax
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0), a
9
+ * copy of which is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category OnePica
13
+ * @package OnePica_AvaTax
14
+ * @author OnePica Codemaster <codemaster@onepica.com>
15
+ * @copyright Copyright (c) 2015 One Pica, Inc.
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ -->
19
+ <config>
20
+ <sections>
21
+ <tax>
22
+ <groups>
23
+ <avatax>
24
+ <fields>
25
+ <avatax16_onepage_validate_address_message translate="label comment">
26
+ <label>Address Validation Error</label>
27
+ <comment>Only applies if address validation is enabled</comment>
28
+ <frontend_type>textarea</frontend_type>
29
+ <sort_order>325</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ </avatax16_onepage_validate_address_message>
34
+ </fields>
35
+ </avatax>
36
+ </groups>
37
+ </tax>
38
+ </sections>
39
+ </config>
app/code/community/OnePica/AvaTax/etc/system-avatax16.xml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * OnePica_AvaTax
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0), a
9
+ * copy of which is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category OnePica
13
+ * @package OnePica_AvaTax
14
+ * @author OnePica Codemaster <codemaster@onepica.com>
15
+ * @copyright Copyright (c) 2015 One Pica, Inc.
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ -->
19
+ <config>
20
+ <sections>
21
+ <tax>
22
+ <groups>
23
+ <avatax>
24
+ <fields>
25
+ <avatax16_onepage_validate_address_message translate="label comment">
26
+ <label>Address Validation Error</label>
27
+ <comment>Only applies if address validation is enabled</comment>
28
+ <frontend_type>textarea</frontend_type>
29
+ <sort_order>325</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ </avatax16_onepage_validate_address_message>
34
+ </fields>
35
+ </avatax>
36
+ <sales_display>
37
+ <fields>
38
+ <full_summary>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ <show_in_store>1</show_in_store>
42
+ </full_summary>
43
+ </fields>
44
+ </sales_display>
45
+ </groups>
46
+ </tax>
47
+ </sections>
48
+ </config>
app/code/community/OnePica/AvaTax/etc/system-disabled.xml CHANGED
@@ -128,7 +128,7 @@
128
  </sales_display>
129
  <cart_display>
130
  <fields>
131
- <price >
132
  <show_in_default>1</show_in_default>
133
  <show_in_website>1</show_in_website>
134
  <show_in_store>1</show_in_store>
128
  </sales_display>
129
  <cart_display>
130
  <fields>
131
+ <price>
132
  <show_in_default>1</show_in_default>
133
  <show_in_website>1</show_in_website>
134
  <show_in_store>1</show_in_store>
app/code/community/OnePica/AvaTax/etc/system.xml CHANGED
@@ -23,10 +23,6 @@
23
  <groups>
24
  <avatax translate="label comment">
25
  <label>AvaTax</label>
26
- <comment><![CDATA[
27
- <style type="text/css"> #tax_avatax textarea { height:65px; } #tax_avatax .multiselect { height:155px; } </style>
28
- <p class="switcher">For complete and up-to-date documentation, please visit <a href="http://www.onepica.com/magento-extensions/avatax/" target="_blank">http://www.onepica.com/magento-extensions/avatax</a>.</p>
29
- ]]></comment>
30
  <sort_order>0</sort_order>
31
  <show_in_default>1</show_in_default>
32
  <show_in_website>1</show_in_website>
@@ -51,7 +47,8 @@
51
  </action>
52
  <url translate="label">
53
  <label>URL</label>
54
- <frontend_type>text</frontend_type>
 
55
  <sort_order>20</sort_order>
56
  <show_in_default>1</show_in_default>
57
  <show_in_website>1</show_in_website>
@@ -66,7 +63,7 @@
66
  <show_in_store>1</show_in_store>
67
  </account>
68
  <license translate="label">
69
- <label>License Key</label>
70
  <frontend_type>text</frontend_type>
71
  <sort_order>40</sort_order>
72
  <show_in_default>1</show_in_default>
@@ -306,6 +303,54 @@
306
  <show_in_store>1</show_in_store>
307
  <depends><upc_check_status>1</upc_check_status></depends>
308
  </upc_attribute_code>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
 
310
  <title_address_validation translate="label">
311
  <label><![CDATA[<strong>Shipping Address Options</strong>]]></label>
@@ -518,7 +563,6 @@
518
  <sales_display>
519
  <fields>
520
  <full_summary>
521
- <!-- Jurisdiction data is not kept in Magento at this time after the quote -->
522
  <show_in_default>0</show_in_default>
523
  <show_in_website>0</show_in_website>
524
  <show_in_store>0</show_in_store>
23
  <groups>
24
  <avatax translate="label comment">
25
  <label>AvaTax</label>
 
 
 
 
26
  <sort_order>0</sort_order>
27
  <show_in_default>1</show_in_default>
28
  <show_in_website>1</show_in_website>
47
  </action>
48
  <url translate="label">
49
  <label>URL</label>
50
+ <frontend_type>select</frontend_type>
51
+ <source_model>avatax/source_url</source_model>
52
  <sort_order>20</sort_order>
53
  <show_in_default>1</show_in_default>
54
  <show_in_website>1</show_in_website>
63
  <show_in_store>1</show_in_store>
64
  </account>
65
  <license translate="label">
66
+ <label>Key</label>
67
  <frontend_type>text</frontend_type>
68
  <sort_order>40</sort_order>
69
  <show_in_default>1</show_in_default>
303
  <show_in_store>1</show_in_store>
304
  <depends><upc_check_status>1</upc_check_status></depends>
305
  </upc_attribute_code>
306
+ <!-- TODO: Remove this code if we will not use those properties
307
+ <default_avalara_goods_and_services_type translate="label comment">
308
+ <label>Default Avalara Goods And Services Type</label>
309
+ <comment>Optional.</comment>
310
+ <frontend_type>text</frontend_type>
311
+ <sort_order>271</sort_order>
312
+ <show_in_default>1</show_in_default>
313
+ <show_in_website>1</show_in_website>
314
+ <show_in_store>1</show_in_store>
315
+ </default_avalara_goods_and_services_type>
316
+ <default_avalara_goods_and_services_modifier_type translate="label comment">
317
+ <label>Default Avalara Goods And Services Modifier Type</label>
318
+ <comment>Optional.</comment>
319
+ <frontend_type>text</frontend_type>
320
+ <sort_order>272</sort_order>
321
+ <show_in_default>1</show_in_default>
322
+ <show_in_website>1</show_in_website>
323
+ <show_in_store>1</show_in_store>
324
+ </default_avalara_goods_and_services_modifier_type>
325
+ <default_tax_payer_code translate="label comment">
326
+ <label>Default Tax Payer Code</label>
327
+ <comment>Optional.</comment>
328
+ <frontend_type>text</frontend_type>
329
+ <sort_order>273</sort_order>
330
+ <show_in_default>1</show_in_default>
331
+ <show_in_website>1</show_in_website>
332
+ <show_in_store>1</show_in_store>
333
+ </default_tax_payer_code>
334
+ <default_use_type translate="label comment">
335
+ <label>Default Use Type</label>
336
+ <comment>Optional.</comment>
337
+ <frontend_type>select</frontend_type>
338
+ <source_model>avatax/source_avatax16_usetype</source_model>
339
+ <sort_order>274</sort_order>
340
+ <show_in_default>1</show_in_default>
341
+ <show_in_website>1</show_in_website>
342
+ <show_in_store>1</show_in_store>
343
+ </default_use_type>
344
+ <default_buyer_type translate="label comment">
345
+ <label>Default Buyer Type</label>
346
+ <comment>Optional.</comment>
347
+ <frontend_type>select</frontend_type>
348
+ <source_model>avatax/source_avatax16_buyertype</source_model>
349
+ <sort_order>275</sort_order>
350
+ <show_in_default>1</show_in_default>
351
+ <show_in_website>1</show_in_website>
352
+ <show_in_store>1</show_in_store>
353
+ </default_buyer_type> -->
354
 
355
  <title_address_validation translate="label">
356
  <label><![CDATA[<strong>Shipping Address Options</strong>]]></label>
563
  <sales_display>
564
  <fields>
565
  <full_summary>
 
566
  <show_in_default>0</show_in_default>
567
  <show_in_website>0</show_in_website>
568
  <show_in_store>0</show_in_store>
app/code/community/OnePica/AvaTax/sql/avatax_records_setup/mysql4-upgrade-3.0.0.1-3.0.0.2.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica_AvaTax
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0), a
8
+ * copy of which is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category OnePica
12
+ * @package OnePica_AvaTax
13
+ * @author OnePica Codemaster <codemaster@onepica.com>
14
+ * @copyright Copyright (c) 2015 One Pica, Inc.
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ $installer = $this;
18
+ $this->startSetup();
19
+ /* @var $this Mage_Core_Model_Resource_Setup */
20
+ $adapter = $this->getConnection();
21
+
22
+ $installer->run("
23
+
24
+ ALTER TABLE `" . $this->getTable('avatax_records/log') . "`
25
+ CHANGE COLUMN `result` `result` MEDIUMTEXT NULL COMMENT 'Result';");
26
+
27
+ $this->endSetup();
lib/AvaTax/classes/ValidateRequest.class.php CHANGED
@@ -73,6 +73,7 @@ class ValidateRequest
73
  * </pre>
74
  *
75
  * @var Address
 
76
  */
77
 
78
  public function setAddress(&$value) { $this->Address = $value; return $this; }
@@ -97,6 +98,7 @@ class ValidateRequest
97
  *
98
  * @var string
99
  * @see TextCase
 
100
  */
101
 
102
  public function setTextCase($value)
@@ -120,6 +122,7 @@ class ValidateRequest
120
  * Default value is <b>false</b>
121
  * </p>
122
  * @var boolean
 
123
  */
124
  public function setCoordinates($value) { $this->Coordinates = ($value ? true : false); return $this; }
125
 
73
  * </pre>
74
  *
75
  * @var Address
76
+ * @return $this
77
  */
78
 
79
  public function setAddress(&$value) { $this->Address = $value; return $this; }
98
  *
99
  * @var string
100
  * @see TextCase
101
+ * @return $this
102
  */
103
 
104
  public function setTextCase($value)
122
  * Default value is <b>false</b>
123
  * </p>
124
  * @var boolean
125
+ * @return $this
126
  */
127
  public function setCoordinates($value) { $this->Coordinates = ($value ? true : false); return $this; }
128
 
lib/OnePica/AvaTax16/AddressResolution.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_AddressResolution
21
+ */
22
+ class OnePica_AvaTax16_AddressResolution extends OnePica_AvaTax16_ResourceAbstract
23
+ {
24
+ /**
25
+ * Url path for address resolution
26
+ */
27
+ const ADDRESS_RESOLUTION_URL_PATH = '/address';
28
+
29
+ /**
30
+ * Resolve a Single Address
31
+ *
32
+ * @param OnePica_AvaTax16_Document_Part_Location_Address $address
33
+ * @return OnePica_AvaTax16_AddressResolution_ResolveSingleAddressResponse $result
34
+ */
35
+ public function resolveSingleAddress($address)
36
+ {
37
+ $config = $this->getConfig();
38
+ $postUrl = $config->getBaseUrl()
39
+ . self::ADDRESS_RESOLUTION_URL_PATH
40
+ . '/account/'
41
+ . $config->getAccountId()
42
+ . '/company/'
43
+ . $config->getCompanyCode()
44
+ . '/resolve';
45
+
46
+ $postData = $address->toArray();
47
+ $requestOptions = array(
48
+ 'requestType' => 'POST',
49
+ 'data' => $postData,
50
+ 'returnClass' => 'OnePica_AvaTax16_AddressResolution_ResolveSingleAddressResponse'
51
+ );
52
+ $result = $this->_sendRequest($postUrl, $requestOptions);
53
+ return $result;
54
+ }
55
+ }
lib/OnePica/AvaTax16/AddressResolution/PingResponse.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_AddressResolution_PingResponse
21
+ */
22
+ class OnePica_AvaTax16_AddressResolution_PingResponse extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Has error
26
+ *
27
+ * @var bool
28
+ */
29
+ protected $_hasError = false;
30
+
31
+ /**
32
+ * Errors
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_errors;
37
+ }
lib/OnePica/AvaTax16/AddressResolution/ResolveSingleAddressResponse.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_AddressResolution_ResolveSingleAddressResponse
21
+ */
22
+ class OnePica_AvaTax16_AddressResolution_ResolveSingleAddressResponse extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Has error
26
+ *
27
+ * @var bool
28
+ */
29
+ protected $_hasError = false;
30
+
31
+ /**
32
+ * Errors
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_errors;
37
+
38
+ /**
39
+ * Types of complex properties
40
+ *
41
+ * @var array
42
+ */
43
+ protected $_propertyComplexTypes = array(
44
+ '_address' => array(
45
+ 'type' => 'OnePica_AvaTax16_Document_Part_Location_Address'
46
+ ),
47
+ '_coordinates' => array(
48
+ 'type' => 'OnePica_AvaTax16_Document_Part_Location_LatLong'
49
+ ),
50
+ '_taxAuthorities' => array(
51
+ 'type' => 'OnePica_AvaTax16_AddressResolution_TaxAuthority',
52
+ 'isArrayOf' => 'true'
53
+ ),
54
+ );
55
+
56
+ /**
57
+ * Address
58
+ *
59
+ * @var OnePica_AvaTax16_Document_Part_Location_Address
60
+ */
61
+ protected $_address;
62
+
63
+ /**
64
+ * Coordinates
65
+ *
66
+ * @var OnePica_AvaTax16_Document_Part_Location_LatLong
67
+ */
68
+ protected $_coordinates;
69
+
70
+ /**
71
+ * Resolution Quality
72
+ *
73
+ * @var string
74
+ */
75
+ protected $_resolutionQuality;
76
+
77
+ /**
78
+ * Tax Authorities
79
+ *
80
+ * @var array
81
+ */
82
+ protected $_taxAuthorities;
83
+ }
lib/OnePica/AvaTax16/AddressResolution/TaxAuthority.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_AddressResolution_TaxAuthority
21
+ */
22
+ class OnePica_AvaTax16_AddressResolution_TaxAuthority extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Avalara Id
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_avalaraId;
30
+
31
+ /**
32
+ * Jurisdiction Name
33
+ *
34
+ * @var string
35
+ */
36
+ protected $_jurisdictionName;
37
+
38
+ /**
39
+ * Jurisdiction Type
40
+ *
41
+ * @var string
42
+ */
43
+ protected $_jurisdictionType;
44
+
45
+ /**
46
+ * Signature Code
47
+ *
48
+ * @var string
49
+ */
50
+ protected $_signatureCode;
51
+ }
lib/OnePica/AvaTax16/Calculation.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Calculation
21
+ */
22
+ class OnePica_AvaTax16_Calculation extends OnePica_AvaTax16_ResourceAbstract
23
+ {
24
+ /**
25
+ * Url path for calculations
26
+ */
27
+ const CALCULATION_URL_PATH = '/calculations';
28
+
29
+ /**
30
+ * Create Calculation
31
+ *
32
+ * @param OnePica_AvaTax16_Document_Request $documentRequest
33
+ * @return OnePica_AvaTax16_Document_Response $documentResponse
34
+ */
35
+ public function createCalculation($documentRequest)
36
+ {
37
+ $postUrl = $this->_config->getBaseUrl() . self::CALCULATION_URL_PATH;
38
+ $postData = $documentRequest->toArray();
39
+ $requestOptions = array(
40
+ 'requestType' => 'POST',
41
+ 'data' => $postData,
42
+ 'returnClass' => 'OnePica_AvaTax16_Document_Response'
43
+ );
44
+ $documentResponse = $this->_sendRequest($postUrl, $requestOptions);
45
+ return $documentResponse;
46
+ }
47
+
48
+ /**
49
+ * Get Calculation
50
+ *
51
+ * @param string $transactionType
52
+ * @param string $documentCode
53
+ * @return OnePica_AvaTax16_Document_Response $documentResponse
54
+ */
55
+ public function getCalculation($transactionType, $documentCode)
56
+ {
57
+ $config = $this->getConfig();
58
+ $getUrl = $config->getBaseUrl()
59
+ . self::CALCULATION_URL_PATH
60
+ . '/account/'
61
+ . $config->getAccountId()
62
+ . '/company/'
63
+ . $config->getCompanyCode()
64
+ . '/'
65
+ . $transactionType
66
+ . '/'
67
+ . $documentCode;
68
+
69
+ $requestOptions = array(
70
+ 'requestType' => 'GET',
71
+ 'returnClass' => 'OnePica_AvaTax16_Document_Response'
72
+ );
73
+ $documentResponse = $this->_sendRequest($getUrl, $requestOptions);
74
+ return $documentResponse;
75
+ }
76
+
77
+ /**
78
+ * Get List Of Calculations
79
+ *
80
+ * @param string $transactionType
81
+ * @param int $limit
82
+ * @param string $startDate
83
+ * @param string $endDate
84
+ * @param string $startCode (not implemented)
85
+ * @return OnePica_AvaTax16_Calculation_ListResponse $calculationListResponse
86
+ */
87
+ public function getListOfCalculations($transactionType, $limit = null, $startDate = null, $endDate = null,
88
+ $startCode = null)
89
+ {
90
+ $config = $this->getConfig();
91
+ $getUrl = $config->getBaseUrl()
92
+ . self::CALCULATION_URL_PATH
93
+ . '/account/'
94
+ . $config->getAccountId()
95
+ . '/company/'
96
+ . $config->getCompanyCode()
97
+ . '/'
98
+ . $transactionType;
99
+ $filterData = array(
100
+ 'limit' => $limit,
101
+ 'startDate' => $startDate,
102
+ 'endDate' => $endDate,
103
+ 'startCode' => $startCode,
104
+ );
105
+
106
+ $requestOptions = array(
107
+ 'requestType' => 'GET',
108
+ 'data' => $filterData,
109
+ 'returnClass' => 'OnePica_AvaTax16_Calculation_ListResponse'
110
+ );
111
+ $calculationListResponse = $this->_sendRequest($getUrl, $requestOptions);
112
+ return $calculationListResponse;
113
+ }
114
+ }
lib/OnePica/AvaTax16/Calculation/ListItemResponse.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Calculation_ListItemResponse
21
+ */
22
+ class OnePica_AvaTax16_Calculation_ListItemResponse extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Types of complex properties
26
+ *
27
+ * @var array
28
+ */
29
+ protected $_propertyComplexTypes = array(
30
+ '_header' => array(
31
+ 'type' => 'OnePica_AvaTax16_Calculation_ListItemResponse_Header'
32
+ ),
33
+ '_lines' => array(
34
+ 'type' => 'OnePica_AvaTax16_Calculation_ListItemResponse_Line',
35
+ 'isArrayOf' => 'true'
36
+ ),
37
+ '_calculatedTaxSummary' => array(
38
+ 'type' => 'OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary'
39
+ ),
40
+ '_processingInfo' => array(
41
+ 'type' => 'OnePica_AvaTax16_Calculation_ListItemResponse_ProcessingInfo'
42
+ ),
43
+ );
44
+
45
+ /**
46
+ * Header
47
+ *
48
+ * @var OnePica_AvaTax16_Calculation_ListItemResponse_Header
49
+ */
50
+ protected $_header;
51
+
52
+ /**
53
+ * Lines
54
+ *
55
+ * @var Array
56
+ */
57
+ protected $_lines;
58
+
59
+ /**
60
+ * Feedback
61
+ *
62
+ * @var OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary
63
+ */
64
+ protected $_calculatedTaxSummary;
65
+
66
+ /**
67
+ * Feedback
68
+ *
69
+ * @var OnePica_AvaTax16_Calculation_ListItemResponse_ProcessingInfo
70
+ */
71
+ protected $_processingInfo;
72
+ }
lib/OnePica/AvaTax16/Calculation/ListItemResponse/CalculatedTaxSummary.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary
21
+ */
22
+ class OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary
23
+ extends OnePica_AvaTax16_Document_Part
24
+ {
25
+ /**
26
+ * Types of complex properties
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_propertyComplexTypes = array(
31
+ '_taxByType' => array(
32
+ 'type' => 'OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary_TaxByType',
33
+ 'isArrayOf' => 'true'
34
+ )
35
+ );
36
+
37
+ /**
38
+ * Number Of Lines
39
+ *
40
+ * @var int
41
+ */
42
+ protected $_numberOfLines;
43
+
44
+ /**
45
+ * Subtotal
46
+ *
47
+ * @var float
48
+ */
49
+ protected $_subtotal;
50
+
51
+ /**
52
+ * Total Tax
53
+ *
54
+ * @var float
55
+ */
56
+ protected $_totalTax;
57
+
58
+ /**
59
+ * Tax By Type
60
+ *
61
+ * @var OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary_TaxByType
62
+ */
63
+ protected $_taxByType;
64
+
65
+ /**
66
+ * Subtotal Taxable
67
+ *
68
+ * @var float
69
+ */
70
+ protected $_subtotalTaxable;
71
+
72
+ /**
73
+ * Subtotal Exempt
74
+ *
75
+ * @var float
76
+ */
77
+ protected $_subtotalExempt;
78
+
79
+ /**
80
+ * Tax
81
+ *
82
+ * @var float
83
+ */
84
+ protected $_tax;
85
+
86
+ /**
87
+ * Grand Total
88
+ *
89
+ * @var float
90
+ */
91
+ protected $_grandTotal;
92
+ }
lib/OnePica/AvaTax16/Calculation/ListItemResponse/CalculatedTaxSummary/TaxByType.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary_TaxByType
21
+ */
22
+ class OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary_TaxByType
23
+ extends OnePica_AvaTax16_Document_Part
24
+ {
25
+ /**
26
+ * Types of complex properties
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_propertyComplexTypes = array(
31
+ '_jurisdictions' => array(
32
+ 'type' => 'OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary_TaxByType_Details'
33
+ )
34
+ );
35
+
36
+ /**
37
+ * Tax
38
+ *
39
+ * @var float
40
+ */
41
+ protected $_tax;
42
+
43
+ /**
44
+ * jurisdictions
45
+ *
46
+ * @var OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary_TaxByType_Details
47
+ */
48
+ protected $_jurisdictions;
49
+
50
+ /**
51
+ * Comment
52
+ *
53
+ * @var string
54
+ */
55
+ protected $_comment;
56
+ }
lib/OnePica/AvaTax16/Calculation/ListItemResponse/CalculatedTaxSummary/TaxByType/Details.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary_TaxByType_Details
21
+ */
22
+ class OnePica_AvaTax16_Calculation_ListItemResponse_CalculatedTaxSummary_TaxByType_Details
23
+ extends OnePica_AvaTax16_Document_Part
24
+ {
25
+ /**
26
+ * Jurisdiction Name
27
+ *
28
+ * @var string
29
+ */
30
+ protected $_jurisdictionName;
31
+
32
+ /**
33
+ * Jurisdiction Type
34
+ *
35
+ * @var string
36
+ */
37
+ protected $_jurisdictionType;
38
+
39
+ /**
40
+ * Tax
41
+ *
42
+ * @var float
43
+ */
44
+ protected $_tax ;
45
+
46
+ /**
47
+ * Comment
48
+ *
49
+ * @var float
50
+ */
51
+ protected $_comment;
52
+ }
lib/OnePica/AvaTax16/Calculation/ListItemResponse/Header.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Calculation_ListItemResponse_Header
21
+ */
22
+ class OnePica_AvaTax16_Calculation_ListItemResponse_Header extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Account Id
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_accountId;
30
+
31
+ /**
32
+ * Company Code
33
+ *
34
+ * @var string
35
+ */
36
+ protected $_companyCode;
37
+
38
+ /**
39
+ * Transaction Type
40
+ *
41
+ * @var string
42
+ */
43
+ protected $_transactionType;
44
+
45
+ /**
46
+ * Document Code
47
+ *
48
+ * @var string
49
+ */
50
+ protected $_documentCode;
51
+
52
+ /**
53
+ * Customer Code
54
+ *
55
+ * @var string
56
+ */
57
+ protected $_customerCode;
58
+
59
+ /**
60
+ * Transaction Date
61
+ *
62
+ * @var string
63
+ */
64
+ protected $_transactionDate;
65
+
66
+ /**
67
+ * Currency
68
+ *
69
+ * @var string
70
+ */
71
+ protected $_currency;
72
+
73
+ /**
74
+ * Total Tax Override Amount
75
+ *
76
+ * @var string
77
+ */
78
+ protected $_totalTaxOverrideAmount;
79
+ }
lib/OnePica/AvaTax16/Calculation/ListItemResponse/Line.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Calculation_ListItemResponse_Line
21
+ */
22
+ class OnePica_AvaTax16_Calculation_ListItemResponse_Line extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Avalara Goods And Services Modifier type
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_avalaraGoodsAndServicesModifierType;
30
+ }
lib/OnePica/AvaTax16/Calculation/ListItemResponse/ProcessingInfo.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Calculation_ListItemResponse_ProcessingInfo
21
+ */
22
+ class OnePica_AvaTax16_Calculation_ListItemResponse_ProcessingInfo extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Transaction State
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_transactionState;
30
+
31
+ /**
32
+ * Version Id
33
+ *
34
+ * @var string
35
+ */
36
+ protected $_versionId;
37
+
38
+ /**
39
+ * Format Id
40
+ *
41
+ * @var string
42
+ */
43
+ protected $_formatId;
44
+
45
+ /**
46
+ * Duration
47
+ *
48
+ * @var float
49
+ */
50
+ protected $_duration;
51
+
52
+ /**
53
+ * Modified Date
54
+ *
55
+ * @var string
56
+ */
57
+ protected $_modifiedDate;
58
+
59
+ /**
60
+ * Batch Id
61
+ *
62
+ * @var string
63
+ */
64
+ protected $_batchId;
65
+
66
+ /**
67
+ * Document Id
68
+ *
69
+ * @var string
70
+ */
71
+ protected $_documentId;
72
+
73
+ /**
74
+ * Message
75
+ *
76
+ * @var string
77
+ */
78
+ protected $_message;
79
+ }
lib/OnePica/AvaTax16/Calculation/ListResponse.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Calculation_ListResponse
21
+ */
22
+ class OnePica_AvaTax16_Calculation_ListResponse extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Has error
26
+ *
27
+ * @var bool
28
+ */
29
+ protected $_hasError = false;
30
+
31
+ /**
32
+ * Errors
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_errors;
37
+
38
+ /**
39
+ * List items
40
+ *
41
+ * @var OnePica_AvaTax16_Calculation_ListItemResponse[]
42
+ */
43
+ protected $_items;
44
+
45
+ /**
46
+ * Fill data from object
47
+ *
48
+ * @param StdClass|array $data
49
+ * @return $this
50
+ */
51
+ public function fillData($data)
52
+ {
53
+ $result = array();
54
+ if (is_array($data)) {
55
+ foreach ($data as $dataItem) {
56
+ $calculationListItem = new OnePica_AvaTax16_Calculation_ListItemResponse();
57
+ $result[] = $calculationListItem->fillData($dataItem);
58
+ }
59
+ }
60
+ $this->setItems($result);
61
+ }
62
+ }
lib/OnePica/AvaTax16/Config.php ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Config
21
+ */
22
+ class OnePica_AvaTax16_Config
23
+ {
24
+ /**
25
+ * Accept header
26
+ */
27
+ const ACCEPT_HEADER = 'application/json; document-version=1';
28
+
29
+ /**
30
+ * Content type header
31
+ */
32
+ const CONTENT_TYPE_HEADER = 'application/json';
33
+
34
+ /**
35
+ * Default user agent
36
+ */
37
+ const USER_AGENT_DEFAULT = 'AvaTax16 agent';
38
+
39
+ /**
40
+ * Base url
41
+ *
42
+ * @var string
43
+ */
44
+ protected $_baseUrl;
45
+
46
+ /**
47
+ * Account id
48
+ *
49
+ * @var string
50
+ */
51
+ protected $_accountId;
52
+
53
+ /**
54
+ * Company code
55
+ *
56
+ * @var string
57
+ */
58
+ protected $_companyCode;
59
+
60
+ /**
61
+ * Authorization header
62
+ *
63
+ * @var string
64
+ */
65
+ protected $_authorizationHeader;
66
+
67
+ /**
68
+ * User agent
69
+ *
70
+ * @var string
71
+ */
72
+ protected $_userAgent;
73
+
74
+ /**
75
+ * Construct
76
+ */
77
+ public function __construct()
78
+ {
79
+ // init default values
80
+ $this->setUserAgent(self::USER_AGENT_DEFAULT);
81
+ }
82
+
83
+ /**
84
+ * Set base url
85
+ *
86
+ * @param string $value
87
+ * @return OnePica_AvaTax16_Config
88
+ */
89
+ public function setBaseUrl($value)
90
+ {
91
+ $this->_baseUrl = $value;
92
+ }
93
+
94
+ /**
95
+ * Get base url
96
+ *
97
+ * @return string
98
+ */
99
+ public function getBaseUrl()
100
+ {
101
+ return $this->_baseUrl;
102
+ }
103
+
104
+ /**
105
+ * Set user agent
106
+ *
107
+ * @param string $value
108
+ * @return OnePica_AvaTax16_Config
109
+ */
110
+ public function setUserAgent($value)
111
+ {
112
+ $this->_userAgent = $value;
113
+ }
114
+
115
+ /**
116
+ * Get user agent
117
+ *
118
+ * @return string
119
+ */
120
+ public function getUserAgent()
121
+ {
122
+ return $this->_userAgent;
123
+ }
124
+
125
+ /**
126
+ * Set account id
127
+ *
128
+ * @param string $value
129
+ * @return OnePica_AvaTax16_Config
130
+ */
131
+ public function setAccountId($value)
132
+ {
133
+ $this->_accountId = $value;
134
+ }
135
+
136
+ /**
137
+ * Get account id
138
+ *
139
+ * @return string
140
+ */
141
+ public function getAccountId()
142
+ {
143
+ return $this->_accountId;
144
+ }
145
+
146
+ /**
147
+ * Set company code
148
+ *
149
+ * @param string $value
150
+ * @return OnePica_AvaTax16_Config
151
+ */
152
+ public function setCompanyCode($value)
153
+ {
154
+ $this->_companyCode = $value;
155
+ }
156
+
157
+ /**
158
+ * Get company code
159
+ *
160
+ * @return string
161
+ */
162
+ public function getCompanyCode()
163
+ {
164
+ return $this->_companyCode;
165
+ }
166
+
167
+ /**
168
+ * Set authorization header
169
+ *
170
+ * @param string $value
171
+ * @return OnePica_AvaTax16_Config
172
+ */
173
+ public function setAuthorizationHeader($value)
174
+ {
175
+ $this->_authorizationHeader = $value;
176
+ }
177
+
178
+ /**
179
+ * Get authorization header
180
+ *
181
+ * @return string
182
+ */
183
+ public function getAuthorizationHeader()
184
+ {
185
+ return $this->_authorizationHeader;
186
+ }
187
+
188
+ /**
189
+ * Get accept header
190
+ *
191
+ * @return string
192
+ */
193
+ public function getAcceptHeader()
194
+ {
195
+ return self::ACCEPT_HEADER;
196
+ }
197
+
198
+ /**
199
+ * Get accept header
200
+ *
201
+ * @return string
202
+ */
203
+ public function getContentTypeHeader()
204
+ {
205
+ return self::CONTENT_TYPE_HEADER;
206
+ }
207
+
208
+ /**
209
+ * Get if config values are available for requests
210
+ *
211
+ * @return bool
212
+ */
213
+ public function isValid()
214
+ {
215
+ if ($this->getBaseUrl()
216
+ && $this->getAccountId()
217
+ && $this->getCompanyCode()
218
+ && $this->getAuthorizationHeader()
219
+ && $this->getAcceptHeader()
220
+ && $this->getContentTypeHeader()
221
+ && $this->getUserAgent()
222
+ ) {
223
+ return true;
224
+ } else {
225
+ return false;
226
+ }
227
+ }
228
+ }
lib/OnePica/AvaTax16/Document/Part.php ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Part
21
+ */
22
+ class OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Required properties
26
+ *
27
+ * @var array
28
+ */
29
+ protected $_requiredProperties = array();
30
+
31
+ /**
32
+ * Excluded properties (will be ignored during toArray function)
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_excludedProperties = array();
37
+
38
+ /**
39
+ * Types of complex properties
40
+ *
41
+ * @var array
42
+ */
43
+ protected $_propertyComplexTypes = array();
44
+
45
+ /**
46
+ * Properties get and set methods
47
+ */
48
+ public function __call($name, $arguments)
49
+ {
50
+ $action = substr($name, 0, 3);
51
+ switch ($action) {
52
+ case 'get':
53
+ $property = '_' . lcfirst(substr($name, 3));
54
+ if (property_exists($this,$property)) {
55
+ return $this->{$property};
56
+ } else {
57
+ $this->_throwWrongMethodErrorException($name);
58
+ }
59
+ break;
60
+ case 'set':
61
+ $property = '_' . lcfirst(substr($name, 3));
62
+ if (property_exists($this,$property)) {
63
+ $this->{$property} = $arguments[0];
64
+ } else {
65
+ $this->_throwWrongMethodErrorException($name);
66
+ }
67
+ break;
68
+ default :
69
+ $this->_throwWrongMethodErrorException($name);
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Throw Wrong Method Error Exception
75
+ *
76
+ * @param string $methodName
77
+ * @throws OnePica_AvaTax16_Exception
78
+ */
79
+ protected function _throwWrongMethodErrorException($methodName)
80
+ {
81
+ $trace = debug_backtrace();
82
+ $errorMessage = 'Undefined method '
83
+ . $methodName
84
+ . ' in '
85
+ . $trace[0]['file']
86
+ . ' on line '
87
+ . $trace[0]['line'];
88
+ throw new OnePica_AvaTax16_Exception($errorMessage);
89
+ }
90
+
91
+ /**
92
+ * Checks if document part is valid
93
+ *
94
+ * @return bool
95
+ */
96
+ public function isValid()
97
+ {
98
+ foreach ($this as $key => $value) {
99
+ if (in_array($key, $this->_requiredProperties) && (null === $value)) {
100
+ return false;
101
+ }
102
+ }
103
+ return true;
104
+ }
105
+
106
+ /**
107
+ * Convert object data to array
108
+ *
109
+ * @return array
110
+ * @throws OnePica_AvaTax16_Exception
111
+ */
112
+ public function toArray()
113
+ {
114
+ if (!$this->isValid()) {
115
+ throw new OnePica_AvaTax16_Exception("Not valid data in " . get_class($this));
116
+ }
117
+ $result = array();
118
+ foreach ($this as $key => $value) {
119
+ if (in_array($key, $this->_excludedProperties)
120
+ || in_array($key, array('_requiredProperties', '_excludedProperties', '_propertyComplexTypes'))
121
+ || (null === $value)) {
122
+ // skip property
123
+ continue;
124
+ }
125
+ $name = substr($key, 1);
126
+ $result[$name] = $this->_proceedToArrayItem($value);
127
+ }
128
+ return $result;
129
+ }
130
+
131
+ /**
132
+ * Convert object data to array
133
+ *
134
+ * @param OnePica_AvaTax16_Document_Part|array|string $item
135
+ * @return array|string
136
+ */
137
+ protected function _proceedToArrayItem($item)
138
+ {
139
+ $result = null;
140
+ $itemType = ($item instanceof OnePica_AvaTax16_Document_Part) ? 'documentPart' :
141
+ ((is_array($item)) ? 'array' : 'simple');
142
+
143
+ switch ($itemType) {
144
+ case 'documentPart':
145
+ $result = $item->toArray();
146
+ break;
147
+ case 'array':
148
+ foreach ($item as $key => $value) {
149
+ $result[$key] = $this->_proceedToArrayItem($value);
150
+ }
151
+ break;
152
+ case 'simple':
153
+ $result = (string) $item;
154
+ break;
155
+ }
156
+
157
+ return $result;
158
+ }
159
+
160
+ /**
161
+ * Fill data from object
162
+ *
163
+ * @param StdClass|array $data
164
+ * @return $this
165
+ */
166
+ public function fillData($data)
167
+ {
168
+ foreach ($data as $key => $value) {
169
+ $propName = '_' . $key;
170
+ $method = 'set' . ucfirst($key);
171
+ if (!property_exists ($this, $propName)) {
172
+ // skip unknown property received from response to prevent error
173
+ continue;
174
+ }
175
+ if (isset($this->_propertyComplexTypes[$propName])) {
176
+ $propertyType = $this->_propertyComplexTypes[$propName]['type'];
177
+ if (isset($this->_propertyComplexTypes[$propName]['isArrayOf'])) {
178
+ $items = null;
179
+ if (count($value) > 0) {
180
+ foreach ($value as $itemKey => $itemData) {
181
+ $item = $this->_createItemAndFillData($propertyType, $itemData);
182
+ $items[$itemKey] = $item;
183
+ }
184
+ }
185
+ $this->$method($items);
186
+ } else {
187
+ $item = $value ? $this->_createItemAndFillData($propertyType, $value) : null;
188
+ $this->$method($item);
189
+ }
190
+ } else {
191
+ $this->$method($value);
192
+ }
193
+ }
194
+ return $this;
195
+ }
196
+
197
+ /**
198
+ * Create item object and fill data in it
199
+ *
200
+ * @param string $itemClassName
201
+ * @param StdClass|array $data
202
+ * @return object $item
203
+ */
204
+ protected function _createItemAndFillData($itemClassName, $data)
205
+ {
206
+ $item = new $itemClassName();
207
+ $item->fillData($data);
208
+ return $item;
209
+ }
210
+ }
lib/OnePica/AvaTax16/Document/Part/Feedback.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Part_Feedback
21
+ */
22
+ class OnePica_AvaTax16_Document_Part_Feedback extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Latency Data
26
+ *
27
+ * @var OnePica_AvaTax16_Document_Part_Feedback_LatencyData
28
+ */
29
+ protected $_latencyData;
30
+ }
lib/OnePica/AvaTax16/Document/Part/Feedback/LatencyData.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Part_Feedback_LatencyData
21
+ */
22
+ class OnePica_AvaTax16_Document_Part_Feedback_LatencyData extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Latency
26
+ *
27
+ * @var int
28
+ */
29
+ protected $_latency;
30
+
31
+ /**
32
+ * Version Id
33
+ *
34
+ * @var string
35
+ */
36
+ protected $_versionId;
37
+ }
lib/OnePica/AvaTax16/Document/Part/Location.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Part_Location
21
+ */
22
+ class OnePica_AvaTax16_Document_Part_Location extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Types of complex properties
26
+ *
27
+ * @var array
28
+ */
29
+ protected $_propertyComplexTypes = array(
30
+ '_address' => array(
31
+ 'type' => 'OnePica_AvaTax16_Document_Part_Location_Address'
32
+ ),
33
+ '_latlong' => array(
34
+ 'type' => 'OnePica_AvaTax16_Document_Part_Location_LatLong'
35
+ ),
36
+ '_feedback' => array(
37
+ 'type' => 'OnePica_AvaTax16_Document_Part_Feedback'
38
+ ),
39
+ );
40
+
41
+ /**
42
+ * Tax Location Purpose
43
+ * (Required)
44
+ *
45
+ * @var string
46
+ */
47
+ protected $_taxLocationPurpose;
48
+ /**
49
+ * Address
50
+ *
51
+ * @var OnePica_AvaTax16_Document_Part_Location_Address
52
+ */
53
+ protected $_address;
54
+
55
+ /**
56
+ * Latitude and longitude
57
+ *
58
+ * @var OnePica_AvaTax16_Document_Part_Location_LatLong
59
+ */
60
+ protected $_latlong;
61
+
62
+ /**
63
+ * Location code
64
+ * (Not currently supported)
65
+ *
66
+ * @var string
67
+ */
68
+ protected $_locationCode;
69
+
70
+ /**
71
+ * Ip Address
72
+ * (Not currently supported)
73
+ *
74
+ * @var string
75
+ */
76
+ protected $_ipAddress;
77
+
78
+ /**
79
+ * Resolution Quality
80
+ *
81
+ * @var string
82
+ */
83
+ protected $_resolutionQuality;
84
+
85
+ /**
86
+ * Address Tax Payer Code
87
+ * (Not currently supported)
88
+ *
89
+ * @var string
90
+ */
91
+ protected $_addressTaxPayerCode;
92
+
93
+ /**
94
+ * Address Buyer Type
95
+ *
96
+ * @var string
97
+ */
98
+ protected $_addressBuyerType;
99
+
100
+ /**
101
+ * Address Use Type
102
+ *
103
+ * @var string
104
+ */
105
+ protected $_addressUseType;
106
+
107
+ /**
108
+ * Set Address
109
+ *
110
+ * @param OnePica_AvaTax16_Document_Part_Location_Address $value
111
+ * @return $this
112
+ */
113
+ public function setAddress($value)
114
+ {
115
+ $this->_address = $value;
116
+ return $this;
117
+ }
118
+
119
+ /**
120
+ * Get Address
121
+ *
122
+ * @return OnePica_AvaTax16_Document_Part_Location_Address
123
+ */
124
+ public function getAddress()
125
+ {
126
+ return $this->_address;
127
+ }
128
+ }
lib/OnePica/AvaTax16/Document/Part/Location/Address.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Part_Location_Address
21
+ */
22
+ class OnePica_AvaTax16_Document_Part_Location_Address extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Required properties
26
+ *
27
+ * @var array
28
+ */
29
+ protected $_requiredProperties = array('_line1');
30
+
31
+ /**
32
+ * Line 1
33
+ * (Required)
34
+ *
35
+ * @var string
36
+ */
37
+ protected $_line1;
38
+
39
+ /**
40
+ * Line 2
41
+ *
42
+ * @var string
43
+ */
44
+ protected $_line2;
45
+
46
+ /**
47
+ * Line3
48
+ *
49
+ * @var string
50
+ */
51
+ protected $_line3;
52
+
53
+ /**
54
+ * City
55
+ * city, municipality, town are synonyms. Should be set only one of them
56
+ *
57
+ * @var string
58
+ */
59
+ protected $_city;
60
+
61
+ /**
62
+ * Municipality
63
+ * city, municipality, town are synonyms. Should be set only one of them
64
+ *
65
+ * @var string
66
+ */
67
+ protected $_municipality;
68
+
69
+ /**
70
+ * Town
71
+ * city, municipality, town are synonyms. Should be set only one of them
72
+ *
73
+ * @var string
74
+ */
75
+ protected $_town;
76
+
77
+ /**
78
+ * State
79
+ * state, province are synonyms. Should be set only one of them
80
+ *
81
+ * @var string
82
+ */
83
+ protected $_state;
84
+
85
+ /**
86
+ * Province
87
+ * state, province are synonyms. Should be set only one of them
88
+ *
89
+ * @var string
90
+ */
91
+ protected $_province;
92
+
93
+ /**
94
+ * Country
95
+ *
96
+ * @var string
97
+ */
98
+ protected $_country;
99
+
100
+ /**
101
+ * Zip Code
102
+ * zipcode, postalCode, postcode are synonyms. Should be set only one of them
103
+ *
104
+ * @var string
105
+ */
106
+ protected $_zipcode;
107
+
108
+ /**
109
+ * Postal Code
110
+ * zipcode, postalCode, postcode are synonyms. Should be set only one of them
111
+ *
112
+ * @var string
113
+ */
114
+ protected $_postalCode;
115
+
116
+ /**
117
+ * Post Code
118
+ * zipcode, postalCode, postcode are synonyms. Should be set only one of them
119
+ *
120
+ * @var string
121
+ */
122
+ protected $_postcode;
123
+ }
lib/OnePica/AvaTax16/Document/Part/Location/LatLong.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Part_Location_LatLong
21
+ */
22
+ class OnePica_AvaTax16_Document_Part_Location_LatLong extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Latitude
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_latitude;
30
+
31
+ /**
32
+ * Longitude
33
+ *
34
+ * @var string
35
+ */
36
+ protected $_longitude;
37
+ }
lib/OnePica/AvaTax16/Document/Request.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Request
21
+ */
22
+ class OnePica_AvaTax16_Document_Request extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Has error
26
+ *
27
+ * @var bool
28
+ */
29
+ protected $_hasError = false;
30
+
31
+ /**
32
+ * Errors
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_errors;
37
+
38
+ /**
39
+ * Types of complex properties
40
+ *
41
+ * @var array
42
+ */
43
+ protected $_propertyComplexTypes = array(
44
+ '_header' => array(
45
+ 'type' => 'OnePica_AvaTax16_Document_Request_Header'
46
+ ),
47
+ '_lines' => array(
48
+ 'type' => 'OnePica_AvaTax16_Document_Request_Line',
49
+ 'isArrayOf' => 'true'
50
+ ),
51
+ '_feedback' => array(
52
+ 'type' => 'OnePica_AvaTax16_Document_Part_Feedback'
53
+ ),
54
+ );
55
+
56
+ /**
57
+ * Header
58
+ *
59
+ * @var OnePica_AvaTax16_Document_Request_Header
60
+ */
61
+ protected $_header;
62
+
63
+ /**
64
+ * Lines
65
+ *
66
+ * @var OnePica_AvaTax16_Document_Request_Line[]
67
+ */
68
+ protected $_lines;
69
+
70
+ /**
71
+ * Feedback
72
+ *
73
+ * @var OnePica_AvaTax16_Document_Part_Feedback
74
+ */
75
+ protected $_feedback;
76
+ }
lib/OnePica/AvaTax16/Document/Request/Header.php ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Request_Header
21
+ */
22
+ class OnePica_AvaTax16_Document_Request_Header extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Types of complex properties
26
+ *
27
+ * @var array
28
+ */
29
+ protected $_propertyComplexTypes = array(
30
+ '_defaultLocations' => array(
31
+ 'type' => 'OnePica_AvaTax16_Document_Part_Location',
32
+ 'isArrayOf' => 'true'
33
+ ),
34
+ );
35
+
36
+ /**
37
+ * Required properties
38
+ *
39
+ * @var array
40
+ */
41
+ protected $_requiredProperties = array('_accountId', '_companyCode', '_transactionType', '_documentCode',
42
+ '_customerCode', '_transactionDate', '_defaultLocations');
43
+
44
+ /**
45
+ * Account Id
46
+ * (Required)
47
+ *
48
+ * @var string
49
+ */
50
+ protected $_accountId;
51
+
52
+ /**
53
+ * Company Code
54
+ * (Required)
55
+ *
56
+ * @var string
57
+ */
58
+ protected $_companyCode;
59
+
60
+ /**
61
+ * Transaction Type
62
+ * (Required)
63
+ *
64
+ * @var string
65
+ */
66
+ protected $_transactionType;
67
+
68
+ /**
69
+ * Document Code
70
+ * (Required)
71
+ *
72
+ * @var string
73
+ */
74
+ protected $_documentCode;
75
+
76
+ /**
77
+ * Customer Code
78
+ * (Required)
79
+ *
80
+ * @var string
81
+ */
82
+ protected $_customerCode;
83
+
84
+ /**
85
+ * Vendor Code
86
+ * (Required)
87
+ *
88
+ * @var string
89
+ */
90
+ protected $_vendorCode;
91
+
92
+ /**
93
+ * Transaction Date
94
+ * (Required)
95
+ *
96
+ * @var string
97
+ */
98
+ protected $_transactionDate;
99
+
100
+ /**
101
+ * Currency
102
+ * (Not currently supported)
103
+ *
104
+ * @var string
105
+ */
106
+ protected $_currency;
107
+
108
+ /**
109
+ * Total Tax Override Amount
110
+ * (Not currently supported)
111
+ *
112
+ * @var float
113
+ */
114
+ protected $_totalTaxOverrideAmount;
115
+
116
+ /**
117
+ * Tax Calculation Date
118
+ *
119
+ * @var string
120
+ */
121
+ protected $_taxCalculationDate;
122
+
123
+ /**
124
+ * Default Avalara Goods And Services Type
125
+ * (Not currently supported)
126
+ *
127
+ * @var string
128
+ */
129
+ protected $_defaultAvalaraGoodsAndServicesType;
130
+
131
+ /**
132
+ * Default Avalara Goods And Services Modifier Type
133
+ * (Not currently supported)
134
+ *
135
+ * @var string
136
+ */
137
+ protected $_defaultAvalaraGoodsAndServicesModifierType;
138
+
139
+ /**
140
+ * Default locations
141
+ * (Required)
142
+ *
143
+ * @var OnePica_AvaTax16_Document_Part_Location[]
144
+ */
145
+ protected $_defaultLocations;
146
+
147
+ /**
148
+ * Default Tax Payer Code
149
+ * (Not currently supported)
150
+ *
151
+ * @var string
152
+ */
153
+ protected $_defaultTaxPayerCode;
154
+
155
+ /**
156
+ * Default Buyer Type
157
+ *
158
+ * @var string
159
+ */
160
+ protected $_defaultBuyerType;
161
+
162
+ /**
163
+ * Default Use Type
164
+ *
165
+ * @var string
166
+ */
167
+ protected $_defaultUseType;
168
+
169
+ /**
170
+ * Purchase Order Number
171
+ *
172
+ * @var string
173
+ */
174
+ protected $_purchaseOrderNumber;
175
+
176
+ /**
177
+ * Metadata
178
+ *
179
+ * @var array
180
+ */
181
+ protected $_metadata;
182
+
183
+ /**
184
+ * Set Metadata
185
+ *
186
+ * @param array|StdClass $value
187
+ * @return $this
188
+ */
189
+ public function setMetadata($value)
190
+ {
191
+ if ($value instanceof StdClass) {
192
+ // convert object data to array
193
+ // it is used during filling data from response
194
+ $this->_metadata = (array) $value;
195
+ } else {
196
+ $this->_metadata = $value;
197
+ }
198
+ }
199
+ }
lib/OnePica/AvaTax16/Document/Request/Line.php ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Request_Line
21
+ */
22
+ class OnePica_AvaTax16_Document_Request_Line extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Required properties
26
+ *
27
+ * @var array
28
+ */
29
+ protected $_requiredProperties = array('_lineCode', '_lineAmount');
30
+
31
+ /**
32
+ * Types of complex properties
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_propertyComplexTypes = array(
37
+ '_locations' => array(
38
+ 'type' => 'OnePica_AvaTax16_Document_Part_Location',
39
+ 'isArrayOf' => 'true'
40
+ ),
41
+ );
42
+
43
+ /**
44
+ * Line Code
45
+ * (Required)
46
+ *
47
+ * @var string
48
+ */
49
+ protected $_lineCode;
50
+
51
+ /**
52
+ * Item code
53
+ *
54
+ * @var string
55
+ */
56
+ protected $_itemCode;
57
+
58
+ /**
59
+ * Avalara Goods And Services Type
60
+ *
61
+ * @var string
62
+ */
63
+ protected $_avalaraGoodsAndServicesType;
64
+
65
+ /**
66
+ * Avalara Goods And Services Modifier Type
67
+ *
68
+ * @var string
69
+ */
70
+ protected $_avalaraGoodsAndServicesModifierType;
71
+
72
+ /**
73
+ * Number Of Items
74
+ *
75
+ * @var float
76
+ */
77
+ protected $_numberOfItems;
78
+
79
+ /**
80
+ * Line Amount (The total cost of this line. In its simplest form lineAmount = unit price * numberOfItems)
81
+ * (Required)
82
+ *
83
+ * @var float
84
+ */
85
+ protected $_lineAmount;
86
+
87
+ /**
88
+ * Discounted
89
+ *
90
+ * @var bool
91
+ */
92
+ protected $_discounted;
93
+
94
+ /**
95
+ * Item Description
96
+ *
97
+ * @var string
98
+ */
99
+ protected $_itemDescription;
100
+
101
+ /**
102
+ * Unit Of Measure
103
+ * (Not currently supported)
104
+ *
105
+ * @var string
106
+ */
107
+ protected $_unitOfMeasure;
108
+
109
+ /**
110
+ * Locations
111
+ *
112
+ * @var OnePica_AvaTax16_Document_Part_Location[]
113
+ */
114
+ protected $_locations;
115
+
116
+ /**
117
+ * Tax Payer Code
118
+ * (Not currently supported)
119
+ *
120
+ * @var string
121
+ */
122
+ protected $_taxPayerCode;
123
+
124
+ /**
125
+ * Buyer Type
126
+ *
127
+ * @var string
128
+ */
129
+ protected $_buyerType;
130
+
131
+ /**
132
+ * Use Type
133
+ *
134
+ * @var string
135
+ */
136
+ protected $_useType;
137
+
138
+ /**
139
+ * Tax Override Amount
140
+ * (Not currently supported)
141
+ *
142
+ * @var float
143
+ */
144
+ protected $_taxOverrideAmount;
145
+
146
+ /**
147
+ * Tax Included
148
+ * (Not currently supported)
149
+ *
150
+ * @var bool
151
+ */
152
+ protected $_taxIncluded;
153
+
154
+ /**
155
+ * Tax Included
156
+ *
157
+ * @var array
158
+ */
159
+ protected $_metadata;
160
+
161
+ /**
162
+ * Set Metadata
163
+ *
164
+ * @param array|StdClass $value
165
+ * @return $this
166
+ */
167
+ public function setMetadata($value)
168
+ {
169
+ if ($value instanceof StdClass) {
170
+ // convert object data to array
171
+ // it is used during filling data from response
172
+ $this->_metadata = (array) $value;
173
+ } else {
174
+ $this->_metadata = $value;
175
+ }
176
+ }
177
+ }
lib/OnePica/AvaTax16/Document/Response.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Response
21
+ */
22
+ class OnePica_AvaTax16_Document_Response extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Has error
26
+ *
27
+ * @var bool
28
+ */
29
+ protected $_hasError = false;
30
+
31
+ /**
32
+ * Errors
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_errors;
37
+
38
+ /**
39
+ * Types of complex properties
40
+ *
41
+ * @var array
42
+ */
43
+ protected $_propertyComplexTypes = array(
44
+ '_header' => array(
45
+ 'type' => 'OnePica_AvaTax16_Document_Response_Header'
46
+ ),
47
+ '_lines' => array(
48
+ 'type' => 'OnePica_AvaTax16_Document_Response_Line',
49
+ 'isArrayOf' => 'true'
50
+ ),
51
+ '_calculatedTaxSummary' => array(
52
+ 'type' => 'OnePica_AvaTax16_Document_Response_CalculatedTaxSummary'
53
+ ),
54
+ '_feedback' => array(
55
+ 'type' => 'OnePica_AvaTax16_Document_Part_Feedback'
56
+ ),
57
+ '_processingInfo' => array(
58
+ 'type' => 'OnePica_AvaTax16_Document_Response_ProcessingInfo'
59
+ ),
60
+ );
61
+
62
+ /**
63
+ * Header
64
+ *
65
+ * @var OnePica_AvaTax16_Document_Response_Header
66
+ */
67
+ protected $_header;
68
+
69
+ /**
70
+ * Lines
71
+ *
72
+ * @var OnePica_AvaTax16_Document_Response_Line[]
73
+ */
74
+ protected $_lines;
75
+
76
+ /**
77
+ * Calculated Tax Summary
78
+ *
79
+ * @var OnePica_AvaTax16_Document_Response_CalculatedTaxSummary
80
+ */
81
+ protected $_calculatedTaxSummary;
82
+
83
+ /**
84
+ * Feedback
85
+ *
86
+ * @var OnePica_AvaTax16_Document_Part_Feedback
87
+ */
88
+ protected $_feedback;
89
+
90
+ /**
91
+ * Processing Info
92
+ *
93
+ * @var OnePica_AvaTax16_Document_Response_ProcessingInfo
94
+ */
95
+ protected $_processingInfo;
96
+ }
lib/OnePica/AvaTax16/Document/Response/CalculatedTaxSummary.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Response_CalculatedTaxSummary
21
+ */
22
+ class OnePica_AvaTax16_Document_Response_CalculatedTaxSummary
23
+ extends OnePica_AvaTax16_Document_Part
24
+ {
25
+ /**
26
+ * Types of complex properties
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_propertyComplexTypes = array(
31
+ '_taxByType' => array(
32
+ 'type' => 'OnePica_AvaTax16_Document_Response_CalculatedTaxSummary_TaxByType',
33
+ 'isArrayOf' => 'true'
34
+ )
35
+ );
36
+
37
+ /**
38
+ * Number Of Lines
39
+ *
40
+ * @var int
41
+ */
42
+ protected $_numberOfLines;
43
+
44
+ /**
45
+ * Subtotal
46
+ *
47
+ * @var float
48
+ */
49
+ protected $_subtotal;
50
+
51
+ /**
52
+ * Total Tax
53
+ *
54
+ * @var float
55
+ */
56
+ protected $_totalTax;
57
+
58
+ /**
59
+ * Tax By Type
60
+ *
61
+ * @var OnePica_AvaTax16_Document_Response_CalculatedTaxSummary_TaxByType[]
62
+ */
63
+ protected $_taxByType;
64
+
65
+ /**
66
+ * Tax
67
+ *
68
+ * @var float
69
+ */
70
+ protected $_tax;
71
+
72
+ /**
73
+ * Grand Total
74
+ *
75
+ * @var float
76
+ */
77
+ protected $_grandTotal;
78
+ }
lib/OnePica/AvaTax16/Document/Response/CalculatedTaxSummary/TaxByType.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Response_CalculatedTaxSummary_TaxByType
21
+ */
22
+ class OnePica_AvaTax16_Document_Response_CalculatedTaxSummary_TaxByType
23
+ extends OnePica_AvaTax16_Document_Part
24
+ {
25
+ /**
26
+ * Types of complex properties
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_propertyComplexTypes = array(
31
+ '_jurisdictions' => array(
32
+ 'type' => 'OnePica_AvaTax16_Document_Response_CalculatedTaxSummary_TaxByType_Details',
33
+ 'isArrayOf' => true
34
+ )
35
+ );
36
+
37
+ /**
38
+ * Tax
39
+ *
40
+ * @var float
41
+ */
42
+ protected $_tax;
43
+
44
+ /**
45
+ * jurisdictions
46
+ *
47
+ * @var OnePica_AvaTax16_Document_Response_CalculatedTaxSummary_TaxByType_Details
48
+ */
49
+ protected $_jurisdictions;
50
+
51
+ /**
52
+ * Comment
53
+ *
54
+ * @var string
55
+ */
56
+ protected $_comment ;
57
+ }
lib/OnePica/AvaTax16/Document/Response/CalculatedTaxSummary/TaxByType/Details.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Response_CalculatedTaxSummary_TaxByType_Details
21
+ */
22
+ class OnePica_AvaTax16_Document_Response_CalculatedTaxSummary_TaxByType_Details
23
+ extends OnePica_AvaTax16_Document_Part
24
+ {
25
+ /**
26
+ * Jurisdiction Name
27
+ *
28
+ * @var string
29
+ */
30
+ protected $_jurisdictionName;
31
+
32
+ /**
33
+ * Jurisdiction Type
34
+ *
35
+ * @var string
36
+ */
37
+ protected $_jurisdictionType;
38
+
39
+ /**
40
+ * Tax
41
+ *
42
+ * @var float
43
+ */
44
+ protected $_tax ;
45
+
46
+ /**
47
+ * Comment
48
+ *
49
+ * @var float
50
+ */
51
+ protected $_comment;
52
+ }
lib/OnePica/AvaTax16/Document/Response/Header.php ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Response_Header
21
+ */
22
+ class OnePica_AvaTax16_Document_Response_Header extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Types of complex properties
26
+ *
27
+ * @var array
28
+ */
29
+ protected $_propertyComplexTypes = array(
30
+ '_defaultLocations' => array(
31
+ 'type' => 'OnePica_AvaTax16_Document_Part_Location',
32
+ 'isArrayOf' => 'true'
33
+ ),
34
+ );
35
+
36
+ /**
37
+ * Account Id
38
+ * (Required)
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_accountId;
43
+
44
+ /**
45
+ * Company Code
46
+ * (Required)
47
+ *
48
+ * @var string
49
+ */
50
+ protected $_companyCode;
51
+
52
+ /**
53
+ * Transaction Type
54
+ * (Required)
55
+ *
56
+ * @var string
57
+ */
58
+ protected $_transactionType;
59
+
60
+ /**
61
+ * Document Code
62
+ * (Required)
63
+ *
64
+ * @var string
65
+ */
66
+ protected $_documentCode;
67
+
68
+ /**
69
+ * Customer Code
70
+ * (Required)
71
+ *
72
+ * @var string
73
+ */
74
+ protected $_customerCode;
75
+
76
+ /**
77
+ * Vendor Code
78
+ * (Required)
79
+ *
80
+ * @var string
81
+ */
82
+ protected $_vendorCode;
83
+
84
+ /**
85
+ * Transaction Date
86
+ * (Required)
87
+ *
88
+ * @var string
89
+ */
90
+ protected $_transactionDate;
91
+
92
+ /**
93
+ * Currency
94
+ * (Not currently supported)
95
+ *
96
+ * @var string
97
+ */
98
+ protected $_currency;
99
+
100
+ /**
101
+ * Total Tax Override Amount
102
+ * (Not currently supported)
103
+ *
104
+ * @var float
105
+ */
106
+ protected $_totalTaxOverrideAmount;
107
+
108
+ /**
109
+ * Tax Calculation Date
110
+ *
111
+ * @var string
112
+ */
113
+ protected $_taxCalculationDate;
114
+
115
+ /**
116
+ * Default Avalara Goods And Services Modifier Type
117
+ * (Not currently supported)
118
+ *
119
+ * @var string
120
+ */
121
+ protected $_defaultAvalaraGoodsAndServicesModifierType;
122
+
123
+ /**
124
+ * Default locations
125
+ * (Required)
126
+ *
127
+ * @var OnePica_AvaTax16_Document_Part_Location[]
128
+ */
129
+ protected $_defaultLocations;
130
+
131
+ /**
132
+ * Default Tax Payer Code
133
+ * (Not currently supported)
134
+ *
135
+ * @var string
136
+ */
137
+ protected $_defaultTaxPayerCode;
138
+
139
+ /**
140
+ * Default Buyer Type
141
+ *
142
+ * @var string
143
+ */
144
+ protected $_defaultBuyerType;
145
+
146
+ /**
147
+ * Default Use Type
148
+ *
149
+ * @var string
150
+ */
151
+ protected $_defaultUseType;
152
+
153
+ /**
154
+ * Purchase Order Number
155
+ *
156
+ * @var string
157
+ */
158
+ protected $_purchaseOrderNumber;
159
+
160
+ /**
161
+ * Metadata
162
+ *
163
+ * @var array
164
+ */
165
+ protected $_metadata;
166
+
167
+ /**
168
+ * Set Metadata
169
+ *
170
+ * @param array|StdClass $value
171
+ * @return $this
172
+ */
173
+ public function setMetadata($value)
174
+ {
175
+ if ($value instanceof StdClass) {
176
+ // convert object data to array
177
+ // it is used during filling data from response
178
+ $this->_metadata = (array) $value;
179
+ } else {
180
+ $this->_metadata = $value;
181
+ }
182
+ }
183
+ }
lib/OnePica/AvaTax16/Document/Response/Line.php ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Response_Line
21
+ */
22
+ class OnePica_AvaTax16_Document_Response_Line extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Required properties
26
+ *
27
+ * @var array
28
+ */
29
+ protected $_requiredProperties = array('_lineCode', '_lineAmount');
30
+
31
+ /**
32
+ * Types of complex properties
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_propertyComplexTypes = array(
37
+ '_locations' => array(
38
+ 'type' => 'OnePica_AvaTax16_Document_Part_Location',
39
+ 'isArrayOf' => 'true'
40
+ ),
41
+ '_calculatedTax' => array(
42
+ 'type' => 'OnePica_AvaTax16_Document_Response_Line_CalculatedTax',
43
+ ),
44
+ );
45
+
46
+ /**
47
+ * Line Code
48
+ * (Required)
49
+ *
50
+ * @var string
51
+ */
52
+ protected $_lineCode;
53
+
54
+ /**
55
+ * Item code
56
+ *
57
+ * @var string
58
+ */
59
+ protected $_itemCode;
60
+
61
+ /**
62
+ * Avalara Goods And Services Type
63
+ *
64
+ * @var string
65
+ */
66
+ protected $_avalaraGoodsAndServicesType;
67
+
68
+ /**
69
+ * Avalara Goods And Services Modifier Type
70
+ *
71
+ * @var string
72
+ */
73
+ protected $_avalaraGoodsAndServicesModifierType;
74
+
75
+ /**
76
+ * Number Of Items
77
+ *
78
+ * @var float
79
+ */
80
+ protected $_numberOfItems;
81
+
82
+ /**
83
+ * Line Amount
84
+ *
85
+ * @var float
86
+ */
87
+ protected $_lineAmount;
88
+
89
+ /**
90
+ * Item Description
91
+ *
92
+ * @var string
93
+ */
94
+ protected $_itemDescription;
95
+
96
+ /**
97
+ * Unit Of Measure
98
+ * (Not currently supported)
99
+ *
100
+ * @var string
101
+ */
102
+ protected $_unitOfMeasure;
103
+
104
+ /**
105
+ * Locations
106
+ *
107
+ * @var OnePica_AvaTax16_Document_Part_Location[]
108
+ */
109
+ protected $_locations;
110
+
111
+ /**
112
+ * Tax Payer Code
113
+ * (Not currently supported)
114
+ *
115
+ * @var string
116
+ */
117
+ protected $_taxPayerCode;
118
+
119
+ /**
120
+ * Buyer Type
121
+ *
122
+ * @var string
123
+ */
124
+ protected $_buyerType;
125
+
126
+ /**
127
+ * Use Type
128
+ *
129
+ * @var string
130
+ */
131
+ protected $_useType;
132
+
133
+ /**
134
+ * Line Attributes
135
+ * (Not currently supported)
136
+ *
137
+ * @var string
138
+ */
139
+ protected $_lineAttributes;
140
+
141
+ /**
142
+ * Tax Override Amount
143
+ * (Not currently supported)
144
+ *
145
+ * @var float
146
+ */
147
+ protected $_taxOverrideAmount;
148
+
149
+ /**
150
+ * Tax Included
151
+ * (Not currently supported)
152
+ *
153
+ * @var bool
154
+ */
155
+ protected $_taxIncluded;
156
+
157
+ /**
158
+ * Tax Included
159
+ *
160
+ * @var array
161
+ */
162
+ protected $_metadata;
163
+
164
+ /**
165
+ * Calculated Tax
166
+ * (Only response)
167
+ *
168
+ * @var OnePica_AvaTax16_Document_Response_Line_CalculatedTax
169
+ */
170
+ protected $_calculatedTax;
171
+
172
+ /**
173
+ * Set Metadata
174
+ *
175
+ * @param array|StdClass $value
176
+ * @return $this
177
+ */
178
+ public function setMetadata($value)
179
+ {
180
+ if ($value instanceof StdClass) {
181
+ // convert object data to array
182
+ // it is used during filling data from response
183
+ $this->_metadata = (array) $value;
184
+ } else {
185
+ $this->_metadata = $value;
186
+ }
187
+ }
188
+ }
lib/OnePica/AvaTax16/Document/Response/Line/CalculatedTax.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Response_Line_CalculatedTax
21
+ */
22
+ class OnePica_AvaTax16_Document_Response_Line_CalculatedTax extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Types of complex properties
26
+ *
27
+ * @var array
28
+ */
29
+ protected $_propertyComplexTypes = array(
30
+ '_taxByType' => array(
31
+ 'type' => 'OnePica_AvaTax16_Document_Response_Line_CalculatedTax_TaxByType',
32
+ 'isArrayOf' => 'true'
33
+ ),
34
+ '_details' => array(
35
+ 'type' => 'OnePica_AvaTax16_Document_Response_Line_CalculatedTax_Details',
36
+ 'isArrayOf' => 'true'
37
+ )
38
+ );
39
+
40
+ /**
41
+ * Tax By Type
42
+ *
43
+ * @var OnePica_AvaTax16_Document_Response_Line_CalculatedTax_TaxByType[]
44
+ */
45
+ protected $_taxByType;
46
+
47
+ /**
48
+ * Tax
49
+ *
50
+ * @var float
51
+ */
52
+ protected $_tax;
53
+
54
+ /**
55
+ * Details
56
+ *
57
+ * @var OnePica_AvaTax16_Document_Response_Line_CalculatedTax_Details[]
58
+ */
59
+ protected $_details;
60
+ }
lib/OnePica/AvaTax16/Document/Response/Line/CalculatedTax/Details.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Response_Line_CalculatedTax_Details
21
+ */
22
+ class OnePica_AvaTax16_Document_Response_Line_CalculatedTax_Details
23
+ extends OnePica_AvaTax16_Document_Part
24
+ {
25
+ /**
26
+ * Jurisdiction Name
27
+ *
28
+ * @var string
29
+ */
30
+ protected $_jurisdictionName;
31
+
32
+ /**
33
+ * Jurisdiction Type
34
+ *
35
+ * @var string
36
+ */
37
+ protected $_jurisdictionType;
38
+
39
+ /**
40
+ * Tax Type
41
+ *
42
+ * @var string
43
+ */
44
+ protected $_taxType;
45
+
46
+ /**
47
+ * Rate Type
48
+ *
49
+ * @var string
50
+ */
51
+ protected $_rateType;
52
+
53
+ /**
54
+ * Scenario
55
+ *
56
+ * @var string
57
+ */
58
+ protected $_scenario;
59
+
60
+ /**
61
+ * Subtotal Taxable
62
+ *
63
+ * @var float
64
+ */
65
+ protected $_subtotalTaxable;
66
+
67
+ /**
68
+ * Subtotal Exempt
69
+ *
70
+ * @var float
71
+ */
72
+ protected $_subtotalExempt;
73
+
74
+ /**
75
+ * Rate
76
+ *
77
+ * @var float
78
+ */
79
+ protected $_rate;
80
+
81
+ /**
82
+ * Tax
83
+ *
84
+ * @var float
85
+ */
86
+ protected $_tax;
87
+
88
+ /**
89
+ * Exempt
90
+ *
91
+ * @var bool
92
+ */
93
+ protected $_exempt;
94
+
95
+ /**
96
+ * ExemptionReason
97
+ *
98
+ * @var string
99
+ */
100
+ protected $_exemptionReason;
101
+
102
+ /**
103
+ * Significant Locations
104
+ *
105
+ * @var string[]
106
+ */
107
+ protected $_significantLocations;
108
+
109
+ /**
110
+ * Comment
111
+ *
112
+ * @var string
113
+ */
114
+ protected $_comment;
115
+ }
lib/OnePica/AvaTax16/Document/Response/Line/CalculatedTax/TaxByType.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Response_Line_CalculatedTax_TaxByType
21
+ */
22
+ class OnePica_AvaTax16_Document_Response_Line_CalculatedTax_TaxByType
23
+ extends OnePica_AvaTax16_Document_Part
24
+ {
25
+ /**
26
+ * Types of complex properties
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_propertyComplexTypes = array(
31
+ '_jurisdictions' => array(
32
+ 'type' => 'OnePica_AvaTax16_Document_Response_Line_CalculatedTax_TaxByType_Details',
33
+ 'isArrayOf' => true
34
+ )
35
+ );
36
+
37
+ /**
38
+ * Tax
39
+ *
40
+ * @var float
41
+ */
42
+ protected $_tax;
43
+ }
lib/OnePica/AvaTax16/Document/Response/ProcessingInfo.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Document_Response_ProcessingInfo
21
+ */
22
+ class OnePica_AvaTax16_Document_Response_ProcessingInfo extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Transaction State
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_transactionState;
30
+
31
+ /**
32
+ * Version Id
33
+ *
34
+ * @var string
35
+ */
36
+ protected $_versionId;
37
+
38
+ /**
39
+ * Format Id
40
+ *
41
+ * @var string
42
+ */
43
+ protected $_formatId;
44
+
45
+ /**
46
+ * Duration
47
+ *
48
+ * @var float
49
+ */
50
+ protected $_duration;
51
+
52
+ /**
53
+ * Modified Date
54
+ *
55
+ * @var string
56
+ */
57
+ protected $_modifiedDate;
58
+
59
+ /**
60
+ * Batch Id
61
+ *
62
+ * @var string
63
+ */
64
+ protected $_batchId;
65
+
66
+ /**
67
+ * Document Id
68
+ *
69
+ * @var string
70
+ */
71
+ protected $_documentId;
72
+
73
+ /**
74
+ * Message
75
+ *
76
+ * @var string
77
+ */
78
+ protected $_message;
79
+ }
lib/OnePica/AvaTax16/Exception.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Exception
21
+ */
22
+ class OnePica_AvaTax16_Exception extends Exception
23
+ {
24
+ }
lib/OnePica/AvaTax16/IO/CaseInsensitiveArray.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_IO_CaseInsensitiveArray
21
+ */
22
+ class OnePica_AvaTax16_IO_CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
23
+ {
24
+ /**
25
+ * Container
26
+ *
27
+ * @var array
28
+ */
29
+ protected $_container = array();
30
+
31
+ /**
32
+ * Offset Set
33
+ *
34
+ * @param string $offset
35
+ * @param mixed $value
36
+ * @return $this
37
+ */
38
+ public function offsetSet($offset, $value)
39
+ {
40
+ if ($offset === null) {
41
+ $this->_container[] = $value;
42
+ } else {
43
+ $index = array_search(strtolower($offset), array_keys(array_change_key_case($this->_container, CASE_LOWER)));
44
+ if (!($index === false)) {
45
+ $keys = array_keys($this->_container);
46
+ unset($this->_container[$keys[$index]]);
47
+ }
48
+ $this->_container[$offset] = $value;
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Offset Exists
54
+ *
55
+ * @param string $offset
56
+ * @return bool
57
+ */
58
+ public function offsetExists($offset)
59
+ {
60
+ return array_key_exists(strtolower($offset), array_change_key_case($this->_container, CASE_LOWER));
61
+ }
62
+
63
+ /**
64
+ * Offset Unset
65
+ *
66
+ * @param string $offset
67
+ * @return $this
68
+ */
69
+ public function offsetUnset($offset)
70
+ {
71
+ unset($this->_container[$offset]);
72
+ }
73
+
74
+ /**
75
+ * Offset Get
76
+ *
77
+ * @param string $offset
78
+ * @return object|null
79
+ */
80
+ public function offsetGet($offset)
81
+ {
82
+ $index = array_search(strtolower($offset), array_keys(array_change_key_case($this->_container, CASE_LOWER)));
83
+ if ($index === false) {
84
+ return null;
85
+ }
86
+
87
+ $values = array_values($this->_container);
88
+ return $values[$index];
89
+ }
90
+
91
+ /**
92
+ * Count
93
+ *
94
+ * @return int
95
+ */
96
+ public function count()
97
+ {
98
+ return count($this->_container);
99
+ }
100
+
101
+ /**
102
+ * Current
103
+ *
104
+ * @return mixed
105
+ */
106
+ public function current()
107
+ {
108
+ return current($this->_container);
109
+ }
110
+
111
+ /**
112
+ * Next
113
+ *
114
+ * @return mixed
115
+ */
116
+ public function next()
117
+ {
118
+ return next($this->_container);
119
+ }
120
+
121
+ /**
122
+ * Key
123
+ *
124
+ * @return mixed
125
+ */
126
+ public function key()
127
+ {
128
+ return key($this->_container);
129
+ }
130
+
131
+ /**
132
+ * Valid
133
+ *
134
+ * @return bool
135
+ */
136
+ public function valid()
137
+ {
138
+ return !($this->current() === false);
139
+ }
140
+
141
+ /**
142
+ * Rewind
143
+ *
144
+ * @return mixed
145
+ */
146
+ public function rewind()
147
+ {
148
+ reset($this->_container);
149
+ }
150
+ }
lib/OnePica/AvaTax16/IO/Curl.php ADDED
@@ -0,0 +1,1382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_IO_Curl
21
+ */
22
+ class OnePica_AvaTax16_IO_Curl
23
+ {
24
+ /**
25
+ * Version
26
+ */
27
+ const VERSION = '1.0.0';
28
+
29
+ /**
30
+ * Default timeout
31
+ */
32
+ const DEFAULT_TIMEOUT = 30;
33
+
34
+ /**
35
+ * cUrl resource.
36
+ *
37
+ * @var resource
38
+ */
39
+ protected $_curl;
40
+
41
+ /**
42
+ * Id
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_id = null;
47
+
48
+ /**
49
+ * Error
50
+ *
51
+ * @var bool
52
+ */
53
+ protected $_error = false;
54
+
55
+ /**
56
+ * Error code
57
+ *
58
+ * @var int
59
+ */
60
+ protected $_errorCode = 0;
61
+
62
+ /**
63
+ * Error message
64
+ *
65
+ * @var string
66
+ */
67
+ protected $_errorMessage = null;
68
+
69
+ /**
70
+ * Curl error
71
+ *
72
+ * @var bool
73
+ */
74
+ protected $_curlError = false;
75
+
76
+ /**
77
+ * Curl error code
78
+ *
79
+ * @var int
80
+ */
81
+ protected $_curlErrorCode = 0;
82
+
83
+ /**
84
+ * Curl error message
85
+ *
86
+ * @var string
87
+ */
88
+ protected $_curlErrorMessage = null;
89
+
90
+ /**
91
+ * Http error
92
+ *
93
+ * @var bool
94
+ */
95
+ protected $_httpError = false;
96
+
97
+ /**
98
+ * Http status code
99
+ *
100
+ * @var int
101
+ */
102
+ protected $_httpStatusCode = 0;
103
+
104
+ /**
105
+ * Http error message
106
+ *
107
+ * @var string
108
+ */
109
+ protected $_httpErrorMessage = null;
110
+
111
+ /**
112
+ * Base url
113
+ *
114
+ * @var string
115
+ */
116
+ protected $_baseUrl = null;
117
+
118
+ /**
119
+ * Url
120
+ *
121
+ * @var string
122
+ */
123
+ protected $_url = null;
124
+
125
+ /**
126
+ * Request headers
127
+ *
128
+ * @var array
129
+ */
130
+ protected $_requestHeaders = null;
131
+
132
+ /**
133
+ * Response headers
134
+ *
135
+ * @var array
136
+ */
137
+ protected $_responseHeaders = null;
138
+
139
+ /**
140
+ * Raw response headers
141
+ *
142
+ * @var string
143
+ */
144
+ protected $_rawResponseHeaders = '';
145
+
146
+ /**
147
+ * Response
148
+ *
149
+ * @var mixed
150
+ */
151
+ protected $_response = null;
152
+
153
+ /**
154
+ * Raw response
155
+ *
156
+ * @var string
157
+ */
158
+ protected $_rawResponse = null;
159
+
160
+ /**
161
+ * Before send function
162
+ *
163
+ * @var string
164
+ */
165
+ protected $_beforeSendFunction = null;
166
+
167
+ /**
168
+ * Download complete function
169
+ *
170
+ * @var string
171
+ */
172
+ protected $_downloadCompleteFunction = null;
173
+
174
+ /**
175
+ * Success function
176
+ *
177
+ * @var string
178
+ */
179
+ protected $_successFunction = null;
180
+
181
+ /**
182
+ * Error function
183
+ *
184
+ * @var string
185
+ */
186
+ protected $_errorFunction = null;
187
+
188
+ /**
189
+ * Complete function
190
+ *
191
+ * @var string
192
+ */
193
+ protected $_completeFunction = null;
194
+
195
+ /**
196
+ * Cookies
197
+ *
198
+ * @var array
199
+ */
200
+ protected $_cookies = array();
201
+
202
+ /**
203
+ * Response cookies
204
+ *
205
+ * @var array
206
+ */
207
+ protected $_responseCookies = array();
208
+
209
+ /**
210
+ * Headers
211
+ *
212
+ * @var array
213
+ */
214
+ protected $_headers = array();
215
+
216
+ /**
217
+ * Options
218
+ *
219
+ * @var array
220
+ */
221
+ protected $_options = array();
222
+
223
+ /**
224
+ * Options
225
+ *
226
+ * @var function
227
+ */
228
+ protected $_jsonDecoder = null;
229
+
230
+ /**
231
+ * Json pattern
232
+ *
233
+ * @var string
234
+ */
235
+ protected $_jsonPattern = '/^(?:application|text)\/(?:[a-z]+(?:[\.-][0-9a-z]+){0,}[\+\.]|x-)?json(?:-[a-z]+)?/i';
236
+
237
+ /**
238
+ * XML pattern
239
+ *
240
+ * @var string
241
+ */
242
+ protected $_xmlPattern = '~^(?:text/|application/(?:atom\+|rss\+)?)xml~i';
243
+
244
+ /**
245
+ * Construct
246
+ *
247
+ * @access public
248
+ * @param $base_url
249
+ * @throws \ErrorException
250
+ */
251
+ public function __construct($base_url = null)
252
+ {
253
+ if (!extension_loaded('curl')) {
254
+ throw new \ErrorException('cURL library is not loaded');
255
+ }
256
+
257
+ $this->_curl = curl_init();
258
+ $this->_id = 1;
259
+ $this->setDefaultUserAgent();
260
+ $this->setDefaultJsonDecoder();
261
+ $this->setDefaultTimeout();
262
+ $this->setOpt(CURLINFO_HEADER_OUT, true);
263
+ $this->setOpt(CURLOPT_HEADERFUNCTION, array($this, 'headerCallback'));
264
+ $this->setOpt(CURLOPT_RETURNTRANSFER, true);
265
+ $this->_headers = new OnePica_AvaTax16_IO_CaseInsensitiveArray();
266
+ $this->setURL($base_url);
267
+ }
268
+
269
+ /**
270
+ * Build Post Data
271
+ *
272
+ * @access public
273
+ * @param $data
274
+ *
275
+ * @return array|string
276
+ */
277
+ public function buildPostData($data)
278
+ {
279
+ if (is_array($data)) {
280
+ if (self::is_array_multidim($data)) {
281
+ if (isset($this->_headers['Content-Type']) &&
282
+ preg_match($this->_jsonPattern, $this->_headers['Content-Type'])) {
283
+ $json_str = json_encode($data);
284
+ if (!($json_str === false)) {
285
+ $data = $json_str;
286
+ }
287
+ } else {
288
+ $data = self::http_build_multi_query($data);
289
+ }
290
+ } else {
291
+ $binary_data = false;
292
+ foreach ($data as $key => $value) {
293
+ // Fix "Notice: Array to string conversion" when $value in
294
+ // curl_setopt($ch, CURLOPT_POSTFIELDS, $value) is an array
295
+ // that contains an empty array.
296
+ if (is_array($value) && empty($value)) {
297
+ $data[$key] = '';
298
+ // Fix "curl_setopt(): The usage of the @filename API for
299
+ // file uploading is deprecated. Please use the CURLFile
300
+ // class instead".
301
+ } elseif (is_string($value) && strpos($value, '@') === 0) {
302
+ $binary_data = true;
303
+ if (class_exists('CURLFile')) {
304
+ $data[$key] = new \CURLFile(substr($value, 1));
305
+ }
306
+ } elseif ($value instanceof \CURLFile) {
307
+ $binary_data = true;
308
+ }
309
+ }
310
+
311
+ if (!$binary_data) {
312
+ if (isset($this->_headers['Content-Type']) &&
313
+ preg_match($this->_jsonPattern, $this->_headers['Content-Type'])) {
314
+ $json_str = json_encode($data);
315
+ if (!($json_str === false)) {
316
+ $data = $json_str;
317
+ }
318
+ } else {
319
+ $data = http_build_query($data, '', '&');
320
+ }
321
+ }
322
+ }
323
+ }
324
+
325
+ return $data;
326
+ }
327
+
328
+ /**
329
+ * Call
330
+ *
331
+ * @access public
332
+ */
333
+ public function call()
334
+ {
335
+ $args = func_get_args();
336
+ $function = array_shift($args);
337
+ if (is_callable($function)) {
338
+ array_unshift($args, $this);
339
+ call_user_func_array($function, $args);
340
+ }
341
+ }
342
+
343
+ /**
344
+ * Close
345
+ *
346
+ * @access public
347
+ */
348
+ public function close()
349
+ {
350
+ if (is_resource($this->_curl)) {
351
+ curl_close($this->_curl);
352
+ }
353
+ $this->_options = null;
354
+ $this->_jsonDecoder = null;
355
+ }
356
+
357
+ /**
358
+ * Complete
359
+ *
360
+ * @access public
361
+ * @param $callback
362
+ */
363
+ public function complete($callback)
364
+ {
365
+ $this->_completeFunction = $callback;
366
+ }
367
+
368
+ /**
369
+ * Progress
370
+ *
371
+ * @access public
372
+ * @param $callback
373
+ */
374
+ public function progress($callback)
375
+ {
376
+ $this->setOpt(CURLOPT_PROGRESSFUNCTION, $callback);
377
+ $this->setOpt(CURLOPT_NOPROGRESS, false);
378
+ }
379
+
380
+ /**
381
+ * Delete
382
+ *
383
+ * @access public
384
+ * @param $url
385
+ * @param $query_parameters
386
+ * @param $data
387
+ *
388
+ * @return string
389
+ */
390
+ public function delete($url, $query_parameters = array(), $data = array())
391
+ {
392
+ if (is_array($url)) {
393
+ $data = $query_parameters;
394
+ $query_parameters = $url;
395
+ $url = $this->_baseUrl;
396
+ }
397
+
398
+ $this->setURL($url, $query_parameters);
399
+ $this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
400
+ $this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
401
+ return $this->exec();
402
+ }
403
+
404
+ /**
405
+ * Download Complete
406
+ *
407
+ * @access public
408
+ * @param $fh
409
+ */
410
+ public function downloadComplete($fh)
411
+ {
412
+ if (!$this->_error && $this->_downloadCompleteFunction) {
413
+ rewind($fh);
414
+ $this->call($this->_downloadCompleteFunction, $fh);
415
+ $this->_downloadCompleteFunction = null;
416
+ }
417
+
418
+ if (is_resource($fh)) {
419
+ fclose($fh);
420
+ }
421
+
422
+ // Fix "PHP Notice: Use of undefined constant STDOUT" when reading the
423
+ // PHP script from stdin. Using null causes "Warning: curl_setopt():
424
+ // supplied argument is not a valid File-Handle resource".
425
+ if (!defined('STDOUT')) {
426
+ define('STDOUT', fopen('php://stdout', 'w'));
427
+ }
428
+
429
+ // Reset CURLOPT_FILE with STDOUT to avoid: "curl_exec(): CURLOPT_FILE
430
+ // resource has gone away, resetting to default".
431
+ $this->setOpt(CURLOPT_FILE, STDOUT);
432
+
433
+ // Reset CURLOPT_RETURNTRANSFER to tell cURL to return subsequent
434
+ // responses as the return value of curl_exec(). Without this,
435
+ // curl_exec() will revert to returning boolean values.
436
+ $this->setOpt(CURLOPT_RETURNTRANSFER, true);
437
+ }
438
+
439
+ /**
440
+ * Download
441
+ *
442
+ * @access public
443
+ * @param $url
444
+ * @param $mixed_filename
445
+ *
446
+ * @return boolean
447
+ */
448
+ public function download($url, $mixed_filename)
449
+ {
450
+ if (is_callable($mixed_filename)) {
451
+ $this->_downloadCompleteFunction = $mixed_filename;
452
+ $fh = tmpfile();
453
+ } else {
454
+ $filename = $mixed_filename;
455
+ $fh = fopen($filename, 'wb');
456
+ }
457
+
458
+ $this->setOpt(CURLOPT_FILE, $fh);
459
+ $this->get($url);
460
+ $this->downloadComplete($fh);
461
+
462
+ return ! $this->_error;
463
+ }
464
+
465
+ /**
466
+ * Error
467
+ *
468
+ * @access public
469
+ * @param $callback
470
+ */
471
+ public function error($callback)
472
+ {
473
+ $this->_errorFunction = $callback;
474
+ }
475
+
476
+ /**
477
+ * Exec
478
+ *
479
+ * @access public
480
+ * @param $ch
481
+ *
482
+ * @return string
483
+ */
484
+ public function exec($ch = null)
485
+ {
486
+ $this->_responseCookies = array();
487
+ if (!($ch === null)) {
488
+ $this->_rawResponse = curl_multi_getcontent($ch);
489
+ } else {
490
+ $this->call($this->_beforeSendFunction);
491
+ $this->_rawResponse = curl_exec($this->_curl);
492
+ $this->_curlErrorCode = curl_errno($this->_curl);
493
+ }
494
+ $this->_curlErrorMessage = curl_error($this->_curl);
495
+ $this->_curlError = !($this->_curlErrorCode === 0);
496
+ $this->_httpStatusCode = curl_getinfo($this->_curl, CURLINFO_HTTP_CODE);
497
+ $this->_httpError = in_array(floor($this->_httpStatusCode / 100), array(4, 5));
498
+ $this->_error = $this->_curlError || $this->_httpError;
499
+ $this->_errorCode = $this->_error ? ($this->_curlError ? $this->_curlErrorCode : $this->_httpStatusCode) : 0;
500
+
501
+ // NOTE: CURLINFO_HEADER_OUT set to true is required for requestHeaders
502
+ // to not be empty (e.g. $curl->setOpt(CURLINFO_HEADER_OUT, true);).
503
+ if ($this->getOpt(CURLINFO_HEADER_OUT) === true) {
504
+ $this->_requestHeaders = $this->_parseRequestHeaders(curl_getinfo($this->_curl, CURLINFO_HEADER_OUT));
505
+ }
506
+ $this->_responseHeaders = $this->_parseResponseHeaders($this->_rawResponseHeaders);
507
+ list($this->_response, $this->_rawResponse) = $this->_parseResponse($this->_responseHeaders, $this->_rawResponse);
508
+
509
+ $this->_httpErrorMessage = '';
510
+ if ($this->_error) {
511
+ if (isset($this->_responseHeaders['Status-Line'])) {
512
+ $this->_httpErrorMessage = $this->_responseHeaders['Status-Line'];
513
+ }
514
+ }
515
+ $this->_errorMessage = $this->_curlError ? $this->_curlErrorMessage : $this->_httpErrorMessage;
516
+
517
+ if (!$this->_error) {
518
+ $this->call($this->_successFunction);
519
+ } else {
520
+ $this->call($this->_errorFunction);
521
+ }
522
+
523
+ $this->call($this->_completeFunction);
524
+
525
+ return $this->_response;
526
+ }
527
+
528
+ /**
529
+ * Get
530
+ *
531
+ * @access public
532
+ * @param $url
533
+ * @param $data
534
+ *
535
+ * @return string
536
+ */
537
+ public function get($url, $data = array())
538
+ {
539
+ if (is_array($url)) {
540
+ $data = $url;
541
+ $url = $this->_baseUrl;
542
+ }
543
+ $this->setURL($url, $data);
544
+ $this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
545
+ $this->setOpt(CURLOPT_HTTPGET, true);
546
+ return $this->exec();
547
+ }
548
+
549
+ /**
550
+ * Get Opt
551
+ *
552
+ * @access public
553
+ * @param $option
554
+ *
555
+ * @return mixed
556
+ */
557
+ public function getOpt($option)
558
+ {
559
+ return $this->_options[$option];
560
+ }
561
+
562
+ /**
563
+ * Head
564
+ *
565
+ * @access public
566
+ * @param $url
567
+ * @param $data
568
+ *
569
+ * @return string
570
+ */
571
+ public function head($url, $data = array())
572
+ {
573
+ if (is_array($url)) {
574
+ $data = $url;
575
+ $url = $this->_baseUrl;
576
+ }
577
+ $this->setURL($url, $data);
578
+ $this->setOpt(CURLOPT_CUSTOMREQUEST, 'HEAD');
579
+ $this->setOpt(CURLOPT_NOBODY, true);
580
+ return $this->exec();
581
+ }
582
+
583
+ /**
584
+ * Header Callback
585
+ *
586
+ * @access public
587
+ * @param $ch
588
+ * @param $header
589
+ *
590
+ * @return integer
591
+ */
592
+ public function headerCallback($ch, $header)
593
+ {
594
+ if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) == 1) {
595
+ $this->_responseCookies[$cookie[1]] = $cookie[2];
596
+ }
597
+ $this->_rawResponseHeaders .= $header;
598
+ return strlen($header);
599
+ }
600
+
601
+ /**
602
+ * Options
603
+ *
604
+ * @access public
605
+ * @param $url
606
+ * @param $data
607
+ *
608
+ * @return string
609
+ */
610
+ public function options($url, $data = array())
611
+ {
612
+ if (is_array($url)) {
613
+ $data = $url;
614
+ $url = $this->_baseUrl;
615
+ }
616
+ $this->setURL($url, $data);
617
+ $this->unsetHeader('Content-Length');
618
+ $this->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS');
619
+ return $this->exec();
620
+ }
621
+
622
+ /**
623
+ * Patch
624
+ *
625
+ * @access public
626
+ * @param $url
627
+ * @param $data
628
+ *
629
+ * @return string
630
+ */
631
+ public function patch($url, $data = array())
632
+ {
633
+ if (is_array($url)) {
634
+ $data = $url;
635
+ $url = $this->_baseUrl;
636
+ }
637
+
638
+ if (is_array($data) && empty($data)) {
639
+ $this->unsetHeader('Content-Length');
640
+ }
641
+
642
+ $this->setURL($url);
643
+ $this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
644
+ $this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
645
+ return $this->exec();
646
+ }
647
+
648
+ /**
649
+ * Post
650
+ *
651
+ * @access public
652
+ * @param $url
653
+ * @param $data
654
+ *
655
+ * @return string
656
+ */
657
+ public function post($url, $data = array())
658
+ {
659
+ if (is_array($url)) {
660
+ $data = $url;
661
+ $url = $this->_baseUrl;
662
+ }
663
+
664
+ $this->setURL($url);
665
+ $this->setOpt(CURLOPT_CUSTOMREQUEST, 'POST');
666
+ $this->setOpt(CURLOPT_POST, true);
667
+ $this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
668
+ return $this->exec();
669
+ }
670
+
671
+ /**
672
+ * Put
673
+ *
674
+ * @access public
675
+ * @param $url
676
+ * @param $data
677
+ *
678
+ * @return string
679
+ */
680
+ public function put($url, $data = array())
681
+ {
682
+ if (is_array($url)) {
683
+ $data = $url;
684
+ $url = $this->_baseUrl;
685
+ }
686
+ $this->setURL($url);
687
+ $this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT');
688
+ $put_data = $this->buildPostData($data);
689
+ if (empty($this->_options[CURLOPT_INFILE]) && empty($this->_options[CURLOPT_INFILESIZE])) {
690
+ $this->setHeader('Content-Length', strlen($put_data));
691
+ }
692
+ $this->setOpt(CURLOPT_POSTFIELDS, $put_data);
693
+ return $this->exec();
694
+ }
695
+
696
+ /**
697
+ * Set Basic Authentication
698
+ *
699
+ * @access public
700
+ * @param $username
701
+ * @param $password
702
+ */
703
+ public function setBasicAuthentication($username, $password = '')
704
+ {
705
+ $this->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
706
+ $this->setOpt(CURLOPT_USERPWD, $username . ':' . $password);
707
+ }
708
+
709
+ /**
710
+ * Set Digest Authentication
711
+ *
712
+ * @access public
713
+ * @param $username
714
+ * @param $password
715
+ */
716
+ public function setDigestAuthentication($username, $password = '')
717
+ {
718
+ $this->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
719
+ $this->setOpt(CURLOPT_USERPWD, $username . ':' . $password);
720
+ }
721
+
722
+ /**
723
+ * Set Cookie
724
+ *
725
+ * @access public
726
+ * @param $key
727
+ * @param $value
728
+ */
729
+ public function setCookie($key, $value)
730
+ {
731
+ $this->_cookies[$key] = $value;
732
+ $this->setOpt(CURLOPT_COOKIE, str_replace(' ', '%20', urldecode(http_build_query($this->_cookies, '', '; '))));
733
+ }
734
+
735
+ /**
736
+ * Get cookie.
737
+ *
738
+ * @access public
739
+ * @param $key
740
+ */
741
+ public function getCookie($key)
742
+ {
743
+ return $this->getResponseCookie($key);
744
+ }
745
+
746
+ /**
747
+ * Get response cookie.
748
+ *
749
+ * @access public
750
+ * @param $key
751
+ */
752
+ public function getResponseCookie($key)
753
+ {
754
+ return isset($this->_responseCookies[$key]) ? $this->_responseCookies[$key] : null;
755
+ }
756
+
757
+ /**
758
+ * Set Port
759
+ *
760
+ * @access public
761
+ * @param $port
762
+ */
763
+ public function setPort($port)
764
+ {
765
+ $this->setOpt(CURLOPT_PORT, intval($port));
766
+ }
767
+
768
+ /**
769
+ * Set Connect Timeout
770
+ *
771
+ * @access public
772
+ * @param $seconds
773
+ */
774
+ public function setConnectTimeout($seconds)
775
+ {
776
+ $this->setOpt(CURLOPT_CONNECTTIMEOUT, $seconds);
777
+ }
778
+
779
+ /**
780
+ * Set Cookie File
781
+ *
782
+ * @access public
783
+ * @param $cookie_file
784
+ */
785
+ public function setCookieFile($cookie_file)
786
+ {
787
+ $this->setOpt(CURLOPT_COOKIEFILE, $cookie_file);
788
+ }
789
+
790
+ /**
791
+ * Set Cookie Jar
792
+ *
793
+ * @access public
794
+ * @param $cookie_jar
795
+ */
796
+ public function setCookieJar($cookie_jar)
797
+ {
798
+ $this->setOpt(CURLOPT_COOKIEJAR, $cookie_jar);
799
+ }
800
+
801
+ /**
802
+ * Set Default JSON Decoder
803
+ *
804
+ * @access public
805
+ */
806
+ public function setDefaultJsonDecoder()
807
+ {
808
+ $this->_jsonDecoder = function($response) {
809
+ $json_obj = json_decode($response, false);
810
+ if (!($json_obj === null)) {
811
+ $response = $json_obj;
812
+ }
813
+ return $response;
814
+ };
815
+ }
816
+
817
+ /**
818
+ * Set Default Timeout
819
+ *
820
+ * @access public
821
+ */
822
+ public function setDefaultTimeout()
823
+ {
824
+ $this->setTimeout(self::DEFAULT_TIMEOUT);
825
+ }
826
+
827
+ /**
828
+ * Set Default User Agent
829
+ *
830
+ * @access public
831
+ */
832
+ public function setDefaultUserAgent()
833
+ {
834
+ $user_agent = 'PHP-Curl-Class/' . self::VERSION;
835
+ $user_agent .= ' PHP/' . PHP_VERSION;
836
+ $curl_version = curl_version();
837
+ $user_agent .= ' curl/' . $curl_version['version'];
838
+ $this->setUserAgent($user_agent);
839
+ }
840
+
841
+ /**
842
+ * Set Header
843
+ *
844
+ * @access public
845
+ * @param $key
846
+ * @param $value
847
+ *
848
+ * @return string
849
+ */
850
+ public function setHeader($key, $value)
851
+ {
852
+ $this->_headers[$key] = $value;
853
+ $headers = array();
854
+ foreach ($this->_headers as $key => $value) {
855
+ $headers[] = $key . ': ' . $value;
856
+ }
857
+ $this->setOpt(CURLOPT_HTTPHEADER, $headers);
858
+ }
859
+
860
+ /**
861
+ * Set JSON Decoder
862
+ *
863
+ * @access public
864
+ * @param $function
865
+ */
866
+ public function setJsonDecoder($function)
867
+ {
868
+ if (is_callable($function)) {
869
+ $this->_jsonDecoder = $function;
870
+ }
871
+ }
872
+
873
+ /**
874
+ * Set Opt
875
+ *
876
+ * @access public
877
+ * @param $option
878
+ * @param $value
879
+ *
880
+ * @return boolean
881
+ */
882
+ public function setOpt($option, $value)
883
+ {
884
+ $required_options = array(
885
+ CURLOPT_RETURNTRANSFER => 'CURLOPT_RETURNTRANSFER',
886
+ );
887
+
888
+ if (in_array($option, array_keys($required_options), true) && !($value === true)) {
889
+ trigger_error($required_options[$option] . ' is a required option', E_USER_WARNING);
890
+ }
891
+
892
+ $this->_options[$option] = $value;
893
+ return curl_setopt($this->_curl, $option, $value);
894
+ }
895
+
896
+ /**
897
+ * Set Referer
898
+ *
899
+ * @access public
900
+ * @param $referer
901
+ */
902
+ public function setReferer($referer)
903
+ {
904
+ $this->setReferrer($referer);
905
+ }
906
+
907
+ /**
908
+ * Set Referrer
909
+ *
910
+ * @access public
911
+ * @param $referrer
912
+ */
913
+ public function setReferrer($referrer)
914
+ {
915
+ $this->setOpt(CURLOPT_REFERER, $referrer);
916
+ }
917
+
918
+ /**
919
+ * Set Timeout
920
+ *
921
+ * @access public
922
+ * @param $seconds
923
+ */
924
+ public function setTimeout($seconds)
925
+ {
926
+ $this->setOpt(CURLOPT_TIMEOUT, $seconds);
927
+ }
928
+
929
+ /**
930
+ * Set Url
931
+ *
932
+ * @access public
933
+ * @param $url
934
+ * @param $data
935
+ */
936
+ public function setURL($url, $data = array())
937
+ {
938
+ $this->_baseUrl = $url;
939
+ $this->_url = $this->_buildURL($url, $data);
940
+ $this->setOpt(CURLOPT_URL, $this->_url);
941
+ }
942
+
943
+ /**
944
+ * Set User Agent
945
+ *
946
+ * @access public
947
+ * @param $user_agent
948
+ */
949
+ public function setUserAgent($user_agent)
950
+ {
951
+ $this->setOpt(CURLOPT_USERAGENT, $user_agent);
952
+ }
953
+
954
+ /**
955
+ * Success
956
+ *
957
+ * @access public
958
+ * @param $callback
959
+ */
960
+ public function success($callback)
961
+ {
962
+ $this->_successFunction = $callback;
963
+ }
964
+
965
+ /**
966
+ * Unset Header
967
+ *
968
+ * @access public
969
+ * @param $key
970
+ */
971
+ public function unsetHeader($key)
972
+ {
973
+ $this->setHeader($key, '');
974
+ unset($this->_headers[$key]);
975
+ }
976
+
977
+ /**
978
+ * Verbose
979
+ *
980
+ * @access public
981
+ * @param $on
982
+ */
983
+ public function verbose($on = true)
984
+ {
985
+ $this->setOpt(CURLOPT_VERBOSE, $on);
986
+ }
987
+
988
+ /**
989
+ * Destruct
990
+ *
991
+ * @access public
992
+ */
993
+ public function __destruct()
994
+ {
995
+ $this->close();
996
+ }
997
+
998
+ /**
999
+ * Build Url
1000
+ *
1001
+ * @access protected
1002
+ * @param $url
1003
+ * @param $data
1004
+ *
1005
+ * @return string
1006
+ */
1007
+ protected function _buildURL($url, $data = array())
1008
+ {
1009
+ return $url . (empty($data) ? '' : '?' . http_build_query($data));
1010
+ }
1011
+
1012
+ /**
1013
+ * Parse Headers
1014
+ *
1015
+ * @access protected
1016
+ * @param $raw_headers
1017
+ *
1018
+ * @return array
1019
+ */
1020
+ protected function _parseHeaders($raw_headers)
1021
+ {
1022
+ $raw_headers = preg_split('/\r\n/', $raw_headers, null, PREG_SPLIT_NO_EMPTY);
1023
+ $http_headers = new OnePica_AvaTax16_IO_CaseInsensitiveArray();
1024
+
1025
+ $raw_headers_count = count($raw_headers);
1026
+ for ($i = 1; $i < $raw_headers_count; $i++) {
1027
+ list($key, $value) = explode(':', $raw_headers[$i], 2);
1028
+ $key = trim($key);
1029
+ $value = trim($value);
1030
+ // Use isset() as array_key_exists() and ArrayAccess are not compatible.
1031
+ if (isset($http_headers[$key])) {
1032
+ $http_headers[$key] .= ',' . $value;
1033
+ } else {
1034
+ $http_headers[$key] = $value;
1035
+ }
1036
+ }
1037
+
1038
+ return array(isset($raw_headers['0']) ? $raw_headers['0'] : '', $http_headers);
1039
+ }
1040
+
1041
+ /**
1042
+ * Parse Request Headers
1043
+ *
1044
+ * @access protected
1045
+ * @param $raw_headers
1046
+ *
1047
+ * @return array
1048
+ */
1049
+ protected function _parseRequestHeaders($raw_headers)
1050
+ {
1051
+ $request_headers = new OnePica_AvaTax16_IO_CaseInsensitiveArray();
1052
+ list($first_line, $headers) = $this->_parseHeaders($raw_headers);
1053
+ $request_headers['Request-Line'] = $first_line;
1054
+ foreach ($headers as $key => $value) {
1055
+ $request_headers[$key] = $value;
1056
+ }
1057
+ return $request_headers;
1058
+ }
1059
+
1060
+ /**
1061
+ * Parse Response
1062
+ *
1063
+ * @access protected
1064
+ * @param $response_headers
1065
+ * @param $raw_response
1066
+ *
1067
+ * @return array
1068
+ */
1069
+ protected function _parseResponse($response_headers, $raw_response)
1070
+ {
1071
+ $response = $raw_response;
1072
+ if (isset($response_headers['Content-Type'])) {
1073
+ if (preg_match($this->_jsonPattern, $response_headers['Content-Type'])) {
1074
+ $json_decoder = $this->_jsonDecoder;
1075
+ if (is_callable($json_decoder)) {
1076
+ $response = $json_decoder($response);
1077
+ }
1078
+ } elseif (preg_match($this->_xmlPattern, $response_headers['Content-Type'])) {
1079
+ $xml_obj = @simplexml_load_string($response);
1080
+ if (!($xml_obj === false)) {
1081
+ $response = $xml_obj;
1082
+ }
1083
+ }
1084
+ }
1085
+
1086
+ return array($response, $raw_response);
1087
+ }
1088
+
1089
+ /**
1090
+ * Parse Response Headers
1091
+ *
1092
+ * @access protected
1093
+ * @param $raw_response_headers
1094
+ *
1095
+ * @return array
1096
+ */
1097
+ protected function _parseResponseHeaders($raw_response_headers)
1098
+ {
1099
+ $response_header_array = explode("\r\n\r\n", $raw_response_headers);
1100
+ $response_header = '';
1101
+ for ($i = count($response_header_array) - 1; $i >= 0; $i--) {
1102
+ if (stripos($response_header_array[$i], 'HTTP/') === 0) {
1103
+ $response_header = $response_header_array[$i];
1104
+ break;
1105
+ }
1106
+ }
1107
+
1108
+ $response_headers = new OnePica_AvaTax16_IO_CaseInsensitiveArray();
1109
+ list($first_line, $headers) = $this->_parseHeaders($response_header);
1110
+ $response_headers['Status-Line'] = $first_line;
1111
+ foreach ($headers as $key => $value) {
1112
+ $response_headers[$key] = $value;
1113
+ }
1114
+ return $response_headers;
1115
+ }
1116
+
1117
+ /**
1118
+ * Http Build Multi Query
1119
+ *
1120
+ * @access public
1121
+ * @param $data
1122
+ * @param $key
1123
+ *
1124
+ * @return string
1125
+ */
1126
+ public static function http_build_multi_query($data, $key = null)
1127
+ {
1128
+ $query = array();
1129
+
1130
+ if (empty($data)) {
1131
+ return $key . '=';
1132
+ }
1133
+
1134
+ $is_array_assoc = self::is_array_assoc($data);
1135
+
1136
+ foreach ($data as $k => $value) {
1137
+ if (is_string($value) || is_numeric($value)) {
1138
+ $brackets = $is_array_assoc ? '[' . $k . ']' : '[]';
1139
+ $query[] = urlencode($key === null ? $k : $key . $brackets) . '=' . rawurlencode($value);
1140
+ } elseif (is_array($value)) {
1141
+ $nested = $key === null ? $k : $key . '[' . $k . ']';
1142
+ $query[] = self::http_build_multi_query($value, $nested);
1143
+ }
1144
+ }
1145
+
1146
+ return implode('&', $query);
1147
+ }
1148
+
1149
+ /**
1150
+ * Is Array Assoc
1151
+ *
1152
+ * @access public
1153
+ * @param $array
1154
+ *
1155
+ * @return boolean
1156
+ */
1157
+ public static function is_array_assoc($array)
1158
+ {
1159
+ return (bool)count(array_filter(array_keys($array), 'is_string'));
1160
+ }
1161
+
1162
+ /**
1163
+ * Is Array Multidim
1164
+ *
1165
+ * @access public
1166
+ * @param $array
1167
+ *
1168
+ * @return boolean
1169
+ */
1170
+ public static function is_array_multidim($array)
1171
+ {
1172
+ if (!is_array($array)) {
1173
+ return false;
1174
+ }
1175
+
1176
+ return (bool)count(array_filter($array, 'is_array'));
1177
+ }
1178
+
1179
+ /**
1180
+ * Get Error
1181
+ *
1182
+ * @return bool
1183
+ */
1184
+ public function getError()
1185
+ {
1186
+ return $this->_error;
1187
+ }
1188
+
1189
+ /**
1190
+ * Get Error Code
1191
+ *
1192
+ * @return int
1193
+ */
1194
+ public function getErrorCode()
1195
+ {
1196
+ return $this->_errorCode;
1197
+ }
1198
+
1199
+ /**
1200
+ * Get Error Message
1201
+ *
1202
+ * @return string
1203
+ */
1204
+ public function getErrorMessage()
1205
+ {
1206
+ return $this->_errorMessage;
1207
+ }
1208
+
1209
+ /**
1210
+ * Get Curl Error
1211
+ *
1212
+ * @return bool
1213
+ */
1214
+ public function getCurlError()
1215
+ {
1216
+ return $this->_curlError;
1217
+ }
1218
+
1219
+ /**
1220
+ * Get Curl Error Code
1221
+ *
1222
+ * @return int
1223
+ */
1224
+ public function getCurlErrorCode()
1225
+ {
1226
+ return $this->_curlErrorCode;
1227
+ }
1228
+
1229
+ /**
1230
+ * Get Curl Error Message
1231
+ *
1232
+ * @return string
1233
+ */
1234
+ public function getCurlErrorMessage()
1235
+ {
1236
+ return $this->_curlErrorMessage;
1237
+ }
1238
+
1239
+ /**
1240
+ * Get Http Error
1241
+ *
1242
+ * @return bool
1243
+ */
1244
+ public function getHttpError()
1245
+ {
1246
+ return $this->_httpError;
1247
+ }
1248
+
1249
+ /**
1250
+ * Get http Status Code
1251
+ *
1252
+ * @return int
1253
+ */
1254
+ public function getHttpStatusCode()
1255
+ {
1256
+ return $this->_httpStatusCode;
1257
+ }
1258
+
1259
+ /**
1260
+ * Get Http Error Message
1261
+ *
1262
+ * @return string
1263
+ */
1264
+ public function getHttpErrorMessage()
1265
+ {
1266
+ return $this->_httpErrorMessage;
1267
+ }
1268
+
1269
+ /**
1270
+ * Get Base Url
1271
+ *
1272
+ * @return string
1273
+ */
1274
+ public function getBaseUrl()
1275
+ {
1276
+ return $this->_baseUrl;
1277
+ }
1278
+
1279
+ /**
1280
+ * Get Url
1281
+ *
1282
+ * @return string
1283
+ */
1284
+ public function getUrl()
1285
+ {
1286
+ return $this->_url;
1287
+ }
1288
+
1289
+ /**
1290
+ * Get Request Headers
1291
+ *
1292
+ * @return array
1293
+ */
1294
+ public function getRequestHeaders()
1295
+ {
1296
+ return $this->_requestHeaders;
1297
+ }
1298
+
1299
+ /**
1300
+ * Get Response Headers
1301
+ *
1302
+ * @return array
1303
+ */
1304
+ public function getResponseHeaders()
1305
+ {
1306
+ return $this->_responseHeaders;
1307
+ }
1308
+
1309
+ /**
1310
+ * Get Raw Response Headers
1311
+ *
1312
+ * @return string
1313
+ */
1314
+ public function getRawResponseHeaders()
1315
+ {
1316
+ return $this->_rawResponseHeaders;
1317
+ }
1318
+
1319
+ /**
1320
+ * Get Response
1321
+ *
1322
+ * @return mixed
1323
+ */
1324
+ public function getResponse()
1325
+ {
1326
+ return $this->_response;
1327
+ }
1328
+
1329
+ /**
1330
+ * Get Raw Response
1331
+ *
1332
+ * @return string
1333
+ */
1334
+ public function getRawResponse()
1335
+ {
1336
+ return $this->_rawResponse;
1337
+ }
1338
+
1339
+ /**
1340
+ * Get Before Send Function
1341
+ *
1342
+ * @return string
1343
+ */
1344
+ public function getBeforeSendFunction()
1345
+ {
1346
+ return $this->_beforeSendFunction;
1347
+ }
1348
+
1349
+ /**
1350
+ * Set Before Send Function
1351
+ *
1352
+ * @param string $function
1353
+ * @return $this
1354
+ */
1355
+ public function setBeforeSendFunction($function)
1356
+ {
1357
+ $this->_beforeSendFunction = $function;
1358
+ return $this;
1359
+ }
1360
+
1361
+ /**
1362
+ * Get Download Complete Function
1363
+ *
1364
+ * @return string
1365
+ */
1366
+ public function getDownloadCompleteFunction()
1367
+ {
1368
+ return $this->_downloadCompleteFunction;
1369
+ }
1370
+
1371
+ /**
1372
+ * Get Download Complete Function
1373
+ *
1374
+ * @param string $function
1375
+ * @return $this
1376
+ */
1377
+ public function setDownloadCompleteFunction($function)
1378
+ {
1379
+ $this->_downloadCompleteFunction = $function;
1380
+ return $this;
1381
+ }
1382
+ }
lib/OnePica/AvaTax16/ResourceAbstract.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Abstract class OnePica_AvaTax16_ResourceAbstract
21
+ */
22
+ abstract class OnePica_AvaTax16_ResourceAbstract
23
+ {
24
+ /**
25
+ * Config
26
+ *
27
+ * @var OnePica_AvaTax16_Config
28
+ */
29
+ protected $_config;
30
+
31
+ /**
32
+ * Construct
33
+ *
34
+ * @param OnePica_AvaTax16_Config $config
35
+ */
36
+ public function __construct($config)
37
+ {
38
+ $this->_config = $config;
39
+ }
40
+
41
+ /**
42
+ * Get config
43
+ *
44
+ * @return OnePica_AvaTax16_Config
45
+ */
46
+ public function getConfig()
47
+ {
48
+ return $this->_config;
49
+ }
50
+
51
+ /**
52
+ * Get Curl Object with headers from config
53
+ *
54
+ * @return OnePica_AvaTax16_IO_Curl
55
+ */
56
+ protected function _getCurlObjectWithHeaders()
57
+ {
58
+ $curl = new OnePica_AvaTax16_IO_Curl();
59
+ $config = $this->getConfig();
60
+ $curl->setHeader('Authorization', $config->getAuthorizationHeader());
61
+ $curl->setHeader('Accept', $config->getAcceptHeader());
62
+ $curl->setHeader('Content-Type', $config->getContentTypeHeader());
63
+ $curl->setHeader('User-Agent', $config->getUserAgent());
64
+ return $curl;
65
+ }
66
+
67
+ /**
68
+ * Set Error Data To Response If Exists
69
+ *
70
+ * @param OnePica_AvaTax16_Document_Part $response
71
+ * @param OnePica_AvaTax16_IO_Curl $curl
72
+ * @return $this
73
+ */
74
+ protected function _setErrorDataToResponseIfExists($response, $curl)
75
+ {
76
+ if ($curl->getError()) {
77
+ $response->setHasError(true);
78
+ $errors = array();
79
+ $responseData = $curl->getResponse();
80
+ if ($responseData instanceof stdClass) {
81
+ if (isset($responseData->errors) && count($responseData->errors)) {
82
+ foreach ($responseData->errors as $value) {
83
+ if (is_array($value)) {
84
+ $errors[] = implode(' ', $value);
85
+ } else {
86
+ $errors[] = $value;
87
+ }
88
+ }
89
+ }
90
+ if (isset($responseData->message)) {
91
+ $errors['message'] = $responseData->message;
92
+ }
93
+ } else {
94
+ $errors['message'] = $responseData;
95
+ }
96
+ $response->setErrors($errors);
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Send Request To Service And Get Response Object
102
+ *
103
+ * @param string $url
104
+ * @param array $options
105
+ * @return mixed $result
106
+ */
107
+ protected function _sendRequest($url, $options = array())
108
+ {
109
+ $requestType = (isset($options['requestType'])) ? $options['requestType'] : 'GET';
110
+ $data = (isset($options['data'])) ? $options['data'] : null;
111
+ $returnClass = (isset($options['returnClass'])) ? $options['returnClass'] : null;
112
+ $curl = $this->_getCurlObjectWithHeaders();
113
+ $result = null;
114
+ switch ($requestType) {
115
+ case 'GET':
116
+ $curl->get($url, $data);
117
+ break;
118
+ case 'POST':
119
+ $curl->post($url, $data);
120
+ break;
121
+ }
122
+ if (isset($returnClass)) {
123
+ $responseObject = new $returnClass();
124
+ $this->_setErrorDataToResponseIfExists($responseObject, $curl);
125
+ if (!$responseObject->getHasError()) {
126
+ $responseData = $curl->getResponse();
127
+ $responseObject->fillData($responseData);
128
+ }
129
+ $result = $responseObject;
130
+ } else {
131
+ $result = $curl->getResponse();
132
+ }
133
+ return $result;
134
+ }
135
+ }
lib/OnePica/AvaTax16/TaxService.php ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_TaxService
21
+ */
22
+ class OnePica_AvaTax16_TaxService extends OnePica_AvaTax16_ResourceAbstract
23
+ {
24
+ /**
25
+ * Config
26
+ *
27
+ * @var OnePica_AvaTax16_Config
28
+ */
29
+ protected $_config;
30
+
31
+ /**
32
+ * Construct
33
+ *
34
+ * @param OnePica_AvaTax16_Config $config
35
+ * @throws OnePica_AvaTax16_Exception
36
+ */
37
+ public function __construct($config)
38
+ {
39
+ if (!$config->isValid()) {
40
+ throw new OnePica_AvaTax16_Exception("Not valid data in config!");
41
+ }
42
+ $this->_config = $config;
43
+ }
44
+
45
+ /**
46
+ * Get config
47
+ *
48
+ * @return OnePica_AvaTax16_Config
49
+ */
50
+ public function getConfig()
51
+ {
52
+ return $this->_config;
53
+ }
54
+
55
+ /**
56
+ * Create Transaction
57
+ *
58
+ * @param string $type
59
+ * @return mixed $taxResource
60
+ */
61
+ protected function _getTaxResource($type)
62
+ {
63
+ $config = $this->getConfig();
64
+ $taxResource = null;
65
+ switch ($type) {
66
+ case 'calculation':
67
+ $taxResource = new OnePica_AvaTax16_Calculation($config);
68
+ break;
69
+ case 'transaction':
70
+ $taxResource = new OnePica_AvaTax16_Transaction($config);
71
+ break;
72
+ case 'addressResolution':
73
+ $taxResource = new OnePica_AvaTax16_AddressResolution($config);
74
+ break;
75
+ }
76
+ return $taxResource;
77
+ }
78
+
79
+ /**
80
+ * Create Transaction
81
+ *
82
+ * @param OnePica_AvaTax16_Document_Request $documentRequest
83
+ * @return OnePica_AvaTax16_Document_Response $documentResponse
84
+ */
85
+ public function createCalculation($documentRequest)
86
+ {
87
+ $calculationResource = $this->_getTaxResource('calculation');
88
+ $documentResponse = $calculationResource->createCalculation($documentRequest);
89
+ return $documentResponse;
90
+ }
91
+
92
+ /**
93
+ * Get Calculation
94
+ *
95
+ * @param string $transactionType
96
+ * @param string $documentCode
97
+ * @return OnePica_AvaTax16_Document_Response $documentResponse
98
+ */
99
+ public function getCalculation($transactionType, $documentCode)
100
+ {
101
+ $calculationResource = $this->_getTaxResource('calculation');
102
+ $documentResponse = $calculationResource->getCalculation($transactionType, $documentCode);
103
+ return $documentResponse;
104
+ }
105
+
106
+ /**
107
+ * Get List Of Calculations
108
+ *
109
+ * @param string $transactionType
110
+ * @param int $limit
111
+ * @param string $startDate
112
+ * @param string $endDate
113
+ * @param string $startCode (not implemented)
114
+ * @return OnePica_AvaTax16_Calculation_ListResponse $calculationListResponse
115
+ */
116
+ public function getListOfCalculations($transactionType, $limit = null, $startDate = null, $endDate = null,
117
+ $startCode = null)
118
+ {
119
+ $calculationResource = $this->_getTaxResource('calculation');
120
+ $calculationListResponse = $calculationResource->getListOfCalculations($transactionType, $limit, $startDate,
121
+ $endDate, $startCode);
122
+ return $calculationListResponse;
123
+ }
124
+
125
+ /**
126
+ * Create Transaction
127
+ *
128
+ * @param OnePica_AvaTax16_Document_Request $documentRequest
129
+ * @return OnePica_AvaTax16_Document_Response $documentResponse
130
+ */
131
+ public function createTransaction($documentRequest)
132
+ {
133
+ $transactionResource = $this->_getTaxResource('transaction');
134
+ $documentResponse = $transactionResource->createTransaction($documentRequest);
135
+ return $documentResponse;
136
+ }
137
+
138
+ /**
139
+ * Create Transaction from Calculation
140
+ *
141
+ * @param string $transactionType
142
+ * @param string $documentCode
143
+ * @param bool $recalculate
144
+ * @param string $comment
145
+ * @return OnePica_AvaTax16_Document_Response $documentResponse
146
+ */
147
+ public function createTransactionFromCalculation($transactionType, $documentCode, $recalculate = null,
148
+ $comment = null)
149
+ {
150
+ $transactionResource = $this->_getTaxResource('transaction');
151
+ $documentResponse = $transactionResource->createTransactionFromCalculation($transactionType, $documentCode,
152
+ $recalculate, $comment);
153
+ return $documentResponse;
154
+ }
155
+
156
+ /**
157
+ * Get Transaction
158
+ *
159
+ * @param string $transactionType
160
+ * @param string $documentCode
161
+ * @return OnePica_AvaTax16_Document_Response $documentResponse
162
+ */
163
+ public function getTransaction($transactionType, $documentCode)
164
+ {
165
+ $transactionResource = $this->_getTaxResource('transaction');
166
+ $documentResponse = $transactionResource->getTransaction($transactionType, $documentCode);
167
+ return $documentResponse;
168
+ }
169
+
170
+ /**
171
+ * Get List Of Transactions
172
+ *
173
+ * @param string $transactionType
174
+ * @param int $limit
175
+ * @param string $startDate
176
+ * @param string $endDate
177
+ * @param string $startCode (not implemented)
178
+ * @return OnePica_AvaTax16_Transaction_ListResponse $transactionListResponse
179
+ */
180
+ public function getListOfTransactions($transactionType, $limit = null, $startDate = null, $endDate = null,
181
+ $startCode = null)
182
+ {
183
+ $transactionResource = $this->_getTaxResource('transaction');
184
+ $transactionListResponse = $transactionResource->getListOfTransactions($transactionType, $limit, $startDate,
185
+ $endDate, $startCode);
186
+ return $transactionListResponse;
187
+ }
188
+
189
+ /**
190
+ * Get Transaction Input
191
+ *
192
+ * @param string $transactionType
193
+ * @param string $documentCode
194
+ * @return OnePica_AvaTax16_Document_Request $transactionInput
195
+ */
196
+ public function getTransactionInput($transactionType, $documentCode)
197
+ {
198
+ $transactionResource = $this->_getTaxResource('transaction');
199
+ $transactionInput = $transactionResource->getTransactionInput($transactionType, $documentCode);
200
+ return $transactionInput;
201
+ }
202
+
203
+ /**
204
+ * Transition Transaction State
205
+ *
206
+ * @param string $transactionType
207
+ * @param string $documentCode
208
+ * @param string $type
209
+ * @param string $comment
210
+ * @return OnePica_AvaTax16_Transaction_TransitionTransactionStateResponse $transitionTransactionStateResponse
211
+ */
212
+ public function transitionTransactionState($transactionType, $documentCode, $type, $comment)
213
+ {
214
+ $transactionResource = $this->_getTaxResource('transaction');
215
+ $transitionTransactionStateResponse = $transactionResource->transitionTransactionState($transactionType,
216
+ $documentCode, $type, $comment);
217
+ return $transitionTransactionStateResponse;
218
+ }
219
+
220
+ /**
221
+ * Resolve a Single Address
222
+ *
223
+ * @param OnePica_AvaTax16_Document_Part_Location_Address $address
224
+ * @return OnePica_AvaTax16_AddressResolution_ResolveSingleAddressResponse $resolvedAddressResponse
225
+ */
226
+ public function resolveSingleAddress($address)
227
+ {
228
+ $addressResolutionResource = $this->_getTaxResource('addressResolution');
229
+ $resolvedAddressResponse = $addressResolutionResource->resolveSingleAddress($address);
230
+ return $resolvedAddressResponse;
231
+ }
232
+
233
+ /**
234
+ * Ping
235
+ * Is used to test if service is available
236
+ *
237
+ * @return OnePica_AvaTax16_AddressResolution_PingResponse $pingResponse
238
+ */
239
+ public function ping()
240
+ {
241
+ // set some predefined address to ping API service
242
+ $address = new OnePica_AvaTax16_Document_Part_Location_Address();
243
+ $address->setLine1('Avenue');
244
+ $address->setZipcode('10022');
245
+ $address->setCountry('USA');
246
+ $addressResolutionResource = $this->_getTaxResource('addressResolution');
247
+ $resolvedAddress = $addressResolutionResource->resolveSingleAddress($address);
248
+ // set data to response object
249
+ $pingResponse = new OnePica_AvaTax16_AddressResolution_PingResponse();
250
+ $pingResponse->setHasError($resolvedAddress->getHasError());
251
+ $pingResponse->setErrors($resolvedAddress->getErrors());
252
+ return $pingResponse;
253
+ }
254
+ }
lib/OnePica/AvaTax16/Transaction.php ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Transaction
21
+ */
22
+ class OnePica_AvaTax16_Transaction extends OnePica_AvaTax16_ResourceAbstract
23
+ {
24
+ /**
25
+ * Url path for calculations
26
+ */
27
+ const CALCULATION_URL_PATH = '/calculations';
28
+
29
+ /**
30
+ * Url path for transactions
31
+ */
32
+ const TRANSACTION_URL_PATH = '/transactions';
33
+
34
+ /**
35
+ * Create Transaction
36
+ *
37
+ * @param OnePica_AvaTax16_Document_Request $documentRequest
38
+ * @return OnePica_AvaTax16_Document_Response $documentResponse
39
+ */
40
+ public function createTransaction($documentRequest)
41
+ {
42
+ $postUrl = $this->_config->getBaseUrl() . self::TRANSACTION_URL_PATH;
43
+ $postData = $documentRequest->toArray();
44
+ $requestOptions = array(
45
+ 'requestType' => 'POST',
46
+ 'data' => $postData,
47
+ 'returnClass' => 'OnePica_AvaTax16_Document_Response'
48
+ );
49
+ $documentResponse = $this->_sendRequest($postUrl, $requestOptions);
50
+ return $documentResponse;
51
+ }
52
+
53
+ /**
54
+ * Create Transaction from Calculation
55
+ *
56
+ * @param string $transactionType
57
+ * @param string $documentCode
58
+ * @param bool $recalculate
59
+ * @param string $comment
60
+ * @return OnePica_AvaTax16_Document_Response $documentResponse
61
+ */
62
+ public function createTransactionFromCalculation($transactionType, $documentCode, $recalculate = null,
63
+ $comment = null)
64
+ {
65
+ $config = $this->getConfig();
66
+ $postUrl = $config->getBaseUrl()
67
+ . self::CALCULATION_URL_PATH
68
+ . '/account/'
69
+ . $config->getAccountId()
70
+ . '/company/'
71
+ . $config->getCompanyCode()
72
+ . '/'
73
+ . $transactionType
74
+ . '/'
75
+ . $documentCode
76
+ . self::TRANSACTION_URL_PATH;
77
+
78
+ $postData = array(
79
+ 'recalculate' => $recalculate,
80
+ 'documentCode' => $documentCode,
81
+ 'comment' => $comment
82
+ );
83
+
84
+ $requestOptions = array(
85
+ 'requestType' => 'POST',
86
+ 'data' => $postData,
87
+ 'returnClass' => 'OnePica_AvaTax16_Document_Response'
88
+ );
89
+ $documentResponse = $this->_sendRequest($postUrl, $requestOptions);
90
+ return $documentResponse;
91
+ }
92
+
93
+ /**
94
+ * Get Transaction
95
+ *
96
+ * @param string $transactionType
97
+ * @param string $documentCode
98
+ * @return OnePica_AvaTax16_Document_Response $documentResponse
99
+ */
100
+ public function getTransaction($transactionType, $documentCode)
101
+ {
102
+ $config = $this->getConfig();
103
+ $getUrl = $config->getBaseUrl()
104
+ . self::TRANSACTION_URL_PATH
105
+ . '/account/'
106
+ . $config->getAccountId()
107
+ . '/company/'
108
+ . $config->getCompanyCode()
109
+ . '/'
110
+ . $transactionType
111
+ . '/'
112
+ . $documentCode;
113
+
114
+ $requestOptions = array(
115
+ 'requestType' => 'GET',
116
+ 'returnClass' => 'OnePica_AvaTax16_Document_Response'
117
+ );
118
+ $documentResponse = $this->_sendRequest($getUrl, $requestOptions);
119
+ return $documentResponse;
120
+ }
121
+
122
+ /**
123
+ * Get List Of Transactions
124
+ *
125
+ * @param string $transactionType
126
+ * @param int $limit
127
+ * @param string $startDate
128
+ * @param string $endDate
129
+ * @param string $startCode (not implemented)
130
+ * @return OnePica_AvaTax16_Transaction_ListResponse $transactionListResponse
131
+ */
132
+ public function getListOfTransactions($transactionType, $limit = null, $startDate = null, $endDate = null,
133
+ $startCode = null)
134
+ {
135
+ $config = $this->getConfig();
136
+ $getUrl = $config->getBaseUrl()
137
+ . self::TRANSACTION_URL_PATH
138
+ . '/account/'
139
+ . $config->getAccountId()
140
+ . '/company/'
141
+ . $config->getCompanyCode()
142
+ . '/'
143
+ . $transactionType;
144
+
145
+ $filterData = array(
146
+ 'limit' => $limit,
147
+ 'startDate' => $startDate,
148
+ 'endDate' => $endDate,
149
+ 'startCode' => $startCode,
150
+ );
151
+
152
+ $requestOptions = array(
153
+ 'requestType' => 'GET',
154
+ 'data' => $filterData,
155
+ 'returnClass' => 'OnePica_AvaTax16_Transaction_ListResponse'
156
+ );
157
+ $transactionListResponse = $this->_sendRequest($getUrl, $requestOptions);
158
+ return $transactionListResponse;
159
+ }
160
+
161
+ /**
162
+ * Get Transaction Input
163
+ *
164
+ * @param string $transactionType
165
+ * @param string $documentCode
166
+ * @return OnePica_AvaTax16_Document_Request $transactionInput
167
+ */
168
+ public function getTransactionInput($transactionType, $documentCode)
169
+ {
170
+ $config = $this->getConfig();
171
+ $getUrl = $config->getBaseUrl()
172
+ . self::TRANSACTION_URL_PATH
173
+ . '/account/'
174
+ . $config->getAccountId()
175
+ . '/company/'
176
+ . $config->getCompanyCode()
177
+ . '/'
178
+ . $transactionType
179
+ . '/'
180
+ . $documentCode
181
+ . '/source';
182
+
183
+ $requestOptions = array(
184
+ 'requestType' => 'GET',
185
+ 'returnClass' => 'OnePica_AvaTax16_Document_Request'
186
+ );
187
+ $transactionInput = $this->_sendRequest($getUrl, $requestOptions);
188
+ return $transactionInput;
189
+ }
190
+
191
+ /**
192
+ * Transition Transaction State
193
+ *
194
+ * @param string $transactionType
195
+ * @param string $documentCode
196
+ * @param string $type
197
+ * @param string $comment
198
+ * @return OnePica_AvaTax16_Transaction_TransitionTransactionStateResponse $transitionTransactionStateResponse
199
+ */
200
+ public function transitionTransactionState($transactionType, $documentCode, $type, $comment)
201
+ {
202
+ $config = $this->getConfig();
203
+ $postUrl = $config->getBaseUrl()
204
+ . self::TRANSACTION_URL_PATH
205
+ . '/account/'
206
+ . $config->getAccountId()
207
+ . '/company/'
208
+ . $config->getCompanyCode()
209
+ . '/'
210
+ . $transactionType
211
+ . '/'
212
+ . $documentCode
213
+ . '/stateTransitions';
214
+
215
+ $postData = array(
216
+ 'type' => $type,
217
+ 'comment' => $comment
218
+ );
219
+
220
+ $curl = $this->_getCurlObjectWithHeaders();
221
+ $curl->post($postUrl, $postData);
222
+ $transitionTransactionStateResponse = new OnePica_AvaTax16_Transaction_TransitionTransactionStateResponse();
223
+ $this->_setErrorDataToResponseIfExists($transitionTransactionStateResponse, $curl);
224
+ $transitionTransactionStateResponse->setHttpStatus($curl->getHttpStatusCode());
225
+ return $transitionTransactionStateResponse;
226
+ }
227
+ }
lib/OnePica/AvaTax16/Transaction/ListItemResponse.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Transaction_ListItemResponse
21
+ */
22
+ class OnePica_AvaTax16_Transaction_ListItemResponse
23
+ extends OnePica_AvaTax16_Calculation_ListItemResponse
24
+ {
25
+ }
lib/OnePica/AvaTax16/Transaction/ListResponse.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Transaction_ListResponse
21
+ */
22
+ class OnePica_AvaTax16_Transaction_ListResponse extends OnePica_AvaTax16_Document_Part
23
+ {
24
+ /**
25
+ * Has error
26
+ *
27
+ * @var bool
28
+ */
29
+ protected $_hasError = false;
30
+
31
+ /**
32
+ * Errors
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_errors;
37
+
38
+ /**
39
+ * List items
40
+ *
41
+ * @var OnePica_AvaTax16_Transaction_ListItemResponse[]
42
+ */
43
+ protected $_items;
44
+
45
+ /**
46
+ * Fill data from object
47
+ *
48
+ * @param StdClass|array $data
49
+ * @return $this
50
+ */
51
+ public function fillData($data)
52
+ {
53
+ $result = array();
54
+ if (is_array($data)) {
55
+ foreach ($data as $dataItem) {
56
+ $calculationListItem = new OnePica_AvaTax16_Transaction_ListItemResponse();
57
+ $result[] = $calculationListItem->fillData($dataItem);
58
+ }
59
+ }
60
+ $this->setItems($result);
61
+ }
62
+ }
lib/OnePica/AvaTax16/Transaction/TransitionTransactionStateResponse.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class OnePica_AvaTax16_Transaction_TransitionTransactionStateResponse
21
+ */
22
+ class OnePica_AvaTax16_Transaction_TransitionTransactionStateResponse
23
+ extends OnePica_AvaTax16_Document_Part
24
+ {
25
+ /**
26
+ * Has error
27
+ *
28
+ * @var bool
29
+ */
30
+ protected $_hasError = false;
31
+
32
+ /**
33
+ * Errors
34
+ *
35
+ * @var array
36
+ */
37
+ protected $_errors;
38
+
39
+ /**
40
+ * Http Status (code)
41
+ *
42
+ * @var int
43
+ */
44
+ protected $_httpStatus;
45
+ }
lib/OnePica/autoload.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OnePica
4
+ * NOTICE OF LICENSE
5
+ * This source file is subject to the Open Software License (OSL 3.0)
6
+ * that is bundled with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to codemaster@onepica.com so we can send you a copy immediately.
12
+ *
13
+ * @category OnePica
14
+ * @package OnePica_AvaTax
15
+ * @copyright Copyright (c) 2015 One Pica, Inc. (http://www.onepica.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Register autoload function
21
+ */
22
+ spl_autoload_register(
23
+ /**
24
+ * Defines class loading search path
25
+ *
26
+ * @param string $className
27
+ */
28
+ function ($className) {
29
+ $classPath = explode('_', $className);
30
+ if ($classPath[0] != 'OnePica') {
31
+ return;
32
+ }
33
+ // Drop 'OnePica', and maximum class file path depth in this project is 8.
34
+ $classPath = array_slice($classPath, 1, 8);
35
+ $filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php';
36
+ if (file_exists($filePath)) {
37
+ require_once($filePath);
38
+ }
39
+ }
40
+ );
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>OnePica_AvaTax</name>
4
- <version>2.6.9</version>
5
  <stability>stable</stability>
6
  <license>Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
@@ -18,11 +18,19 @@ Released as a commercial extension, this software will not work unless you have
18
  &#xD;
19
  &#xD;
20
  At One Pica (www.onepica.com), we strive to build increasingly scalable and flexible enterprise systems for all of our clients, large and small. We want to give back to this community both to promote its success and as a sign of our gratitude. Please feel free to contact us on ways we can improve this extension or extend on this framework.</description>
21
- <notes>Fixed invoice/creditmemo doubling in queue</notes>
 
 
 
 
 
 
 
 
22
  <authors><author><name>Rostyslav Redko</name><user>marketing</user><email>avalara@onepica.com</email></author></authors>
23
- <date>2016-01-28</date>
24
- <time>11:43:41</time>
25
- <contents><target name="magecommunity"><dir name="OnePica"><dir name="AvaTax"><dir name="Block"><dir name="Adminhtml"><dir name="Export"><dir name="Abstract"><file name="Grid.php" hash="5f96ca490c5f7bd3fac23e30b00336e5"/></dir><dir name="Log"><file name="Grid.php" hash="311c55d8bc770e6d6aa6f377c2eee6fd"/><file name="View.php" hash="097d82a3e2b1a8820d335a63f212451b"/></dir><dir name="Queue"><file name="Grid.php" hash="1ef8ba9bf3e0870ea6dc50bb202a0b91"/></dir></dir><dir name="Notification"><file name="Toolbar.php" hash="2d8bc84188c162aada45548d5a901f9a"/></dir><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Export.php" hash="3e019b9551b95c71f4cfd67a14d62a27"/></dir></dir></dir></dir><dir name="Tax"><dir name="Class"><dir name="Edit"><file name="Form.php" hash="0e78c592366ee2746f3891cf91a388d3"/></dir><file name="Grid.php" hash="d731eb160457b8a22cfcd28682a1c485"/></dir></dir></dir><dir name="Checkout"><dir name="Onepage"><dir name="Shipping"><dir name="Method"><file name="Available.php" hash="c8ad904b71f344cfd1e01ceea7556dd1"/></dir></dir></dir></dir></dir><file name="Exception.php" hash="fc752f8da808a402baae2425c4072d22"/><dir name="Helper"><file name="Data.php" hash="a90c0bf748428583b04ca516a364bc66"/><dir name="GiftWrapping"><file name="Data.php" hash="6165e5c10c2582023456210573d89256"/></dir><dir name="Tax"><file name="Data.php" hash="e041b574919704a2ddc5173d38edda91"/></dir></dir><dir name="Model"><file name="Abstract.php" hash="97f0ae95e164849371f09dbb7b1afd86"/><dir name="Admin"><file name="Session.php" hash="e3dc3353c7eebf4e17c22ea4039585c5"/></dir><dir name="Adminhtml"><file name="Config.php" hash="e3656ed052c4bd143822369ffed5a5c7"/><dir name="Sales"><dir name="Order"><file name="Create.php" hash="08253fde693e39124b4b4f242c238852"/></dir></dir></dir><dir name="Avatax"><file name="Abstract.php" hash="a186b0d54d454e889f59e271e0b7eaae"/><file name="Address.php" hash="6acca70d1173e2bf05a04cc8d2ad51b4"/><file name="Estimate.php" hash="7bea18db264df43d7b2d63d8b82e3670"/><dir name="Exception"><file name="Address.php" hash="66761b418530d8682666a0ed6987ff3e"/><file name="Commitfailure.php" hash="81257541dd1d679493cfd2d3c5b6366e"/><file name="Unbalanced.php" hash="dc7967d9c5780b45ecb0828d5a1fc6dc"/></dir><file name="Invoice.php" hash="c91ba2a1d84fc7aaf836aa02ce164cfe"/><file name="Ping.php" hash="57b77948291fda5c6fe15733fd96a3c0"/></dir><file name="Config.php" hash="623922ea0cb4b335d2fca188f6f4f405"/><dir name="Export"><dir name="Adapter"><file name="Abstract.php" hash="840c8b87acd97646572bba9bb3b8f5ea"/><file name="Sql.php" hash="0e9bedb400f411785311f78ebbf676da"/></dir><dir name="Entity"><file name="Abstract.php" hash="d38a2293452c31e92f81bf5be59c3e1c"/><file name="Log.php" hash="a1dd28eee3e72d1a4ef7bddd865ddbae"/><file name="Queue.php" hash="14a97c283aa74f97982ab71160017aa3"/></dir></dir><file name="Export.php" hash="b94613b678b413d6268b07d314ba122e"/><file name="Observer.php" hash="0d7fa33ba5bd63c9afbe2e447ab928d9"/><dir name="Records"><file name="Log.php" hash="9a95ea609f75fa416c4564de8d3af4a2"/><dir name="Mysql4"><dir name="Log"><file name="Collection.php" hash="29db8163f4dda862ff822ddffd04554d"/></dir><file name="Log.php" hash="d6fb7997768b7e0f1b39363fd4de5917"/><dir name="Queue"><file name="Collection.php" hash="11bba1561c81f39695f091b94bd81560"/></dir><file name="Queue.php" hash="ad319339f577fdbbba740c52848a272c"/></dir><dir name="Queue"><file name="Process.php" hash="77092de76e08561d16759660b4a4f0c4"/></dir><file name="Queue.php" hash="17e369325bcac42042676bb61a2248c5"/></dir><dir name="Sales"><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Grand.php" hash="63fb5a808ad3c16d2ed15f1dafad7937"/><file name="Tax.php" hash="cf83ec631fc356095f7e1ce6f581adaf"/></dir></dir><file name="Address.php" hash="3191bbdf4e2227d35cf588dde798731b"/></dir></dir><file name="Session.php" hash="429142089e75418a702e70edc56374cf"/><dir name="Source"><file name="Actions.php" hash="879b80f92f735402f57e316546b16984"/><file name="Addressvalidation.php" hash="9f2315018910f7336ad894156d49d9b9"/><file name="Customercodeformat.php" hash="cfcfcbaa27ed29add072324816da0c9d"/><file name="Error.php" hash="7f5495a2f295ded2d0a30f2f7108d009"/><file name="Fieldlist.php" hash="18987603d4d58130959a8ac76716ed08"/><file name="Logmode.php" hash="24d61da578a3b4adb896fea7d4d4d8ec"/><file name="Logtype.php" hash="4079ebbf7ef44593e631b8cc9f0fc2a5"/><file name="Onerrorfrontend.php" hash="ef4154ae563d8157c1083f20e0adf563"/><dir name="Regionfilter"><file name="List.php" hash="ed98a569d45cb5b014107f0fda52d735"/><file name="Mode.php" hash="27fdc94c6f162100d55005285b5170df"/></dir></dir><dir name="Tax"><file name="Config.php" hash="8897cfa4fef8099c937559ebe9dfee5e"/></dir><dir name="Total"><dir name="Quote"><dir name="Tax"><file name="Giftwrapping.php" hash="ff5f4418766f31933ae0a184ffaab946"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="AvaTax"><file name="ExportController.php" hash="ead5ebea03db8f885d0ec6114dcb185c"/><file name="GridController.php" hash="5c7e822890a6feaec2db348e6c5a19e1"/></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="aa39dba65fb2c685dec016a376c4aede"/><file name="config.xml" hash="1061cd1b7d65f81e52c8725fbccb9f97"/><file name="system-disabled.xml" hash="46d8b175492d3e2fd6910471d481c18e"/><file name="system.xml" hash="fe00657faaad115555246ed67d9d404d"/></dir><dir name="sql"><dir name="avatax_records_setup"><file name="mysql4-data-upgrade-2.2.0-2.2.1.php" hash="260d1c57754ebadba00d8ccdbb0ec996"/><file name="mysql4-install-0.1.0.php" hash="3d16899179b36bfde69609a99a2faae6"/><file name="mysql4-upgrade-0.1.4-0.1.5.php" hash="94d0cf2fc0e9bbe2de2829198ce3026f"/><file name="mysql4-upgrade-1.0.1-2.0.0.php" hash="905d7519328cdb1c46bba4221288c41c"/><file name="mysql4-upgrade-2.5.0.0-2.5.0.1.php" hash="4b439957397049bbe01d458fd7cfe0a2"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="OnePica_AvaTax.xml" hash="07fd9423811b4dc084060d6131b889d7"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="onepica"><file name="avatax.xml" hash="de338ca651fcce096d089b2bbbcc1374"/></dir></dir><dir name="template"><dir name="onepica"><dir name="avatax"><dir name="log"><file name="view.phtml" hash="df14eee805bbedd484cf500dbf2335ed"/></dir><dir name="notification"><file name="toolbar.phtml" hash="fd368e043843df76ec3a74290b87dc3e"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="onepica"><file name="avatax.xml" hash="38c6ce2165f6ccfd6641eb1487faad39"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="de_DE"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="en_US"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="es_ES"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="fr_FR"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="nl_NL"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="pt_BR"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="zh_CN"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir></target><target name="magelib"><dir name="AvaTax"><file name="AvaTax.php" hash="46bf3fb7795482b7494b2fdc266af3bc"/><dir name="classes"><file name="ATConfig.class.php" hash="dd1c39643f677e0c3b612c549686812c"/><file name="ATObject.class.php" hash="83359fd7639c98449836dc11d08c899d"/><file name="Address.class.php" hash="68bf4fe1306a60e672b7345a0dc7fcc6"/><file name="AddressServiceSoap.class.php" hash="c59bf4a586da207611f7bace4f08c880"/><file name="AddressType.class.php" hash="62c9ff3c533aaf5ad1fd4de95702be40"/><file name="AdjustTaxRequest.class.php" hash="47dbfa8044ca893bf214d8e71ab4864e"/><file name="AdjustTaxResult.class.php" hash="cf63aa5b7c3b52b3ec86695c4cdf0fcc"/><file name="ApplyPaymentRequest.class.php" hash="69d69dff63cbd284d8aea62247142692"/><file name="ApplyPaymentResult.class.php" hash="0e37bda0f1221c2ed2432717a2d8cc08"/><dir name="AvaCert2Svc"><file name="AvaCert2Soap.class.php" hash="0567793d9e4e496b45c3e8a0459f944a"/><file name="Certificate.class.php" hash="dd3f0dd2a2b03c97552f9dbd5c6463ba"/><file name="CertificateGetRequest.class.php" hash="4c11fd111cab99fa4dbc2c2250e0f3ad"/><file name="CertificateGetResult.class.php" hash="6a95a06e71bd13839c6142bba08bfba5"/><file name="CertificateImageGetRequest.class.php" hash="32f61011abe3d1c74ea7fc209e3e4224"/><file name="CertificateImageGetResult.class.php" hash="beda0f1fd54951b84b7dd77ead92bda3"/><file name="CertificateJurisdiction.class.php" hash="e666d572fb34d17fcd91127a50616195"/><file name="CertificateRequest.class.php" hash="7b76dc3675e507975ae6cf01abfa6059"/><file name="CertificateRequestGetRequest.class.php" hash="0cf2fafae88f795a754d75291947cb56"/><file name="CertificateRequestGetResult.class.php" hash="eceffe3acec787506649669b1b5edcf7"/><file name="CertificateRequestInitiateRequest.class.php" hash="148a5c4c881c885be863f403582b4974"/><file name="CertificateRequestInitiateResult.class.php" hash="a7a55cb398cd2fb9f0e11b8c6b09498d"/><file name="CertificateRequestStage.class.php" hash="92dec7da28f83f1a419d9573e6cec1fa"/><file name="CertificateRequestStatus.class.php" hash="a5d5c1629ce4f5ee0c18a8924204ca22"/><file name="CertificateStatus.class.php" hash="6ae43ab57ae9df37d07ac4203270c25e"/><file name="CertificateUsage.class.php" hash="bad34570daa7679b267f1288bf0a371f"/><file name="CommunicationMode.class.php" hash="71d2743c1d2afffe11d2903e89ff9c0e"/><file name="Customer.class.php" hash="e9f13f38f75cb4e1b845c55e6f26a5ab"/><file name="CustomerSaveRequest.class.php" hash="58ff71b04bb3a308b7f0199c6fae1e56"/><file name="CustomerSaveResult.class.php" hash="98cf79bdb7c0558963670b21e66b7d85"/><file name="FormatType.class.php" hash="714d183d3d365a07ef606d1211c732b0"/><file name="RequestType.class.php" hash="6144c2731baaf67400ea34e50440c1df"/><file name="ReviewStatus.class.php" hash="0dd208ecbf6b45196f51f304b1d48b03"/></dir><file name="AvalaraSoapClient.class.php" hash="dd605cefabb4396ef1b46b6d23b439b5"/><file name="BaseResult.class.php" hash="85d2c23ecc62bf4b828d04f405f83d37"/><dir name="BatchSvc"><file name="AuditMessage.class.php" hash="798d8169506357af02e6912b4bca9148"/><file name="AvaTaxBatchSvc.php" hash="8d65fd4a02cd4fc1104aa9c24b35e4fb"/><file name="BaseResult.class.php" hash="727ef623b821e95a73cf6d1eda891379"/><file name="Batch.class.php" hash="c028822bcf2a4f1fae6fc7dca76f247a"/><file name="BatchDelete.class.php" hash="0bcff09309ccad969d65c2d27fa63dda"/><file name="BatchDeleteResponse.class.php" hash="46afd464673459efb54ccaf509d37eef"/><file name="BatchFetch.class.php" hash="74f96ecc3c2df87271d60c4c969e43f8"/><file name="BatchFetchResponse.class.php" hash="b2acf63deea2c0fd374f80745b60fef5"/><file name="BatchFetchResult.class.php" hash="83d8de067f4bd59acafe4cd065f90163"/><file name="BatchFile.class.php" hash="65cee20383c8040fac1d4c45bbe757dd"/><file name="BatchFileDelete.class.php" hash="01d0bc10cb0ada43a9a00ca0efffef17"/><file name="BatchFileDeleteResponse.class.php" hash="b4e7881d26b7071303650973144f418b"/><file name="BatchFileFetch.class.php" hash="c5e91b8073fb756545d0f74803fdf3d6"/><file name="BatchFileFetchResponse.class.php" hash="c37ce819a975cdae5e7a82432b4b2334"/><file name="BatchFileFetchResult.class.php" hash="6bc54523d34356a83cdc4ecd2f696ea5"/><file name="BatchFileSave.class.php" hash="8434b0ffdd1fba4991535248ee3d618e"/><file name="BatchFileSaveResponse.class.php" hash="d52f79b42467b59f2177359f8a73cd3a"/><file name="BatchFileSaveResult.class.php" hash="19d3a2f20ccc42e80759b280842cf03c"/><file name="BatchProcess.class.php" hash="44d9efe13d01fce15bd444e5729b320c"/><file name="BatchProcessRequest.class.php" hash="04684b987c6d77319cc6881941091de9"/><file name="BatchProcessResponse.class.php" hash="c22b08c125eefc4006495c55984ed91e"/><file name="BatchProcessResult.class.php" hash="f9cac2270aafae49fc0892ea729c3713"/><file name="BatchSave.class.php" hash="d3a397348b905d49a0c91be780f3ec04"/><file name="BatchSaveResponse.class.php" hash="4c3088b85590fd697b5686aa1dddd89e"/><file name="BatchSaveResult.class.php" hash="7ea7fe3dc7d580711f6b52d991c43dce"/><file name="BatchSvc.class.php" hash="fa903f70b06d1e3b86384f2b6fb60616"/><file name="DeleteRequest.class.php" hash="43f945ef1e59ef02494df6df6ec3d1b6"/><file name="DeleteResult.class.php" hash="f7d64582f1182ae0337d6d84a5f60e8d"/><file name="FetchRequest.class.php" hash="7271317a8909672261ea0e00867e810b"/><file name="FilterRequest.class.php" hash="3c1eaec68f84531931a3cd6143533576"/><file name="FilterResult.class.php" hash="f4c0eeac0153b735ec589fcff7accd86"/><file name="IsAuthorized.class.php" hash="8339a2b249d954efaaf64f10665976fc"/><file name="IsAuthorizedResponse.class.php" hash="613c91f36370dc38ca07b83a29f2a45f"/><file name="IsAuthorizedResult.class.php" hash="65f9665508a5e7f33e4aee2835a9806e"/><file name="Message.class.php" hash="576327c8d9cd74bd96d9ccd62a2daa5b"/><file name="Ping.class.php" hash="3a2246f5557a5279fa260c65b36a9b44"/><file name="PingResponse.class.php" hash="b9f5e8b43382ee605d93768db8af1805"/><file name="PingResult.class.php" hash="2e05acfe74aad28003ad7d8ed102c3c6"/><file name="Profile.class.php" hash="a16a4819018dd8510ddab8feb9ee0f7e"/><file name="SeverityLevel.class.php" hash="5736530f3b5fd0cd932c783418563647"/></dir><file name="BoundaryLevel.class.php" hash="e9c2f2e3173e44fa8351f2a6dbb578fe"/><file name="CancelCode.class.php" hash="fd0b8ad2865e8fcf622b1faafc677527"/><file name="CancelTaxRequest.class.php" hash="08a114e32ec9eda9268ec337f79cb86f"/><file name="CancelTaxResult.class.php" hash="687be65bab85e6c6e8f99764c0475d9b"/><file name="CommitTaxRequest.class.php" hash="66ef55bc094d233b75e36b029995aed7"/><file name="CommitTaxResult.class.php" hash="ef90276817207e63e4e96ea518618f50"/><file name="DetailLevel.class.php" hash="2439f7137a4f9f52e28a6b321c4bcf16"/><file name="DocStatus.class.php" hash="9e3384a0f2ace05fa67fe05eba295fcd"/><file name="DocumentType.class.php" hash="94b4509b914d638a94f946b5518b8993"/><file name="DynamicSoapClient.class.php" hash="5bb36f2d4db3955ae059488eb9511ca9"/><file name="Enum.class.php" hash="d3ff4c898aff49f3c425042433826257"/><file name="GetTaxHistoryRequest.class.php" hash="3ed4c54de1e015f476ce7aa58c802468"/><file name="GetTaxHistoryResult.class.php" hash="7e8209e1f64df52b538927312b1bd934"/><file name="GetTaxRequest.class.php" hash="a3343ef6a1e27e48c9a75aa9e02777c4"/><file name="GetTaxResult.class.php" hash="7e2b7415a018fd76b62ab49637833533"/><file name="IsAuthorizedResult.class.php" hash="58164457677a61e93309f788fe61dc0c"/><file name="JurisdictionType.class.php" hash="a345fe5db379af87a6f7ec833ff86586"/><file name="Line.class.php" hash="7fefbd0230ee2fe8a8e6468abf338b80"/><file name="Message.class.php" hash="073be6cbcccacf2d1d55a04c045eab63"/><file name="PingResult.class.php" hash="18f88589588f08b619488c926cf5547c"/><file name="PostTaxRequest.class.php" hash="be8ea4ee2fddb10b62cb1be7e38179e3"/><file name="PostTaxResult.class.php" hash="bf2ee0b1293301ee00ac9b8b8390e780"/><file name="ReconcileTaxHistoryRequest.class.php" hash="41f2cfe04495612a9c293b1bc19220ce"/><file name="ReconcileTaxHistoryResult.class.php" hash="dd20684e0e017f56c98e29297180a0d7"/><file name="SearchTaxHistoryResult.class.php" hash="e3171e00482f7c2c0ed9753ffd05cd14"/><file name="ServiceMode.class.php" hash="0c66b3e25f4466461cebf32735e207e0"/><file name="SeverityLevel.class.php" hash="68fc81e651fe7f01c81b43b0d28ff0dc"/><file name="TaxDetail.class.php" hash="56065f8ea68505152b23e41238b80dfb"/><file name="TaxLine.class.php" hash="05376f01ad9a14f438ad0f1d5d423b61"/><file name="TaxOverride.class.php" hash="94d28efa3cdf58a87ba45a313ce93fc7"/><file name="TaxOverrideType.class.php" hash="d23f90c9ac639954c8fcee57ba763b21"/><file name="TaxRequest.class.php" hash="7339016da0c3cbe51843767987e7fbed"/><file name="TaxServiceSoap.class.php" hash="bc7e4eb0e66dd1bd956e19e0da337171"/><file name="TaxType.class.php" hash="ee87ecc8721076f0cda67fe1cc5b0db7"/><file name="TextCase.class.php" hash="8fb2eccc49eacdc1a4f5624c0716a750"/><file name="ValidAddress.class.php" hash="2f8eebcd379208198cd38632f1e34b0a"/><file name="ValidateRequest.class.php" hash="340822f22dee80e160193cacdc9c8dfb"/><file name="ValidateResult.class.php" hash="23de6a26defed9324ddcdcedfd2228bf"/><dir name="wsdl"><file name="Address.wsdl" hash="37ac1778f42147b548e09c8bb39b3cfc"/><file name="AvaCert2Svc.wsdl" hash="60da5aa0484ce00b82d7675ea3fd6454"/><file name="AvaCertSvc.wsdl" hash="25d03720f7018ea027c3345ec2c69c8e"/><file name="BatchSvc.wsdl" hash="798a715e28b9751b01666a29554135f7"/><file name="Tax.wsdl" hash="051420912d3e0b2489ae250c47059166"/></dir></dir><file name="functions.php" hash="57734d162b59cbc65933d25bf3950270"/></dir></target></contents>
26
  <compatible/>
27
  <dependencies><required><php><min>5.2.3</min><max>6.0.0</max></php><extension><name>Core</name><min/><max/></extension><extension><name>curl</name><min/><max/></extension><extension><name>soap</name><min/><max/></extension></required></dependencies>
28
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>OnePica_AvaTax</name>
4
+ <version>3.0.0</version>
5
  <stability>stable</stability>
6
  <license>Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
18
  &#xD;
19
  &#xD;
20
  At One Pica (www.onepica.com), we strive to build increasingly scalable and flexible enterprise systems for all of our clients, large and small. We want to give back to this community both to promote its success and as a sign of our gratitude. Please feel free to contact us on ways we can improve this extension or extend on this framework.</description>
21
+ <notes>Improved performance&#xD;
22
+ Reduced number of GetTax calls&#xD;
23
+ Fixed error displaying&#xD;
24
+ Fixed logs export&#xD;
25
+ Fixed Customer Tax Code sending for not logged in customer group&#xD;
26
+ Fixed tax calculation if change customer group while place order via admin&#xD;
27
+ Fixed request settings for Multiple Checkout&#xD;
28
+ Fixed buttons "View Shopping Cart" and "Checkout" displaying in the MiniCart if user enters non taxable address during Multiple Checkout&#xD;
29
+ Fixed tax rates in checkout when shipping address changing four times</notes>
30
  <authors><author><name>Rostyslav Redko</name><user>marketing</user><email>avalara@onepica.com</email></author></authors>
31
+ <date>2016-02-11</date>
32
+ <time>09:49:07</time>
33
+ <contents><target name="magecommunity"><dir name="OnePica"><dir name="AvaTax"><dir name="Block"><dir name="Adminhtml"><dir name="Export"><dir name="Abstract"><file name="Grid.php" hash="5f96ca490c5f7bd3fac23e30b00336e5"/></dir><dir name="Log"><file name="Grid.php" hash="311c55d8bc770e6d6aa6f377c2eee6fd"/><file name="View.php" hash="097d82a3e2b1a8820d335a63f212451b"/></dir><dir name="Queue"><file name="Grid.php" hash="1ef8ba9bf3e0870ea6dc50bb202a0b91"/></dir></dir><dir name="Notification"><file name="Toolbar.php" hash="26f7e382432289c3ff07647141cf9324"/></dir><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Export.php" hash="3e019b9551b95c71f4cfd67a14d62a27"/></dir></dir></dir></dir><dir name="Tax"><dir name="Class"><dir name="Edit"><file name="Form.php" hash="0e78c592366ee2746f3891cf91a388d3"/></dir><file name="Grid.php" hash="d731eb160457b8a22cfcd28682a1c485"/></dir></dir></dir><dir name="Checkout"><dir name="Onepage"><dir name="Shipping"><dir name="Method"><file name="Available.php" hash="a0bdc5f63955148cf7e755c8803e01de"/></dir></dir></dir></dir></dir><file name="Exception.php" hash="fc752f8da808a402baae2425c4072d22"/><dir name="Helper"><file name="Address.php" hash="df731a75957cf712d0b1410b1d831dd6"/><file name="Calculation.php" hash="3a3bcbd4a33a061700c495a14afd8b3a"/><file name="Config.php" hash="b7a48f682638fca9b53e2db1460e45f4"/><file name="Data.php" hash="111f31427c4cc0d77830643b7271b08c"/><file name="Errors.php" hash="1fc34a932db296ecd1617a4e50e150d7"/><dir name="GiftWrapping"><file name="Data.php" hash="4428b400b540be990dc1bab2d345cb4c"/></dir><file name="Lib.php" hash="ce05e31b4aba7ba84bfc016df8c2a559"/><dir name="Tax"><file name="Data.php" hash="eb76f852d84cf8f498cd0d4b236136db"/></dir></dir><dir name="Model"><dir name="Action"><file name="Abstract.php" hash="de2bc126be0cfe69ffe6af60a8307d16"/><file name="Calculator.php" hash="91bea26e2779235309c881cd1ff08a96"/><file name="Creditmemo.php" hash="23639271a8fad749a3ee3a13fc8b0b27"/><file name="Invoice.php" hash="20458660bda4a277c0677b1406feb481"/><file name="Ping.php" hash="7e08308fff72493e0cb75b9244551de6"/><file name="Validator.php" hash="595d79c22f3027b89498b5c004b8be2b"/></dir><dir name="Admin"><file name="Session.php" hash="e3dc3353c7eebf4e17c22ea4039585c5"/></dir><dir name="Adminhtml"><file name="Config.php" hash="388f532f03fa8dacc9fde122a2fe0c64"/><dir name="Sales"><dir name="Order"><file name="Create.php" hash="2a1b42b629b8da1373e11860c4a2c8c0"/></dir></dir></dir><dir name="Export"><dir name="Adapter"><file name="Abstract.php" hash="840c8b87acd97646572bba9bb3b8f5ea"/><file name="Sql.php" hash="0e9bedb400f411785311f78ebbf676da"/></dir><dir name="Entity"><file name="Abstract.php" hash="d38a2293452c31e92f81bf5be59c3e1c"/><file name="Log.php" hash="a1dd28eee3e72d1a4ef7bddd865ddbae"/><file name="Queue.php" hash="14a97c283aa74f97982ab71160017aa3"/></dir></dir><file name="Export.php" hash="b94613b678b413d6268b07d314ba122e"/><dir name="Observer"><file name="Abstract.php" hash="4cef8e34c047b97e34ab08b0c937082c"/><file name="AdminSystemConfigChangedSectionTax.php" hash="e0e703abb46b48185dc6dda2944b89cc"/><file name="CheckoutSubmitAllAfter.php" hash="4ee09c54a9098b568dac726964d782c0"/><file name="CheckoutTypeMultishippingCreateOrdersSingle.php" hash="eeaffffddd4e2ce387325dfb58381a77"/><file name="CleanLog.php" hash="4043bb0a3df982b756bfb1dfab5d56de"/><file name="ControllerActionPostdispatchCheckoutCartEstimatePost.php" hash="5b2facd906e8fb33a49f23c7f3fe36b7"/><file name="ControllerActionPostdispatchCheckoutCartEstimateUpdatePost.php" hash="4006ae1c1074915312301260ed88925c"/><file name="ControllerActionPostdispatchCheckoutOnepageSaveShippingMethod.php" hash="0b600e585f4b008e457995676019c2b4"/><file name="ControllerActionPredispatchAdminhtmlSalesOrderCreateLoadBlock.php" hash="07ef318adffde6bba762da8300e17324"/><file name="ControllerActionPredispatchCheckoutCartEstimatePost.php" hash="2b2cce8f619488fd795a027b80d20d2a"/><file name="ControllerActionPredispatchCheckoutCartIndex.php" hash="ec46c279439967df90395882a5804de1"/><file name="ControllerActionPredispatchCheckoutMultishippingIndex.php" hash="d6d7a1d0272c51f3ec4cacbce8574da3"/><file name="ControllerActionPredispatchCheckoutOnepageIndex.php" hash="01c4280273e34a2f82ed6764792f3568"/><file name="LoadAvaTaxExternalLib.php" hash="0b10ed2f15ef8202362f4828fad15262"/><file name="MultishippingSetShippingItems.php" hash="e4a1f3c4e1506797692a7b7d2dc23217"/><file name="ProcessQueue.php" hash="35375793d039f6848e7b2af05e0eef41"/><file name="SalesModelServiceQuoteSubmitAfter.php" hash="6499cfe8e1c9176b12af58c0bce331eb"/><file name="SalesModelServiceQuoteSubmitBefore.php" hash="4e67278a1c20a969f8709237f817b6e0"/><file name="SalesOrderCreditmemoRefund.php" hash="3e9049e39b53ec06b8aa1ab274d1e00d"/><file name="SalesOrderCreditmemoSaveAfter.php" hash="a01af2f4a66912383b772be42fddbdea"/><file name="SalesOrderInvoicePay.php" hash="ac7884c312f986d123912f01346b031a"/><file name="SalesOrderInvoiceSaveAfter.php" hash="00279b77e0a3bbac120b9248d6f9223d"/><file name="SalesQuoteCollectTotalsBefore.php" hash="c0ae978e4895cec8a1b4c1ec2a3a5522"/></dir><dir name="Records"><file name="Log.php" hash="32926db85023ad21ea6179bf4ad77ef4"/><dir name="Mysql4"><dir name="Log"><file name="Collection.php" hash="29db8163f4dda862ff822ddffd04554d"/></dir><file name="Log.php" hash="d6fb7997768b7e0f1b39363fd4de5917"/><dir name="Queue"><file name="Collection.php" hash="11bba1561c81f39695f091b94bd81560"/></dir><file name="Queue.php" hash="12ba62949dab080c6dc6ae7fcbbf4838"/></dir><dir name="Queue"><file name="Process.php" hash="82d837f47b78b4a037938dd88dfe3217"/></dir><file name="Queue.php" hash="2906b0c99e686f2e85169cbd49c8af2e"/></dir><dir name="Sales"><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Grand.php" hash="7c2e06c4582f37cfa21d453fb9dfa5ea"/><file name="Tax.php" hash="3d9fa316f2eb70c30e83e2ba2763c054"/></dir></dir><file name="Address.php" hash="7a9717d123bba20ce14144b80d1da5da"/></dir></dir><dir name="Service"><dir name="Abstract"><file name="Config.php" hash="2b5ebe4312f82b0c13b03db2c261964f"/><file name="Tools.php" hash="8268ab2a43b4767c7d18a18ee420ae5f"/></dir><file name="Abstract.php" hash="29cee53a912adeb0f682bc931972823d"/><dir name="Avatax"><file name="Abstract.php" hash="629fc49a518505a87f1548c3b29ef666"/><file name="Address.php" hash="5f6d2257e4132a436dff7cc0cc08eb67"/><file name="Config.php" hash="25198070b781c8ce632b4f3d3c3b21e0"/><file name="Estimate.php" hash="6af94ed789360a60fd5eafb8f75ec06b"/><file name="Invoice.php" hash="4f2c0dbb67b8b5e58fecdcb02d0b7360"/><file name="Ping.php" hash="8dd09babe7e8b206564544b2ace9a661"/><file name="Tax.php" hash="3002e239f7f5a84f3377d288861cf4d2"/></dir><file name="Avatax.php" hash="b6fa49f95a3ab05546bd597689a14ed7"/><dir name="Avatax16"><file name="Abstract.php" hash="9b061b6d7bebc7539efa4a33789c23e2"/><file name="Address.php" hash="834681944f93504537e26217f9690cd5"/><file name="Config.php" hash="34c888b2db0c2c72bfea6ddad0dbf053"/><file name="Estimate.php" hash="e99cbc11369f3dfc40bc0a0747cce2ca"/><file name="Invoice.php" hash="97ef4ebf3df4f6ab854c6224fa22d20b"/><file name="Ping.php" hash="853a6c8078296263adc241befc5eaa92"/><file name="Tax.php" hash="0680fb53318af5eac219909162657037"/></dir><file name="Avatax16.php" hash="cd3743c413edb08904781900c0064eaf"/><dir name="Exception"><file name="Address.php" hash="2519f1a2b302db97337c933d99a6d116"/><file name="Commitfailure.php" hash="7f0c5a5bf9242651d2542336d0b4cb96"/><file name="Unbalanced.php" hash="43595e010b314e8a91dd0fef4fad96c2"/></dir><dir name="Result"><file name="Address.php" hash="7a711e27f7f5e478a8a290a1880586f6"/><file name="AddressValidate.php" hash="62d14d7f4147b83001ef7f64726276c1"/><file name="Creditmemo.php" hash="8b1ac1eda1a522c70bca574b938c6359"/><file name="Invoice.php" hash="83f157b7fd24e5e6c0b51f6a162ee316"/></dir></dir><file name="Service.php" hash="7fda34c9ce1db70ae9757561d505a5b7"/><file name="Session.php" hash="429142089e75418a702e70edc56374cf"/><dir name="Source"><file name="Actions.php" hash="b5392f0820f15c3159e76ea67148992a"/><file name="Addressvalidation.php" hash="9f2315018910f7336ad894156d49d9b9"/><dir name="Avatax"><file name="Actions.php" hash="c72aa0df9013c6d5c5fddc0c4b4027b0"/><file name="Logtype.php" hash="6fde0a0dda9a7884bb13484ffa244409"/><file name="Url.php" hash="cff45c6a590360711867112533b068d8"/></dir><dir name="Avatax16"><file name="Actions.php" hash="86b7d4067faad9478f9b61101d0fd6ae"/><file name="Buyertype.php" hash="6b029a7bbacc0eda36ed4fbb6f6e467b"/><file name="Logtype.php" hash="09ddc0a3106e206e90ed45d8a2539d78"/><file name="Url.php" hash="02ae82a6eae3916f613b0db458b0756a"/><file name="Usetype.php" hash="107c03d384fb6a8b990e4c16f49fab87"/></dir><file name="Customercodeformat.php" hash="cfcfcbaa27ed29add072324816da0c9d"/><file name="Error.php" hash="7f5495a2f295ded2d0a30f2f7108d009"/><file name="Fieldlist.php" hash="18987603d4d58130959a8ac76716ed08"/><file name="Logmode.php" hash="24d61da578a3b4adb896fea7d4d4d8ec"/><file name="Logtype.php" hash="25dce563940ac9763e642e3e96365043"/><file name="Onerrorfrontend.php" hash="ef4154ae563d8157c1083f20e0adf563"/><dir name="Regionfilter"><file name="List.php" hash="d73ebe7197a2c6cfa45d52775d6f0977"/><file name="Mode.php" hash="2216d28bf9adba614025538cc62a49b6"/></dir><file name="Url.php" hash="794ec57a2b350931f70e95eb6677c253"/></dir><dir name="Tax"><file name="Config.php" hash="c3d5778516662f5090aebf25519c2547"/></dir><dir name="Total"><dir name="Quote"><dir name="Tax"><file name="Giftwrapping.php" hash="7b264455ac9084a751468ef6dbc36fe5"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="AvaTax"><file name="ExportController.php" hash="ead5ebea03db8f885d0ec6114dcb185c"/><file name="GridController.php" hash="5c7e822890a6feaec2db348e6c5a19e1"/></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="aca07ae89478c72fd1d2d41228c28b8e"/><file name="config.xml" hash="0d5f326d815701c9925a15001a0cd596"/><file name="system-avatax16-disabled.xml" hash="b24027def3daab9000047bf7fee41c4f"/><file name="system-avatax16.xml" hash="b5a9543409521633ceec2af4d9c5d1b7"/><file name="system-disabled.xml" hash="1ef23998fa4452c8c4fc68d05b9a2f89"/><file name="system.xml" hash="98797f0be09a53b9c0c7bebdb14bbc4e"/></dir><dir name="sql"><dir name="avatax_records_setup"><file name="mysql4-data-upgrade-2.2.0-2.2.1.php" hash="260d1c57754ebadba00d8ccdbb0ec996"/><file name="mysql4-install-0.1.0.php" hash="3d16899179b36bfde69609a99a2faae6"/><file name="mysql4-upgrade-0.1.4-0.1.5.php" hash="94d0cf2fc0e9bbe2de2829198ce3026f"/><file name="mysql4-upgrade-1.0.1-2.0.0.php" hash="905d7519328cdb1c46bba4221288c41c"/><file name="mysql4-upgrade-2.5.0.0-2.5.0.1.php" hash="4b439957397049bbe01d458fd7cfe0a2"/><file name="mysql4-upgrade-3.0.0.1-3.0.0.2.php" hash="46caa743f17221575b4a639b262a9275"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="OnePica_AvaTax.xml" hash="07fd9423811b4dc084060d6131b889d7"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="onepica"><file name="avatax.xml" hash="de338ca651fcce096d089b2bbbcc1374"/></dir></dir><dir name="template"><dir name="onepica"><dir name="avatax"><dir name="log"><file name="view.phtml" hash="df14eee805bbedd484cf500dbf2335ed"/></dir><dir name="notification"><file name="toolbar.phtml" hash="fd368e043843df76ec3a74290b87dc3e"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="onepica"><file name="avatax.xml" hash="38c6ce2165f6ccfd6641eb1487faad39"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="de_DE"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="en_US"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="es_ES"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="fr_FR"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="nl_NL"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="pt_BR"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir><dir name="zh_CN"><file name="OnePica_AvaTax.csv" hash="43d2dee74aee6f15abd471a65b4f407c"/></dir></target><target name="magelib"><dir name="AvaTax"><file name="AvaTax.php" hash="46bf3fb7795482b7494b2fdc266af3bc"/><dir name="classes"><file name="ATConfig.class.php" hash="dd1c39643f677e0c3b612c549686812c"/><file name="ATObject.class.php" hash="83359fd7639c98449836dc11d08c899d"/><file name="Address.class.php" hash="68bf4fe1306a60e672b7345a0dc7fcc6"/><file name="AddressServiceSoap.class.php" hash="c59bf4a586da207611f7bace4f08c880"/><file name="AddressType.class.php" hash="62c9ff3c533aaf5ad1fd4de95702be40"/><file name="AdjustTaxRequest.class.php" hash="47dbfa8044ca893bf214d8e71ab4864e"/><file name="AdjustTaxResult.class.php" hash="cf63aa5b7c3b52b3ec86695c4cdf0fcc"/><file name="ApplyPaymentRequest.class.php" hash="69d69dff63cbd284d8aea62247142692"/><file name="ApplyPaymentResult.class.php" hash="0e37bda0f1221c2ed2432717a2d8cc08"/><dir name="AvaCert2Svc"><file name="AvaCert2Soap.class.php" hash="0567793d9e4e496b45c3e8a0459f944a"/><file name="Certificate.class.php" hash="dd3f0dd2a2b03c97552f9dbd5c6463ba"/><file name="CertificateGetRequest.class.php" hash="4c11fd111cab99fa4dbc2c2250e0f3ad"/><file name="CertificateGetResult.class.php" hash="6a95a06e71bd13839c6142bba08bfba5"/><file name="CertificateImageGetRequest.class.php" hash="32f61011abe3d1c74ea7fc209e3e4224"/><file name="CertificateImageGetResult.class.php" hash="beda0f1fd54951b84b7dd77ead92bda3"/><file name="CertificateJurisdiction.class.php" hash="e666d572fb34d17fcd91127a50616195"/><file name="CertificateRequest.class.php" hash="7b76dc3675e507975ae6cf01abfa6059"/><file name="CertificateRequestGetRequest.class.php" hash="0cf2fafae88f795a754d75291947cb56"/><file name="CertificateRequestGetResult.class.php" hash="eceffe3acec787506649669b1b5edcf7"/><file name="CertificateRequestInitiateRequest.class.php" hash="148a5c4c881c885be863f403582b4974"/><file name="CertificateRequestInitiateResult.class.php" hash="a7a55cb398cd2fb9f0e11b8c6b09498d"/><file name="CertificateRequestStage.class.php" hash="92dec7da28f83f1a419d9573e6cec1fa"/><file name="CertificateRequestStatus.class.php" hash="a5d5c1629ce4f5ee0c18a8924204ca22"/><file name="CertificateStatus.class.php" hash="6ae43ab57ae9df37d07ac4203270c25e"/><file name="CertificateUsage.class.php" hash="bad34570daa7679b267f1288bf0a371f"/><file name="CommunicationMode.class.php" hash="71d2743c1d2afffe11d2903e89ff9c0e"/><file name="Customer.class.php" hash="e9f13f38f75cb4e1b845c55e6f26a5ab"/><file name="CustomerSaveRequest.class.php" hash="58ff71b04bb3a308b7f0199c6fae1e56"/><file name="CustomerSaveResult.class.php" hash="98cf79bdb7c0558963670b21e66b7d85"/><file name="FormatType.class.php" hash="714d183d3d365a07ef606d1211c732b0"/><file name="RequestType.class.php" hash="6144c2731baaf67400ea34e50440c1df"/><file name="ReviewStatus.class.php" hash="0dd208ecbf6b45196f51f304b1d48b03"/></dir><file name="AvalaraSoapClient.class.php" hash="dd605cefabb4396ef1b46b6d23b439b5"/><file name="BaseResult.class.php" hash="85d2c23ecc62bf4b828d04f405f83d37"/><dir name="BatchSvc"><file name="AuditMessage.class.php" hash="798d8169506357af02e6912b4bca9148"/><file name="AvaTaxBatchSvc.php" hash="8d65fd4a02cd4fc1104aa9c24b35e4fb"/><file name="BaseResult.class.php" hash="727ef623b821e95a73cf6d1eda891379"/><file name="Batch.class.php" hash="c028822bcf2a4f1fae6fc7dca76f247a"/><file name="BatchDelete.class.php" hash="0bcff09309ccad969d65c2d27fa63dda"/><file name="BatchDeleteResponse.class.php" hash="46afd464673459efb54ccaf509d37eef"/><file name="BatchFetch.class.php" hash="74f96ecc3c2df87271d60c4c969e43f8"/><file name="BatchFetchResponse.class.php" hash="b2acf63deea2c0fd374f80745b60fef5"/><file name="BatchFetchResult.class.php" hash="83d8de067f4bd59acafe4cd065f90163"/><file name="BatchFile.class.php" hash="65cee20383c8040fac1d4c45bbe757dd"/><file name="BatchFileDelete.class.php" hash="01d0bc10cb0ada43a9a00ca0efffef17"/><file name="BatchFileDeleteResponse.class.php" hash="b4e7881d26b7071303650973144f418b"/><file name="BatchFileFetch.class.php" hash="c5e91b8073fb756545d0f74803fdf3d6"/><file name="BatchFileFetchResponse.class.php" hash="c37ce819a975cdae5e7a82432b4b2334"/><file name="BatchFileFetchResult.class.php" hash="6bc54523d34356a83cdc4ecd2f696ea5"/><file name="BatchFileSave.class.php" hash="8434b0ffdd1fba4991535248ee3d618e"/><file name="BatchFileSaveResponse.class.php" hash="d52f79b42467b59f2177359f8a73cd3a"/><file name="BatchFileSaveResult.class.php" hash="19d3a2f20ccc42e80759b280842cf03c"/><file name="BatchProcess.class.php" hash="44d9efe13d01fce15bd444e5729b320c"/><file name="BatchProcessRequest.class.php" hash="04684b987c6d77319cc6881941091de9"/><file name="BatchProcessResponse.class.php" hash="c22b08c125eefc4006495c55984ed91e"/><file name="BatchProcessResult.class.php" hash="f9cac2270aafae49fc0892ea729c3713"/><file name="BatchSave.class.php" hash="d3a397348b905d49a0c91be780f3ec04"/><file name="BatchSaveResponse.class.php" hash="4c3088b85590fd697b5686aa1dddd89e"/><file name="BatchSaveResult.class.php" hash="7ea7fe3dc7d580711f6b52d991c43dce"/><file name="BatchSvc.class.php" hash="fa903f70b06d1e3b86384f2b6fb60616"/><file name="DeleteRequest.class.php" hash="43f945ef1e59ef02494df6df6ec3d1b6"/><file name="DeleteResult.class.php" hash="f7d64582f1182ae0337d6d84a5f60e8d"/><file name="FetchRequest.class.php" hash="7271317a8909672261ea0e00867e810b"/><file name="FilterRequest.class.php" hash="3c1eaec68f84531931a3cd6143533576"/><file name="FilterResult.class.php" hash="f4c0eeac0153b735ec589fcff7accd86"/><file name="IsAuthorized.class.php" hash="8339a2b249d954efaaf64f10665976fc"/><file name="IsAuthorizedResponse.class.php" hash="613c91f36370dc38ca07b83a29f2a45f"/><file name="IsAuthorizedResult.class.php" hash="65f9665508a5e7f33e4aee2835a9806e"/><file name="Message.class.php" hash="576327c8d9cd74bd96d9ccd62a2daa5b"/><file name="Ping.class.php" hash="3a2246f5557a5279fa260c65b36a9b44"/><file name="PingResponse.class.php" hash="b9f5e8b43382ee605d93768db8af1805"/><file name="PingResult.class.php" hash="2e05acfe74aad28003ad7d8ed102c3c6"/><file name="Profile.class.php" hash="a16a4819018dd8510ddab8feb9ee0f7e"/><file name="SeverityLevel.class.php" hash="5736530f3b5fd0cd932c783418563647"/></dir><file name="BoundaryLevel.class.php" hash="e9c2f2e3173e44fa8351f2a6dbb578fe"/><file name="CancelCode.class.php" hash="fd0b8ad2865e8fcf622b1faafc677527"/><file name="CancelTaxRequest.class.php" hash="08a114e32ec9eda9268ec337f79cb86f"/><file name="CancelTaxResult.class.php" hash="687be65bab85e6c6e8f99764c0475d9b"/><file name="CommitTaxRequest.class.php" hash="66ef55bc094d233b75e36b029995aed7"/><file name="CommitTaxResult.class.php" hash="ef90276817207e63e4e96ea518618f50"/><file name="DetailLevel.class.php" hash="2439f7137a4f9f52e28a6b321c4bcf16"/><file name="DocStatus.class.php" hash="9e3384a0f2ace05fa67fe05eba295fcd"/><file name="DocumentType.class.php" hash="94b4509b914d638a94f946b5518b8993"/><file name="DynamicSoapClient.class.php" hash="5bb36f2d4db3955ae059488eb9511ca9"/><file name="Enum.class.php" hash="d3ff4c898aff49f3c425042433826257"/><file name="GetTaxHistoryRequest.class.php" hash="3ed4c54de1e015f476ce7aa58c802468"/><file name="GetTaxHistoryResult.class.php" hash="7e8209e1f64df52b538927312b1bd934"/><file name="GetTaxRequest.class.php" hash="a3343ef6a1e27e48c9a75aa9e02777c4"/><file name="GetTaxResult.class.php" hash="7e2b7415a018fd76b62ab49637833533"/><file name="IsAuthorizedResult.class.php" hash="58164457677a61e93309f788fe61dc0c"/><file name="JurisdictionType.class.php" hash="a345fe5db379af87a6f7ec833ff86586"/><file name="Line.class.php" hash="7fefbd0230ee2fe8a8e6468abf338b80"/><file name="Message.class.php" hash="073be6cbcccacf2d1d55a04c045eab63"/><file name="PingResult.class.php" hash="18f88589588f08b619488c926cf5547c"/><file name="PostTaxRequest.class.php" hash="be8ea4ee2fddb10b62cb1be7e38179e3"/><file name="PostTaxResult.class.php" hash="bf2ee0b1293301ee00ac9b8b8390e780"/><file name="ReconcileTaxHistoryRequest.class.php" hash="41f2cfe04495612a9c293b1bc19220ce"/><file name="ReconcileTaxHistoryResult.class.php" hash="dd20684e0e017f56c98e29297180a0d7"/><file name="SearchTaxHistoryResult.class.php" hash="e3171e00482f7c2c0ed9753ffd05cd14"/><file name="ServiceMode.class.php" hash="0c66b3e25f4466461cebf32735e207e0"/><file name="SeverityLevel.class.php" hash="68fc81e651fe7f01c81b43b0d28ff0dc"/><file name="TaxDetail.class.php" hash="56065f8ea68505152b23e41238b80dfb"/><file name="TaxLine.class.php" hash="05376f01ad9a14f438ad0f1d5d423b61"/><file name="TaxOverride.class.php" hash="94d28efa3cdf58a87ba45a313ce93fc7"/><file name="TaxOverrideType.class.php" hash="d23f90c9ac639954c8fcee57ba763b21"/><file name="TaxRequest.class.php" hash="7339016da0c3cbe51843767987e7fbed"/><file name="TaxServiceSoap.class.php" hash="bc7e4eb0e66dd1bd956e19e0da337171"/><file name="TaxType.class.php" hash="ee87ecc8721076f0cda67fe1cc5b0db7"/><file name="TextCase.class.php" hash="8fb2eccc49eacdc1a4f5624c0716a750"/><file name="ValidAddress.class.php" hash="2f8eebcd379208198cd38632f1e34b0a"/><file name="ValidateRequest.class.php" hash="98faedd50b2f4ea7ffb9d53ab1ca116c"/><file name="ValidateResult.class.php" hash="23de6a26defed9324ddcdcedfd2228bf"/><dir name="wsdl"><file name="Address.wsdl" hash="37ac1778f42147b548e09c8bb39b3cfc"/><file name="AvaCert2Svc.wsdl" hash="60da5aa0484ce00b82d7675ea3fd6454"/><file name="AvaCertSvc.wsdl" hash="25d03720f7018ea027c3345ec2c69c8e"/><file name="BatchSvc.wsdl" hash="798a715e28b9751b01666a29554135f7"/><file name="Tax.wsdl" hash="051420912d3e0b2489ae250c47059166"/></dir></dir><file name="functions.php" hash="57734d162b59cbc65933d25bf3950270"/></dir><dir name="OnePica"><dir name="AvaTax16"><dir name="AddressResolution"><file name="PingResponse.php" hash="42cf1ee8601e559d025b009ecb7201b3"/><file name="ResolveSingleAddressResponse.php" hash="7305c3bbe38e5c440678361847c43e84"/><file name="TaxAuthority.php" hash="86b3584391c9ef8af8ffeda1b7162637"/></dir><file name="AddressResolution.php" hash="3acfa74ff528a1d50d539a756614137c"/><dir name="Calculation"><dir name="ListItemResponse"><dir name="CalculatedTaxSummary"><dir name="TaxByType"><file name="Details.php" hash="53ffdc3b1df7f9ffbe1418d863b279f9"/></dir><file name="TaxByType.php" hash="182d258bad391e4b82406d43dcf9eaca"/></dir><file name="CalculatedTaxSummary.php" hash="d4ae2eeb74d7641db65226f76ee965de"/><file name="Header.php" hash="846a2ef2aa31b271b864b908e43f59e5"/><file name="Line.php" hash="974554064e6a61a4e2b9ab6db5e2fd34"/><file name="ProcessingInfo.php" hash="6ea7c0a0c86036c648ef4e0476eea99e"/></dir><file name="ListItemResponse.php" hash="bbdc204f0d848e992119280761d8d7cc"/><file name="ListResponse.php" hash="2d15f8cdf48993d8ab90938cd4d37190"/></dir><file name="Calculation.php" hash="5311fefa3e82c63ef725f32f84a04aab"/><file name="Config.php" hash="5eb6a3001370bca29d977fe9b24800ea"/><dir name="Document"><dir name="Part"><dir name="Feedback"><file name="LatencyData.php" hash="4f5c765cf6d028bcb4107b01f2e5b807"/></dir><file name="Feedback.php" hash="fac9eb4e3478fc4386567cd41668e1e1"/><dir name="Location"><file name="Address.php" hash="15ee70c3901080d53cef56cd63d4cf57"/><file name="LatLong.php" hash="97b968fdca26d5a8f5602e4f28162190"/></dir><file name="Location.php" hash="6054bcad769a7d7287445aa590ef2a2d"/></dir><file name="Part.php" hash="b1ef99e465e25df5338080610daa977d"/><dir name="Request"><file name="Header.php" hash="92bac296417f904a70287dc55dee9d1c"/><file name="Line.php" hash="0acdeea9894a70410cb64398e90ab7d0"/></dir><file name="Request.php" hash="1440ad02232e98d286ce37f696a086a7"/><dir name="Response"><dir name="CalculatedTaxSummary"><dir name="TaxByType"><file name="Details.php" hash="b0bf6211fa2744285d3b42cd8660c8e5"/></dir><file name="TaxByType.php" hash="6a427c932fe5b60588864fcf5a0c81f2"/></dir><file name="CalculatedTaxSummary.php" hash="86c0321b176d6c52222f6d688408b87c"/><file name="Header.php" hash="787e68feae0eacc4b0359f66cd180cd1"/><dir name="Line"><dir name="CalculatedTax"><file name="Details.php" hash="5a80a57a785b7e4d9b2ce6c946319279"/><file name="TaxByType.php" hash="3267edf3a25c9313dc7f838da7669add"/></dir><file name="CalculatedTax.php" hash="f47fc24daeb236106e52c6309bc1f3e5"/></dir><file name="Line.php" hash="a068c319dfcdc79f63b8ad1291eaf3b2"/><file name="ProcessingInfo.php" hash="b175ab3cffde010db67a666a0ac1f6c6"/></dir><file name="Response.php" hash="b0d922b0a0ff81d9c690828e7149bc29"/></dir><file name="Exception.php" hash="62f3fb8c7fee6758dbf00e9a90053dde"/><dir name="IO"><file name="CaseInsensitiveArray.php" hash="5ff9551b29e56f6fe92ee4f802a983f3"/><file name="Curl.php" hash="90f0df8763a82d597fc0f93deaa13249"/></dir><file name="ResourceAbstract.php" hash="86bb4526bc73b7cf63d675c1f6eaac44"/><file name="TaxService.php" hash="03f1799cd82cd95e5412d4a2ac915361"/><dir name="Transaction"><file name="ListItemResponse.php" hash="3cbe80a9923a0b25e2350c4c6daaa3fc"/><file name="ListResponse.php" hash="491506f6f1e4044e14f1c43b2082a03a"/><file name="TransitionTransactionStateResponse.php" hash="7b9e0beb239ff0679a360d1d14945fba"/></dir><file name="Transaction.php" hash="282113bda5b0abe544fd58c844c9ee87"/></dir><file name="autoload.php" hash="997d00ba2d67253ec64a95c89c92c36b"/></dir></target></contents>
34
  <compatible/>
35
  <dependencies><required><php><min>5.2.3</min><max>6.0.0</max></php><extension><name>Core</name><min/><max/></extension><extension><name>curl</name><min/><max/></extension><extension><name>soap</name><min/><max/></extension></required></dependencies>
36
  </package>