Source for file gTaxRule.php

Documentation is available at gTaxRule.php

  1. <?php
  2.  
  3. /**
  4. * ========================================================
  5. * phpGCheckout, Open Source PHP G Checkout Library
  6. * http://www.phpgcheckout.com
  7. * ========================================================
  8. *
  9. * Copyright (c) 2006 Expert Database Solutions, LLC
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation the
  14. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. * copies of the Software, and to permit persons to whom the Software is
  16. * furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in all
  19. * copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  22. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  23. * PARTICULAR PURPOSE AND NONINFRINGEMENT.
  24. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  25. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
  26. * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. *
  28. */
  29. /**
  30. * Google Checkout Tax Rule Primitive
  31. *
  32. * Google Checkout API Tax Tables are agregated into tax rules.
  33. * ie. Tax Tables 1-* Tax Rules.
  34. *
  35. * This class is the abstraction of a Google Checkout Tax Rule object.
  36. *
  37. * @author Ron Howard
  38. * @copyright Expert Database Solutions, LLC 2006
  39. *
  40. */
  41. class gTaxRule {
  42. var $_rate;
  43. var $_country_area;
  44. var $_arr_states;
  45. var $_arr_zips;
  46. var $_type;
  47. var $_shipping_taxed;
  48. /**
  49. * Google Checkout Tax Rule Constructor
  50. *
  51. * Note: $type parameter is here just for unit testing
  52. * during construction of the tax table. The rule will
  53. * be set to the type of the tax table.
  54. *
  55. * ie if a default tax table calls the getXML() method
  56. * then the tax rule will be set to type = 'default'
  57. *
  58. * @param unknown_type $rate
  59. * @param unknown_type $country_area
  60. * @param unknown_type $arr_states
  61. * @param unknown_type $arr_zips
  62. * @param unknown_type $type
  63. * @return gTaxRule
  64. */
  65. function gTaxRule($rate, $country_area = null, $arr_states = null, $arr_zips = null, $type="alternate") {
  66. $this->_rate = $rate;
  67. $this->_country_area = $country_area;
  68. $this->_arr_states = $arr_states;
  69. $this->_arr_zips = $arr_zips;
  70. $this->_type = $type;
  71. $this->_shipping_taxed = null;
  72. }
  73. /**
  74. * Are we taxing the shipping as well
  75. *
  76. * @param unknown_type $shipping_taxed
  77. */
  78. function setShippingTaxed($shipping_taxed = 'false'){
  79. $this->_shipping_taxed = $shipping_taxed;
  80. }
  81. /**
  82. * Returns the XML Representation of tax rule
  83. *
  84. * @return XML representation of a tax rul
  85. * @access public
  86. */
  87. function getXML() {
  88. $str_xml = " <$this->_type-tax-rule>";
  89. $str_xml .= " <rate>$this->_rate</rate>";
  90. if(!empty($this->_shipping_taxed) && $this->_type == TAX_TABLE_DEFAULT)
  91. $str_xml .= " <shipping-taxed>$this->_shipping_taxed</shipping-taxed>";
  92. /**
  93. * Check for restrictions
  94. */
  95. if(!empty($this->_country_area) || !empty($this->_arr_states) || !empty($this->_arr_zips)){
  96. $str_xml .= "<tax-area>";
  97. /**
  98. * Country Area
  99. */
  100. if(!empty($this->_country_area))
  101. $str_xml .= "<us-country-area country-area=\"$this->_country_area\" />";
  102. /**
  103. * State Areas
  104. */
  105. if(!empty($this->_arr_states)) {
  106. foreach($this->_arr_states as $state){
  107. $str_xml .="<us-state-area><state>$state</state></us-state-area>";
  108. }
  109. }
  110. /**
  111. * Zip Areas
  112. */
  113. if(!empty($this->_arr_zips)) {
  114. foreach($this->_arr_zips as $zip){
  115. $str_xml .= "<us-zip-area><zip-pattern>$zip</zip-pattern></us-zip-area>";
  116. }
  117. }
  118. $str_xml .= "</tax-area>";
  119. }
  120. /**
  121. * close tax rule
  122. */
  123. $str_xml .="</$this->_type-tax-rule>";
  124. return $str_xml;
  125. }
  126. }
  127. ?>

Documentation generated on Mon, 04 Dec 2006 11:09:40 -0500 by phpDocumentor 1.3.0RC3