Source Code Documentation


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


  1. <?php
  2. /**
  3. * PayPal® Checkout Forms (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\PayPal
  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_paypal_checkout_rdp_in"))
  37. {
  38. /**
  39. * PayPal® Checkout Forms (inner processing routines).
  40. *
  41. * This version handles Real-Time Direct Pay *(mission critical)*, when:
  42. * ``$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_paypal_checkout_rdp"] == true``.
  43. *
  44. * @package s2Member\PayPal
  45. * @since 1.5
  46. */
  47. class c_ws_plugin__s2member_pro_paypal_checkout_rdp_in
  48. {
  49. /**
  50. * Handles processing of Pro Form checkouts.
  51. *
  52. * @package s2Member\PayPal
  53. * @since 1.5
  54. *
  55. * @attaches-to ``add_action("init");``
  56. *
  57. * @return null Or exits script execution after a custom URL redirection; or upon Express Checkout redirection.
  58. */
  59. public static function paypal_checkout ()
  60. {
  61. if ((!empty ($_POST["s2member_pro_paypal_checkout"]["nonce"]) && ($nonce = $_POST["s2member_pro_paypal_checkout"]["nonce"]) && wp_verify_nonce ($nonce, "s2member-pro-paypal-checkout"))
  62. || (!empty ($_GET["s2member_paypal_xco"]) && $_GET["s2member_paypal_xco"] === "s2member_pro_paypal_checkout_return" // PayPal® Express Checkout with $_GET["token"] & $_GET["PayerID"]?
  63. && !empty ($_GET["token"]) && ($_GET["token"] = esc_html ($_GET["token"])) && (empty ($_GET["PayerID"]) || ($_GET["PayerID"] = esc_html ($_GET["PayerID"]))) // PayerID is not required.
  64. && ($xco_post_vars = get_transient ("s2m_" . md5 ("s2member_transient_express_checkout_" . $_GET["token"])))))
  65. {
  66. $GLOBALS["ws_plugin__s2member_pro_paypal_checkout_response"] = array (); // This holds the global response details.
  67. $global_response = &$GLOBALS["ws_plugin__s2member_pro_paypal_checkout_response"]; // This is a shorter reference.
  68.  
  69. $post_vars = ($xco_post_vars) ? $xco_post_vars : $_POST["s2member_pro_paypal_checkout"];
  70. $post_vars = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($post_vars)); // And Filter.
  71. $post_vars["attr"] = (!$xco_post_vars) ? unserialize (c_ws_plugin__s2member_utils_encryption::decrypt ($post_vars["attr"])) : $post_vars["attr"];
  72. $post_vars["attr"] = (!$xco_post_vars) ? apply_filters ("ws_plugin__s2member_pro_paypal_checkout_post_attr", $post_vars["attr"], get_defined_vars ()) : $post_vars["attr"];
  73.  
  74. if($xco_post_vars) // No need to re-validate this upon return from Express Checkout.
  75. $post_vars["attr"]["captcha"] = "0";
  76.  
  77. $post_vars["recaptcha_challenge_field"] = (!$post_vars["recaptcha_challenge_field"]) ? trim (stripslashes ($_POST["recaptcha_challenge_field"])) : $post_vars["recaptcha_challenge_field"];
  78. $post_vars["recaptcha_response_field"] = (!$post_vars["recaptcha_response_field"]) ? trim (stripslashes ($_POST["recaptcha_response_field"])) : $post_vars["recaptcha_response_field"];
  79.  
  80. $post_vars["name"] = trim ($post_vars["first_name"] . " " . $post_vars["last_name"]);
  81. $post_vars["email"] = apply_filters ("user_registration_email", sanitize_email ($post_vars["email"]), get_defined_vars ());
  82. $post_vars["username"] = (is_multisite()) ? strtolower($post_vars["username"]) : $post_vars["username"]; // Force lowercase.
  83. $post_vars["username"] = preg_replace ("/\s+/", "", sanitize_user (($post_vars["_o_username"] = $post_vars["username"]), is_multisite ()));
  84.  
  85. (!empty ($_GET["token"])) ? delete_transient ("s2m_" . md5 ("s2member_transient_express_checkout_" . $_GET["token"])) : null;
  86.  
  87. if (!c_ws_plugin__s2member_pro_paypal_responses::paypal_form_attr_validation_errors ($post_vars["attr"])) // Attr errors?
  88. {
  89. if (!($error = c_ws_plugin__s2member_pro_paypal_responses::paypal_form_submission_validation_errors ("checkout", $post_vars)))
  90. {
  91. $cp_attr = c_ws_plugin__s2member_pro_paypal_utilities::paypal_apply_coupon ($post_vars["attr"], $post_vars["coupon"], "attr", array ("affiliates-silent-post"));
  92. $cp_2gbp_attr = c_ws_plugin__s2member_pro_paypal_utilities::paypal_maestro_solo_2gbp ( /* Now we use the new array of ``$cp_attr``. */$cp_attr, $post_vars["card_type"]);
  93. $cost_calculations = c_ws_plugin__s2member_pro_paypal_utilities::paypal_cost ($cp_2gbp_attr["ta"], $cp_2gbp_attr["ra"], $post_vars["state"], $post_vars["country"], $post_vars["zip"], $cp_2gbp_attr["cc"], $cp_2gbp_attr["desc"]);
  94.  
  95. $use_recurring_profile = ($post_vars["attr"]["rr"] === "BN" || (!$post_vars["attr"]["tp"] && !$post_vars["attr"]["rr"])) ? false : true;
  96. $is_independent_ccaps_sale = ($post_vars["attr"]["level"] === "*") ? true : false; // Selling Independent Custom Capabilities?
  97.  
  98. if (empty ($_GET["s2member_paypal_xco"]) && $post_vars["card_type"] === "PayPal")
  99. {
  100. $return_url = $cancel_url = (is_ssl ()) ? "https://" : "http://";
  101. $return_url = $cancel_url = ($return_url = $cancel_url) . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
  102. $return_url = $cancel_url = /* Ditch. */ remove_query_arg (array ("token", "PayerID"), ($return_url = $cancel_url));
  103. $return_url = add_query_arg ("s2member_paypal_xco", urlencode ("s2member_pro_paypal_checkout_return"), $return_url);
  104. $cancel_url = add_query_arg ("s2member_paypal_xco", urlencode ("s2member_pro_paypal_checkout_cancel"), $cancel_url);
  105.  
  106. $user = (is_user_logged_in () && is_object ($user = wp_get_current_user ()) && ($user_id = $user->ID)) ? $user : false;
  107.  
  108. if (!($paypal_set_xco = array ())) // PayPal® Express Checkout.
  109. {
  110. $paypal_set_xco["METHOD"] = "SetExpressCheckout";
  111.  
  112. $paypal_set_xco["RETURNURL"] = $return_url;
  113. $paypal_set_xco["CANCELURL"] = $cancel_url;
  114.  
  115. $paypal_set_xco["PAGESTYLE"] = $post_vars["attr"]["ps"];
  116. $paypal_set_xco["LOCALECODE"] = $post_vars["attr"]["lc"];
  117. $paypal_set_xco["NOSHIPPING"] = $post_vars["attr"]["ns"];
  118. $paypal_set_xco["SOLUTIONTYPE"] = "Sole";
  119. $paypal_set_xco["LANDINGPAGE"] = "Billing";
  120. $paypal_set_xco["ALLOWNOTE"] = "0";
  121.  
  122. if ($use_recurring_profile) // Recurring Profile?
  123. {
  124. $paypal_set_xco["L_BILLINGTYPE0"] = "RecurringPayments";
  125. $paypal_set_xco["L_BILLINGAGREEMENTDESCRIPTION0"] = $cost_calculations["desc"];
  126.  
  127. if (!$post_vars["attr"]["tp"] || ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0))
  128. {
  129. $paypal_set_xco["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
  130.  
  131. $paypal_set_xco["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"];
  132. $paypal_set_xco["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"];
  133.  
  134. if ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)
  135. {
  136. $paypal_set_xco["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  137. $paypal_set_xco["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["trial_sub_total"];
  138. $paypal_set_xco["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["trial_tax"];
  139. $paypal_set_xco["PAYMENTREQUEST_0_AMT"] = $cost_calculations["trial_total"];
  140.  
  141. $paypal_set_xco["L_PAYMENTREQUEST_0_QTY0"] = "1"; // Always (1).
  142. $paypal_set_xco["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  143. $paypal_set_xco["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  144. $paypal_set_xco["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["trial_sub_total"];
  145. }
  146. else // Else we need to charge the first Regular payment in the billing cycle.
  147. {
  148. $paypal_set_xco["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  149. $paypal_set_xco["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"];
  150. $paypal_set_xco["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"];
  151. $paypal_set_xco["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"];
  152.  
  153. $paypal_set_xco["L_PAYMENTREQUEST_0_QTY0"] = "1"; // Always (1).
  154. $paypal_set_xco["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  155. $paypal_set_xco["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  156. $paypal_set_xco["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"];
  157. }
  158. }
  159. }
  160. else // Otherwise, we use fields for a "Buy Now" purchase.
  161. {
  162. $paypal_set_xco["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
  163.  
  164. $paypal_set_xco["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"];
  165. $paypal_set_xco["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"];
  166.  
  167. $paypal_set_xco["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  168. $paypal_set_xco["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"];
  169. $paypal_set_xco["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"];
  170. $paypal_set_xco["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"];
  171.  
  172. $paypal_set_xco["L_PAYMENTREQUEST_0_QTY0"] = "1"; // Always (1).
  173. $paypal_set_xco["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  174. $paypal_set_xco["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  175. $paypal_set_xco["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"];
  176. }
  177.  
  178. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTONAME"] = $post_vars["name"];
  179. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOSTREET"] = $post_vars["street"];
  180. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOCITY"] = $post_vars["city"];
  181. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOSTATE"] = $post_vars["state"];
  182. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE"] = $post_vars["country"];
  183. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOZIP"] = $post_vars["zip"];
  184.  
  185. $paypal_set_xco["EMAIL"] = ($user) ? $user->user_email : $post_vars["email"];
  186. }
  187.  
  188. if (($paypal_set_xco = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal_set_xco)) && empty ($paypal_set_xco["__error"]))
  189. {
  190. set_transient ("s2m_" . md5 ("s2member_transient_express_checkout_" . $paypal_set_xco["TOKEN"]), $post_vars, 10800);
  191.  
  192. $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_sandbox"]) ? "www.sandbox.paypal.com" : "www.paypal.com";
  193.  
  194. wp_redirect(add_query_arg ("token", urlencode ($paypal_set_xco["TOKEN"]), "https://" . $endpoint . "/cgi-bin/webscr?cmd=_express-checkout"));
  195.  
  196. exit /* Clean exit. */ ();
  197. }
  198. else // Else, an error.
  199. {
  200. $global_response = array ("response" => $paypal_set_xco["__error"], "error" => true);
  201. }
  202. }
  203.  
  204. else if ($use_recurring_profile && is_user_logged_in () && is_object ($user = wp_get_current_user ()) && ($user_id = $user->ID))
  205. {
  206. if (!($cur__subscr_id = get_user_option ("s2member_subscr_id")) || !($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response (array ("METHOD" => "GetRecurringPaymentsProfileDetails", "PROFILEID" => $cur__subscr_id))) || !empty ($paypal["__error"]) || !preg_match ("/^(Pending|PendingProfile)$/i", $paypal["STATUS"]))
  207. {
  208. $period1 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period1 ($post_vars["attr"]["tp"] . " " . $post_vars["attr"]["tt"]);
  209. $period3 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period3 ($post_vars["attr"]["rp"] . " " . $post_vars["attr"]["rt"]);
  210.  
  211. $start_time = ($post_vars["attr"]["tp"]) ? // If there's an Initial/Trial Period; start when it's over.
  212. c_ws_plugin__s2member_pro_paypal_utilities::paypal_start_time ($period1) : // After Trial is over.
  213. c_ws_plugin__s2member_pro_paypal_utilities::paypal_start_time ($period3); // Or next billing cycle.
  214.  
  215. $reference = $start_time . ":" . $period1 . ":" . $period3 . "~" . $_SERVER["HTTP_HOST"] . "~" . $post_vars["attr"]["level_ccaps_eotper"];
  216.  
  217. update_user_meta ($user_id, "first_name", $post_vars["first_name"]) . update_user_meta ($user_id, "last_name", $post_vars["last_name"]);
  218.  
  219. if (!($_paypal = array ()) // A first Initial/Trial payment?
  220. && (!$post_vars["attr"]["tp"] || ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)))
  221. {
  222. if ($_GET["s2member_paypal_xco"] === "s2member_pro_paypal_checkout_return" && !empty ($_GET["token"]) && ($_paypal_xco_details = array ("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($_paypal_xco_details = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($_paypal_xco_details)) && empty ($_paypal_xco_details["__error"]))
  223. {
  224. $_paypal["METHOD"] = "DoExpressCheckoutPayment";
  225.  
  226. $_paypal["TOKEN"] = $_paypal_xco_details["TOKEN"];
  227. $_paypal["PAYERID"] = $_paypal_xco_details["PAYERID"];
  228.  
  229. $_paypal["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
  230.  
  231. $_paypal["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"];
  232. $_paypal["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"];
  233.  
  234. if ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)
  235. {
  236. $_paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  237. $_paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["trial_sub_total"];
  238. $_paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["trial_tax"];
  239. $_paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["trial_total"];
  240.  
  241. $_paypal["L_PAYMENTREQUEST_0_QTY0"] = "1"; // Always (1).
  242. $_paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  243. $_paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  244. $_paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["trial_sub_total"];
  245. }
  246. else // Otherwise, charge for the first Regular payment.
  247. {
  248. $_paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  249. $_paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"];
  250. $_paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"];
  251. $_paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"];
  252.  
  253. $_paypal["L_PAYMENTREQUEST_0_QTY0"] = "1"; // Always (1).
  254. $_paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  255. $_paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  256. $_paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"];
  257. }
  258. }
  259. else // NOT using PayPal® Express Checkout.
  260. {
  261. $_paypal["METHOD"] = "DoDirectPayment";
  262. $_paypal["PAYMENTACTION"] = "Sale";
  263.  
  264. $_paypal["EMAIL"] = $user->user_email;
  265. $_paypal["FIRSTNAME"] = $post_vars["first_name"];
  266. $_paypal["LASTNAME"] = $post_vars["last_name"];
  267. $_paypal["IPADDRESS"] = $_SERVER["REMOTE_ADDR"];
  268.  
  269. $_paypal["DESC"] = $cost_calculations["desc"];
  270. $_paypal["CUSTOM"] = $post_vars["attr"]["custom"];
  271.  
  272. if ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)
  273. {
  274. $_paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  275. $_paypal["ITEMAMT"] = $cost_calculations["trial_sub_total"];
  276. $_paypal["TAXAMT"] = $cost_calculations["trial_tax"];
  277. $_paypal["AMT"] = $cost_calculations["trial_total"];
  278.  
  279. $_paypal["L_QTY0"] = "1"; // Always (1).
  280. $_paypal["L_NAME0"] = $cost_calculations["desc"];
  281. $_paypal["L_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  282. $_paypal["L_AMT0"] = $cost_calculations["trial_sub_total"];
  283. }
  284. else // Otherwise, charge for the first Regular payment.
  285. {
  286. $_paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  287. $_paypal["ITEMAMT"] = $cost_calculations["sub_total"];
  288. $_paypal["TAXAMT"] = $cost_calculations["tax"];
  289. $_paypal["AMT"] = $cost_calculations["total"];
  290.  
  291. $_paypal["L_QTY0"] = "1"; // Always (1).
  292. $_paypal["L_NAME0"] = $cost_calculations["desc"];
  293. $_paypal["L_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  294. $_paypal["L_AMT0"] = $cost_calculations["sub_total"];
  295. }
  296.  
  297. $_paypal["CREDITCARDTYPE"] = $post_vars["card_type"];
  298. $_paypal["ACCT"] = preg_replace ("/[^0-9]/", "", $post_vars["card_number"]);
  299. $_paypal["EXPDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_expiration"]);
  300. $_paypal["CVV2"] = $post_vars["card_verification"];
  301.  
  302. if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  303. if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  304. $_paypal["STARTDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  305. else // Otherwise, we assume they provided an Issue Number instead.
  306. $_paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"];
  307.  
  308. $_paypal["STREET"] = $post_vars["street"];
  309. $_paypal["CITY"] = $post_vars["city"];
  310. $_paypal["STATE"] = $post_vars["state"];
  311. $_paypal["COUNTRYCODE"] = $post_vars["country"];
  312. $_paypal["ZIP"] = $post_vars["zip"];
  313. }
  314. }
  315.  
  316. if (!($paypal = array ())) // Recurring Profile.
  317. {
  318. $paypal["METHOD"] = "CreateRecurringPaymentsProfile";
  319.  
  320. $paypal["EMAIL"] = $user->user_email;
  321. $paypal["FIRSTNAME"] = $post_vars["first_name"];
  322. $paypal["LASTNAME"] = $post_vars["last_name"];
  323. $paypal["SUBSCRIBERNAME"] = $post_vars["name"];
  324.  
  325. $paypal["DESC"] = $cost_calculations["desc"];
  326. $paypal["PROFILEREFERENCE"] = $reference;
  327.  
  328. $paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  329. $paypal["AMT"] = $cost_calculations["sub_total"];
  330. $paypal["TAXAMT"] = $cost_calculations["tax"];
  331.  
  332. $paypal["MAXFAILEDPAYMENTS"] = $post_vars["attr"]["rra"];
  333. $paypal["AUTOBILLOUTAMT"] = apply_filters ("ws_plugin__s2member_pro_paypal_auto_bill_op", "AddToNextBilling", get_defined_vars ());
  334.  
  335. $paypal["PROFILESTARTDATE"] = date ("Y-m-d", $start_time) . "T00:00:00Z";
  336.  
  337. $paypal["BILLINGPERIOD"] = c_ws_plugin__s2member_paypal_utilities::paypal_pro_term ($post_vars["attr"]["rt"]);
  338. $paypal["TOTALBILLINGCYCLES"] = ($post_vars["attr"]["rr"]) ? (($post_vars["attr"]["rrt"]) ? $post_vars["attr"]["rrt"] : "0") : "1";
  339. $paypal["BILLINGFREQUENCY"] = $post_vars["attr"]["rp"];
  340.  
  341. if ($_GET["s2member_paypal_xco"] === "s2member_pro_paypal_checkout_return" && !empty ($_GET["token"]) && ((!empty ($_paypal_xco_details) && empty ($_paypal_xco_details["__error"]) && ($paypal_xco_details = $_paypal_xco_details)) || (($paypal_xco_details = array ("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($paypal_xco_details = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal_xco_details)) && empty ($paypal_xco_details["__error"]))))
  342. {
  343. $paypal["TOKEN"] = $paypal_xco_details["TOKEN"];
  344. }
  345. else // Otherwise, they're using a major credit card.
  346. {
  347. $paypal["CREDITCARDTYPE"] = $post_vars["card_type"];
  348. $paypal["ACCT"] = preg_replace ("/[^0-9]/", "", $post_vars["card_number"]);
  349. $paypal["EXPDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_expiration"]);
  350. $paypal["CVV2"] = $post_vars["card_verification"];
  351.  
  352. if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  353. if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  354. $paypal["STARTDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  355. else // Otherwise, we assume they provided an Issue Number instead.
  356. $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"];
  357.  
  358. $paypal["STREET"] = $post_vars["street"];
  359. $paypal["CITY"] = $post_vars["city"];
  360. $paypal["STATE"] = $post_vars["state"];
  361. $paypal["COUNTRYCODE"] = $post_vars["country"];
  362. $paypal["ZIP"] = $post_vars["zip"];
  363. }
  364. }
  365.  
  366. if (!$_paypal || (($_paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($_paypal)) && empty ($_paypal["__error"])))
  367. {
  368. if (($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal)) && empty ($paypal["__error"]))
  369. {
  370. $new__txn_id = ($_paypal && !empty ($_paypal["PAYMENTINFO_0_TRANSACTIONID"])) ? $_paypal["PAYMENTINFO_0_TRANSACTIONID"] : false;
  371. $new__txn_id = (!$new__txn_id && $_paypal && !empty ($_paypal["TRANSACTIONID"])) ? $_paypal["TRANSACTIONID"] : $new__txn_id;
  372. $old__subscr_or_wp_id = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id ();
  373. $old__subscr_id = get_user_option ("s2member_subscr_id");
  374. $new__subscr_id = $paypal["PROFILEID"];
  375.  
  376. if (!($ipn = array ())) // Simulated PayPal® IPN.
  377. {
  378. $ipn["txn_type"] = "subscr_signup";
  379. $ipn["subscr_id"] = $new__subscr_id;
  380. $ipn["custom"] = $post_vars["attr"]["custom"];
  381.  
  382. $ipn["txn_id"] = ($new__txn_id) ? $new__txn_id : $new__subscr_id;
  383.  
  384. $ipn["period1"] = $period1;
  385. $ipn["period3"] = $period3;
  386.  
  387. $ipn["mc_amount1"] = $cost_calculations["trial_total"];
  388. $ipn["mc_amount3"] = $cost_calculations["total"];
  389.  
  390. $ipn["mc_gross"] = (preg_match ("/^[1-9]/", $ipn["period1"])) ? $ipn["mc_amount1"] : $ipn["mc_amount3"];
  391.  
  392. $ipn["mc_currency"] = $cost_calculations["cur"];
  393. $ipn["tax"] = $cost_calculations["tax"];
  394.  
  395. $ipn["recurring"] = ($post_vars["attr"]["rr"]) ? "1" : "";
  396.  
  397. $ipn["payer_email"] = $user->user_email;
  398. $ipn["first_name"] = $post_vars["first_name"];
  399. $ipn["last_name"] = $post_vars["last_name"];
  400.  
  401. $ipn["option_name1"] = "Referencing Customer ID";
  402. $ipn["option_selection1"] = $old__subscr_or_wp_id;
  403.  
  404. $ipn["option_name2"] = "Customer IP Address";
  405. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  406.  
  407. $ipn["item_name"] = $cost_calculations["desc"];
  408. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  409.  
  410. $ipn["s2member_paypal_proxy"] = "paypal";
  411. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  412. $ipn["s2member_paypal_proxy_use"] .= ($ipn["mc_gross"] > 0) ? ",subscr-signup-as-subscr-payment" : "";
  413. $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"]);
  414. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  415. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  416.  
  417. $ipn["s2member_paypal_proxy_return_url"] = trim (c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20)));
  418. }
  419.  
  420. if (!($paypal = array ()) && ($paypal["PROFILEID"] = $old__subscr_id))
  421. {
  422. $paypal["METHOD"] = "ManageRecurringPaymentsProfileStatus";
  423. $paypal["ACTION"] = "Cancel";
  424.  
  425. c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal);
  426. }
  427.  
  428. 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);
  429.  
  430. $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 ())));
  431.  
  432. if ($post_vars["attr"]["success"] && substr ($ipn["s2member_paypal_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_paypal_proxy_return_url"])) && ($custom_success_url = trim (preg_replace ("/%%(.+?)%%/i", "", $custom_success_url))))
  433. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig ($custom_success_url, "s2p-v")) . exit ();
  434. }
  435. else // Else, an error.
  436. {
  437. $global_response = array ("response" => $paypal["__error"], "error" => true);
  438. }
  439. }
  440. else // Else, an error.
  441. {
  442. $global_response = array ("response" => $_paypal["__error"], "error" => true);
  443. }
  444. }
  445. else // Else, an error. The existing Billing Profile is still in a pending state.
  446. {
  447. $global_response = array ("response" => _x ('<strong>Sorry.</strong> Your account is pending other changes. Please try again in 15 minutes.', "s2member-front", "s2member"), "error" => true);
  448. }
  449. }
  450.  
  451. else if ($use_recurring_profile && !is_user_logged_in ()) // Create a new account.
  452. {
  453. $period1 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period1 ($post_vars["attr"]["tp"] . " " . $post_vars["attr"]["tt"]);
  454. $period3 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period3 ($post_vars["attr"]["rp"] . " " . $post_vars["attr"]["rt"]);
  455.  
  456. $start_time = ($post_vars["attr"]["tp"]) ? // If there's an Initial/Trial Period; start when it's over.
  457. c_ws_plugin__s2member_pro_paypal_utilities::paypal_start_time ($period1) : // After Trial is over.
  458. c_ws_plugin__s2member_pro_paypal_utilities::paypal_start_time ($period3); // Or next billing cycle.
  459.  
  460. $reference = $start_time . ":" . $period1 . ":" . $period3 . "~" . $_SERVER["HTTP_HOST"] . "~" . $post_vars["attr"]["level_ccaps_eotper"];
  461.  
  462. if (!($_paypal = array ()) // A first Initial/Trial payment?
  463. && (!$post_vars["attr"]["tp"] || ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)))
  464. {
  465. if ($_GET["s2member_paypal_xco"] === "s2member_pro_paypal_checkout_return" && !empty ($_GET["token"]) && ($_paypal_xco_details = array ("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($_paypal_xco_details = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($_paypal_xco_details)) && empty ($_paypal_xco_details["__error"]))
  466. {
  467. $_paypal["METHOD"] = "DoExpressCheckoutPayment";
  468.  
  469. $_paypal["TOKEN"] = $_paypal_xco_details["TOKEN"];
  470. $_paypal["PAYERID"] = $_paypal_xco_details["PAYERID"];
  471.  
  472. $_paypal["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
  473.  
  474. $_paypal["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"];
  475. $_paypal["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"];
  476.  
  477. if ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)
  478. {
  479. $_paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  480. $_paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["trial_sub_total"];
  481. $_paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["trial_tax"];
  482. $_paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["trial_total"];
  483.  
  484. $_paypal["L_PAYMENTREQUEST_0_QTY0"] = "1"; // Always (1).
  485. $_paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  486. $_paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  487. $_paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["trial_sub_total"];
  488. }
  489. else // Otherwise, charge for the first Regular payment.
  490. {
  491. $_paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  492. $_paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"];
  493. $_paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"];
  494. $_paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"];
  495.  
  496. $_paypal["L_PAYMENTREQUEST_0_QTY0"] = "1"; // Always (1).
  497. $_paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  498. $_paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  499. $_paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"];
  500. }
  501. }
  502. else // NOT using PayPal® Express Checkout.
  503. {
  504. $_paypal["METHOD"] = "DoDirectPayment";
  505. $_paypal["PAYMENTACTION"] = "Sale";
  506.  
  507. $_paypal["EMAIL"] = $post_vars["email"];
  508. $_paypal["FIRSTNAME"] = $post_vars["first_name"];
  509. $_paypal["LASTNAME"] = $post_vars["last_name"];
  510. $_paypal["IPADDRESS"] = $_SERVER["REMOTE_ADDR"];
  511.  
  512. $_paypal["DESC"] = $cost_calculations["desc"];
  513. $_paypal["CUSTOM"] = $post_vars["attr"]["custom"];
  514.  
  515. if ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0)
  516. {
  517. $_paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  518. $_paypal["ITEMAMT"] = $cost_calculations["trial_sub_total"];
  519. $_paypal["TAXAMT"] = $cost_calculations["trial_tax"];
  520. $_paypal["AMT"] = $cost_calculations["trial_total"];
  521.  
  522. $_paypal["L_QTY0"] = "1"; // Always (1).
  523. $_paypal["L_NAME0"] = $cost_calculations["desc"];
  524. $_paypal["L_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  525. $_paypal["L_AMT0"] = $cost_calculations["trial_sub_total"];
  526. }
  527. else // Otherwise, charge for the first Regular payment.
  528. {
  529. $_paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  530. $_paypal["ITEMAMT"] = $cost_calculations["sub_total"];
  531. $_paypal["TAXAMT"] = $cost_calculations["tax"];
  532. $_paypal["AMT"] = $cost_calculations["total"];
  533.  
  534. $_paypal["L_QTY0"] = "1"; // Always (1).
  535. $_paypal["L_NAME0"] = $cost_calculations["desc"];
  536. $_paypal["L_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  537. $_paypal["L_AMT0"] = $cost_calculations["sub_total"];
  538. }
  539.  
  540. $_paypal["CREDITCARDTYPE"] = $post_vars["card_type"];
  541. $_paypal["ACCT"] = preg_replace ("/[^0-9]/", "", $post_vars["card_number"]);
  542. $_paypal["EXPDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_expiration"]);
  543. $_paypal["CVV2"] = $post_vars["card_verification"];
  544.  
  545. if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  546. if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  547. $_paypal["STARTDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  548. else // Otherwise, we assume they provided an Issue Number instead.
  549. $_paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"];
  550.  
  551. $_paypal["STREET"] = $post_vars["street"];
  552. $_paypal["CITY"] = $post_vars["city"];
  553. $_paypal["STATE"] = $post_vars["state"];
  554. $_paypal["COUNTRYCODE"] = $post_vars["country"];
  555. $_paypal["ZIP"] = $post_vars["zip"];
  556. }
  557. }
  558.  
  559. if (!($paypal = array ())) // Recurring Profile.
  560. {
  561. $paypal["METHOD"] = "CreateRecurringPaymentsProfile";
  562.  
  563. $paypal["EMAIL"] = $post_vars["email"];
  564. $paypal["FIRSTNAME"] = $post_vars["first_name"];
  565. $paypal["LASTNAME"] = $post_vars["last_name"];
  566. $paypal["SUBSCRIBERNAME"] = $post_vars["name"];
  567.  
  568. $paypal["DESC"] = $cost_calculations["desc"];
  569. $paypal["PROFILEREFERENCE"] = $reference;
  570.  
  571. $paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  572. $paypal["AMT"] = $cost_calculations["sub_total"];
  573. $paypal["TAXAMT"] = $cost_calculations["tax"];
  574.  
  575. $paypal["MAXFAILEDPAYMENTS"] = $post_vars["attr"]["rra"];
  576. $paypal["AUTOBILLOUTAMT"] = apply_filters ("ws_plugin__s2member_pro_paypal_auto_bill_op", "AddToNextBilling", get_defined_vars ());
  577.  
  578. $paypal["PROFILESTARTDATE"] = date ("Y-m-d", $start_time) . "T00:00:00Z";
  579.  
  580. $paypal["BILLINGPERIOD"] = c_ws_plugin__s2member_paypal_utilities::paypal_pro_term ($post_vars["attr"]["rt"]);
  581. $paypal["TOTALBILLINGCYCLES"] = ($post_vars["attr"]["rr"]) ? (($post_vars["attr"]["rrt"]) ? $post_vars["attr"]["rrt"] : "0") : "1";
  582. $paypal["BILLINGFREQUENCY"] = $post_vars["attr"]["rp"];
  583.  
  584. if ($_GET["s2member_paypal_xco"] === "s2member_pro_paypal_checkout_return" && !empty ($_GET["token"]) && ((!empty ($_paypal_xco_details) && empty ($_paypal_xco_details["__error"]) && ($paypal_xco_details = $_paypal_xco_details)) || (($paypal_xco_details = array ("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($paypal_xco_details = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal_xco_details)) && empty ($paypal_xco_details["__error"]))))
  585. {
  586. $paypal["TOKEN"] = $paypal_xco_details["TOKEN"];
  587. }
  588. else // Otherwise, they're using a major credit card.
  589. {
  590. $paypal["CREDITCARDTYPE"] = $post_vars["card_type"];
  591. $paypal["ACCT"] = preg_replace ("/[^0-9]/", "", $post_vars["card_number"]);
  592. $paypal["EXPDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_expiration"]);
  593. $paypal["CVV2"] = $post_vars["card_verification"];
  594.  
  595. if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  596. if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  597. $paypal["STARTDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  598. else // Otherwise, we assume they provided an Issue Number instead.
  599. $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"];
  600.  
  601. $paypal["STREET"] = $post_vars["street"];
  602. $paypal["CITY"] = $post_vars["city"];
  603. $paypal["STATE"] = $post_vars["state"];
  604. $paypal["COUNTRYCODE"] = $post_vars["country"];
  605. $paypal["ZIP"] = $post_vars["zip"];
  606. }
  607. }
  608.  
  609. if (!$_paypal || (($_paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($_paypal)) && empty ($_paypal["__error"])))
  610. {
  611. if (($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal)) && empty ($paypal["__error"]))
  612. {
  613. $new__txn_id = ($_paypal && !empty ($_paypal["PAYMENTINFO_0_TRANSACTIONID"])) ? $_paypal["PAYMENTINFO_0_TRANSACTIONID"] : false;
  614. $new__txn_id = (!$new__txn_id && $_paypal && !empty ($_paypal["TRANSACTIONID"])) ? $_paypal["TRANSACTIONID"] : $new__txn_id;
  615. $new__subscr_id = $paypal["PROFILEID"];
  616.  
  617. if (!($ipn = array ())) // Simulated PayPal® IPN.
  618. {
  619. $ipn["txn_type"] = "subscr_signup";
  620. $ipn["subscr_id"] = $new__subscr_id;
  621. $ipn["custom"] = $post_vars["attr"]["custom"];
  622.  
  623. $ipn["txn_id"] = ($new__txn_id) ? $new__txn_id : $new__subscr_id;
  624.  
  625. $ipn["period1"] = $period1;
  626. $ipn["period3"] = $period3;
  627.  
  628. $ipn["mc_amount1"] = $cost_calculations["trial_total"];
  629. $ipn["mc_amount3"] = $cost_calculations["total"];
  630.  
  631. $ipn["mc_gross"] = (preg_match ("/^[1-9]/", $ipn["period1"])) ? $ipn["mc_amount1"] : $ipn["mc_amount3"];
  632.  
  633. $ipn["mc_currency"] = $cost_calculations["cur"];
  634. $ipn["tax"] = $cost_calculations["tax"];
  635.  
  636. $ipn["recurring"] = ($post_vars["attr"]["rr"]) ? "1" : "";
  637.  
  638. $ipn["payer_email"] = $post_vars["email"];
  639. $ipn["first_name"] = $post_vars["first_name"];
  640. $ipn["last_name"] = $post_vars["last_name"];
  641.  
  642. $ipn["option_name1"] = "Originating Domain";
  643. $ipn["option_selection1"] = $_SERVER["HTTP_HOST"];
  644.  
  645. $ipn["option_name2"] = "Customer IP Address";
  646. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  647.  
  648. $ipn["item_name"] = $cost_calculations["desc"];
  649. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  650.  
  651. $ipn["s2member_paypal_proxy"] = "paypal";
  652. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  653. $ipn["s2member_paypal_proxy_use"] .= ($ipn["mc_gross"] > 0) ? ",subscr-signup-as-subscr-payment" : "";
  654. $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"]);
  655. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  656. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  657. }
  658.  
  659. if (!($create_user = array ())) // Build post fields for registration configuration, and then the creation array.
  660. {
  661. $_POST["ws_plugin__s2member_custom_reg_field_user_pass1"] = $post_vars["password1"]; // Fake this for registration configuration.
  662. $_POST["ws_plugin__s2member_custom_reg_field_first_name"] = $post_vars["first_name"]; // Fake this for registration configuration.
  663. $_POST["ws_plugin__s2member_custom_reg_field_last_name"] = $post_vars["last_name"]; // Fake this for registration configuration.
  664. $_POST["ws_plugin__s2member_custom_reg_field_opt_in"] = $post_vars["custom_fields"]["opt_in"]; // Fake this too.
  665.  
  666. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  667. foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  668. {
  669. $field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
  670. $field_id_class = preg_replace ("/_/", "-", $field_var);
  671.  
  672. if (isset ($post_vars["custom_fields"][$field_var]))
  673. $_POST["ws_plugin__s2member_custom_reg_field_" . $field_var] = $post_vars["custom_fields"][$field_var];
  674. }
  675.  
  676. $_COOKIE["s2member_subscr_gateway"] = c_ws_plugin__s2member_utils_encryption::encrypt ("paypal"); // Fake this for registration configuration.
  677. $_COOKIE["s2member_subscr_id"] = c_ws_plugin__s2member_utils_encryption::encrypt ($new__subscr_id); // Fake this for registration configuration.
  678. $_COOKIE["s2member_custom"] = c_ws_plugin__s2member_utils_encryption::encrypt ($post_vars["attr"]["custom"]); // Fake this for registration configuration.
  679. $_COOKIE["s2member_item_number"] = c_ws_plugin__s2member_utils_encryption::encrypt ($post_vars["attr"]["level_ccaps_eotper"]); // Fake this too.
  680.  
  681. $create_user["user_login"] = $post_vars["username"]; // Copy this into a separate array for `wp_create_user()`.
  682. $create_user["user_pass"] = wp_generate_password (); // Which may fire `c_ws_plugin__s2member_registrations::generate_password()`.
  683. $create_user["user_email"] = $post_vars["email"]; // Copy this into a separate array for `wp_create_user()`.
  684. }
  685.  
  686. if ($post_vars["password1"] && $post_vars["password1"] === $create_user["user_pass"]) // A custom Password is being used?
  687. {
  688. 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))
  689. {
  690. wp_new_user_notification ($new__user_id, $create_user["user_pass"]);
  691.  
  692. $ipn["s2member_paypal_proxy_return_url"] = trim (c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20)));
  693.  
  694. $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 ())));
  695.  
  696. if ($post_vars["attr"]["success"] && substr ($ipn["s2member_paypal_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_paypal_proxy_return_url"])) && ($custom_success_url = trim (preg_replace ("/%%(.+?)%%/i", "", $custom_success_url))))
  697. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig ($custom_success_url, "s2p-v")) . exit ();
  698. }
  699. else // Else, an error reponse should be given.
  700. {
  701. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20));
  702.  
  703. $global_response = array ("response" => _x ('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  704. }
  705. }
  706. else // Otherwise, they'll need to check their email for the auto-generated Password.
  707. {
  708. 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))
  709. {
  710. update_user_option ($new__user_id, "default_password_nag", true, true); // Password nag.
  711. wp_new_user_notification ($new__user_id, $create_user["user_pass"]);
  712.  
  713. $ipn["s2member_paypal_proxy_return_url"] = trim (c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20)));
  714.  
  715. $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"));
  716.  
  717. if ($post_vars["attr"]["success"] && substr ($ipn["s2member_paypal_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_paypal_proxy_return_url"])) && ($custom_success_url = trim (preg_replace ("/%%(.+?)%%/i", "", $custom_success_url))))
  718. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig ($custom_success_url, "s2p-v")) . exit ();
  719. }
  720. else // Else, an error reponse should be given.
  721. {
  722. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20));
  723.  
  724. $global_response = array ("response" => _x ('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  725. }
  726. }
  727. }
  728. else // Else, an error.
  729. {
  730. $global_response = array ("response" => $paypal["__error"], "error" => true);
  731. }
  732. }
  733. else // Else, an error.
  734. {
  735. $global_response = array ("response" => $_paypal["__error"], "error" => true);
  736. }
  737. }
  738.  
  739. else if (!$use_recurring_profile && is_user_logged_in () && is_object ($user = wp_get_current_user ()) && ($user_id = $user->ID))
  740. {
  741. if ($is_independent_ccaps_sale || !($cur__subscr_id = get_user_option ("s2member_subscr_id")) || !($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response (array ("METHOD" => "GetRecurringPaymentsProfileDetails", "PROFILEID" => $cur__subscr_id))) || !empty ($paypal["__error"]) || !preg_match ("/^(Pending|PendingProfile)$/i", $paypal["STATUS"]))
  742. {
  743. update_user_meta ($user_id, "first_name", $post_vars["first_name"]) . update_user_meta ($user_id, "last_name", $post_vars["last_name"]);
  744.  
  745. if (!($paypal = array ())) // Prepare a "Buy Now" transaction.
  746. {
  747. if ($_GET["s2member_paypal_xco"] === "s2member_pro_paypal_checkout_return" && !empty ($_GET["token"]) && ($paypal_xco_details = array ("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($paypal_xco_details = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal_xco_details)) && empty ($paypal_xco_details["__error"]))
  748. {
  749. $paypal["METHOD"] = "DoExpressCheckoutPayment";
  750.  
  751. $paypal["TOKEN"] = $paypal_xco_details["TOKEN"];
  752. $paypal["PAYERID"] = $paypal_xco_details["PAYERID"];
  753.  
  754. $paypal["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
  755.  
  756. $paypal["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"];
  757. $paypal["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"];
  758.  
  759. $paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  760. $paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"];
  761. $paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"];
  762. $paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"];
  763.  
  764. $paypal["L_PAYMENTREQUEST_0_QTY0"] = "1"; // Always (1).
  765. $paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  766. $paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  767. $paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"];
  768. }
  769. else // NOT using PayPal® Express Checkout.
  770. {
  771. $paypal["METHOD"] = "DoDirectPayment";
  772. $paypal["PAYMENTACTION"] = "Sale";
  773.  
  774. $paypal["EMAIL"] = $user->user_email;
  775. $paypal["FIRSTNAME"] = $post_vars["first_name"];
  776. $paypal["LASTNAME"] = $post_vars["last_name"];
  777. $paypal["IPADDRESS"] = $_SERVER["REMOTE_ADDR"];
  778.  
  779. $paypal["DESC"] = $cost_calculations["desc"];
  780. $paypal["CUSTOM"] = $post_vars["attr"]["custom"];
  781.  
  782. $paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  783. $paypal["ITEMAMT"] = $cost_calculations["sub_total"];
  784. $paypal["TAXAMT"] = $cost_calculations["tax"];
  785. $paypal["AMT"] = $cost_calculations["total"];
  786.  
  787. $paypal["L_QTY0"] = "1"; // Always (1).
  788. $paypal["L_NAME0"] = $cost_calculations["desc"];
  789. $paypal["L_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  790. $paypal["L_AMT0"] = $cost_calculations["sub_total"];
  791.  
  792. $paypal["CREDITCARDTYPE"] = $post_vars["card_type"];
  793. $paypal["ACCT"] = preg_replace ("/[^0-9]/", "", $post_vars["card_number"]);
  794. $paypal["EXPDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_expiration"]);
  795. $paypal["CVV2"] = $post_vars["card_verification"];
  796.  
  797. if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  798. if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  799. $paypal["STARTDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  800. else // Otherwise, we assume they provided an Issue Number instead.
  801. $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"];
  802.  
  803. $paypal["STREET"] = $post_vars["street"];
  804. $paypal["CITY"] = $post_vars["city"];
  805. $paypal["STATE"] = $post_vars["state"];
  806. $paypal["COUNTRYCODE"] = $post_vars["country"];
  807. $paypal["ZIP"] = $post_vars["zip"];
  808. }
  809. }
  810.  
  811. if (($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal)) && empty ($paypal["__error"]))
  812. {
  813. $old__subscr_id = get_user_option ("s2member_subscr_id");
  814. $old__subscr_or_wp_id = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id ();
  815. $new__subscr_id = $new__txn_id = (!empty ($paypal["PAYMENTINFO_0_TRANSACTIONID"])) ? $paypal["PAYMENTINFO_0_TRANSACTIONID"] : false;
  816. $new__subscr_id = $new__txn_id = (!$new__subscr_id && !empty ($paypal["TRANSACTIONID"])) ? $paypal["TRANSACTIONID"] : $new__subscr_id;
  817.  
  818. if (!($ipn = array ())) // Simulated PayPal® IPN.
  819. {
  820. $ipn["txn_type"] = "web_accept";
  821. $ipn["txn_id"] = $new__subscr_id;
  822. $ipn["custom"] = $post_vars["attr"]["custom"];
  823.  
  824. $ipn["mc_gross"] = $cost_calculations["total"];
  825. $ipn["mc_currency"] = $cost_calculations["cur"];
  826. $ipn["tax"] = $cost_calculations["tax"];
  827.  
  828. $ipn["payer_email"] = $user->user_email;
  829. $ipn["first_name"] = $post_vars["first_name"];
  830. $ipn["last_name"] = $post_vars["last_name"];
  831.  
  832. $ipn["option_name1"] = "Referencing Customer ID";
  833. $ipn["option_selection1"] = $old__subscr_or_wp_id;
  834.  
  835. $ipn["option_name2"] = "Customer IP Address";
  836. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  837.  
  838. $ipn["item_name"] = $cost_calculations["desc"];
  839. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  840.  
  841. $ipn["s2member_paypal_proxy"] = "paypal";
  842. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  843. $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"]);
  844. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  845. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  846.  
  847. $ipn["s2member_paypal_proxy_return_url"] = trim (c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20)));
  848. }
  849.  
  850. if (!$is_independent_ccaps_sale) // Independent?
  851. if (!($paypal = array ()) && ($paypal["PROFILEID"] = $old__subscr_id))
  852. {
  853. $paypal["METHOD"] = "ManageRecurringPaymentsProfileStatus";
  854. $paypal["ACTION"] = "Cancel";
  855.  
  856. c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal);
  857. }
  858.  
  859. 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);
  860.  
  861. $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 ())));
  862.  
  863. if ($post_vars["attr"]["success"] && substr ($ipn["s2member_paypal_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_paypal_proxy_return_url"])) && ($custom_success_url = trim (preg_replace ("/%%(.+?)%%/i", "", $custom_success_url))))
  864. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig ($custom_success_url, "s2p-v")) . exit ();
  865. }
  866. else // Else, an error.
  867. {
  868. $global_response = array ("response" => $paypal["__error"], "error" => true);
  869. }
  870. }
  871. else // Else, an error. The existing Billing Profile is still in a pending state.
  872. {
  873. $global_response = array ("response" => _x ('<strong>Sorry.</strong> Your account is pending other changes. Please try again in 15 minutes.', "s2member-front", "s2member"), "error" => true);
  874. }
  875. }
  876.  
  877. else if (!$use_recurring_profile && !is_user_logged_in ())
  878. {
  879. if (!($paypal = array ())) // Prepare a "Buy Now" transaction.
  880. {
  881. if ($_GET["s2member_paypal_xco"] === "s2member_pro_paypal_checkout_return" && !empty ($_GET["token"]) && ($paypal_xco_details = array ("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($paypal_xco_details = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal_xco_details)) && empty ($paypal_xco_details["__error"]))
  882. {
  883. $paypal["METHOD"] = "DoExpressCheckoutPayment";
  884.  
  885. $paypal["TOKEN"] = $paypal_xco_details["TOKEN"];
  886. $paypal["PAYERID"] = $paypal_xco_details["PAYERID"];
  887.  
  888. $paypal["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
  889.  
  890. $paypal["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"];
  891. $paypal["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"];
  892.  
  893. $paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  894. $paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"];
  895. $paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"];
  896. $paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"];
  897.  
  898. $paypal["L_PAYMENTREQUEST_0_QTY0"] = "1"; // Always (1).
  899. $paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  900. $paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  901. $paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"];
  902. }
  903. else // NOT using PayPal® Express Checkout.
  904. {
  905. $paypal["METHOD"] = "DoDirectPayment";
  906. $paypal["PAYMENTACTION"] = "Sale";
  907.  
  908. $paypal["EMAIL"] = $post_vars["email"];
  909. $paypal["FIRSTNAME"] = $post_vars["first_name"];
  910. $paypal["LASTNAME"] = $post_vars["last_name"];
  911. $paypal["IPADDRESS"] = $_SERVER["REMOTE_ADDR"];
  912.  
  913. $paypal["DESC"] = $cost_calculations["desc"];
  914. $paypal["CUSTOM"] = $post_vars["attr"]["custom"];
  915.  
  916. $paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  917. $paypal["ITEMAMT"] = $cost_calculations["sub_total"];
  918. $paypal["TAXAMT"] = $cost_calculations["tax"];
  919. $paypal["AMT"] = $cost_calculations["total"];
  920.  
  921. $paypal["L_QTY0"] = "1"; // Always (1).
  922. $paypal["L_NAME0"] = $cost_calculations["desc"];
  923. $paypal["L_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  924. $paypal["L_AMT0"] = $cost_calculations["sub_total"];
  925.  
  926. $paypal["CREDITCARDTYPE"] = $post_vars["card_type"];
  927. $paypal["ACCT"] = preg_replace ("/[^0-9]/", "", $post_vars["card_number"]);
  928. $paypal["EXPDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_expiration"]);
  929. $paypal["CVV2"] = $post_vars["card_verification"];
  930.  
  931. if (in_array ($post_vars["card_type"], array ("Maestro", "Solo")))
  932. if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  933. $paypal["STARTDATE"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  934. else // Otherwise, we assume they provided an Issue Number instead.
  935. $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"];
  936.  
  937. $paypal["STREET"] = $post_vars["street"];
  938. $paypal["CITY"] = $post_vars["city"];
  939. $paypal["STATE"] = $post_vars["state"];
  940. $paypal["COUNTRYCODE"] = $post_vars["country"];
  941. $paypal["ZIP"] = $post_vars["zip"];
  942. }
  943. }
  944.  
  945. if (($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal)) && empty ($paypal["__error"]))
  946. {
  947. $new__subscr_id = (!empty ($paypal["PAYMENTINFO_0_TRANSACTIONID"])) ? $paypal["PAYMENTINFO_0_TRANSACTIONID"] : false;
  948. $new__subscr_id = (!$new__subscr_id && !empty ($paypal["TRANSACTIONID"])) ? $paypal["TRANSACTIONID"] : $new__subscr_id;
  949.  
  950. if (!($ipn = array ())) // Simulated PayPal® IPN.
  951. {
  952. $ipn["txn_type"] = "web_accept";
  953. $ipn["txn_id"] = $new__subscr_id;
  954. $ipn["custom"] = $post_vars["attr"]["custom"];
  955.  
  956. $ipn["mc_gross"] = $cost_calculations["total"];
  957. $ipn["mc_currency"] = $cost_calculations["cur"];
  958. $ipn["tax"] = $cost_calculations["tax"];
  959.  
  960. $ipn["payer_email"] = $post_vars["email"];
  961. $ipn["first_name"] = $post_vars["first_name"];
  962. $ipn["last_name"] = $post_vars["last_name"];
  963.  
  964. $ipn["option_name1"] = "Originating Domain";
  965. $ipn["option_selection1"] = $_SERVER["HTTP_HOST"];
  966.  
  967. $ipn["option_name2"] = "Customer IP Address";
  968. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  969.  
  970. $ipn["item_name"] = $cost_calculations["desc"];
  971. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  972.  
  973. $ipn["s2member_paypal_proxy"] = "paypal";
  974. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  975. $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"]);
  976. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  977. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  978. }
  979.  
  980. if (!($create_user = array ())) // Build post fields for registration configuration, and then the creation array.
  981. {
  982. $_POST["ws_plugin__s2member_custom_reg_field_user_pass1"] = $post_vars["password1"]; // Fake this for registration configuration.
  983. $_POST["ws_plugin__s2member_custom_reg_field_first_name"] = $post_vars["first_name"]; // Fake this for registration configuration.
  984. $_POST["ws_plugin__s2member_custom_reg_field_last_name"] = $post_vars["last_name"]; // Fake this for registration configuration.
  985. $_POST["ws_plugin__s2member_custom_reg_field_opt_in"] = $post_vars["custom_fields"]["opt_in"]; // Fake this too.
  986.  
  987. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  988. foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  989. {
  990. $field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
  991. $field_id_class = preg_replace ("/_/", "-", $field_var);
  992.  
  993. if (isset ($post_vars["custom_fields"][$field_var]))
  994. $_POST["ws_plugin__s2member_custom_reg_field_" . $field_var] = $post_vars["custom_fields"][$field_var];
  995. }
  996.  
  997. $_COOKIE["s2member_subscr_gateway"] = c_ws_plugin__s2member_utils_encryption::encrypt ("paypal"); // Fake this for registration configuration.
  998. $_COOKIE["s2member_subscr_id"] = c_ws_plugin__s2member_utils_encryption::encrypt ($new__subscr_id); // Fake this for registration configuration.
  999. $_COOKIE["s2member_custom"] = c_ws_plugin__s2member_utils_encryption::encrypt ($post_vars["attr"]["custom"]); // Fake this for registration configuration.
  1000. $_COOKIE["s2member_item_number"] = c_ws_plugin__s2member_utils_encryption::encrypt ($post_vars["attr"]["level_ccaps_eotper"]); // Fake this too.
  1001.  
  1002. $create_user["user_login"] = $post_vars["username"]; // Copy this into a separate array for `wp_create_user()`.
  1003. $create_user["user_pass"] = wp_generate_password (); // Which may fire `c_ws_plugin__s2member_registrations::generate_password()`.
  1004. $create_user["user_email"] = $post_vars["email"]; // Copy this into a separate array for `wp_create_user()`.
  1005. }
  1006.  
  1007. if ($post_vars["password1"] && $post_vars["password1"] === $create_user["user_pass"]) // A custom Password is being used?
  1008. {
  1009. 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))
  1010. {
  1011. wp_new_user_notification ($new__user_id, $create_user["user_pass"]);
  1012.  
  1013. $ipn["s2member_paypal_proxy_return_url"] = trim (c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20)));
  1014.  
  1015. $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 ())));
  1016.  
  1017. if ($post_vars["attr"]["success"] && substr ($ipn["s2member_paypal_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_paypal_proxy_return_url"])) && ($custom_success_url = trim (preg_replace ("/%%(.+?)%%/i", "", $custom_success_url))))
  1018. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig ($custom_success_url, "s2p-v")) . exit ();
  1019. }
  1020. else // Else, an error reponse should be given.
  1021. {
  1022. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20));
  1023.  
  1024. $global_response = array ("response" => _x ('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  1025. }
  1026. }
  1027. else // Otherwise, they'll need to check their email for the auto-generated Password.
  1028. {
  1029. 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))
  1030. {
  1031. update_user_option ($new__user_id, "default_password_nag", true, true); // Password nag.
  1032. wp_new_user_notification ($new__user_id, $create_user["user_pass"]);
  1033.  
  1034. $ipn["s2member_paypal_proxy_return_url"] = trim (c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20)));
  1035.  
  1036. $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"));
  1037.  
  1038. if ($post_vars["attr"]["success"] && substr ($ipn["s2member_paypal_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_paypal_proxy_return_url"])) && ($custom_success_url = trim (preg_replace ("/%%(.+?)%%/i", "", $custom_success_url))))
  1039. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig ($custom_success_url, "s2p-v")) . exit ();
  1040. }
  1041. else // Else, an error reponse should be given.
  1042. {
  1043. c_ws_plugin__s2member_utils_urls::remote (site_url ("/?s2member_paypal_notify=1"), $ipn, array ("timeout" => 20));
  1044.  
  1045. $global_response = array ("response" => _x ('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  1046. }
  1047. }
  1048. }
  1049. else // Else, an error.
  1050. {
  1051. $global_response = array ("response" => $paypal["__error"], "error" => true);
  1052. }
  1053. }
  1054. else // Else, we have an unknown scenario.
  1055. {
  1056. $global_response = array ("response" => _x ('<strong>Unknown error.</strong> Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  1057. }
  1058. }
  1059. else // Else, an error.
  1060. {
  1061. $global_response = $error;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. }
  1067. }
  1068. ?>

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

Source Code Documentation