Source Code Documentation


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


  1. <?php
  2. /**
  3. * Authorize.Net® Silent Post *( aka: IPN )* ( 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\AuthNet
  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_authnet_notify_in"))
  37. {
  38. /**
  39. * Authorize.Net® Silent Post *( aka: IPN )* ( inner processing routines ).
  40. *
  41. * @package s2Member\AuthNet
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_authnet_notify_in
  45. {
  46. /**
  47. * Handles Authorize.Net® IPN URL processing.
  48. *
  49. * @package s2Member\AuthNet
  50. * @since 1.5
  51. *
  52. * @attaches-to ``add_action("init");``
  53. *
  54. * @return null Or exits script execution after handling IPN processing.
  55. */
  56. public static function authnet_notify ()
  57. {
  58. global $current_site, $current_blog; /* For Multisite support. */
  59. /**/
  60. if (!empty ($_GET["s2member_pro_authnet_notify"]) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_authnet_api_login_id"])
  61. {
  62. @ignore_user_abort (true); /* Continue processing even if/when connection is broken by the sender. */
  63. /**/
  64. if (is_array ($authnet = c_ws_plugin__s2member_pro_authnet_utilities::authnet_postvars ()) && ($_authnet = $authnet))
  65. {
  66. $authnet["s2member_log"][] = "IPN received on: " . date ("D M j, Y g:i:s a T");
  67. $authnet["s2member_log"][] = "s2Member POST vars verified with Authorize.Net®.";
  68. /**/
  69. if ($authnet["x_subscription_id"] && $authnet["x_subscription_paynum"] && $authnet["x_response_code"] === "1")
  70. {
  71. if (($_authnet = c_ws_plugin__s2member_pro_authnet_utilities::authnet_parse_arb_desc ($authnet)) && ($authnet = $_authnet))
  72. {
  73. $authnet["s2member_log"][] = "Authorize.Net® transaction identified as ( `ARB / PAYMENT #" . $authnet["x_subscription_paynum"] . "` ).";
  74. $authnet["s2member_log"][] = "IPN reformulated. Piping through s2Member's core/standard PayPal® processor as `txn_type` ( `subscr_payment` ).";
  75. $authnet["s2member_log"][] = "Please check PayPal® IPN logs for further processing details.";
  76. /**/
  77. $processing = $processed = true;
  78. $ipn = array (); /* Reset. */
  79. /**/
  80. $ipn["txn_type"] = "subscr_payment";
  81. $ipn["subscr_id"] = $authnet["x_subscription_id"];
  82. $ipn["txn_id"] = $authnet["x_trans_id"];
  83. /**/
  84. $ipn["custom"] = $authnet["s2_custom"];
  85. /**/
  86. $ipn["mc_gross"] = number_format ($authnet["x_amount"], 2, ".", "");
  87. $ipn["mc_currency"] = strtoupper ("USD"); /* Auth.Net® uses USD. */
  88. $ipn["tax"] = number_format ($authnet["x_tax"], 2, ".", "");
  89. /**/
  90. $ipn["payer_email"] = $authnet["x_email"];
  91. $ipn["first_name"] = $authnet["x_first_name"];
  92. $ipn["last_name"] = $authnet["x_last_name"];
  93. /**/
  94. $ipn["option_name1"] = "Referencing Customer ID";
  95. $ipn["option_selection1"] = $authnet["x_subscription_id"];
  96. /**/
  97. $ipn["option_name2"] = "Customer IP Address";
  98. $ipn["option_selection2"] = null;
  99. /**/
  100. $ipn["item_number"] = $authnet["s2_invoice"];
  101. $ipn["item_name"] = $authnet["x_description"];
  102. /**/
  103. $ipn_q = "&s2member_paypal_proxy=authnet&s2member_paypal_proxy_use=pro-emails";
  104. $ipn_q .= "&s2member_paypal_proxy_verification=" . urlencode (c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen ());
  105. /**/
  106. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1" . $ipn_q), $ipn, array ("timeout" => 20));
  107. }
  108. else /* Otherwise, we don't have enough information to reforumalte this IPN response. An error must be generated. */
  109. {
  110. $authnet["s2member_log"][] = "Authorize.Net® transaction identified as ( `ARB / PAYMENT #" . $authnet["x_subscription_paynum"] . "` ).";
  111. $authnet["s2member_log"][] = "Ignoring this IPN. The transaction does NOT contain a valid reference value/desc.";
  112. }
  113. }
  114. /**/
  115. else if ($authnet["x_subscription_id"] && $authnet["x_subscription_paynum"] && preg_match ("/^(2|3)$/", $authnet["x_response_code"]))
  116. {
  117. if (($_authnet = c_ws_plugin__s2member_pro_authnet_utilities::authnet_parse_arb_desc ($authnet)) && ($authnet = $_authnet))
  118. {
  119. $authnet["s2member_log"][] = "Authorize.Net® transaction identified as ( `ARB / FAILED PAYMENT` ).";
  120. $authnet["s2member_log"][] = "s2Member does NOT respond to individual failed payment notifications.";
  121. $authnet["s2member_log"][] = "When multiple consecutive payments fail, s2Member is notified via ARB services.";
  122. $authnet["s2member_log"][] = "This does not require any action ( at the moment ) on the part of s2Member.";
  123. }
  124. else /* Otherwise, we don't have enough information to reforumalte this IPN response. An error must be generated. */
  125. {
  126. $authnet["s2member_log"][] = "Authorize.Net® transaction identified as ( `ARB / FAILED PAYMENT` ).";
  127. $authnet["s2member_log"][] = "Ignoring this IPN. The transaction does NOT contain a valid reference value/desc.";
  128. }
  129. }
  130. /**/
  131. else if (!$processed) /* If nothing was processed, here we add a message to the logs indicating the IPN was ignored. */
  132. $authnet["s2member_log"][] = "Ignoring this IPN. The transaction does NOT require any action on the part of s2Member.";
  133. }
  134. else /* Extensive log reporting here. This is an area where many site owners find trouble. Depending on server configuration; remote HTTPS connections may fail. */
  135. {
  136. $authnet["s2member_log"][] = "Unable to verify POST vars. This is most likely related to an invalid Authorize.Net® configuration. Please check: s2Member -> Authorize.Net® Options.";
  137. $authnet["s2member_log"][] = "If you're absolutely SURE that your Authorize.Net® 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 Authorize.Net® over an HTTPS connection.";
  138. $authnet["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.";
  139. $authnet["s2member_log"][] = var_export ($_REQUEST, true); /* Recording _POST + _GET vars for analysis and debugging. */
  140. }
  141. /*
  142. If debugging/logging is enabled; we need to append $authnet to the log file.
  143. Logging now supports Multisite Networking as well.
  144. */
  145. $logv = c_ws_plugin__s2member_utilities::ver_details ();
  146. $logm = c_ws_plugin__s2member_utilities::mem_details ();
  147. $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"];
  148. $log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4;
  149. $log2 = (is_multisite () && !is_main_site ()) ? "authnet-ipn-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "authnet-ipn.log";
  150. /**/
  151. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
  152. if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
  153. if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ())
  154. file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export ($authnet, true) . "\n\n", FILE_APPEND);
  155. /**/
  156. status_header (200); /* Send a 200 OK status header. */
  157. header ("Content-Type: text/plain; charset=utf-8"); /* Content-Type text/plain with UTF-8. */
  158. eval ('while (@ob_end_clean ());'); /* End/clean all output buffers that may or may not exist. */
  159. /**/
  160. exit (); /* Exit now. */
  161. }
  162. }
  163. }
  164. }
  165. ?>

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

Source Code Documentation