Source Code Documentation


pro\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 /* For Multisite support. */ $current_site, $current_blog;
  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["s2member_paypal_proxy"] = "ccbill";
  102. $ipn["s2member_paypal_proxy_use"] = "standard-emails";
  103. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  104.  
  105. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20));
  106. }
  107.  
  108. else if (!$ccbill["denialId"] && $ccbill["subscription_id"] && $ccbill["recurringPeriod"])
  109. {
  110. $ccbill["s2member_log"][] = "ccBill® transaction identified as ( `RECURRING/SUBSCRIPTION` ).";
  111. $ccbill["s2member_log"][] = "IPN reformulated. Piping through s2Member's core/standard PayPal® processor as `txn_type` ( `subscr_signup` ).";
  112. $ccbill["s2member_log"][] = "Please check PayPal® IPN logs for further processing details.";
  113.  
  114. $processing = $processed = true;
  115. $ipn = array (); // Reset.
  116.  
  117. $ipn["txn_type"] = "subscr_signup";
  118. $ipn["subscr_id"] = $ccbill["subscription_id"];
  119. $ipn["recurring"] = "1"; // Yes, recurring.
  120.  
  121. $ipn["txn_id"] = $ccbill["subscription_id"];
  122.  
  123. $ipn["custom"] = $ccbill["s2_custom"];
  124.  
  125. $ipn["period1"] = $ccbill["s2_p1"];
  126. $ipn["period3"] = $ccbill["s2_p3"];
  127.  
  128. $ipn["mc_amount1"] = number_format ($ccbill["initialPrice"], 2, ".", "");
  129. $ipn["mc_amount3"] = number_format ($ccbill["recurringPrice"], 2, ".", "");
  130.  
  131. $ipn["mc_gross"] = (preg_match ("/^[1-9]/", $ipn["period1"])) ? $ipn["mc_amount1"] : $ipn["mc_amount3"];
  132.  
  133. $ipn["mc_currency"] = c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_currency_code ($ccbill["currencyCode"]);
  134. $ipn["tax"] = number_format ("0.00", 2, ".", "");
  135.  
  136. $ipn["payer_email"] = $ccbill["email"];
  137. $ipn["first_name"] = $ccbill["customer_fname"];
  138. $ipn["last_name"] = $ccbill["customer_lname"];
  139.  
  140. $ipn["option_name1"] = ($ccbill["s2_referencing"]) ? "Referencing Customer ID" : "Originating Domain";
  141. $ipn["option_selection1"] = ($ccbill["s2_referencing"]) ? $ccbill["s2_referencing"] : $_SERVER["HTTP_HOST"];
  142.  
  143. $ipn["option_name2"] = "Customer IP Address";
  144. $ipn["option_selection2"] = $ccbill["s2_customer_ip"];
  145.  
  146. $ipn["item_number"] = $ccbill["s2_invoice"];
  147. $ipn["item_name"] = $ccbill["s2_desc"];
  148.  
  149. $ipn["s2member_paypal_proxy"] = "ccbill";
  150. $ipn["s2member_paypal_proxy_use"] = "standard-emails";
  151. $ipn["s2member_paypal_proxy_use"] .= ($ipn["mc_gross"] > 0) ? ",subscr-signup-as-subscr-payment" : "";
  152. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  153.  
  154. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20));
  155. }
  156.  
  157. else if (!$processed) // If nothing was processed, here we add a message to the logs indicating the IPN was ignored.
  158. $ccbill["s2member_log"][] = "Ignoring this IPN request. The transaction does NOT require any action on the part of s2Member.";
  159. }
  160. else // Extensive log reporting here. This is an area where many site owners find trouble. Depending on server configuration; remote HTTPS connections may fail.
  161. {
  162. $ccbill["s2member_log"][] = "Unable to verify POST vars. This is most likely related to an invalid ccBill® configuration. Please check: s2Member -› ccBill® Options.";
  163. $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.";
  164. $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.";
  165. $ccbill["s2member_log"][] = var_export ($_REQUEST, true); // Recording _POST + _GET vars for analysis and debugging.
  166. }
  167. /*
  168. If debugging/logging is enabled; we need to append $ccbill to the log file.
  169. Logging now supports Multisite Networking as well.
  170. */
  171. $logt = c_ws_plugin__s2member_utilities::time_details ();
  172. $logv = c_ws_plugin__s2member_utilities::ver_details ();
  173. $logm = c_ws_plugin__s2member_utilities::mem_details ();
  174. $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"];
  175. $log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4;
  176. $log2 = (is_multisite () && !is_main_site ()) ? "ccbill-ipn-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "ccbill-ipn.log";
  177.  
  178. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
  179. if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
  180. if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ())
  181. file_put_contents ($logs_dir . "/" . $log2,
  182. "LOG ENTRY: ".$logt . "\n" . $logv . "\n" . $logm . "\n" . $log4 . "\n" .
  183. c_ws_plugin__s2member_utils_logs::conceal_private_info(var_export ($ccbill, true)) . "\n\n",
  184. FILE_APPEND);
  185.  
  186. status_header (200); // Send a 200 OK status header.
  187. header ("Content-Type: text/plain; charset=UTF-8"); // Content-Type text/plain with UTF-8.
  188. while (@ob_end_clean ()); // Clean any existing output buffers.
  189.  
  190. exit (); // Exit now.
  191. }
  192. }
  193. }
  194. }
  195. ?>

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

Source Code Documentation