Source Code Documentation


pro\s2member-pro\includes\classes\gateways\paypal\paypal-checkout-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_in"))
  37. {
  38. /**
  39. * PayPal® Checkout Forms (inner processing routines).
  40. *
  41. * @package s2Member\PayPal
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_paypal_checkout_in
  45. {
  46. /**
  47. * Handles processing of Pro Form checkouts.
  48. *
  49. * @package s2Member\PayPal
  50. * @since 1.5
  51. *
  52. * @attaches-to ``add_action("init");``
  53. *
  54. * @return null Or exits script execution after a custom URL redirection; or upon Express Checkout redirection.
  55. */
  56. public static function paypal_checkout()
  57. {
  58. if((!empty($_POST["s2member_pro_paypal_checkout"]["nonce"]) && ($nonce = $_POST["s2member_pro_paypal_checkout"]["nonce"]) && wp_verify_nonce($nonce, "s2member-pro-paypal-checkout"))
  59. || (!empty($_GET["s2member_paypal_xco"]) && $_GET["s2member_paypal_xco"] === "s2member_pro_paypal_checkout_return" // PayPal® Express Checkout with $_GET["token"] & $_GET["PayerID"]?
  60. && !empty($_GET["token"]) && ($_GET["token"] = esc_html($_GET["token"])) && (empty($_GET["PayerID"]) || ($_GET["PayerID"] = esc_html($_GET["PayerID"]))) // PayerID is not required.
  61. && ($xco_post_vars = get_transient("s2m_".md5("s2member_transient_express_checkout_".$_GET["token"])))))
  62. {
  63. $GLOBALS["ws_plugin__s2member_pro_paypal_checkout_response"] = /* This holds the global response details. */array();
  64. $global_response = /* This is a shorter reference. */&$GLOBALS["ws_plugin__s2member_pro_paypal_checkout_response"];
  65.  
  66. $post_vars = ($xco_post_vars) ? $xco_post_vars : $_POST["s2member_pro_paypal_checkout"];
  67. $post_vars = /* And Filter. */c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($post_vars));
  68. $post_vars["attr"] = (!$xco_post_vars) ? unserialize(c_ws_plugin__s2member_utils_encryption::decrypt($post_vars["attr"])) : $post_vars["attr"];
  69. $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"];
  70.  
  71. if /* No need to re-validate this upon return from Express Checkout. */($xco_post_vars) $post_vars["attr"]["captcha"] = "0";
  72.  
  73. $post_vars["recaptcha_challenge_field"] = (!$post_vars["recaptcha_challenge_field"]) ? trim(stripslashes($_POST["recaptcha_challenge_field"])) : $post_vars["recaptcha_challenge_field"];
  74. $post_vars["recaptcha_response_field"] = (!$post_vars["recaptcha_response_field"]) ? trim(stripslashes($_POST["recaptcha_response_field"])) : $post_vars["recaptcha_response_field"];
  75.  
  76. $post_vars["name"] = trim($post_vars["first_name"]." ".$post_vars["last_name"]);
  77. $post_vars["email"] = apply_filters("user_registration_email", sanitize_email($post_vars["email"]), get_defined_vars());
  78. $post_vars["username"] = (is_multisite()) ? strtolower($post_vars["username"]) : $post_vars["username"]; // Force lowercase.
  79. $post_vars["username"] = preg_replace("/\s+/", "", sanitize_user(($post_vars["_o_username"] = $post_vars["username"]), is_multisite()));
  80.  
  81. (!empty($_GET["token"])) ? delete_transient("s2m_".md5("s2member_transient_express_checkout_".$_GET["token"])) : null;
  82.  
  83. if /* Attr errors? */(!c_ws_plugin__s2member_pro_paypal_responses::paypal_form_attr_validation_errors($post_vars["attr"]))
  84. {
  85. if(!($error = c_ws_plugin__s2member_pro_paypal_responses::paypal_form_submission_validation_errors("checkout", $post_vars)))
  86. {
  87. $cp_attr = c_ws_plugin__s2member_pro_paypal_utilities::paypal_apply_coupon($post_vars["attr"], $post_vars["coupon"], "attr", array("affiliates-silent-post"));
  88. $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"]);
  89. $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"]);
  90.  
  91. $use_recurring_profile = ($post_vars["attr"]["rr"] === "BN" || (!$post_vars["attr"]["tp"] && !$post_vars["attr"]["rr"])) ? false : true;
  92. $is_independent_ccaps_sale = /* Selling Independent Custom Capabilities? */ ($post_vars["attr"]["level"] === "*") ? true : false;
  93.  
  94. if(empty($_GET["s2member_paypal_xco"]) && $post_vars["card_type"] === "PayPal")
  95. {
  96. $return_url = $cancel_url = (is_ssl()) ? "https://" : "http://";
  97. $return_url = $cancel_url = ($return_url = $cancel_url).$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
  98. $return_url = $cancel_url = /* Ditch. */ remove_query_arg(array("token", "PayerID"), ($return_url = $cancel_url));
  99. $return_url = add_query_arg("s2member_paypal_xco", urlencode("s2member_pro_paypal_checkout_return"), $return_url);
  100. $cancel_url = add_query_arg("s2member_paypal_xco", urlencode("s2member_pro_paypal_checkout_cancel"), $cancel_url);
  101.  
  102. $user = (is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID)) ? $user : false;
  103.  
  104. if /* PayPal® Express Checkout. */(!($paypal_set_xco = array()))
  105. {
  106. $paypal_set_xco["METHOD"] = "SetExpressCheckout";
  107.  
  108. $paypal_set_xco["RETURNURL"] = $return_url;
  109. $paypal_set_xco["CANCELURL"] = $cancel_url;
  110.  
  111. $paypal_set_xco["PAGESTYLE"] = $post_vars["attr"]["ps"];
  112. $paypal_set_xco["LOCALECODE"] = $post_vars["attr"]["lc"];
  113. $paypal_set_xco["NOSHIPPING"] = $post_vars["attr"]["ns"];
  114. $paypal_set_xco["SOLUTIONTYPE"] = "Sole";
  115. $paypal_set_xco["LANDINGPAGE"] = "Billing";
  116. $paypal_set_xco["ALLOWNOTE"] = "0";
  117.  
  118. if /* Recurring Profile? */($use_recurring_profile)
  119. {
  120. $paypal_set_xco["L_BILLINGTYPE0"] = "RecurringPayments";
  121. $paypal_set_xco["L_BILLINGAGREEMENTDESCRIPTION0"] = $cost_calculations["desc"];
  122. }
  123. else // Otherwise, we use fields for a "Buy Now" purchase.
  124. {
  125. $paypal_set_xco["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
  126.  
  127. $paypal_set_xco["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"];
  128. $paypal_set_xco["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"];
  129.  
  130. $paypal_set_xco["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  131. $paypal_set_xco["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"];
  132. $paypal_set_xco["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"];
  133. $paypal_set_xco["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"];
  134.  
  135. $paypal_set_xco["L_PAYMENTREQUEST_0_QTY0"] = /* Always (1). */ "1";
  136. $paypal_set_xco["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  137. $paypal_set_xco["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  138. $paypal_set_xco["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"];
  139. }
  140. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTONAME"] = $post_vars["name"];
  141. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOSTREET"] = $post_vars["street"];
  142. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOCITY"] = $post_vars["city"];
  143. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOSTATE"] = $post_vars["state"];
  144. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE"] = $post_vars["country"];
  145. $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOZIP"] = $post_vars["zip"];
  146.  
  147. $paypal_set_xco["EMAIL"] = ($user) ? $user->user_email : $post_vars["email"];
  148. }
  149. if(($paypal_set_xco = c_ws_plugin__s2member_paypal_utilities::paypal_api_response($paypal_set_xco)) && empty($paypal_set_xco["__error"]))
  150. {
  151. set_transient("s2m_".md5("s2member_transient_express_checkout_".$paypal_set_xco["TOKEN"]), $post_vars, 10800);
  152.  
  153. $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_sandbox"]) ? "www.sandbox.paypal.com" : "www.paypal.com";
  154.  
  155. wp_redirect(add_query_arg("token", urlencode($paypal_set_xco["TOKEN"]), "https://".$endpoint."/cgi-bin/webscr?cmd=_express-checkout"));
  156.  
  157. exit /* Clean exit. */();
  158. }
  159. else // Else, an error.
  160. {
  161. $global_response = array("response" => $paypal_set_xco["__error"], "error" => true);
  162. }
  163. }
  164. else if($use_recurring_profile && is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID))
  165. {
  166. 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"]))
  167. {
  168. $period1 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period1($post_vars["attr"]["tp"]." ".$post_vars["attr"]["tt"]);
  169. $period3 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period3($post_vars["attr"]["rp"]." ".$post_vars["attr"]["rt"]);
  170.  
  171. $start_time = /* If there's an Initial/Trial Period; start when it's over. */($post_vars["attr"]["tp"]) ?
  172. /* After Trial is over. */c_ws_plugin__s2member_pro_paypal_utilities::paypal_start_time($period1) :
  173. /* Or next billing cycle. */c_ws_plugin__s2member_pro_paypal_utilities::paypal_start_time($period3);
  174.  
  175. $reference = $start_time.":".$period1.":".$period3."~".$_SERVER["HTTP_HOST"]."~".$post_vars["attr"]["level_ccaps_eotper"];
  176.  
  177. update_user_meta($user_id, "first_name", $post_vars["first_name"]).update_user_meta($user_id, "last_name", $post_vars["last_name"]);
  178.  
  179. if /* Recurring Profile. */(!($paypal = array()))
  180. {
  181. $paypal["METHOD"] = "CreateRecurringPaymentsProfile";
  182.  
  183. $paypal["EMAIL"] = $user->user_email;
  184. $paypal["FIRSTNAME"] = $post_vars["first_name"];
  185. $paypal["LASTNAME"] = $post_vars["last_name"];
  186. $paypal["SUBSCRIBERNAME"] = $post_vars["name"];
  187.  
  188. $paypal["DESC"] = $cost_calculations["desc"];
  189. $paypal["PROFILEREFERENCE"] = $reference;
  190.  
  191. if(!$post_vars["attr"]["tp"] || ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0))
  192. {
  193. $paypal["INITAMT"] = ($post_vars["attr"]["tp"]) ? $cost_calculations["trial_total"] : $cost_calculations["total"];
  194. $paypal["FAILEDINITAMTACTION"] = "CancelOnFailure";
  195. }
  196. $paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  197. $paypal["AMT"] = $cost_calculations["sub_total"];
  198. $paypal["TAXAMT"] = $cost_calculations["tax"];
  199.  
  200. $paypal["MAXFAILEDPAYMENTS"] = $post_vars["attr"]["rra"];
  201. $paypal["AUTOBILLOUTAMT"] = apply_filters("ws_plugin__s2member_pro_paypal_auto_bill_op", "AddToNextBilling", get_defined_vars());
  202.  
  203. $paypal["PROFILESTARTDATE"] = date("Y-m-d", $start_time)."T00:00:00Z";
  204.  
  205. $paypal["BILLINGPERIOD"] = c_ws_plugin__s2member_paypal_utilities::paypal_pro_term($post_vars["attr"]["rt"]);
  206. $paypal["TOTALBILLINGCYCLES"] = ($post_vars["attr"]["rr"]) ? (($post_vars["attr"]["rrt"]) ? $post_vars["attr"]["rrt"] : "0") : "1";
  207. $paypal["BILLINGFREQUENCY"] = $post_vars["attr"]["rp"];
  208.  
  209. 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"]))
  210. {
  211. $paypal["TOKEN"] = $paypal_xco_details["TOKEN"];
  212. }
  213. else // Otherwise, they're using a major credit card.
  214. {
  215. $paypal["CREDITCARDTYPE"] = $post_vars["card_type"];
  216. $paypal["ACCT"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]);
  217. $paypal["EXPDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_expiration"]);
  218. $paypal["CVV2"] = $post_vars["card_verification"];
  219.  
  220. if(in_array($post_vars["card_type"], array("Maestro", "Solo")))
  221. if(preg_match("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  222. $paypal["STARTDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  223. else // Otherwise, we assume they provided an Issue Number.
  224. $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"];
  225.  
  226. $paypal["STREET"] = $post_vars["street"];
  227. $paypal["CITY"] = $post_vars["city"];
  228. $paypal["STATE"] = $post_vars["state"];
  229. $paypal["COUNTRYCODE"] = $post_vars["country"];
  230. $paypal["ZIP"] = $post_vars["zip"];
  231. }
  232. }
  233. if(($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response($paypal)) && empty($paypal["__error"]))
  234. {
  235. $old__subscr_or_wp_id = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id();
  236. $old__subscr_id = get_user_option("s2member_subscr_id");
  237. $new__subscr_id = $paypal["PROFILEID"];
  238.  
  239. if /* Simulated PayPal® IPN. */(!($ipn = array()))
  240. {
  241. $ipn["txn_type"] = "subscr_signup";
  242. $ipn["subscr_id"] = $new__subscr_id;
  243. $ipn["custom"] = $post_vars["attr"]["custom"];
  244.  
  245. $ipn["txn_id"] = $new__subscr_id;
  246.  
  247. $ipn["period1"] = $period1;
  248. $ipn["period3"] = $period3;
  249.  
  250. $ipn["mc_amount1"] = $cost_calculations["trial_total"];
  251. $ipn["mc_amount3"] = $cost_calculations["total"];
  252.  
  253. $ipn["mc_gross"] = (preg_match("/^[1-9]/", $ipn["period1"])) ? $ipn["mc_amount1"] : $ipn["mc_amount3"];
  254.  
  255. $ipn["mc_currency"] = $cost_calculations["cur"];
  256. $ipn["tax"] = $cost_calculations["tax"];
  257.  
  258. $ipn["recurring"] = ($post_vars["attr"]["rr"]) ? "1" : "";
  259.  
  260. $ipn["payer_email"] = $user->user_email;
  261. $ipn["first_name"] = $post_vars["first_name"];
  262. $ipn["last_name"] = $post_vars["last_name"];
  263.  
  264. $ipn["option_name1"] = "Referencing Customer ID";
  265. $ipn["option_selection1"] = $old__subscr_or_wp_id;
  266.  
  267. $ipn["option_name2"] = "Customer IP Address";
  268. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  269.  
  270. $ipn["item_name"] = $cost_calculations["desc"];
  271. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  272.  
  273. $ipn["s2member_paypal_proxy"] = "paypal";
  274. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  275. $ipn["s2member_paypal_proxy_use"] .= ($ipn["mc_gross"] > 0) ? ",subscr-signup-as-subscr-payment" : "";
  276. $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"]);
  277. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  278. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  279.  
  280. $ipn["s2member_paypal_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  281. }
  282. if(!($paypal = array()) && ($paypal["PROFILEID"] = $old__subscr_id))
  283. {
  284. $paypal["METHOD"] = "ManageRecurringPaymentsProfileStatus";
  285. $paypal["ACTION"] = "Cancel";
  286.  
  287. c_ws_plugin__s2member_paypal_utilities::paypal_api_response($paypal);
  288. }
  289. 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);
  290.  
  291. $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())));
  292.  
  293. 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))))
  294. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  295. }
  296. else // Else, an error.
  297. {
  298. $global_response = array("response" => $paypal["__error"], "error" => true);
  299. }
  300. }
  301. else // Else, an error. The existing Billing Profile is still in a pending state.
  302. {
  303. $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);
  304. }
  305. }
  306. else if /* Create a new account. */($use_recurring_profile && !is_user_logged_in())
  307. {
  308. $period1 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period1($post_vars["attr"]["tp"]." ".$post_vars["attr"]["tt"]);
  309. $period3 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period3($post_vars["attr"]["rp"]." ".$post_vars["attr"]["rt"]);
  310.  
  311. $start_time = /* If there's an Initial/Trial Period; start when it's over. */($post_vars["attr"]["tp"]) ?
  312. /* After Trial is over. */c_ws_plugin__s2member_pro_paypal_utilities::paypal_start_time($period1) :
  313. /* Or next billing cycle. */c_ws_plugin__s2member_pro_paypal_utilities::paypal_start_time($period3);
  314.  
  315. $reference = $start_time.":".$period1.":".$period3."~".$_SERVER["HTTP_HOST"]."~".$post_vars["attr"]["level_ccaps_eotper"];
  316.  
  317. if /* Recurring Profile. */(!($paypal = array()))
  318. {
  319. $paypal["METHOD"] = "CreateRecurringPaymentsProfile";
  320.  
  321. $paypal["EMAIL"] = $post_vars["email"];
  322. $paypal["FIRSTNAME"] = $post_vars["first_name"];
  323. $paypal["LASTNAME"] = $post_vars["last_name"];
  324. $paypal["SUBSCRIBERNAME"] = $post_vars["name"];
  325.  
  326. $paypal["DESC"] = $cost_calculations["desc"];
  327. $paypal["PROFILEREFERENCE"] = $reference;
  328.  
  329. if(!$post_vars["attr"]["tp"] || ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0))
  330. {
  331. $paypal["INITAMT"] = ($post_vars["attr"]["tp"]) ? $cost_calculations["trial_total"] : $cost_calculations["total"];
  332. $paypal["FAILEDINITAMTACTION"] = "CancelOnFailure";
  333. }
  334. $paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  335. $paypal["AMT"] = $cost_calculations["sub_total"];
  336. $paypal["TAXAMT"] = $cost_calculations["tax"];
  337.  
  338. $paypal["MAXFAILEDPAYMENTS"] = $post_vars["attr"]["rra"];
  339. $paypal["AUTOBILLOUTAMT"] = apply_filters("ws_plugin__s2member_pro_paypal_auto_bill_op", "AddToNextBilling", get_defined_vars());
  340.  
  341. $paypal["PROFILESTARTDATE"] = date("Y-m-d", $start_time)."T00:00:00Z";
  342.  
  343. $paypal["BILLINGPERIOD"] = c_ws_plugin__s2member_paypal_utilities::paypal_pro_term($post_vars["attr"]["rt"]);
  344. $paypal["TOTALBILLINGCYCLES"] = ($post_vars["attr"]["rr"]) ? (($post_vars["attr"]["rrt"]) ? $post_vars["attr"]["rrt"] : "0") : "1";
  345. $paypal["BILLINGFREQUENCY"] = $post_vars["attr"]["rp"];
  346.  
  347. 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"]))
  348. {
  349. $paypal["TOKEN"] = $paypal_xco_details["TOKEN"];
  350. }
  351. else // Otherwise, they're using a major credit card.
  352. {
  353. $paypal["CREDITCARDTYPE"] = $post_vars["card_type"];
  354. $paypal["ACCT"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]);
  355. $paypal["EXPDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_expiration"]);
  356. $paypal["CVV2"] = $post_vars["card_verification"];
  357.  
  358. if(in_array($post_vars["card_type"], array("Maestro", "Solo")))
  359. if(preg_match("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  360. $paypal["STARTDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  361. else // Otherwise, we assume they provided an Issue Number.
  362. $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"];
  363.  
  364. $paypal["STREET"] = $post_vars["street"];
  365. $paypal["CITY"] = $post_vars["city"];
  366. $paypal["STATE"] = $post_vars["state"];
  367. $paypal["COUNTRYCODE"] = $post_vars["country"];
  368. $paypal["ZIP"] = $post_vars["zip"];
  369. }
  370. }
  371. if(($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response($paypal)) && empty($paypal["__error"]))
  372. {
  373. $new__subscr_id = $paypal["PROFILEID"];
  374.  
  375. if /* Simulated PayPal® IPN. */(!($ipn = array()))
  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__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"] = $post_vars["email"];
  397. $ipn["first_name"] = $post_vars["first_name"];
  398. $ipn["last_name"] = $post_vars["last_name"];
  399.  
  400. $ipn["option_name1"] = "Originating Domain";
  401. $ipn["option_selection1"] = $_SERVER["HTTP_HOST"];
  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["s2member_paypal_proxy"] = "paypal";
  410. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  411. $ipn["s2member_paypal_proxy_use"] .= ($ipn["mc_gross"] > 0) ? ",subscr-signup-as-subscr-payment" : "";
  412. $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"]);
  413. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  414. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  415. }
  416. if /* Build post fields for registration configuration, and then the creation array. */(!($create_user = array()))
  417. {
  418. $_POST["ws_plugin__s2member_custom_reg_field_user_pass1"] = /* Fake this for registration configuration. */ $post_vars["password1"];
  419. $_POST["ws_plugin__s2member_custom_reg_field_first_name"] = /* Fake this for registration configuration. */ $post_vars["first_name"];
  420. $_POST["ws_plugin__s2member_custom_reg_field_last_name"] = /* Fake this for registration configuration. */ $post_vars["last_name"];
  421. $_POST["ws_plugin__s2member_custom_reg_field_opt_in"] = /* Fake this too. */ $post_vars["custom_fields"]["opt_in"];
  422.  
  423. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  424. foreach(json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  425. {
  426. $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
  427. $field_id_class = preg_replace("/_/", "-", $field_var);
  428.  
  429. if(isset($post_vars["custom_fields"][$field_var]))
  430. $_POST["ws_plugin__s2member_custom_reg_field_".$field_var] = $post_vars["custom_fields"][$field_var];
  431. }
  432. $_COOKIE["s2member_subscr_gateway"] = /* Fake this for registration configuration. */c_ws_plugin__s2member_utils_encryption::encrypt("paypal");
  433. $_COOKIE["s2member_subscr_id"] = /* Fake this for registration configuration. */ c_ws_plugin__s2member_utils_encryption::encrypt($new__subscr_id);
  434. $_COOKIE["s2member_custom"] = /* Fake this for registration configuration. */c_ws_plugin__s2member_utils_encryption::encrypt($post_vars["attr"]["custom"]);
  435. $_COOKIE["s2member_item_number"] = /* Fake this too. */ c_ws_plugin__s2member_utils_encryption::encrypt($post_vars["attr"]["level_ccaps_eotper"]);
  436.  
  437. $create_user["user_login"] = /* Copy this into a separate array for `wp_create_user()`. */ $post_vars["username"];
  438. $create_user["user_pass"] = /* Which may fire `c_ws_plugin__s2member_registrations::generate_password()`. */ wp_generate_password();
  439. $create_user["user_email"] = /* Copy this into a separate array for `wp_create_user()`. */ $post_vars["email"];
  440. }
  441. if /* A custom Password is being used? */($post_vars["password1"] && $post_vars["password1"] === $create_user["user_pass"])
  442. {
  443. 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))
  444. {
  445. wp_new_user_notification($new__user_id, $create_user["user_pass"]);
  446.  
  447. $ipn["s2member_paypal_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  448.  
  449. $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())));
  450.  
  451. 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))))
  452. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  453. }
  454. else // Else, an error response should be given.
  455. {
  456. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20));
  457.  
  458. $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  459. }
  460. }
  461. else // Otherwise, they'll need to check their email for the auto-generated Password.
  462. {
  463. 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))
  464. {
  465. update_user_option /* Password nag. */($new__user_id, "default_password_nag", true, true);
  466. wp_new_user_notification($new__user_id, $create_user["user_pass"]);
  467.  
  468. $ipn["s2member_paypal_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  469.  
  470. $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"));
  471.  
  472. 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))))
  473. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  474. }
  475. else // Else, an error response should be given.
  476. {
  477. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20));
  478.  
  479. $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  480. }
  481. }
  482. }
  483. else // Else, an error.
  484. {
  485. $global_response = array("response" => $paypal["__error"], "error" => true);
  486. }
  487. }
  488. else if(!$use_recurring_profile && is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID))
  489. {
  490. 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"]))
  491. {
  492. update_user_meta($user_id, "first_name", $post_vars["first_name"]).update_user_meta($user_id, "last_name", $post_vars["last_name"]);
  493.  
  494. if /* Prepare a "Buy Now" transaction. */(!($paypal = array()))
  495. {
  496. 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"]))
  497. {
  498. $paypal["METHOD"] = "DoExpressCheckoutPayment";
  499.  
  500. $paypal["TOKEN"] = $paypal_xco_details["TOKEN"];
  501. $paypal["PAYERID"] = $paypal_xco_details["PAYERID"];
  502.  
  503. $paypal["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
  504.  
  505. $paypal["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"];
  506. $paypal["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"];
  507.  
  508. $paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  509. $paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"];
  510. $paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"];
  511. $paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"];
  512.  
  513. $paypal["L_PAYMENTREQUEST_0_QTY0"] = /* Always (1). */ "1";
  514. $paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  515. $paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  516. $paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"];
  517. }
  518. else // NOT using PayPal® Express Checkout.
  519. {
  520. $paypal["METHOD"] = "DoDirectPayment";
  521. $paypal["PAYMENTACTION"] = "Sale";
  522.  
  523. $paypal["EMAIL"] = $user->user_email;
  524. $paypal["FIRSTNAME"] = $post_vars["first_name"];
  525. $paypal["LASTNAME"] = $post_vars["last_name"];
  526. $paypal["IPADDRESS"] = $_SERVER["REMOTE_ADDR"];
  527.  
  528. $paypal["DESC"] = $cost_calculations["desc"];
  529. $paypal["CUSTOM"] = $post_vars["attr"]["custom"];
  530.  
  531. $paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  532. $paypal["ITEMAMT"] = $cost_calculations["sub_total"];
  533. $paypal["TAXAMT"] = $cost_calculations["tax"];
  534. $paypal["AMT"] = $cost_calculations["total"];
  535.  
  536. $paypal["L_QTY0"] = "1"; // Always (1).
  537. $paypal["L_NAME0"] = $cost_calculations["desc"];
  538. $paypal["L_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  539. $paypal["L_AMT0"] = $cost_calculations["sub_total"];
  540.  
  541. $paypal["CREDITCARDTYPE"] = $post_vars["card_type"];
  542. $paypal["ACCT"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]);
  543. $paypal["EXPDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_expiration"]);
  544. $paypal["CVV2"] = $post_vars["card_verification"];
  545.  
  546. if(in_array($post_vars["card_type"], array("Maestro", "Solo")))
  547. if(preg_match("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  548. $paypal["STARTDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  549. else // Otherwise, we assume they provided an Issue Number instead.
  550. $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"];
  551.  
  552. $paypal["STREET"] = $post_vars["street"];
  553. $paypal["CITY"] = $post_vars["city"];
  554. $paypal["STATE"] = $post_vars["state"];
  555. $paypal["COUNTRYCODE"] = $post_vars["country"];
  556. $paypal["ZIP"] = $post_vars["zip"];
  557. }
  558. }
  559. if(($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response($paypal)) && empty($paypal["__error"]))
  560. {
  561. $old__subscr_id = get_user_option("s2member_subscr_id");
  562. $old__subscr_or_wp_id = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id();
  563. $new__subscr_id = $new__txn_id = (!empty($paypal["PAYMENTINFO_0_TRANSACTIONID"])) ? $paypal["PAYMENTINFO_0_TRANSACTIONID"] : false;
  564. $new__subscr_id = $new__txn_id = (!$new__subscr_id && !empty($paypal["TRANSACTIONID"])) ? $paypal["TRANSACTIONID"] : $new__subscr_id;
  565.  
  566. if /* Simulated PayPal® IPN. */(!($ipn = array()))
  567. {
  568. $ipn["txn_type"] = "web_accept";
  569. $ipn["txn_id"] = $new__subscr_id;
  570. $ipn["custom"] = $post_vars["attr"]["custom"];
  571.  
  572. $ipn["mc_gross"] = $cost_calculations["total"];
  573. $ipn["mc_currency"] = $cost_calculations["cur"];
  574. $ipn["tax"] = $cost_calculations["tax"];
  575.  
  576. $ipn["payer_email"] = $user->user_email;
  577. $ipn["first_name"] = $post_vars["first_name"];
  578. $ipn["last_name"] = $post_vars["last_name"];
  579.  
  580. $ipn["option_name1"] = "Referencing Customer ID";
  581. $ipn["option_selection1"] = $old__subscr_or_wp_id;
  582.  
  583. $ipn["option_name2"] = "Customer IP Address";
  584. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  585.  
  586. $ipn["item_name"] = $cost_calculations["desc"];
  587. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  588.  
  589. $ipn["s2member_paypal_proxy"] = "paypal";
  590. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  591. $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"]);
  592. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  593. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  594.  
  595. $ipn["s2member_paypal_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  596. }
  597. if /* Independent? */(!$is_independent_ccaps_sale)
  598. if(!($paypal = array()) && ($paypal["PROFILEID"] = $old__subscr_id))
  599. {
  600. $paypal["METHOD"] = "ManageRecurringPaymentsProfileStatus";
  601. $paypal["ACTION"] = "Cancel";
  602.  
  603. c_ws_plugin__s2member_paypal_utilities::paypal_api_response($paypal);
  604. }
  605. 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);
  606.  
  607. $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())));
  608.  
  609. 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))))
  610. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  611. }
  612. else // Else, an error.
  613. {
  614. $global_response = array("response" => $paypal["__error"], "error" => true);
  615. }
  616. }
  617. else // Else, an error. The existing Billing Profile is still in a pending state.
  618. {
  619. $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);
  620. }
  621. }
  622. else if(!$use_recurring_profile && !is_user_logged_in())
  623. {
  624. if /* Prepare a "Buy Now" transaction. */(!($paypal = array()))
  625. {
  626. 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"]))
  627. {
  628. $paypal["METHOD"] = "DoExpressCheckoutPayment";
  629.  
  630. $paypal["TOKEN"] = $paypal_xco_details["TOKEN"];
  631. $paypal["PAYERID"] = $paypal_xco_details["PAYERID"];
  632.  
  633. $paypal["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
  634.  
  635. $paypal["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"];
  636. $paypal["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"];
  637.  
  638. $paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"];
  639. $paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"];
  640. $paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"];
  641. $paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"];
  642.  
  643. $paypal["L_PAYMENTREQUEST_0_QTY0"] = "1"; // Always (1).
  644. $paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"];
  645. $paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  646. $paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"];
  647. }
  648. else // NOT using PayPal® Express Checkout.
  649. {
  650. $paypal["METHOD"] = "DoDirectPayment";
  651. $paypal["PAYMENTACTION"] = "Sale";
  652.  
  653. $paypal["EMAIL"] = $post_vars["email"];
  654. $paypal["FIRSTNAME"] = $post_vars["first_name"];
  655. $paypal["LASTNAME"] = $post_vars["last_name"];
  656. $paypal["IPADDRESS"] = $_SERVER["REMOTE_ADDR"];
  657.  
  658. $paypal["DESC"] = $cost_calculations["desc"];
  659. $paypal["CUSTOM"] = $post_vars["attr"]["custom"];
  660.  
  661. $paypal["CURRENCYCODE"] = $cost_calculations["cur"];
  662. $paypal["ITEMAMT"] = $cost_calculations["sub_total"];
  663. $paypal["TAXAMT"] = $cost_calculations["tax"];
  664. $paypal["AMT"] = $cost_calculations["total"];
  665.  
  666. $paypal["L_QTY0"] = /* Always (1). */ "1";
  667. $paypal["L_NAME0"] = $cost_calculations["desc"];
  668. $paypal["L_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"];
  669. $paypal["L_AMT0"] = $cost_calculations["sub_total"];
  670.  
  671. $paypal["CREDITCARDTYPE"] = $post_vars["card_type"];
  672. $paypal["ACCT"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]);
  673. $paypal["EXPDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_expiration"]);
  674. $paypal["CVV2"] = $post_vars["card_verification"];
  675.  
  676. if(in_array($post_vars["card_type"], array("Maestro", "Solo")))
  677. if(preg_match("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"]))
  678. $paypal["STARTDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]);
  679. else // Otherwise, we assume they provided an Issue Number
  680. $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"];
  681.  
  682. $paypal["STREET"] = $post_vars["street"];
  683. $paypal["CITY"] = $post_vars["city"];
  684. $paypal["STATE"] = $post_vars["state"];
  685. $paypal["COUNTRYCODE"] = $post_vars["country"];
  686. $paypal["ZIP"] = $post_vars["zip"];
  687. }
  688. }
  689. if(($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response($paypal)) && empty($paypal["__error"]))
  690. {
  691. $new__subscr_id = (!empty($paypal["PAYMENTINFO_0_TRANSACTIONID"])) ? $paypal["PAYMENTINFO_0_TRANSACTIONID"] : false;
  692. $new__subscr_id = (!$new__subscr_id && !empty($paypal["TRANSACTIONID"])) ? $paypal["TRANSACTIONID"] : $new__subscr_id;
  693.  
  694. if /* Simulated PayPal® IPN. */(!($ipn = array()))
  695. {
  696. $ipn["txn_type"] = "web_accept";
  697. $ipn["txn_id"] = $new__subscr_id;
  698. $ipn["custom"] = $post_vars["attr"]["custom"];
  699.  
  700. $ipn["mc_gross"] = $cost_calculations["total"];
  701. $ipn["mc_currency"] = $cost_calculations["cur"];
  702. $ipn["tax"] = $cost_calculations["tax"];
  703.  
  704. $ipn["payer_email"] = $post_vars["email"];
  705. $ipn["first_name"] = $post_vars["first_name"];
  706. $ipn["last_name"] = $post_vars["last_name"];
  707.  
  708. $ipn["option_name1"] = "Originating Domain";
  709. $ipn["option_selection1"] = $_SERVER["HTTP_HOST"];
  710.  
  711. $ipn["option_name2"] = "Customer IP Address";
  712. $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"];
  713.  
  714. $ipn["item_name"] = $cost_calculations["desc"];
  715. $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"];
  716.  
  717. $ipn["s2member_paypal_proxy"] = "paypal";
  718. $ipn["s2member_paypal_proxy_use"] = "pro-emails";
  719. $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"]);
  720. $ipn["s2member_paypal_proxy_verification"] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen();
  721. $ipn["s2member_paypal_proxy_return_url"] = $post_vars["attr"]["success"];
  722. }
  723. if /* Build post fields for registration configuration, and then the creation array. */(!($create_user = array()))
  724. {
  725. $_POST["ws_plugin__s2member_custom_reg_field_user_pass1"] = /* Fake this for registration configuration. */ $post_vars["password1"];
  726. $_POST["ws_plugin__s2member_custom_reg_field_first_name"] = /* Fake this for registration configuration. */ $post_vars["first_name"];
  727. $_POST["ws_plugin__s2member_custom_reg_field_last_name"] = /* Fake this for registration configuration. */ $post_vars["last_name"];
  728. $_POST["ws_plugin__s2member_custom_reg_field_opt_in"] = /* Fake this too. */$post_vars["custom_fields"]["opt_in"];
  729.  
  730. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  731. foreach(json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  732. {
  733. $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
  734. $field_id_class = preg_replace("/_/", "-", $field_var);
  735.  
  736. if(isset($post_vars["custom_fields"][$field_var]))
  737. $_POST["ws_plugin__s2member_custom_reg_field_".$field_var] = $post_vars["custom_fields"][$field_var];
  738. }
  739. $_COOKIE["s2member_subscr_gateway"] = /* Fake this for registration configuration. */ c_ws_plugin__s2member_utils_encryption::encrypt("paypal");
  740. $_COOKIE["s2member_subscr_id"] = /* Fake this for registration configuration. */ c_ws_plugin__s2member_utils_encryption::encrypt($new__subscr_id);
  741. $_COOKIE["s2member_custom"] = /* Fake this for registration configuration. */ c_ws_plugin__s2member_utils_encryption::encrypt($post_vars["attr"]["custom"]);
  742. $_COOKIE["s2member_item_number"] = /* Fake this too. */ c_ws_plugin__s2member_utils_encryption::encrypt($post_vars["attr"]["level_ccaps_eotper"]);
  743.  
  744. $create_user["user_login"] = /* Copy this into a separate array for `wp_create_user()`. */$post_vars["username"];
  745. $create_user["user_pass"] = /* Which may fire `c_ws_plugin__s2member_registrations::generate_password()`. */wp_generate_password();
  746. $create_user["user_email"] = /* Copy this into a separate array for `wp_create_user()`. */$post_vars["email"];
  747. }
  748. if /* A custom Password is being used? */($post_vars["password1"] && $post_vars["password1"] === $create_user["user_pass"])
  749. {
  750. 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))
  751. {
  752. wp_new_user_notification($new__user_id, $create_user["user_pass"]);
  753.  
  754. $ipn["s2member_paypal_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  755.  
  756. $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())));
  757.  
  758. 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))))
  759. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  760. }
  761. else // Else, an error response should be given.
  762. {
  763. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20));
  764.  
  765. $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  766. }
  767. }
  768. else // Otherwise, they'll need to check their email for the auto-generated Password.
  769. {
  770. 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))
  771. {
  772. update_user_option /* Password nag. */($new__user_id, "default_password_nag", true, true);
  773. wp_new_user_notification($new__user_id, $create_user["user_pass"]);
  774.  
  775. $ipn["s2member_paypal_proxy_return_url"] = trim(c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20)));
  776.  
  777. $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"));
  778.  
  779. 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))))
  780. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, "s2p-v")).exit();
  781. }
  782. else // Else, an error response should be given.
  783. {
  784. c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), $ipn, array("timeout" => 20));
  785.  
  786. $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  787. }
  788. }
  789. }
  790. else // Else, an error.
  791. {
  792. $global_response = array("response" => $paypal["__error"], "error" => true);
  793. }
  794. }
  795. else // Else, we have an unknown scenario.
  796. {
  797. $global_response = array("response" => _x('<strong>Unknown error.</strong> Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  798. }
  799. }
  800. else // Else, an error.
  801. {
  802. $global_response = $error;
  803. }
  804. }
  805. }
  806. }
  807. }
  808. }
  809. ?>

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

Source Code Documentation