Source Code Documentation


pro\s2member-pro\includes\classes\gateways\ccbill\ccbill-utilities.inc.php


  1. <?php
  2. /**
  3. * ccBill® utilities.
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * This WordPress® plugin (s2Member Pro) is comprised of two parts:
  10. *
  11. * o (1) Its PHP code is licensed under the GPL license, as is WordPress®.
  12. * You should have received a copy of the GNU General Public License,
  13. * along with this software. In the main directory, see: /licensing/
  14. * If not, see: {@link http://www.gnu.org/licenses/}.
  15. *
  16. * o (2) All other parts of (s2Member Pro); including, but not limited to:
  17. * the CSS code, some JavaScript code, images, and design;
  18. * are licensed according to the license purchased.
  19. * See: {@link http://www.s2member.com/prices/}
  20. *
  21. * Unless you have our prior written consent, you must NOT directly or indirectly license,
  22. * sub-license, sell, resell, or provide for free; part (2) of the s2Member Pro Module;
  23. * or make an offer to do any of these things. All of these things are strictly
  24. * prohibited with part (2) of the s2Member Pro Module.
  25. *
  26. * Your purchase of s2Member Pro includes free lifetime upgrades via s2Member.com
  27. * (i.e. new features, bug fixes, updates, improvements); along with full access
  28. * to our video tutorial library: {@link http://www.s2member.com/videos/}
  29. *
  30. * @package s2Member\ccBill
  31. * @since 1.5
  32. */
  33. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  34. exit ("Do not access this file directly.");
  35.  
  36. if (!class_exists ("c_ws_plugin__s2member_pro_ccbill_utilities"))
  37. {
  38. /**
  39. * ccBill® utilities.
  40. *
  41. * @package s2Member\ccBill
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_ccbill_utilities
  45. {
  46. /**
  47. * Generates a ccBill® link.
  48. *
  49. * @package s2Member\ccBill
  50. * @since 1.5
  51. *
  52. * @param array $vars An array of variables to include in the ccBill® link.
  53. * @return str A full URL to the ccBill® Payment Gateway.
  54. *
  55. * @todo Optimize this routine with ``empty()`` and ``isset()``.
  56. * @todo Candidate for the use of ``ifsetor()``?
  57. */
  58. public static function ccbill_link_gen ($vars = FALSE)
  59. {
  60. $gateway = "https://bill.ccbill.com/jpost/signup.cgi";
  61.  
  62. $digest_vars = $vars["formPrice"] . $vars["formPeriod"]; // These are always required.
  63. $digest_vars .= $vars["formRecurringPrice"] . $vars["formRecurringPeriod"] . $vars["formRebills"];
  64. $digest_vars .= $vars["currencyCode"]; // Add the currency code to this too (always req).
  65.  
  66. $vars["formDigest"] = md5 ($digest_vars . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_salt_key"]);
  67.  
  68. return add_query_arg (urlencode_deep ($vars), $gateway); // ccBill® link.
  69. }
  70. /**
  71. * Converts currency code to a numeric code for ccBill®.
  72. *
  73. * @package s2Member\ccBill
  74. * @since 1.5
  75. *
  76. * @param str $currency_code Expects a 3 character Currency Code.
  77. * @return int|str A numeric string with a ccBill® Currency Number. Defaults to `840` *( i.e. `USD` )*.
  78. */
  79. public static function ccbill_currency_numr ($currency_code = FALSE)
  80. {
  81. $currency_code = strtoupper ($currency_code); // Force uppercase.
  82.  
  83. $currencies = array ("USD" => "840", "EUR" => "978", "AUD" => "036", "CAD" => "124", "GBP" => "826", "JPY" => "392");
  84.  
  85. return (!empty ($currencies[$currency_code])) ? $currencies[$currency_code] : $currencies["USD"];
  86. }
  87. /**
  88. * Converts Currency Number for ccBill® forms into a valid Currency Code.
  89. *
  90. * @package s2Member\ccBill
  91. * @since 1.5
  92. *
  93. * @param int|str $currency_numr Expects a valid ccBill® Currency Number, numeric.
  94. * @return str A 3 character Currency Code, for use with s2Member. Defaults to `USD` *( i.e. `840` )*.
  95. */
  96. public static function ccbill_currency_code ($currency_numr = FALSE)
  97. {
  98. $currencies = array ("840" => "USD", "978" => "EUR", "036" => "AUD", "124" => "CAD", "826" => "GBP", "392" => "JPY");
  99.  
  100. return (!empty ($currencies[$currency_numr])) ? $currencies[$currency_numr] : $currencies["840"];
  101. }
  102. /**
  103. * Calculates period in days for ccBill® forms.
  104. *
  105. * @package s2Member\ccBill
  106. * @since 1.5
  107. *
  108. * @param int|str $period Optional. A numeric Period that coincides with ``$term``.
  109. * @param str $term Optional. A Term that coincides with ``$period``.
  110. * @return int A "Period Term", in days. Defaults to `0`.
  111. */
  112. public static function ccbill_per_term_2_days ($period = FALSE, $term = FALSE)
  113. {
  114. if (is_numeric ($period) && !is_numeric ($term) && ($term = strtoupper ($term)))
  115. {
  116. $days = ($term === "D") ? 1 : $days;
  117. $days = ($term === "W") ? 7 : $days;
  118. $days = ($term === "M") ? 30 : $days;
  119. $days = ($term === "Y") ? 365 : $days;
  120. $days = ($term === "L") ? 365 : $days;
  121.  
  122. return (int)$period * (int)$days;
  123. }
  124. else
  125. return 0;
  126. }
  127. /**
  128. * Get ``$_POST`` or ``$_REQUEST`` vars from ccBill®.
  129. *
  130. * @package s2Member\ccBill
  131. * @since 1.5
  132. *
  133. * @return array|bool An array of verified ``$_POST`` or ``$_REQUEST`` variables, else false.
  134. *
  135. * @todo Continue optimizing this routine with ``empty()`` and ``isset()``.
  136. * @todo Candidate for the use of ``ifsetor()``?
  137. * @todo Update to use ``strcasecmp()``.
  138. */
  139. public static function ccbill_postvars ()
  140. {
  141. if ((isset ($_REQUEST["s2member_pro_ccbill_return"]) && strlen ($_REQUEST["s2member_pro_ccbill_return"])) || (isset ($_REQUEST["s2member_pro_ccbill_notify"]) && strlen ($_REQUEST["s2member_pro_ccbill_notify"])))
  142. {
  143. $postvars = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_REQUEST));
  144.  
  145. foreach ($postvars as $var => $value)
  146. if (preg_match ("/^s2member_/", $var))
  147. unset ($postvars[$var]);
  148.  
  149. $denial_digest_vars = $postvars["denialId"] . "0";
  150. $approval_digest_vars = $postvars["subscription_id"] . "1";
  151.  
  152. if ($postvars["responseDigest"] === md5 ($approval_digest_vars . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_salt_key"]))
  153. return $postvars;
  154.  
  155. else if ($postvars["responseDigest"] === md5 ($denial_digest_vars . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_salt_key"]))
  156. return $postvars;
  157.  
  158. else // Nope.
  159. return false;
  160. }
  161. else // Nope.
  162. return false;
  163. }
  164. }
  165. }
  166. ?>

pro\s2member-pro\includes\classes\gateways\ccbill\ccbill-utilities.inc.php

Source Code Documentation