Source Code Documentation


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

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

Source Code Documentation