Source Code Documentation


pro\s2member-pro\includes\classes\gateways\authnet\authnet-checkout-in.inc.php


  1. <?php
  2. /**
  3. * Authorize.Net® Checkout Form 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\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_checkout_in"))
  37. {
  38. /**
  39. * Authorize.Net® Checkout Form handler (inner processing routines).
  40. *
  41. * @package s2Member\AuthNet
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_authnet_checkout_in
  45. {
  46. /**
  47. * Handles processing of Pro Form checkouts.
  48. *
  49. * @package s2Member\AuthNet
  50. * @since 1.5
  51. *
  52. * @attaches-to ``add_action("init");``
  53. *
  54. * @return null Or exits script execution after a custom URL redirection.
  55. *
  56. * @todo Build in routine to void first payment if Recurring Profile creation fails for some reason? Seems logical, even though highly unlikely.
  57. */
  58. public static function authnet_checkout()
  59. {
  60. if(!empty($_POST["s2member_pro_authnet_checkout"]["nonce"]) && ($nonce = $_POST["s2member_pro_authnet_checkout"]["nonce"]) && wp_verify_nonce($nonce, "s2member-pro-authnet-checkout"))
  61. {
  62. $GLOBALS["ws_plugin__s2member_pro_authnet_checkout_response"] = array(); // This holds the global response details.
  63. $global_response = &$GLOBALS["ws_plugin__s2member_pro_authnet_checkout_response"]; // This is a shorter reference.
  64.  
  65. $post_vars = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST["s2member_pro_authnet_checkout"]));
  66. $post_vars["attr"] = unserialize(c_ws_plugin__s2member_utils_encryption::decrypt($post_vars["attr"])); // And Filter.
  67. $post_vars["attr"] = apply_filters("ws_plugin__s2member_pro_authnet_checkout_post_attr", $post_vars["attr"], get_defined_vars());
  68.  
  69. $post_vars["recaptcha_challenge_field"] = (!$post_vars["recaptcha_challenge_field"]) ? trim(stripslashes($_POST["recaptcha_challenge_field"])) : $post_vars["recaptcha_challenge_field"];
  70. $post_vars["recaptcha_response_field"] = (!$post_vars["recaptcha_response_field"]) ? trim(stripslashes($_POST["recaptcha_response_field"])) : $post_vars["recaptcha_response_field"];
  71.  
  72. $post_vars["name"] = trim($post_vars["first_name"]." ".$post_vars["last_name"]);
  73. $post_vars["email"] = apply_filters("user_registration_email", sanitize_email($post_vars["email"]), get_defined_vars());
  74. $post_vars["username"] = (is_multisite()) ? strtolower($post_vars["username"]) : $post_vars["username"]; // Force lowercase.
  75. $post_vars["username"] = preg_replace("/\s+/", "", sanitize_user(($post_vars["_o_username"] = $post_vars["username"]), is_multisite()));
  76.  
  77. if(!c_ws_plugin__s2member_pro_authnet_responses::authnet_form_attr_validation_errors($post_vars["attr"])) // Attr errors?
  78. {
  79. if(!($error = c_ws_plugin__s2member_pro_authnet_responses::authnet_form_submission_validation_errors("checkout", $post_vars)))
  80. {
  81. $cp_attr = c_ws_plugin__s2member_pro_authnet_utilities::authnet_apply_coupon($post_vars["attr"], $post_vars["coupon"], "attr", array("affiliates-silent-post"));
  82. $cost_calculations = c_ws_plugin__s2member_pro_authnet_utilities::authnet_cost($cp_attr["ta"], $cp_attr["ra"], $post_vars["state"], $post_vars["country"], $post_vars["zip"], $cp_attr["cc"], $cp_attr["desc"]);
  83.  
  84. $use_recurring_profile = ($post_vars["attr"]["rr"] === "BN" || (!$post_vars["attr"]["tp"] && !$post_vars["attr"]["rr"])) ? false : true;
  85. $is_independent_ccaps_sale = ($post_vars["attr"]["level"] === "*") ? true : false; // Selling Independent Custom Capabilities?
  86.  
  87. if($use_recurring_profile && is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID))
  88. {
  89. $period1 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period1($post_vars["attr"]["tp"]." ".$post_vars["attr"]["tt"]);
  90. $period3 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period3($post_vars["attr"]["rp"]." ".$post_vars["attr"]["rt"]);
  91.  
  92. $start_time = ($post_vars["attr"]["tp"]) ? // If there's an Initial/Trial Period; start when it's over.
  93. c_ws_plugin__s2member_pro_authnet_utilities::authnet_start_time($period1) : // After Trial is over.
  94. c_ws_plugin__s2member_pro_authnet_utilities::authnet_start_time($period3); // Or next billing cycle.
  95.  
  96. $reference = $start_time.":".$period1.":".$period3."~".$_SERVER["HTTP_HOST"]."~".$post_vars["attr"]["level_ccaps_eotper"]."~".$cost_calculations["cur"];
  97.  
  98. update_user_meta($user_id, "first_name", $post_vars["first_name"]).update_user_meta($user_id, "last_name", $post_vars["last_name"]);
  99.  
  100. if(!($_authnet = array()) // A first Initial/Trial payment?
  101. && (!$post_vars["attr"]["tp"] || ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)))
  102. {
  103. $_authnet["x_type"] = "AUTH_CAPTURE";
  104. $_authnet["x_method"] = "CC";
  105.  
  106. $_authnet["x_email"] = $user->user_email;
  107. $_authnet["x_first_name"] = $post_vars["first_name"];
  108. $_authnet["x_last_name"] = $post_vars["last_name"];
  109. $_authnet["x_customer_ip"] = $_SERVER["REMOTE_ADDR"];
  110.  
  111. $_authnet["x_invoice_num"] = "s2-".uniqid();
  112. $_authnet["x_description"] = $cost_calculations["desc"];
  113.  
  114. $_authnet["s2_initial_payment"] = "1"; // Initial.
  115.  
  116. $_authnet["s2_invoice"] = $post_vars["attr"]["level_ccaps_eotper"];
  117. $_authnet["s2_custom"] = $post_vars["attr"]["custom"];
  118.  
  119. if($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)
  120. {
  121. $_authnet["x_tax"] = $cost_calculations["trial_tax"];
  122. $_authnet["x_amount"] = $cost_calculations["trial_total"];
  123. $_authnet["x_currency_code"] = $cost_calculations["cur"];
  124. }
  125. else // Otherwise, charge for the first Regular payment.
  126. {
  127. $_authnet["x_tax"] = $cost_calculations["tax"];
  128. $_authnet["x_amount"] = $cost_calculations["total"];
  129. $_authnet["x_currency_code"] = $cost_calculations["cur"];
  130. }
  131.  
  132. $_authnet["x_card_num"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]);
  133. $_authnet["x_exp_date"] = c_ws_plugin__s2member_pro_authnet_utilities::authnet_exp_date($post_vars["card_expiration"]);
  134. $_authnet["x_card_code"] = $post_vars["card_verification"];
  135.  
  136. #if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  137. # if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  138. # $_authnet["x_card_start_date"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  139. # else // Otherwise, we assume they provided an issue number instead.
  140. # $_authnet["x_card_issue_number"] = $post_vars["card_start_date_issue_number"];
  141.  
  142. $_authnet["x_address"] = $post_vars["street"];
  143. $_authnet["x_city"] = $post_vars["city"];
  144. $_authnet["x_state"] = $post_vars["state"];
  145. $_authnet["x_country"] = $post_vars["country"];
  146. $_authnet["x_zip"] = $post_vars["zip"];
  147. }
  148.  
  149. if(!($authnet = array())) // Recurring Profile.
  150. {
  151. $authnet["x_method"] = "create";
  152.  
  153. $authnet["x_email"] = $user->user_email;
  154. $authnet["x_first_name"] = $post_vars["first_name"];
  155. $authnet["x_last_name"] = $post_vars["last_name"];
  156. $authnet["x_customer_ip"] = $_SERVER["REMOTE_ADDR"];
  157.  
  158. $authnet["x_invoice_num"] = ($_authnet) ? $_authnet["x_invoice_num"] : "s2-".uniqid();
  159. $authnet["x_description"] = $cost_calculations["desc"];
  160. $authnet["x_description"] .= " ((".$reference."))";
  161.  
  162. $authnet["x_amount"] = $cost_calculations["total"];
  163. $authnet["x_currency_code"] = $cost_calculations["cur"];
  164.  
  165. $authnet["x_start_date"] = date("Y-m-d", $start_time);
  166.  
  167. $authnet["x_unit"] = "days"; // Always calculated in days.
  168. $authnet["x_length"] = c_ws_plugin__s2member_pro_authnet_utilities::authnet_per_term_2_days($post_vars["attr"]["rp"], $post_vars["attr"]["rt"]);
  169. $authnet["x_total_occurrences"] = ($post_vars["attr"]["rr"]) ? (($post_vars["attr"]["rrt"]) ? $post_vars["attr"]["rrt"] : "9999") : "1";
  170.  
  171. $authnet["x_card_num"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]);
  172. $authnet["x_exp_date"] = c_ws_plugin__s2member_pro_authnet_utilities::authnet_exp_date($post_vars["card_expiration"]);
  173. $authnet["x_card_code"] = $post_vars["card_verification"];
  174.  
  175. #if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  176. # if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  177. # $authnet["x_card_start_date"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  178. # else // Otherwise, we assume they provided an issue number instead.
  179. # $authnet["x_card_issue_number"] = $post_vars["card_start_date_issue_number"];
  180.  
  181. $authnet["x_address"] = $post_vars["street"];
  182. $authnet["x_city"] = $post_vars["city"];
  183. $authnet["x_state"] = $post_vars["state"];
  184. $authnet["x_country"] = $post_vars["country"];
  185. $authnet["x_zip"] = $post_vars["zip"];
  186. }
  187.  
  188. if(!$_authnet || (($_authnet = c_ws_plugin__s2member_pro_authnet_utilities::authnet_aim_response($_authnet)) && empty($_authnet["__error"])))
  189. {
  190. if(($authnet = c_ws_plugin__s2member_pro_authnet_utilities::authnet_arb_response($authnet)) && (empty($authnet["__error"]) || ($_authnet && !empty($_authnet["transaction_id"]) && $authnet["response_reason_code"] === "E00018")))
  191. {
  192. // $authnet["response_reason_code"] === "E00018" ... Card expires before start time.
  193.  
  194. $new__txn_id = ($_authnet && !empty($_authnet["transaction_id"])) ? $_authnet["transaction_id"] : false;
  195. $new__subscr_id = ($_authnet && !empty($_authnet["transaction_id"]) && $authnet["response_reason_code"] === "E00018") ? $new__txn_id : $authnet["subscription_id"];
  196. $old__subscr_or_wp_id = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id();
  197. $old__subscr_id = get_user_option("s2member_subscr_id");
  198.  
  199. if(!($ipn = array())) // Simulated PayPal® IPN.
  200. {
  201. $ipn["txn_type"] = "subscr_signup";
  202. $ipn["subscr_id"] = $new__subscr_id;
  203. $ipn["custom"] = $post_vars["attr"]["custom"];
  204.  
  205. $ipn["txn_id"] = ($new__txn_id) ? $new__txn_id : $new__subscr_id;
  206.  
  207. $ipn["period1"] = $period1;
  208. $ipn["period3"] = $period3;
  209.  
  210. $ipn["mc_amount1"] = $cost_calculations["trial_total"];
  211. $ipn["mc_amount3"] = $cost_calculations["total"];
  212.  
  213. $ipn["mc_gross"] = (preg_match("/^[1-9]/", $ipn["period1"])) ? $ipn["mc_amount1"] : $ipn["mc_amount3"];
  214.  
  215. $ipn["mc_currency"] = $cost_calculations["cur"];
  216. $ipn["tax"] = $cost_calculations["tax"];
  217.  
  218. $ipn["recurring"] = ($post_vars["attr"]["rr"]) ? "1" : "";
  219.  
  220. $ipn["payer_email"] = $user->user_email;
  221. $ipn["first_name"] = $post_vars["first_name"];
  222. $ipn["last_name"] = $post_vars["last_name"];
  223.  
  224. $ipn["option_name1"] = "Referencing Customer ID";
  225. $ipn["option_selection1"] = $old__subscr_or_wp_id;
  226.  
  227. $ipn["option_name2"] = "Customer IP Address";
  228. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  229.  
  230. $ipn["item_name"] = $cost_calculations["desc"];
  231. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  232.  
  233. $ipn["s2member_paypal_proxy"] = "authnet";
  234. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  235. $ipn["s2member_paypal_proxy_use"] .= ($ipn["mc_gross"] > 0) ? ",subscr-signup-as-subscr-payment" : "";
  236. $ipn["s2member_paypal_proxy_coupon"] = array("coupon_code" => $cp_attr["_coupon_code"], "full_coupon_code" => $cp_attr["_full_coupon_code"], "affiliate_id" => $cp_attr["_coupon_affiliate_id"]);
  237. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  238. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  239.  
  240. $ipn["s2member_authnet_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  241. }
  242.  
  243. if($_authnet && !empty($_authnet["transaction_id"]) && $authnet["response_reason_code"] === "E00018")
  244. {
  245. update_user_option($user_id, "s2member_auto_eot_time", $start_time);
  246. }
  247.  
  248. if(($authnet = array("x_method" => "cancel")) && ($authnet["x_subscription_id"] = $old__subscr_id))
  249. {
  250. c_ws_plugin__s2member_pro_authnet_utilities::authnet_arb_response($authnet);
  251. }
  252.  
  253. setcookie("s2member_tracking", ($s2member_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($new__subscr_id)), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN).setcookie("s2member_tracking", $s2member_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN).($_COOKIE["s2member_tracking"] = $s2member_tracking);
  254.  
  255. $global_response = array("response" => sprintf(_x('<strong>Thank you.</strong> Your account has been updated.<br />&mdash; Please <a href="%s" rel="nofollow">log back in</a> now.', "s2member-front", "s2member"), esc_attr(wp_login_url())));
  256.  
  257. if($post_vars["attr"]["success"] && substr($ipn["s2member_authnet_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", /* Deprecated in v111106 ». */ "%%response%%"), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["s2member_authnet_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url))))
  258. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  259. }
  260. else // Else, an error.
  261. {
  262. $global_response = array("response" => $authnet["__error"], "error" => true);
  263. }
  264. }
  265. else // Else, an error.
  266. {
  267. $global_response = array("response" => $_authnet["__error"], "error" => true);
  268. }
  269. }
  270.  
  271. else if($use_recurring_profile && !is_user_logged_in()) // Create a new account.
  272. {
  273. $period1 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period1($post_vars["attr"]["tp"]." ".$post_vars["attr"]["tt"]);
  274. $period3 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period3($post_vars["attr"]["rp"]." ".$post_vars["attr"]["rt"]);
  275.  
  276. $start_time = ($post_vars["attr"]["tp"]) ? // If there's an Initial/Trial Period; start when it's over.
  277. c_ws_plugin__s2member_pro_authnet_utilities::authnet_start_time($period1) : // After Trial is over.
  278. c_ws_plugin__s2member_pro_authnet_utilities::authnet_start_time($period3); // Or next billing cycle.
  279.  
  280. $reference = $start_time.":".$period1.":".$period3."~".$_SERVER["HTTP_HOST"]."~".$post_vars["attr"]["level_ccaps_eotper"]."~".$cost_calculations["cur"];
  281.  
  282. if(!($_authnet = array()) // A first Initial/Trial payment?
  283. && (!$post_vars["attr"]["tp"] || ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)))
  284. {
  285. $_authnet["x_type"] = "AUTH_CAPTURE";
  286. $_authnet["x_method"] = "CC";
  287.  
  288. $_authnet["x_email"] = $post_vars["email"];
  289. $_authnet["x_first_name"] = $post_vars["first_name"];
  290. $_authnet["x_last_name"] = $post_vars["last_name"];
  291. $_authnet["x_customer_ip"] = $_SERVER["REMOTE_ADDR"];
  292.  
  293. $_authnet["x_invoice_num"] = "s2-".uniqid();
  294. $_authnet["x_description"] = $cost_calculations["desc"];
  295.  
  296. $_authnet["s2_initial_payment"] = "1"; // Initial.
  297.  
  298. $_authnet["s2_invoice"] = $post_vars["attr"]["level_ccaps_eotper"];
  299. $_authnet["s2_custom"] = $post_vars["attr"]["custom"];
  300.  
  301. if($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)
  302. {
  303. $_authnet["x_tax"] = $cost_calculations["trial_tax"];
  304. $_authnet["x_amount"] = $cost_calculations["trial_total"];
  305. $_authnet["x_currency_code"] = $cost_calculations["cur"];
  306. }
  307. else // Otherwise, charge for the first Regular payment.
  308. {
  309. $_authnet["x_tax"] = $cost_calculations["tax"];
  310. $_authnet["x_amount"] = $cost_calculations["total"];
  311. $_authnet["x_currency_code"] = $cost_calculations["cur"];
  312. }
  313.  
  314. $_authnet["x_card_num"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]);
  315. $_authnet["x_exp_date"] = c_ws_plugin__s2member_pro_authnet_utilities::authnet_exp_date($post_vars["card_expiration"]);
  316. $_authnet["x_card_code"] = $post_vars["card_verification"];
  317.  
  318. #if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  319. # if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  320. # $_authnet["x_card_start_date"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  321. # else // Otherwise, we assume they provided an issue number instead.
  322. # $_authnet["x_card_issue_number"] = $post_vars["card_start_date_issue_number"];
  323.  
  324. $_authnet["x_address"] = $post_vars["street"];
  325. $_authnet["x_city"] = $post_vars["city"];
  326. $_authnet["x_state"] = $post_vars["state"];
  327. $_authnet["x_country"] = $post_vars["country"];
  328. $_authnet["x_zip"] = $post_vars["zip"];
  329. }
  330.  
  331. if(!($authnet = array())) // Recurring Profile.
  332. {
  333. $authnet["x_method"] = "create";
  334.  
  335. $authnet["x_email"] = $post_vars["email"];
  336. $authnet["x_first_name"] = $post_vars["first_name"];
  337. $authnet["x_last_name"] = $post_vars["last_name"];
  338. $authnet["x_customer_ip"] = $_SERVER["REMOTE_ADDR"];
  339.  
  340. $authnet["x_invoice_num"] = ($_authnet) ? $_authnet["x_invoice_num"] : "s2-".uniqid();
  341. $authnet["x_description"] = $cost_calculations["desc"];
  342. $authnet["x_description"] .= " ((".$reference."))";
  343.  
  344. $authnet["x_amount"] = $cost_calculations["total"];
  345. $authnet["x_currency_code"] = $cost_calculations["cur"];
  346.  
  347. $authnet["x_start_date"] = date("Y-m-d", $start_time);
  348.  
  349. $authnet["x_unit"] = "days"; // Always calculated in days.
  350. $authnet["x_length"] = c_ws_plugin__s2member_pro_authnet_utilities::authnet_per_term_2_days($post_vars["attr"]["rp"], $post_vars["attr"]["rt"]);
  351. $authnet["x_total_occurrences"] = ($post_vars["attr"]["rr"]) ? (($post_vars["attr"]["rrt"]) ? $post_vars["attr"]["rrt"] : "9999") : "1";
  352.  
  353. $authnet["x_card_num"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]);
  354. $authnet["x_exp_date"] = c_ws_plugin__s2member_pro_authnet_utilities::authnet_exp_date($post_vars["card_expiration"]);
  355. $authnet["x_card_code"] = $post_vars["card_verification"];
  356.  
  357. #if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  358. # if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  359. # $authnet["x_card_start_date"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  360. # else // Otherwise, we assume they provided an issue number instead.
  361. # $authnet["x_card_issue_number"] = $post_vars["card_start_date_issue_number"];
  362.  
  363. $authnet["x_address"] = $post_vars["street"];
  364. $authnet["x_city"] = $post_vars["city"];
  365. $authnet["x_state"] = $post_vars["state"];
  366. $authnet["x_country"] = $post_vars["country"];
  367. $authnet["x_zip"] = $post_vars["zip"];
  368. }
  369.  
  370. if(!$_authnet || (($_authnet = c_ws_plugin__s2member_pro_authnet_utilities::authnet_aim_response($_authnet)) && empty($_authnet["__error"])))
  371. {
  372. if(($authnet = c_ws_plugin__s2member_pro_authnet_utilities::authnet_arb_response($authnet)) && (empty($authnet["__error"]) || ($_authnet && !empty($_authnet["transaction_id"]) && $authnet["response_reason_code"] === "E00018")))
  373. {
  374. // $authnet["response_reason_code"] === "E00018" ... Card expires before start time.
  375.  
  376. $new__txn_id = ($_authnet && !empty($_authnet["transaction_id"])) ? $_authnet["transaction_id"] : false;
  377. $new__subscr_id = ($_authnet && !empty($_authnet["transaction_id"]) && $authnet["response_reason_code"] === "E00018") ? $new__txn_id : $authnet["subscription_id"];
  378.  
  379. if(!($ipn = array())) // Simulated PayPal® IPN.
  380. {
  381. $ipn["txn_type"] = "subscr_signup";
  382. $ipn["subscr_id"] = $new__subscr_id;
  383. $ipn["custom"] = $post_vars["attr"]["custom"];
  384.  
  385. $ipn["txn_id"] = ($new__txn_id) ? $new__txn_id : $new__subscr_id;
  386.  
  387. $ipn["period1"] = $period1;
  388. $ipn["period3"] = $period3;
  389.  
  390. $ipn["mc_amount1"] = $cost_calculations["trial_total"];
  391. $ipn["mc_amount3"] = $cost_calculations["total"];
  392.  
  393. $ipn["mc_gross"] = (preg_match("/^[1-9]/", $ipn["period1"])) ? $ipn["mc_amount1"] : $ipn["mc_amount3"];
  394.  
  395. $ipn["mc_currency"] = $cost_calculations["cur"];
  396. $ipn["tax"] = $cost_calculations["tax"];
  397.  
  398. $ipn["recurring"] = ($post_vars["attr"]["rr"]) ? "1" : "";
  399.  
  400. $ipn["payer_email"] = $post_vars["email"];
  401. $ipn["first_name"] = $post_vars["first_name"];
  402. $ipn["last_name"] = $post_vars["last_name"];
  403.  
  404. $ipn["option_name1"] = "Originating Domain";
  405. $ipn["option_selection1"] = $_SERVER["HTTP_HOST"];
  406.  
  407. $ipn["option_name2"] = "Customer IP Address";
  408. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  409.  
  410. $ipn["item_name"] = $cost_calculations["desc"];
  411. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  412.  
  413. $ipn["s2member_paypal_proxy"] = "authnet";
  414. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  415. $ipn["s2member_paypal_proxy_use"] .= ($ipn["mc_gross"] > 0) ? ",subscr-signup-as-subscr-payment" : "";
  416. $ipn["s2member_paypal_proxy_coupon"] = array("coupon_code" => $cp_attr["_coupon_code"], "full_coupon_code" => $cp_attr["_full_coupon_code"], "affiliate_id" => $cp_attr["_coupon_affiliate_id"]);
  417. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  418. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  419. }
  420.  
  421. if(!($create_user = array())) // Build post fields for registration configuration, and then the creation array.
  422. {
  423. $_POST["ws_plugin__s2member_custom_reg_field_user_pass1"] = $post_vars["password1"]; // Fake this for registration configuration.
  424. $_POST["ws_plugin__s2member_custom_reg_field_first_name"] = $post_vars["first_name"]; // Fake this for registration configuration.
  425. $_POST["ws_plugin__s2member_custom_reg_field_last_name"] = $post_vars["last_name"]; // Fake this for registration configuration.
  426. $_POST["ws_plugin__s2member_custom_reg_field_opt_in"] = $post_vars["custom_fields"]["opt_in"]; // Fake this too.
  427.  
  428. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  429. foreach(json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  430. {
  431. $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
  432. $field_id_class = preg_replace("/_/", "-", $field_var);
  433.  
  434. if(isset($post_vars["custom_fields"][$field_var]))
  435. $_POST["ws_plugin__s2member_custom_reg_field_".$field_var] = $post_vars["custom_fields"][$field_var];
  436. }
  437.  
  438. $_COOKIE["s2member_subscr_gateway"] = c_ws_plugin__s2member_utils_encryption::encrypt("authnet"); // Fake this for registration configuration.
  439. $_COOKIE["s2member_subscr_id"] = c_ws_plugin__s2member_utils_encryption::encrypt($new__subscr_id); // Fake this for registration configuration.
  440. $_COOKIE["s2member_custom"] = c_ws_plugin__s2member_utils_encryption::encrypt($post_vars["attr"]["custom"]); // Fake this for registration configuration.
  441. $_COOKIE["s2member_item_number"] = c_ws_plugin__s2member_utils_encryption::encrypt($post_vars["attr"]["level_ccaps_eotper"]); // Fake this too.
  442.  
  443. $create_user["user_login"] = $post_vars["username"]; // Copy this into a separate array for `wp_create_user()`.
  444. $create_user["user_pass"] = wp_generate_password(); // Which may fire `c_ws_plugin__s2member_registrations::generate_password()`.
  445. $create_user["user_email"] = $post_vars["email"]; // Copy this into a separate array for `wp_create_user()`.
  446. }
  447.  
  448. if($post_vars["password1"] && $post_vars["password1"] === $create_user["user_pass"]) // A custom Password is being used?
  449. {
  450. if(((is_multisite() && ($new__user_id = c_ws_plugin__s2member_registrations::ms_create_existing_user($create_user["user_login"], $create_user["user_email"], $create_user["user_pass"]))) || ($new__user_id = wp_create_user($create_user["user_login"], $create_user["user_pass"], $create_user["user_email"]))) && !is_wp_error($new__user_id))
  451. {
  452. wp_new_user_notification($new__user_id, $create_user["user_pass"]);
  453.  
  454. $ipn["s2member_authnet_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  455.  
  456. if($_authnet && !empty($_authnet["transaction_id"]) && $authnet["response_reason_code"] === "E00018")
  457. update_user_option($new__user_id, "s2member_auto_eot_time", $start_time);
  458.  
  459. $global_response = array("response" => sprintf(_x('<strong>Thank you.</strong> Your account has been approved.<br />&mdash; Please <a href="%s" rel="nofollow">login</a>.', "s2member-front", "s2member"), esc_attr(wp_login_url())));
  460.  
  461. if($post_vars["attr"]["success"] && substr($ipn["s2member_authnet_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", /* Deprecated in v111106 ». */ "%%response%%"), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["s2member_authnet_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url))))
  462. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  463. }
  464. else // Else, an error reponse should be given.
  465. {
  466. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20));
  467.  
  468. $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  469. }
  470. }
  471. else // Otherwise, they'll need to check their email for the auto-generated Password.
  472. {
  473. if(((is_multisite() && ($new__user_id = c_ws_plugin__s2member_registrations::ms_create_existing_user($create_user["user_login"], $create_user["user_email"], $create_user["user_pass"]))) || ($new__user_id = wp_create_user($create_user["user_login"], $create_user["user_pass"], $create_user["user_email"]))) && !is_wp_error($new__user_id))
  474. {
  475. update_user_option($new__user_id, "default_password_nag", true, true); // Password nag.
  476. wp_new_user_notification($new__user_id, $create_user["user_pass"]);
  477.  
  478. $ipn["s2member_authnet_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  479.  
  480. if($_authnet && !empty($_authnet["transaction_id"]) && $authnet["response_reason_code"] === "E00018")
  481. update_user_option($new__user_id, "s2member_auto_eot_time", $start_time);
  482.  
  483. $global_response = array("response" => _x('<strong>Thank you.</strong> Your account has been approved.<br />&mdash; You\'ll receive an email momentarily.', "s2member-front", "s2member"));
  484.  
  485. if($post_vars["attr"]["success"] && substr($ipn["s2member_authnet_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", /* Deprecated in v111106 ». */ "%%response%%"), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["s2member_authnet_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url))))
  486. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  487. }
  488. else // Else, an error reponse should be given.
  489. {
  490. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20));
  491.  
  492. $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  493. }
  494. }
  495. }
  496. else // Else, an error.
  497. {
  498. $global_response = array("response" => $authnet["__error"], "error" => true);
  499. }
  500. }
  501. else // Else, an error.
  502. {
  503. $global_response = array("response" => $_authnet["__error"], "error" => true);
  504. }
  505. }
  506.  
  507. else if(!$use_recurring_profile && is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID))
  508. {
  509. update_user_meta($user_id, "first_name", $post_vars["first_name"]).update_user_meta($user_id, "last_name", $post_vars["last_name"]);
  510.  
  511. if(!($authnet = array())) // Direct payments.
  512. {
  513. $authnet["x_type"] = "AUTH_CAPTURE";
  514. $authnet["x_method"] = "CC";
  515.  
  516. $authnet["x_email"] = $user->user_email;
  517. $authnet["x_first_name"] = $post_vars["first_name"];
  518. $authnet["x_last_name"] = $post_vars["last_name"];
  519. $authnet["x_customer_ip"] = $_SERVER["REMOTE_ADDR"];
  520.  
  521. $authnet["x_invoice_num"] = "s2-".uniqid();
  522. $authnet["x_description"] = $cost_calculations["desc"];
  523.  
  524. $authnet["s2_invoice"] = $post_vars["attr"]["level_ccaps_eotper"];
  525. $authnet["s2_custom"] = $post_vars["attr"]["custom"];
  526.  
  527. $authnet["x_tax"] = $cost_calculations["tax"];
  528. $authnet["x_amount"] = $cost_calculations["total"];
  529. $authnet["x_currency_code"] = $cost_calculations["cur"];
  530.  
  531. $authnet["x_card_num"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]);
  532. $authnet["x_exp_date"] = c_ws_plugin__s2member_pro_authnet_utilities::authnet_exp_date($post_vars["card_expiration"]);
  533. $authnet["x_card_code"] = $post_vars["card_verification"];
  534.  
  535. #if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  536. # if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  537. # $authnet["x_card_start_date"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  538. # else // Otherwise, we assume they provided an issue number instead.
  539. # $authnet["x_card_issue_number"] = $post_vars["card_start_date_issue_number"];
  540.  
  541. $authnet["x_address"] = $post_vars["street"];
  542. $authnet["x_city"] = $post_vars["city"];
  543. $authnet["x_state"] = $post_vars["state"];
  544. $authnet["x_country"] = $post_vars["country"];
  545. $authnet["x_zip"] = $post_vars["zip"];
  546. }
  547.  
  548. if(($authnet = c_ws_plugin__s2member_pro_authnet_utilities::authnet_aim_response($authnet)) && empty($authnet["__error"]))
  549. {
  550. $old__subscr_or_wp_id = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id();
  551. $old__subscr_id = get_user_option("s2member_subscr_id");
  552. $new__subscr_id = $new__txn_id = $authnet["transaction_id"];
  553.  
  554. if(!($ipn = array())) // Simulated PayPal® IPN.
  555. {
  556. $ipn["txn_type"] = "web_accept";
  557. $ipn["txn_id"] = $new__subscr_id;
  558. $ipn["custom"] = $post_vars["attr"]["custom"];
  559.  
  560. $ipn["mc_gross"] = $cost_calculations["total"];
  561. $ipn["mc_currency"] = $cost_calculations["cur"];
  562. $ipn["tax"] = $cost_calculations["tax"];
  563.  
  564. $ipn["payer_email"] = $user->user_email;
  565. $ipn["first_name"] = $post_vars["first_name"];
  566. $ipn["last_name"] = $post_vars["last_name"];
  567.  
  568. $ipn["option_name1"] = "Referencing Customer ID";
  569. $ipn["option_selection1"] = $old__subscr_or_wp_id;
  570.  
  571. $ipn["option_name2"] = "Customer IP Address";
  572. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  573.  
  574. $ipn["item_name"] = $cost_calculations["desc"];
  575. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  576.  
  577. $ipn["s2member_paypal_proxy"] = "authnet";
  578. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  579. $ipn["s2member_paypal_proxy_coupon"] = array("coupon_code" => $cp_attr["_coupon_code"], "full_coupon_code" => $cp_attr["_full_coupon_code"], "affiliate_id" => $cp_attr["_coupon_affiliate_id"]);
  580. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  581. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  582.  
  583. $ipn["s2member_authnet_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  584. }
  585.  
  586. if(!$is_independent_ccaps_sale) // Independent?
  587. if(($authnet = array("x_method" => "cancel")) && ($authnet["x_subscription_id"] = $old__subscr_id))
  588. {
  589. c_ws_plugin__s2member_pro_authnet_utilities::authnet_arb_response($authnet);
  590. }
  591.  
  592. setcookie("s2member_tracking", ($s2member_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($new__subscr_id)), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN).setcookie("s2member_tracking", $s2member_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN).($_COOKIE["s2member_tracking"] = $s2member_tracking);
  593.  
  594. $global_response = array("response" => sprintf(_x('<strong>Thank you.</strong> Your account has been updated.<br />&mdash; Please <a href="%s" rel="nofollow">log back in</a> now.', "s2member-front", "s2member"), esc_attr(wp_login_url())));
  595.  
  596. if($post_vars["attr"]["success"] && substr($ipn["s2member_authnet_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", /* Deprecated in v111106 ». */ "%%response%%"), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["s2member_authnet_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url))))
  597. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  598. }
  599. else // Else, an error.
  600. {
  601. $global_response = array("response" => $authnet["__error"], "error" => true);
  602. }
  603. }
  604.  
  605. else if(!$use_recurring_profile && !is_user_logged_in()) // Create a new account.
  606. {
  607. if(!($authnet = array())) // Direct payments.
  608. {
  609. $authnet["x_type"] = "AUTH_CAPTURE";
  610. $authnet["x_method"] = "CC";
  611.  
  612. $authnet["x_email"] = $post_vars["email"];
  613. $authnet["x_first_name"] = $post_vars["first_name"];
  614. $authnet["x_last_name"] = $post_vars["last_name"];
  615. $authnet["x_customer_ip"] = $_SERVER["REMOTE_ADDR"];
  616.  
  617. $authnet["x_invoice_num"] = "s2-".uniqid();
  618. $authnet["x_description"] = $cost_calculations["desc"];
  619.  
  620. $authnet["s2_invoice"] = $post_vars["attr"]["level_ccaps_eotper"];
  621. $authnet["s2_custom"] = $post_vars["attr"]["custom"];
  622.  
  623. $authnet["x_tax"] = $cost_calculations["tax"];
  624. $authnet["x_amount"] = $cost_calculations["total"];
  625. $authnet["x_currency_code"] = $cost_calculations["cur"];
  626.  
  627. $authnet["x_card_num"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]);
  628. $authnet["x_exp_date"] = c_ws_plugin__s2member_pro_authnet_utilities::authnet_exp_date($post_vars["card_expiration"]);
  629. $authnet["x_card_code"] = $post_vars["card_verification"];
  630.  
  631. #if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  632. # if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  633. # $authnet["x_card_start_date"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  634. # else // Otherwise, we assume they provided an issue number instead.
  635. # $authnet["x_card_issue_number"] = $post_vars["card_start_date_issue_number"];
  636.  
  637. $authnet["x_address"] = $post_vars["street"];
  638. $authnet["x_city"] = $post_vars["city"];
  639. $authnet["x_state"] = $post_vars["state"];
  640. $authnet["x_country"] = $post_vars["country"];
  641. $authnet["x_zip"] = $post_vars["zip"];
  642. }
  643.  
  644. if(($authnet = c_ws_plugin__s2member_pro_authnet_utilities::authnet_aim_response($authnet)) && empty($authnet["__error"]))
  645. {
  646. $new__subscr_id = $authnet["transaction_id"];
  647.  
  648. if(!($ipn = array())) // Simulated PayPal® IPN.
  649. {
  650. $ipn["txn_type"] = "web_accept";
  651. $ipn["txn_id"] = $new__subscr_id;
  652. $ipn["custom"] = $post_vars["attr"]["custom"];
  653.  
  654. $ipn["mc_gross"] = $cost_calculations["total"];
  655. $ipn["mc_currency"] = $cost_calculations["cur"];
  656. $ipn["tax"] = $cost_calculations["tax"];
  657.  
  658. $ipn["payer_email"] = $post_vars["email"];
  659. $ipn["first_name"] = $post_vars["first_name"];
  660. $ipn["last_name"] = $post_vars["last_name"];
  661.  
  662. $ipn["option_name1"] = "Originating Domain";
  663. $ipn["option_selection1"] = $_SERVER["HTTP_HOST"];
  664.  
  665. $ipn["option_name2"] = "Customer IP Address";
  666. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  667.  
  668. $ipn["item_name"] = $cost_calculations["desc"];
  669. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  670.  
  671. $ipn["s2member_paypal_proxy"] = "authnet";
  672. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  673. $ipn["s2member_paypal_proxy_coupon"] = array("coupon_code" => $cp_attr["_coupon_code"], "full_coupon_code" => $cp_attr["_full_coupon_code"], "affiliate_id" => $cp_attr["_coupon_affiliate_id"]);
  674. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  675. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  676. }
  677.  
  678. if(!($create_user = array())) // Build post fields for registration configuration, and then the creation array.
  679. {
  680. $_POST["ws_plugin__s2member_custom_reg_field_user_pass1"] = $post_vars["password1"]; // Fake this for registration configuration.
  681. $_POST["ws_plugin__s2member_custom_reg_field_first_name"] = $post_vars["first_name"]; // Fake this for registration configuration.
  682. $_POST["ws_plugin__s2member_custom_reg_field_last_name"] = $post_vars["last_name"]; // Fake this for registration configuration.
  683. $_POST["ws_plugin__s2member_custom_reg_field_opt_in"] = $post_vars["custom_fields"]["opt_in"]; // Fake this too.
  684.  
  685. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  686. foreach(json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  687. {
  688. $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
  689. $field_id_class = preg_replace("/_/", "-", $field_var);
  690.  
  691. if(isset($post_vars["custom_fields"][$field_var]))
  692. $_POST["ws_plugin__s2member_custom_reg_field_".$field_var] = $post_vars["custom_fields"][$field_var];
  693. }
  694.  
  695. $_COOKIE["s2member_subscr_gateway"] = c_ws_plugin__s2member_utils_encryption::encrypt("authnet"); // Fake this for registration configuration.
  696. $_COOKIE["s2member_subscr_id"] = c_ws_plugin__s2member_utils_encryption::encrypt($new__subscr_id); // Fake this for registration configuration.
  697. $_COOKIE["s2member_custom"] = c_ws_plugin__s2member_utils_encryption::encrypt($post_vars["attr"]["custom"]); // Fake this for registration configuration.
  698. $_COOKIE["s2member_item_number"] = c_ws_plugin__s2member_utils_encryption::encrypt($post_vars["attr"]["level_ccaps_eotper"]); // Fake this too.
  699.  
  700. $create_user["user_login"] = $post_vars["username"]; // Copy this into a separate array for `wp_create_user()`.
  701. $create_user["user_pass"] = wp_generate_password(); // Which may fire `c_ws_plugin__s2member_registrations::generate_password()`.
  702. $create_user["user_email"] = $post_vars["email"]; // Copy this into a separate array for `wp_create_user()`.
  703. }
  704.  
  705. if($post_vars["password1"] && $post_vars["password1"] === $create_user["user_pass"]) // A custom Password is being used?
  706. {
  707. if(((is_multisite() && ($new__user_id = c_ws_plugin__s2member_registrations::ms_create_existing_user($create_user["user_login"], $create_user["user_email"], $create_user["user_pass"]))) || ($new__user_id = wp_create_user($create_user["user_login"], $create_user["user_pass"], $create_user["user_email"]))) && !is_wp_error($new__user_id))
  708. {
  709. wp_new_user_notification($new__user_id, $create_user["user_pass"]);
  710.  
  711. $ipn["s2member_authnet_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  712.  
  713. $global_response = array("response" => sprintf(_x('<strong>Thank you.</strong> Your account has been approved.<br />&mdash; Please <a href="%s" rel="nofollow">login</a>.', "s2member-front", "s2member"), esc_attr(wp_login_url())));
  714.  
  715. if($post_vars["attr"]["success"] && substr($ipn["s2member_authnet_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", /* Deprecated in v111106 ». */ "%%response%%"), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["s2member_authnet_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url))))
  716. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  717. }
  718. else // Else, an error reponse should be given.
  719. {
  720. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20));
  721.  
  722. $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  723. }
  724. }
  725. else // Otherwise, they'll need to check their email for the auto-generated Password.
  726. {
  727. if(((is_multisite() && ($new__user_id = c_ws_plugin__s2member_registrations::ms_create_existing_user($create_user["user_login"], $create_user["user_email"], $create_user["user_pass"]))) || ($new__user_id = wp_create_user($create_user["user_login"], $create_user["user_pass"], $create_user["user_email"]))) && !is_wp_error($new__user_id))
  728. {
  729. update_user_option($new__user_id, "default_password_nag", true, true); // Password nag.
  730. wp_new_user_notification($new__user_id, $create_user["user_pass"]);
  731.  
  732. $ipn["s2member_authnet_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  733.  
  734. $global_response = array("response" => _x('<strong>Thank you.</strong> Your account has been approved.<br />&mdash; You\'ll receive an email momentarily.', "s2member-front", "s2member"));
  735.  
  736. if($post_vars["attr"]["success"] && substr($ipn["s2member_authnet_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", /* Deprecated in v111106 ». */ "%%response%%"), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["s2member_authnet_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url))))
  737. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  738. }
  739. else // Else, an error reponse should be given.
  740. {
  741. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20));
  742.  
  743. $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  744. }
  745. }
  746. }
  747. else // Else, an error.
  748. {
  749. $global_response = array("response" => $authnet["__error"], "error" => true);
  750. }
  751. }
  752. else // Else, we have an unknown scenario.
  753. {
  754. $global_response = array("response" => _x('<strong>Unknown error.</strong> Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  755. }
  756. }
  757. else // Else, an error.
  758. {
  759. $global_response = $error;
  760. }
  761. }
  762. }
  763. }
  764. }
  765. }
  766. ?>

pro\s2member-pro\includes\classes\gateways\authnet\authnet-checkout-in.inc.php

Source Code Documentation