Source Code Documentation


s2member-pro\includes\classes\gateways\authnet\authnet-arb.inc.php


  1. <?php
  2. /**
  3. * Authorize.Net® ARB.
  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_arb"))
  37. {
  38. /**
  39. * Authorize.Net® ARB.
  40. *
  41. * @package s2Member\AuthNet
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_authnet_arb
  45. {
  46. /**
  47. * Connect to and process ARB service information for Authorize.Net®.
  48. *
  49. * s2Member's Auto EOT System must be enabled for this to work properly.
  50. *
  51. * If you have a HUGE userbase, increase the max IPNs per process.
  52. * But NOTE, this runs ``$per_process`` *( per Blog )* on a Multisite Network.
  53. * To increase, use: ``add_filter ("ws_plugin__s2member_pro_arb_service_ipns_per_process");``.
  54. *
  55. * @package s2Member\AuthNet
  56. * @since 1.5
  57. *
  58. * @attaches-to ``add_action("ws_plugin__s2member_after_auto_eot_system");``
  59. *
  60. * @param array $vars Expects an array of defined variables to be passed in by the Action Hook.
  61. * @return null
  62. */
  63. public static function authnet_arb_service ($vars = FALSE)
  64. {
  65. global $wpdb; /* Need global DB obj. */
  66. global $current_site, $current_blog; /* For Multisite support. */
  67. /**/
  68. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_authnet_api_login_id"])
  69. {
  70. $scan_time = apply_filters ("ws_plugin__s2member_pro_arb_service_status_scan_time", strtotime ("-1 day"), get_defined_vars ());
  71. $per_process = apply_filters ("ws_plugin__s2member_pro_arb_service_ipns_per_process", $vars["per_process"], get_defined_vars ());
  72. /**/
  73. if (is_array ($objs = $wpdb->get_results ("SELECT `user_id` AS `ID` FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = '" . $wpdb->prefix . "s2member_subscr_gateway' AND `meta_value` = 'authnet' AND `user_id` NOT IN(SELECT `user_id` FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = '" . $wpdb->prefix . "s2member_last_status_scan' AND `meta_value` > '" . esc_sql ($scan_time) . "')")))
  74. {
  75. foreach ($objs as $obj) /* Run through all of the Paid Member IDs that originated their Subscription through the Authorize.Net® gateway. */
  76. {
  77. if (($user_id = $obj->ID) && ($counter = (int)$counter + 1)) /* Update counter. Only run through X records; given by $per_process. */
  78. {
  79. unset ($authnet, $subscr_id, $ipn_sv, $processing, $processed, $ipn, $ipn_q, $log4, $_log4, $log2, $logs_dir); /* Unset these. */
  80. /**/
  81. if (($authnet = array ("x_method" => "status")) && ($authnet["x_subscription_id"] = $subscr_id = get_user_option ("s2member_subscr_id", $user_id)))
  82. {
  83. if (!get_user_option ("s2member_auto_eot_time", $user_id) && is_array ($ipn_sv = c_ws_plugin__s2member_utils_users::get_user_ipn_signup_vars (false, $subscr_id)))
  84. {
  85. if (($authnet = c_ws_plugin__s2member_pro_authnet_utilities::authnet_arb_response ($authnet)) && empty ($authnet["__error"]) && $authnet["subscription_status"] && is_array ($authnet["arb_ipn_signup_vars"] = $ipn_sv))
  86. {
  87. if (preg_match ("/^expired$/i", $authnet["subscription_status"])) /* Expired? */
  88. {
  89. $authnet["s2member_log"][] = "Authorize.Net® ARB/IPN processed on: " . date ("D M j, Y g:i:s a T");
  90. /**/
  91. $authnet["s2member_log"][] = "Authorize.Net® transaction identified as ( `SUBSCRIPTION EXPIRATION` ).";
  92. $authnet["s2member_log"][] = "IPN reformulated. Piping through s2Member's core/standard PayPal® processor as `txn_type` ( `subscr_eot` ).";
  93. $authnet["s2member_log"][] = "Please check PayPal® IPN logs for further processing details.";
  94. /**/
  95. $processing = $processed = true;
  96. $ipn = array (); /* Reset. */
  97. /**/
  98. $ipn["txn_type"] = "subscr_eot";
  99. $ipn["subscr_id"] = $authnet["arb_ipn_signup_vars"]["subscr_id"];
  100. /**/
  101. $ipn["custom"] = $authnet["arb_ipn_signup_vars"]["custom"];
  102. /**/
  103. $ipn["period1"] = $authnet["arb_ipn_signup_vars"]["period1"];
  104. $ipn["period3"] = $authnet["arb_ipn_signup_vars"]["period3"];
  105. /**/
  106. $ipn["payer_email"] = $authnet["arb_ipn_signup_vars"]["payer_email"];
  107. $ipn["first_name"] = $authnet["arb_ipn_signup_vars"]["first_name"];
  108. $ipn["last_name"] = $authnet["arb_ipn_signup_vars"]["last_name"];
  109. /**/
  110. $ipn["option_name1"] = $authnet["arb_ipn_signup_vars"]["option_name1"];
  111. $ipn["option_selection1"] = $authnet["arb_ipn_signup_vars"]["option_selection1"];
  112. /**/
  113. $ipn["option_name2"] = $authnet["arb_ipn_signup_vars"]["option_name2"];
  114. $ipn["option_selection2"] = $authnet["arb_ipn_signup_vars"]["option_selection2"];
  115. /**/
  116. $ipn["item_number"] = $authnet["arb_ipn_signup_vars"]["item_number"];
  117. $ipn["item_name"] = $authnet["arb_ipn_signup_vars"]["item_name"];
  118. /**/
  119. $ipn_q = "&s2member_paypal_proxy=authnet&s2member_paypal_proxy_use=pro-emails";
  120. $ipn_q .= "&s2member_paypal_proxy_verification=" . urlencode (c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen ());
  121. /**/
  122. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1" . $ipn_q), $ipn, array ("timeout" => 20));
  123. }
  124. /**/
  125. else if (preg_match ("/^(suspended|canceled|terminated)$/i", $authnet["subscription_status"]))
  126. {
  127. $authnet["s2member_log"][] = "Authorize.Net® ARB/IPN processed on: " . date ("D M j, Y g:i:s a T");
  128. /**/
  129. $authnet["s2member_log"][] = "Authorize.Net® transaction identified as ( `SUBSCRIPTION " . strtoupper ($authnet["subscription_status"]) . "` ).";
  130. $authnet["s2member_log"][] = "IPN reformulated. Piping through s2Member's core/standard PayPal® processor as `txn_type` ( `subscr_cancel` ).";
  131. $authnet["s2member_log"][] = "Please check PayPal® IPN logs for further processing details.";
  132. /**/
  133. $processing = $processed = true;
  134. $ipn = array (); /* Reset. */
  135. /**/
  136. $ipn["txn_type"] = "subscr_cancel";
  137. $ipn["subscr_id"] = $authnet["arb_ipn_signup_vars"]["subscr_id"];
  138. /**/
  139. $ipn["custom"] = $authnet["arb_ipn_signup_vars"]["custom"];
  140. /**/
  141. $ipn["period1"] = $authnet["arb_ipn_signup_vars"]["period1"];
  142. $ipn["period3"] = $authnet["arb_ipn_signup_vars"]["period3"];
  143. /**/
  144. $ipn["payer_email"] = $authnet["arb_ipn_signup_vars"]["payer_email"];
  145. $ipn["first_name"] = $authnet["arb_ipn_signup_vars"]["first_name"];
  146. $ipn["last_name"] = $authnet["arb_ipn_signup_vars"]["last_name"];
  147. /**/
  148. $ipn["option_name1"] = $authnet["arb_ipn_signup_vars"]["option_name1"];
  149. $ipn["option_selection1"] = $authnet["arb_ipn_signup_vars"]["option_selection1"];
  150. /**/
  151. $ipn["option_name2"] = $authnet["arb_ipn_signup_vars"]["option_name2"];
  152. $ipn["option_selection2"] = $authnet["arb_ipn_signup_vars"]["option_selection2"];
  153. /**/
  154. $ipn["item_number"] = $authnet["arb_ipn_signup_vars"]["item_number"];
  155. $ipn["item_name"] = $authnet["arb_ipn_signup_vars"]["item_name"];
  156. /**/
  157. $ipn_q = "&s2member_paypal_proxy=authnet&s2member_paypal_proxy_use=pro-emails";
  158. $ipn_q .= "&s2member_paypal_proxy_verification=" . urlencode (c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen ());
  159. /**/
  160. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1" . $ipn_q), $ipn, array ("timeout" => 20));
  161. }
  162. /**/
  163. else if (!$processed) /* If nothing was processed, here we add a message to the logs indicating the status; which is being ignored by s2Member. */
  164. $authnet["s2member_log"][] = "Ignoring this ARB/Status ( `" . $authnet["subscription_status"] . "` ). It does NOT require any action on the part of s2Member.";
  165. /**/
  166. $logv = c_ws_plugin__s2member_utilities::ver_details ();
  167. $logm = c_ws_plugin__s2member_utilities::mem_details ();
  168. $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"];
  169. $log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4;
  170. $log2 = (is_multisite () && !is_main_site ()) ? "authnet-arb-ipn-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "authnet-arb-ipn.log";
  171. /**/
  172. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
  173. if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
  174. if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ())
  175. file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export ($authnet, true) . "\n\n", FILE_APPEND);
  176. }
  177. }
  178. }
  179. /**/
  180. update_user_option ($user_id, "s2member_last_status_scan", time ());
  181. /**/
  182. if ($counter >= $per_process) /* Only this many. */
  183. break; /* Break the loop now. */
  184. }
  185. }
  186. }
  187. }
  188. /**/
  189. return; /* Return for uniformity. */
  190. }
  191. }
  192. }
  193. ?>

s2member-pro\includes\classes\gateways\authnet\authnet-arb.inc.php

Source Code Documentation