Source Code Documentation


s2member-pro\includes\classes\gateways\ccbill\ccbill-notify-in.inc.php


  1. <?php
  2. /**
  3. * ccBill® IPN Handler ( inner processing routines ).
  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_notify_in"))
  37. {
  38. /**
  39. * ccBill® IPN Handler ( inner processing routines ).
  40. *
  41. * @package s2Member\ccBill
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_ccbill_notify_in
  45. {
  46. /**
  47. * Handles ccBill® IPN URL processing.
  48. *
  49. * @package s2Member\ccBill
  50. * @since 1.5
  51. *
  52. * @attaches-to ``add_action("init");``
  53. *
  54. * @return null Or exits script execution after handling the Notification.
  55. */
  56. public static function ccbill_notify ()
  57. {
  58. global $current_site, $current_blog; /* For Multisite support. */
  59. /**/
  60. if (isset ($_GET["s2member_pro_ccbill_notify"]) && strlen ($_GET["s2member_pro_ccbill_notify"]) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_client_id"])
  61. {
  62. @ignore_user_abort (true); /* Continue processing even if/when connection is broken by the sender. */
  63. /**/
  64. if (is_array ($ccbill = c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_postvars ()) && ($_ccbill = $ccbill))
  65. {
  66. $ccbill["s2member_log"][] = "IPN received on: " . date ("D M j, Y g:i:s a T");
  67. $ccbill["s2member_log"][] = "s2Member POST vars verified with ccBill®.";
  68. /**/
  69. if (!$ccbill["denialId"] && $ccbill["subscription_id"] && !$ccbill["recurringPeriod"])
  70. {
  71. $ccbill["s2member_log"][] = "ccBill® transaction identified as ( `NON-RECURRING/BUY-NOW` ).";
  72. $ccbill["s2member_log"][] = "IPN reformulated. Piping through s2Member's core/standard PayPal® processor as `txn_type` ( `web_accept` ).";
  73. $ccbill["s2member_log"][] = "Please check PayPal® IPN logs for further processing details.";
  74. /**/
  75. $processing = $processed = true;
  76. $ipn = array (); /* Reset. */
  77. /**/
  78. $ipn["txn_type"] = "web_accept";
  79. /**/
  80. $ipn["txn_id"] = $ccbill["subscription_id"];
  81. /**/
  82. $ipn["custom"] = $ccbill["s2_custom"];
  83. /**/
  84. $ipn["mc_gross"] = number_format ($ccbill["initialPrice"], 2, ".", "");
  85. $ipn["mc_currency"] = c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_currency_code ($ccbill["currencyCode"]);
  86. $ipn["tax"] = number_format ("0.00", 2, ".", "");
  87. /**/
  88. $ipn["payer_email"] = $ccbill["email"];
  89. $ipn["first_name"] = $ccbill["customer_fname"];
  90. $ipn["last_name"] = $ccbill["customer_lname"];
  91. /**/
  92. $ipn["option_name1"] = ($ccbill["s2_referencing"]) ? "Referencing Customer ID" : "Originating Domain";
  93. $ipn["option_selection1"] = ($ccbill["s2_referencing"]) ? $ccbill["s2_referencing"] : $_SERVER["HTTP_HOST"];
  94. /**/
  95. $ipn["option_name2"] = "Customer IP Address";
  96. $ipn["option_selection2"] = $ccbill["s2_customer_ip"];
  97. /**/
  98. $ipn["item_number"] = $ccbill["s2_invoice"];
  99. $ipn["item_name"] = $ccbill["s2_desc"];
  100. /**/
  101. $ipn_q = "&s2member_paypal_proxy=ccbill&s2member_paypal_proxy_use=standard-emails";
  102. $ipn_q .= "&s2member_paypal_proxy_verification=" . urlencode (c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen ());
  103. /**/
  104. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1" . $ipn_q), $ipn, array ("timeout" => 20));
  105. }
  106. /**/
  107. else if (!$ccbill["denialId"] && $ccbill["subscription_id"] && $ccbill["recurringPeriod"])
  108. {
  109. $ccbill["s2member_log"][] = "ccBill® transaction identified as ( `RECURRING/SUBSCRIPTION` ).";
  110. $ccbill["s2member_log"][] = "IPN reformulated. Piping through s2Member's core/standard PayPal® processor as `txn_type` ( `subscr_signup` ).";
  111. $ccbill["s2member_log"][] = "Please check PayPal® IPN logs for further processing details.";
  112. /**/
  113. $processing = $processed = true;
  114. $ipn = array (); /* Reset. */
  115. /**/
  116. $ipn["txn_type"] = "subscr_signup";
  117. $ipn["subscr_id"] = $ccbill["subscription_id"];
  118. $ipn["recurring"] = "1"; /* Yes, recurring. */
  119. /**/
  120. $ipn["txn_id"] = $ccbill["subscription_id"];
  121. /**/
  122. $ipn["custom"] = $ccbill["s2_custom"];
  123. /**/
  124. $ipn["period1"] = $ccbill["s2_p1"];
  125. $ipn["period3"] = $ccbill["s2_p3"];
  126. /**/
  127. $ipn["mc_amount1"] = number_format ($ccbill["initialPrice"], 2, ".", "");
  128. $ipn["mc_amount3"] = number_format ($ccbill["recurringPrice"], 2, ".", "");
  129. /**/
  130. $ipn["mc_gross"] = (preg_match ("/^[1-9]/", $ipn["period1"])) ? $ipn["mc_amount1"] : $ipn["mc_amount3"];
  131. /**/
  132. $ipn["mc_currency"] = c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_currency_code ($ccbill["currencyCode"]);
  133. $ipn["tax"] = number_format ("0.00", 2, ".", "");
  134. /**/
  135. $ipn["payer_email"] = $ccbill["email"];
  136. $ipn["first_name"] = $ccbill["customer_fname"];
  137. $ipn["last_name"] = $ccbill["customer_lname"];
  138. /**/
  139. $ipn["option_name1"] = ($ccbill["s2_referencing"]) ? "Referencing Customer ID" : "Originating Domain";
  140. $ipn["option_selection1"] = ($ccbill["s2_referencing"]) ? $ccbill["s2_referencing"] : $_SERVER["HTTP_HOST"];
  141. /**/
  142. $ipn["option_name2"] = "Customer IP Address";
  143. $ipn["option_selection2"] = $ccbill["s2_customer_ip"];
  144. /**/
  145. $ipn["item_number"] = $ccbill["s2_invoice"];
  146. $ipn["item_name"] = $ccbill["s2_desc"];
  147. /**/
  148. $ipn_q = "&s2member_paypal_proxy=ccbill&s2member_paypal_proxy_use=standard-emails";
  149. $ipn_q .= ($ipn["mc_gross"] > 0) ? ",subscr-signup-as-subscr-payment" : ""; /* Use as first payment? */
  150. $ipn_q .= "&s2member_paypal_proxy_verification=" . urlencode (c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen ());
  151. /**/
  152. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1" . $ipn_q), $ipn, array ("timeout" => 20));
  153. }
  154. /**/
  155. else if (!$processed) /* If nothing was processed, here we add a message to the logs indicating the IPN was ignored. */
  156. $ccbill["s2member_log"][] = "Ignoring this IPN request. The transaction does NOT require any action on the part of s2Member.";
  157. }
  158. else /* Extensive log reporting here. This is an area where many site owners find trouble. Depending on server configuration; remote HTTPS connections may fail. */
  159. {
  160. $ccbill["s2member_log"][] = "Unable to verify POST vars. This is most likely related to an invalid ccBill® configuration. Please check: s2Member -> ccBill® Options.";
  161. $ccbill["s2member_log"][] = "If you're absolutely SURE that your ccBill® configuration is valid, you may want to run some tests on your server, just to be sure \$_POST variables are populated, and that your server is able to connect to ccBill® over an HTTPS connection.";
  162. $ccbill["s2member_log"][] = "s2Member uses the WP_Http class for remote connections; which will try to use cURL first, and then fall back on the FOPEN method when cURL is not available. On a Windows® server, you may have to disable your cURL extension. Instead, set allow_url_fopen = yes in your php.ini file. The cURL extension (usually) does NOT support SSL connections on a Windows® server.";
  163. $ccbill["s2member_log"][] = var_export ($_REQUEST, true); /* Recording _POST + _GET vars for analysis and debugging. */
  164. }
  165. /*
  166. If debugging/logging is enabled; we need to append $ccbill to the log file.
  167. Logging now supports Multisite Networking as well.
  168. */
  169. $logv = c_ws_plugin__s2member_utilities::ver_details ();
  170. $logm = c_ws_plugin__s2member_utilities::mem_details ();
  171. $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"];
  172. $log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4;
  173. $log2 = (is_multisite () && !is_main_site ()) ? "ccbill-ipn-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "ccbill-ipn.log";
  174. /**/
  175. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
  176. if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
  177. if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ())
  178. file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export ($ccbill, true) . "\n\n", FILE_APPEND);
  179. /**/
  180. status_header (200); /* Send a 200 OK status header. */
  181. header ("Content-Type: text/plain; charset=utf-8"); /* Content-Type text/plain with UTF-8. */
  182. eval ('while (@ob_end_clean ());'); /* End/clean all output buffers that may or may not exist. */
  183. /**/
  184. exit (); /* Exit now. */
  185. }
  186. }
  187. }
  188. }
  189. ?>

s2member-pro\includes\classes\gateways\ccbill\ccbill-notify-in.inc.php

Source Code Documentation