PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/s2member/includes/classes/paypal-notify-in.inc.php

https://gitlab.com/Gashler/dp
PHP | 213 lines | 144 code | 28 blank | 41 comment | 49 complexity | 279f5ef532ac0ae155782622045f126c MD5 | raw file
  1. <?php
  2. /**
  3. * s2Member's PayPal® 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. * Released under the terms of the GNU General Public License.
  10. * You should have received a copy of the GNU General Public License,
  11. * along with this software. In the main directory, see: /licensing/
  12. * If not, see: {@link http://www.gnu.org/licenses/}.
  13. *
  14. * @package s2Member\PayPal
  15. * @since 3.5
  16. */
  17. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  18. exit ("Do not access this file directly.");
  19. if (!class_exists ("c_ws_plugin__s2member_paypal_notify_in"))
  20. {
  21. /**
  22. * s2Member's PayPal® IPN handler (inner processing routines).
  23. *
  24. * @package s2Member\PayPal
  25. * @since 3.5
  26. */
  27. class c_ws_plugin__s2member_paypal_notify_in
  28. {
  29. /**
  30. * Handles PayPal® IPN processing.
  31. *
  32. * These same routines also handle s2Member Pro/PayPal® Pro operations;
  33. * giving you the ability *(as needed)* to Hook into these routines using
  34. * WordPress® Hooks/Filters; as seen in the source code below.
  35. *
  36. * Please do NOT modify the source code directly.
  37. * Instead, use WordPress® Hooks/Filters.
  38. *
  39. * For example, if you'd like to add your own custom conditionals, use:
  40. * ``add_filter ("ws_plugin__s2member_during_paypal_notify_conditionals", "your_function");``
  41. *
  42. * @package s2Member\PayPal
  43. * @since 3.5
  44. *
  45. * @attaches-to ``add_action("init");``
  46. *
  47. * @return null Or exits script execution after handling IPN procesing.
  48. */
  49. public static function paypal_notify ()
  50. {
  51. global /* For Multisite support. */ $current_site, $current_blog;
  52. do_action ("ws_plugin__s2member_before_paypal_notify", get_defined_vars ());
  53. if (!empty ($_GET["s2member_paypal_notify"]) && ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_business"] || !empty ($_REQUEST["s2member_paypal_proxy"])))
  54. {
  55. @ignore_user_abort (true); // Important. Continue processing even if/when the connection is broken by the sending party.
  56. include_once ABSPATH . "wp-admin/includes/admin.php"; // Get administrative functions. Needed for `wp_delete_user()`.
  57. $email_configs_were_on = c_ws_plugin__s2member_email_configs::email_config_status (); // Filters on?
  58. c_ws_plugin__s2member_email_configs::email_config_release (); // Release s2Member Filters.
  59. if (is_array ($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_postvars ()) && ($_paypal = $paypal) && ($_paypal_s = serialize ($_paypal)))
  60. {
  61. $paypal["s2member_log"][] = "IPN received on: " . date ("D M j, Y g:i:s a T");
  62. $paypal["s2member_log"][] = "s2Member POST vars verified " . ((!empty ($paypal["proxy_verified"])) ? "with a Proxy Key" : "through a POST back to PayPal®.");
  63. $payment_status_issues = "/^(failed|denied|expired|refunded|partially_refunded|reversed|reversal|canceled_reversal|voided)$/i";
  64. $paypal["subscr_gateway"] = (!empty ($_REQUEST["s2member_paypal_proxy"])) ? esc_html (trim (stripslashes ($_REQUEST["s2member_paypal_proxy"]))) : "paypal";
  65. $coupon = (!empty($_REQUEST["s2member_paypal_proxy_coupon"]) && is_array($_REQUEST["s2member_paypal_proxy_coupon"])) ? stripslashes_deep($_REQUEST["s2member_paypal_proxy_coupon"]) : array();
  66. $coupon = (isset($coupon["full_coupon_code"], $coupon["coupon_code"], $coupon["affiliate_id"]) && is_string($coupon["full_coupon_code"]) && is_string($coupon["coupon_code"]) && is_string($coupon["affiliate_id"])) ? $coupon : array("full_coupon_code" => "", "coupon_code" => "", "affiliate_id" => "");
  67. if (empty ($paypal["custom"]) && !empty ($paypal["recurring_payment_id"])) // Lookup on Recurring Profiles?
  68. $paypal["custom"] = c_ws_plugin__s2member_utils_users::get_user_custom_with ($paypal["recurring_payment_id"]);
  69. if (!empty ($paypal["custom"]) && preg_match ("/^" . preg_quote (preg_replace ("/\:([0-9]+)$/", "", $_SERVER["HTTP_HOST"]), "/") . "/i", $paypal["custom"]))
  70. {
  71. $paypal["s2member_log"][] = "s2Member originating domain ( `\$_SERVER[\"HTTP_HOST\"]` ) validated.";
  72. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  73. if (!apply_filters ("ws_plugin__s2member_during_paypal_notify_conditionals", false, get_defined_vars ()))
  74. {
  75. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  76. if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_virtual_terminal::cp (get_defined_vars ())))
  77. $paypal = $_paypal_cp;
  78. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_express_checkout::cp (get_defined_vars ())))
  79. $paypal = $_paypal_cp;
  80. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_cart::cp (get_defined_vars ())))
  81. $paypal = $_paypal_cp;
  82. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_send_money::cp (get_defined_vars ())))
  83. $paypal = $_paypal_cp;
  84. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_web_accept_sp::cp (get_defined_vars ())))
  85. $paypal = $_paypal_cp;
  86. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_wa_ccaps_wo_level::cp (get_defined_vars ())))
  87. $paypal = $_paypal_cp;
  88. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_or_wa_w_level::cp (get_defined_vars ())))
  89. $paypal = $_paypal_cp;
  90. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_rec_profile_creation_w_level::cp (get_defined_vars ())))
  91. $paypal = $_paypal_cp;
  92. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_modify_w_level::cp (get_defined_vars ())))
  93. $paypal = $_paypal_cp;
  94. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_or_rp_payment_w_level::cp (get_defined_vars ())))
  95. $paypal = $_paypal_cp;
  96. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_or_rp_payment_failed_w_level::cp (get_defined_vars ())))
  97. $paypal = $_paypal_cp;
  98. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_or_rp_cancellation_w_level::cp (get_defined_vars ())))
  99. $paypal = $_paypal_cp;
  100. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_or_rp_eots_w_level::cp (get_defined_vars ())))
  101. $paypal = $_paypal_cp;
  102. else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_sp_refund_reversal::cp (get_defined_vars ())))
  103. $paypal = $_paypal_cp;
  104. else // Ignoring this IPN request. The txn_type/status does NOT require any action.
  105. $paypal["s2member_log"][] = "Ignoring this IPN request. The `txn_type/status` does NOT require any action on the part of s2Member.";
  106. }
  107. else // Else a custom conditional has been applied by Filters.
  108. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  109. }
  110. else if (!empty ($paypal["txn_type"]) && preg_match ("/^recurring_payment_profile_cancel$/i", $paypal["txn_type"]))
  111. {
  112. $paypal["s2member_log"][] = "Transaction type ( `recurring_payment_profile_cancel` ), but there is no match to an existing account; so verification of `\$_SERVER[\"HTTP_HOST\"]` was not possible.";
  113. $paypal["s2member_log"][] = "It's likely this account was just upgraded/downgraded by s2Member Pro; so the Subscr. ID has probably been updated on-site; nothing to worry about here.";
  114. }
  115. else if (!empty ($paypal["txn_type"]) && preg_match ("/^recurring_/i", $paypal["txn_type"])) // Otherwise, is this a ^recurring_ txn_type?
  116. $paypal["s2member_log"][] = "Transaction type ( `^recurring_?` ), but there is no match to an existing account; so verification of `\$_SERVER[\"HTTP_HOST\"]` was not possible.";
  117. else // Else, use the default ``$_SERVER["HTTP_HOST"]`` error.
  118. $paypal["s2member_log"][] = "Unable to verify `\$_SERVER[\"HTTP_HOST\"]`. Please check the `custom` value in your Button Code. It MUST start with your domain name.";
  119. }
  120. else // Extensive log reporting here. This is an area where many site owners find trouble. Depending on server configuration; remote HTTPS connections may fail.
  121. {
  122. $paypal["s2member_log"][] = "Unable to verify \$_POST vars. This is most likely related to an invalid configuration of s2Member, or a problem with server compatibility.";
  123. $paypal["s2member_log"][] = "Please see this KB article: `http://www.s2member.com/kb/server-scanner/`. We suggest that you run the s2Member® Server Scanner.";
  124. $paypal["s2member_log"][] = var_export ($_REQUEST, true); // Recording _POST + _GET vars for analysis and debugging.
  125. }
  126. if ($email_configs_were_on) // Back on?
  127. c_ws_plugin__s2member_email_configs::email_config ();
  128. /*
  129. Add IPN proxy (when available) to the ``$paypal`` array.
  130. */
  131. if (!empty ($_REQUEST["s2member_paypal_proxy"]))
  132. $paypal["s2member_paypal_proxy"] = $_REQUEST["s2member_paypal_proxy"];
  133. /*
  134. Add IPN proxy use vars (when available) to the ``$paypal`` array.
  135. */
  136. if (!empty ($_REQUEST["s2member_paypal_proxy_use"]))
  137. $paypal["s2member_paypal_proxy_use"] = $_REQUEST["s2member_paypal_proxy_use"];
  138. /*
  139. Add IPN proxy coupon vars (when available) to the ``$paypal`` array.
  140. */
  141. if (!empty ($_REQUEST["s2member_paypal_proxy_coupon"]))
  142. $paypal["s2member_paypal_proxy_coupon"] = $_REQUEST["s2member_paypal_proxy_coupon"];
  143. /*
  144. Also add IPN proxy self-verification (when available) to the ``$paypal`` array.
  145. */
  146. if (!empty ($_REQUEST["s2member_paypal_proxy_verification"]))
  147. $paypal["s2member_paypal_proxy_verification"] = $_REQUEST["s2member_paypal_proxy_verification"];
  148. /*
  149. If debugging/logging is enabled; we need to append ``$paypal`` to the log file.
  150. Logging now supports Multisite Networking as well.
  151. */
  152. $logt = c_ws_plugin__s2member_utilities::time_details ();
  153. $logv = c_ws_plugin__s2member_utilities::ver_details ();
  154. $logm = c_ws_plugin__s2member_utilities::mem_details ();
  155. $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"];
  156. $log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4;
  157. $log2 = (is_multisite () && !is_main_site ()) ? "paypal-ipn-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "paypal-ipn.log";
  158. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
  159. if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
  160. if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ())
  161. file_put_contents ($logs_dir . "/" . $log2,
  162. "LOG ENTRY: ".$logt . "\n" . $logv . "\n" . $logm . "\n" . $log4 . "\n" .
  163. c_ws_plugin__s2member_utils_logs::conceal_private_info(var_export ($paypal, true)) . "\n\n",
  164. FILE_APPEND);
  165. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  166. do_action ("ws_plugin__s2member_during_paypal_notify", get_defined_vars ());
  167. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  168. status_header (200); // Send a 200 OK status header.
  169. header ("Content-Type: text/plain; charset=UTF-8"); // Content-Type text/plain with UTF-8.
  170. while (@ob_end_clean ()); // Clean any existing output buffers.
  171. exit (((!empty ($paypal["s2member_paypal_proxy_return_url"])) ? $paypal["s2member_paypal_proxy_return_url"] : ""));
  172. }
  173. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  174. do_action ("ws_plugin__s2member_after_paypal_notify", get_defined_vars ());
  175. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  176. }
  177. }
  178. }
  179. ?>