Source Code Documentation


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 $current_site, $current_blog; /* For Multisite support. */
  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, $ipn_q, $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_q = "&s2member_paypal_proxy=paypal&s2member_paypal_proxy_use=pro-emails";
  119. $ipn_q .= "&s2member_paypal_proxy_verification=".urlencode(c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen());
  120. /**/
  121. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1".$ipn_q), $ipn, array("timeout" => 20));
  122. }
  123. /**/
  124. else if(preg_match("/(suspended|canceled|terminated|deactivated)/i", $paypal["STATUS"]))
  125. {
  126. $paypal["s2member_log"][] = "Payflow® IPN via polling, processed on: ".date("D M j, Y g:i:s a T");
  127. /**/
  128. $paypal["s2member_log"][] = "Payflow® transaction identified as ( `SUBSCRIPTION ".strtoupper($paypal["STATUS"])."` ).";
  129. $paypal["s2member_log"][] = "IPN reformulated. Piping through s2Member's core/standard PayPal® processor as `txn_type` ( `subscr_cancel` ).";
  130. $paypal["s2member_log"][] = "Please check PayPal® IPN logs for further processing details.";
  131. /**/
  132. $processing = $processed = true;
  133. $ipn = array(); /* Reset. */
  134. /**/
  135. $ipn["txn_type"] = "subscr_cancel";
  136. $ipn["subscr_id"] = $paypal["ipn_signup_vars"]["subscr_id"];
  137. /**/
  138. $ipn["custom"] = $paypal["ipn_signup_vars"]["custom"];
  139. /**/
  140. $ipn["period1"] = $paypal["ipn_signup_vars"]["period1"];
  141. $ipn["period3"] = $paypal["ipn_signup_vars"]["period3"];
  142. /**/
  143. $ipn["payer_email"] = $paypal["ipn_signup_vars"]["payer_email"];
  144. $ipn["first_name"] = $paypal["ipn_signup_vars"]["first_name"];
  145. $ipn["last_name"] = $paypal["ipn_signup_vars"]["last_name"];
  146. /**/
  147. $ipn["option_name1"] = $paypal["ipn_signup_vars"]["option_name1"];
  148. $ipn["option_selection1"] = $paypal["ipn_signup_vars"]["option_selection1"];
  149. /**/
  150. $ipn["option_name2"] = $paypal["ipn_signup_vars"]["option_name2"];
  151. $ipn["option_selection2"] = $paypal["ipn_signup_vars"]["option_selection2"];
  152. /**/
  153. $ipn["item_number"] = $paypal["ipn_signup_vars"]["item_number"];
  154. $ipn["item_name"] = $paypal["ipn_signup_vars"]["item_name"];
  155. /**/
  156. $ipn_q = "&s2member_paypal_proxy=paypal&s2member_paypal_proxy_use=pro-emails";
  157. $ipn_q .= "&s2member_paypal_proxy_verification=".urlencode(c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen());
  158. /**/
  159. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1".$ipn_q), $ipn, array("timeout" => 20));
  160. }
  161. /**/
  162. else if(!$processed) /* If nothing was processed, here we add a message to the logs indicating the status; which is being ignored. */
  163. $paypal["s2member_log"][] = "Ignoring this status ( `".$paypal["STATUS"]."` ). It does NOT require any action on the part of s2Member.";
  164. /**/
  165. $logv = c_ws_plugin__s2member_utilities::ver_details();
  166. $logm = c_ws_plugin__s2member_utilities::mem_details();
  167. $log4 = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]."\nUser-Agent: ".$_SERVER["HTTP_USER_AGENT"];
  168. $log4 = (is_multisite() && !is_main_site()) ? ($_log4 = $current_blog->domain.$current_blog->path)."\n".$log4 : $log4;
  169. $log2 = (is_multisite() && !is_main_site()) ? "paypal-payflow-ipn-4-".trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-").".log" : "paypal-payflow-ipn.log";
  170. /**/
  171. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
  172. if(is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
  173. if(is_writable($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files())
  174. file_put_contents($logs_dir."/".$log2, $logv."\n".$logm."\n".$log4."\n".var_export($paypal, true)."\n\n", FILE_APPEND);
  175. }
  176. }
  177. /**/
  178. update_user_option($user_id, "s2member_last_status_scan", time());
  179. /**/
  180. if($counter >= $per_process) /* Only this many. */
  181. break; /* Break the loop now. */
  182. }
  183. }
  184. }
  185. }
  186. /**/
  187. return; /* Return for uniformity. */
  188. }
  189. }
  190. }
  191. ?>

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

Source Code Documentation