Source Code Documentation


pro\s2member-pro\includes\classes\gateways\paypal\paypal-payflow-poll.inc.php


  1. <?php
  2. /**
  3. * Payflow® Poll.
  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\PayPal
  31. * @since 120514
  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_paypal_payflow_poll"))
  37. {
  38. /**
  39. * Payflow® Poll.
  40. *
  41. * @package s2Member\PayPal
  42. * @since 120514
  43. */
  44. class c_ws_plugin__s2member_pro_paypal_payflow_poll
  45. {
  46. /**
  47. * Connect to and process cancellations/refunds/chargebacks/etc via Payflow®.
  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_payflow_ipns_per_process");``.
  54. *
  55. * @package s2Member\PayPal
  56. * @since 120514
  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 payflow_service($vars = FALSE)
  64. {
  65. global $wpdb; // Need global DB obj.
  66. global /* For Multisite support. */ $current_site, $current_blog;
  67.  
  68. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_payflow_api_username"])
  69. {
  70. $scan_time = apply_filters("ws_plugin__s2member_pro_payflow_status_scan_time", strtotime("-1 day"), get_defined_vars());
  71. $per_process = apply_filters("ws_plugin__s2member_pro_payflow_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` = 'paypal' 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 PayPal® 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 /* Unset these. */($paypal, $subscr_id, $ipn_sv, $processing, $processed, $ipn, $log4, $_log4, $log2, $logs_dir);
  80.  
  81. if(($subscr_id = get_user_option("s2member_subscr_id", $user_id)) && !get_user_option("s2member_auto_eot_time", $user_id))
  82. {
  83. if(is_array($ipn_sv = c_ws_plugin__s2member_utils_users::get_user_ipn_signup_vars(false, $subscr_id)) #
  84. && ($paypal = c_ws_plugin__s2member_pro_paypal_utilities::payflow_get_profile($subscr_id)) && is_array($paypal["ipn_signup_vars"] = $ipn_sv))
  85. {
  86. if(preg_match("/expired/i", $paypal["STATUS"]) /* Expired? */)
  87. {
  88. $paypal["s2member_log"][] = "Payflow® IPN via polling, processed on: ".date("D M j, Y g:i:s a T");
  89.  
  90. $paypal["s2member_log"][] = "Payflow® transaction identified as ( `SUBSCRIPTION EXPIRATION` ).";
  91. $paypal["s2member_log"][] = "IPN reformulated. Piping through s2Member's core/standard PayPal® processor as `txn_type` ( `subscr_eot` ).";
  92. $paypal["s2member_log"][] = "Please check PayPal® IPN logs for further processing details.";
  93.  
  94. $processing = $processed = true;
  95. $ipn = array(); // Reset.
  96.  
  97. $ipn["txn_type"] = "subscr_eot";
  98. $ipn["subscr_id"] = $paypal["ipn_signup_vars"]["subscr_id"];
  99.  
  100. $ipn["custom"] = $paypal["ipn_signup_vars"]["custom"];
  101.  
  102. $ipn["period1"] = $paypal["ipn_signup_vars"]["period1"];
  103. $ipn["period3"] = $paypal["ipn_signup_vars"]["period3"];
  104.  
  105. $ipn["payer_email"] = $paypal["ipn_signup_vars"]["payer_email"];
  106. $ipn["first_name"] = $paypal["ipn_signup_vars"]["first_name"];
  107. $ipn["last_name"] = $paypal["ipn_signup_vars"]["last_name"];
  108.  
  109. $ipn["option_name1"] = $paypal["ipn_signup_vars"]["option_name1"];
  110. $ipn["option_selection1"] = $paypal["ipn_signup_vars"]["option_selection1"];
  111.  
  112. $ipn["option_name2"] = $paypal["ipn_signup_vars"]["option_name2"];
  113. $ipn["option_selection2"] = $paypal["ipn_signup_vars"]["option_selection2"];
  114.  
  115. $ipn["item_number"] = $paypal["ipn_signup_vars"]["item_number"];
  116. $ipn["item_name"] = $paypal["ipn_signup_vars"]["item_name"];
  117.  
  118. $ipn["s2member_paypal_proxy"] = "paypal";
  119. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  120. $ipn["s2member_paypal_proxy_verification"] = 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, array("timeout" => 20));
  123. }
  124.  
  125. else if(preg_match("/(suspended|canceled|terminated|deactivated)/i", $paypal["STATUS"]))
  126. {
  127. $paypal["s2member_log"][] = "Payflow® IPN via polling, processed on: ".date("D M j, Y g:i:s a T");
  128.  
  129. $paypal["s2member_log"][] = "Payflow® transaction identified as ( `SUBSCRIPTION ".strtoupper($paypal["STATUS"])."` ).";
  130. $paypal["s2member_log"][] = "IPN reformulated. Piping through s2Member's core/standard PayPal® processor as `txn_type` ( `subscr_cancel` ).";
  131. $paypal["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"] = $paypal["ipn_signup_vars"]["subscr_id"];
  138.  
  139. $ipn["custom"] = $paypal["ipn_signup_vars"]["custom"];
  140.  
  141. $ipn["period1"] = $paypal["ipn_signup_vars"]["period1"];
  142. $ipn["period3"] = $paypal["ipn_signup_vars"]["period3"];
  143.  
  144. $ipn["payer_email"] = $paypal["ipn_signup_vars"]["payer_email"];
  145. $ipn["first_name"] = $paypal["ipn_signup_vars"]["first_name"];
  146. $ipn["last_name"] = $paypal["ipn_signup_vars"]["last_name"];
  147.  
  148. $ipn["option_name1"] = $paypal["ipn_signup_vars"]["option_name1"];
  149. $ipn["option_selection1"] = $paypal["ipn_signup_vars"]["option_selection1"];
  150.  
  151. $ipn["option_name2"] = $paypal["ipn_signup_vars"]["option_name2"];
  152. $ipn["option_selection2"] = $paypal["ipn_signup_vars"]["option_selection2"];
  153.  
  154. $ipn["item_number"] = $paypal["ipn_signup_vars"]["item_number"];
  155. $ipn["item_name"] = $paypal["ipn_signup_vars"]["item_name"];
  156.  
  157. $ipn["s2member_paypal_proxy"] = "paypal";
  158. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  159. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  160.  
  161. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20));
  162. }
  163.  
  164. else if(!$processed) // If nothing was processed, here we add a message to the logs indicating the status; which is being ignored.
  165. $paypal["s2member_log"][] = "Ignoring this status ( `".$paypal["STATUS"]."` ). It does NOT require any action on the part of s2Member.";
  166.  
  167. $logt = c_ws_plugin__s2member_utilities::time_details ();
  168. $logv = c_ws_plugin__s2member_utilities::ver_details();
  169. $logm = c_ws_plugin__s2member_utilities::mem_details();
  170. $log4 = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]."\nUser-Agent: ".$_SERVER["HTTP_USER_AGENT"];
  171. $log4 = (is_multisite() && !is_main_site()) ? ($_log4 = $current_blog->domain.$current_blog->path)."\n".$log4 : $log4;
  172. $log2 = (is_multisite() && !is_main_site()) ? "paypal-payflow-ipn-4-".trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-").".log" : "paypal-payflow-ipn.log";
  173.  
  174. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
  175. if(is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
  176. if(is_writable($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files())
  177. file_put_contents($logs_dir."/".$log2,
  178. "LOG ENTRY: ".$logt . "\n" . $logv."\n".$logm."\n".$log4."\n".
  179. c_ws_plugin__s2member_utils_logs::conceal_private_info(var_export($paypal, true))."\n\n",
  180. FILE_APPEND);
  181. }
  182. }
  183.  
  184. update_user_option($user_id, "s2member_last_status_scan", time());
  185.  
  186. if($counter >= $per_process) // Only this many.
  187. break; // Break the loop now.
  188. }
  189. }
  190. }
  191. }
  192.  
  193. return /* Return for uniformity. */;
  194. }
  195. }
  196. }
  197. ?>

pro\s2member-pro\includes\classes\gateways\paypal\paypal-payflow-poll.inc.php

Source Code Documentation