Source for file gButton.php

Documentation is available at gButton.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. * Returns Markup for Google Checkout Button
  31. *
  32. */
  33. class gButton {
  34. var $_gCart;
  35. var $_size;
  36. var $_style;
  37. var $_variant;
  38. var $_loc;
  39. /**
  40. * Builds Google Checkout Button Constructor
  41. *
  42. * @param unknown_type $gCart
  43. * @param unknown_type $size
  44. * @param unknown_type $style
  45. * @param unknown_type $variant
  46. * @return gButton
  47. */
  48. function gButton($gCart, $size = "LARGE", $style = "WHITE", $variant = "TEXT") {
  49. $this->_gCart = $gCart;
  50. $this->_size = $size;
  51. $this->_style = $style;
  52. $this->_variant = $variant;
  53. $this->_loc = "en_US";
  54. }
  55. ///////////////////////////////////////
  56. // Public Methods
  57. ///////////////////////////////////////
  58. /**
  59. * Returns HTML Form that Posts to cart to Google Checkout
  60. *
  61. */
  62. function getPostButton(){
  63. /**
  64. * Local Variables
  65. */
  66. $w;
  67. $h;
  68. $var = $this->_variant;
  69. $style = $this->_style;
  70. $loc = $this->_loc;
  71. $merchant_id = $this->_gCart->_mercant_id;
  72. $b64_cart = base64_encode($this->_gCart->getCart());
  73. $b64_signature= base64_encode($this->_gCart->getSignature($this->_gCart->getCart()));
  74. $domain = $GLOBALS['checkout_domain'];
  75. /**
  76. * Set Dimensions
  77. */
  78. $this->_setDimensions($this->_size, &$w, &$h);
  79. /**
  80. * Build HTML String
  81. */
  82. if(strtoupper($this->_variant) == "TEXT") {
  83. $str_html = "
  84. <!-- Google Checkout Button Post -->
  85. <form action=\"https://$domain/cws/v2/Merchant/$merchant_id/checkout\" method=\"post\">
  86. <input type=\"hidden\" name=\"cart\" value=\"$b64_cart\" />
  87. <input type=\"hidden\" name=\"signature\" value=\"$b64_signature\" />
  88. <input type=\"image\" name=\"Google Checkout\" alt=\"Fast checkout through Google\"
  89. src=\"https://$domain/buttons/checkout.gif?merchant_id=$merchant_id&w=$w&h=$h&style=$style&variant=$var&loc=$loc\"
  90. height=\"$h\" width=\"$w\" >
  91. </form>
  92. ";
  93. }
  94. else {
  95. $str_html = "
  96. <!-- Google Checkout Disabled Button Image -->
  97. <input type=\"image\" name=\"Google Checkout\" alt=\"Fast checkout through Google\"
  98. src=\"https://$domain/buttons/checkout.gif?merchant_id=$merchant_id&w=$w&h=$h&style=$style&variant=$var&loc=$loc\"
  99. height=\"$h\" width=\"$w\" >
  100. ";
  101. }
  102. return $str_html;
  103. }
  104. ////////////////////////////////////////
  105. // Private Methods
  106. ////////////////////////////////////////
  107. /**
  108. * Sets Dimensions of the button
  109. *
  110. * @param unknown_type $size
  111. * @param unknown_type $w
  112. * @param unknown_type $h
  113. */
  114. function _setDimensions($size, &$w, &$h) {
  115. switch (strtoupper($size)) {
  116. case "LARGE":
  117. $w = 180;
  118. $h = 46;
  119. break;
  120. case "MEDIUM":
  121. $w = 168;
  122. $h = 44;
  123. break;
  124. case "SMALL":
  125. $w = 160;
  126. $h = 43;
  127. break;
  128. default:
  129. $w = 180;
  130. $h = 46;
  131. }
  132. }
  133.  
  134. }
  135. ?>

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