Source Code Documentation


s2member-pro\includes\classes\gateways\alipay\alipay-return-in.inc.php


  1. <?php
  2. /**
  3. * AliPay® Return URL 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. * 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\AliPay
  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_alipay_return_in"))
  37. {
  38. /**
  39. * AliPay® Return URL handler ( inner processing routines ).
  40. *
  41. * @package s2Member\AliPay
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_alipay_return_in
  45. {
  46. /**
  47. * Handles AliPay® Return URL processing.
  48. *
  49. * @package s2Member\AliPay
  50. * @since 1.5
  51. *
  52. * @attaches-to ``add_action("init");``
  53. *
  54. * @return null Or exits script execution after redirection.
  55. */
  56. public static function alipay_return ()
  57. {
  58. global /* For Multisite support. */ $current_site, $current_blog;
  59. /**/
  60. if (!empty ($_GET["s2member_pro_alipay_return"]) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_alipay_seller_email"])
  61. {
  62. if (is_array ($alipay = c_ws_plugin__s2member_pro_alipay_utilities::alipay_postvars ()) && ($_alipay = $alipay))
  63. {
  64. $alipay["s2member_log"][] = "Return-Data received on: " . date ("D M j, Y g:i:s a T");
  65. $alipay["s2member_log"][] = "s2Member POST vars verified through a POST back to AliPay®.";
  66. /**/
  67. if (preg_match ("/^(TRADE_FINISHED|TRADE_SUCCESS)$/i", $alipay["trade_status"]) && !$alipay["refund_status"])
  68. {
  69. $alipay["s2member_log"][] = "AliPay® transaction identified as ( `TRADE_FINISHED|TRADE_SUCCESS` ).";
  70. $alipay["s2member_log"][] = "Return-Data reformulated. Piping through s2Member's core/standard PayPal® processor as `txn_type` ( `web_accept` ).";
  71. $alipay["s2member_log"][] = "Please check PayPal® RTN logs for further processing details.";
  72. /**/
  73. list ($alipay["invoice"], $alipay["item_number"], $alipay["referencing"], $alipay["customer_ip"]) = preg_split ("/~/", $alipay["out_trade_no"]);
  74. list ($alipay["first_name"], $alipay["last_name"]) = preg_split ("/@/", $alipay["buyer_email"], 2);
  75. /**/
  76. $rtn = /* Reset. */ array ();
  77. /**/
  78. $rtn["txn_type"] = "web_accept";
  79. $rtn["txn_id"] = $alipay["trade_no"];
  80. $rtn["custom"] = $alipay["extra_common_param"];
  81. /**/
  82. $rtn["mc_gross"] = number_format ($alipay["total_fee"], 2, ".", "");
  83. $rtn["mc_currency"] = "CNY"; /* Yuan. */
  84. $rtn["tax"] = "0"; /* No tax. */
  85. /**/
  86. $rtn["payer_email"] = $alipay["buyer_email"];
  87. $rtn["first_name"] = $alipay["first_name"];
  88. $rtn["last_name"] = $alipay["last_name"];
  89. /**/
  90. $rtn["option_name1"] = ($alipay["referencing"]) ? "Referencing Customer ID" : "Originating Domain";
  91. $rtn["option_selection1"] = ($alipay["referencing"]) ? $alipay["referencing"] : $_SERVER["HTTP_HOST"];
  92. /**/
  93. $rtn["option_name2"] = "Customer IP Address";
  94. $rtn["option_selection2"] = $alipay["customer_ip"];
  95. /**/
  96. $rtn["item_number"] = $alipay["item_number"];
  97. $rtn["item_name"] = $alipay["body"];
  98. /**/
  99. $rtn_q = "&s2member_paypal_proxy=alipay&s2member_paypal_proxy_use=standard-emails";
  100. if (!empty /* Using a custom Return URL on success? */ ($_GET["s2member_pro_alipay_return_success"]))
  101. $rtn_q .= "&s2member_paypal_return_success=" . rawurlencode (trim (stripslashes ($_GET["s2member_pro_alipay_return_success"])));
  102. /**/
  103. $rtn_r = add_query_arg (urlencode_deep ($rtn), site_url ("/?s2member_pro_alipay_return&s2member_paypal_return=1" . $rtn_q));
  104. $rtn_r = c_ws_plugin__s2member_utils_urls::add_s2member_sig ($rtn_r, "s2member_paypal_proxy_verification");
  105. /**/
  106. $alipay["s2member_log"][] = /* Log the full Return redirection URL here. */ $rtn_r;
  107. /**/
  108. wp_redirect /* Proxy this through s2Member's core PayPal® processor. */($rtn_r);
  109. }
  110. else /* Else we need to fail here. The AliPay® status was completely unexpected. */
  111. {
  112. $alipay["s2member_log"][] = "Unexpected status. The AliPay® status did not match a required action.";
  113. /**/
  114. $alipay["s2member_log"][] = "Redirecting Customer to the Home Page, due to an error that occurred.";
  115. /**/
  116. echo '<script type="text/javascript">' . "\n";
  117. echo "alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("ERROR: Unexpected status. Please contact Support for assistance.\n\nThe AliPay® status did NOT match a required action.", "s2member-front", "s2member")) . "');" . "\n";
  118. echo "window.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq (home_url ("/")) . "';";
  119. echo '</script>' . "\n";
  120. }
  121. }
  122. else /* Extensive log reporting here. This is an area where many site owners find trouble. Depending on server configuration; remote HTTPS connections may fail. */
  123. {
  124. $alipay["s2member_log"][] = "Unable to verify POST vars. This is most likely related to an invalid AliPay® configuration. Please check: s2Member -> AliPay® Options.";
  125. $alipay["s2member_log"][] = "If you're absolutely SURE that your AliPay® 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 AliPay® over an HTTPS connection.";
  126. $alipay["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.";
  127. $alipay["s2member_log"][] = var_export ($_REQUEST, true); /* Recording _POST + _GET vars for analysis and debugging. */
  128. /**/
  129. $alipay["s2member_log"][] = "Redirecting Customer to the Home Page, due to an error that occurred.";
  130. /**/
  131. echo '<script type="text/javascript">' . "\n";
  132. echo "alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("ERROR: Unable to verify POST vars. Please contact Support for assistance.\n\nThis is most likely related to an invalid AliPay® configuration. If you are the site owner, please check: s2Member -> AliPay® Options.", "s2member-front", "s2member")) . "');" . "\n";
  133. echo "window.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq (home_url ("/")) . "';";
  134. echo '</script>' . "\n";
  135. }
  136. /**/
  137. $logv = c_ws_plugin__s2member_utilities::ver_details ();
  138. $logm = c_ws_plugin__s2member_utilities::mem_details ();
  139. $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"];
  140. $log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4;
  141. $log2 = (is_multisite () && !is_main_site ()) ? "alipay-rtn-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "alipay-rtn.log";
  142. /**/
  143. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
  144. if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
  145. if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ())
  146. file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export ($alipay, true) . "\n\n", FILE_APPEND);
  147. /**/
  148. exit (); /* Exit now. */
  149. }
  150. }
  151. }
  152. }
  153. ?>

s2member-pro\includes\classes\gateways\alipay\alipay-return-in.inc.php

Source Code Documentation