/** * Verifies a reCAPTCHA™ code via Google. * * @package optimizeMember\Utilities * @since 3.5 * * @param str $challenge The value of `recaptcha_challenge_field` during form submisson. * @param str $response The value of `recaptcha_response_field` during form submission. * @return bool True if ``$response`` is valid, else false. */ public static function recaptcha_code_validates($challenge = FALSE, $response = FALSE) { $keys = c_ws_plugin__optimizemember_utils_captchas::recaptcha_keys(); $post_vars = array("privatekey" => $keys["private"], "remoteip" => $_SERVER["REMOTE_ADDR"], "challenge" => $challenge, "response" => $response); /**/ return preg_match("/^true/i", trim(c_ws_plugin__optimizemember_utils_urls::remote("http://www.google.com/recaptcha/api/verify", $post_vars))); }
/** * Currency converter. * * Uses the Google� currency conversion API. * * @package optimizeMember\Utilities * @since 3.5 * * @param int|str $a The amount, in ``$from``. * @param str $from A 3 character Currency Code. * @param str $to A 3 character Currency Code. * @return float|str|bool A numeric amount in ``$to``, * after having been converted. Else false. * * @see http://www.techmug.com/ajax-currency-converter-with-google-api/ */ public static function convert($a = FALSE, $from = FALSE, $to = FALSE) { if (is_numeric($a) && strlen($from = strtoupper($from)) === 3 && strlen($to = strtoupper($to)) === 3) { $q = number_format($a, 2, ".", "") . $from . "=?" . $to; $api = "http://www.google.com/ig/calculator?hl=en&q=" . urlencode($q); /**/ if (($json = preg_replace('/([{,])\\s*([^"]+?)\\s*:/', '$1"$2":', c_ws_plugin__optimizemember_utils_urls::remote($api))) && is_array($json = json_decode($json, true)) && !empty($json["icc"]) && isset($json["rhs"]) && strlen($json["rhs"])) { if (is_numeric($c_a = preg_replace("/ .*\$/", "", trim($json["rhs"]))) && $c_a >= 0) { return number_format($c_a, 2, ".", ""); } } } /**/ return false; /* Default return value. */ }
/** * Handles Google XML Checkout redirections. * * @package optimizeMember\Google * @since 1.5 * * @attaches-to ``add_action("init");`` * * @return null Or exits script execution after redirection to Google Checkout. */ public static function google_co() { global $current_site, $current_blog; /**/ if (!empty($_GET["optimizemember_pro_google_co"]) && c_ws_plugin__optimizemember_utils_urls::optimizemember_sig_ok($_SERVER["REQUEST_URI"]) && !empty($_GET["co"]) && is_array($attr = c_ws_plugin__optimizemember_utils_strings::trim_deep(stripslashes_deep($_GET["co"]))) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_merchant_id"]) { $attr = shortcode_atts(array("ids" => "0", "exp" => "72", "level" => "1", "ccaps" => "", "desc" => "", "cc" => "USD", "custom" => $_SERVER["HTTP_HOST"], "ta" => "0", "tp" => "0", "tt" => "D", "ra" => "0.01", "rp" => "1", "rt" => "M", "rr" => "1", "modify" => "0", "cancel" => "0", "sp" => "0", "image" => "default", "output" => "anchor"), $attr); /**/ $attr["tt"] = strtoupper($attr["tt"]); /* Term lengths absolutely must be provided in upper-case format. Only after running shortcode_atts(). */ $attr["rt"] = strtoupper($attr["rt"]); /* Term lengths absolutely must be provided in upper-case format. Only after running shortcode_atts(). */ $attr["rr"] = strtoupper($attr["rr"]); /* Must be provided in upper-case format. Numerical, or BN value. Only after running shortcode_atts(). */ $attr["ccaps"] = strtolower($attr["ccaps"]); /* Custom Capabilities must be typed in lower-case format. Only after running shortcode_atts(). */ $attr["rr"] = $attr["rt"] === "L" ? "BN" : $attr["rr"]; /* Lifetime Subscriptions require Buy Now. Only after running shortcode_atts(). */ $attr["rr"] = $attr["level"] === "*" ? "BN" : $attr["rr"]; /* Independent Ccaps do NOT recur. Only after running shortcode_atts(). */ $attr["rr"] = !$attr["tp"] && !$attr["rr"] ? "BN" : $attr["rr"]; /* No Trial / non-recurring. Only after running shortcode_atts(). */ /**/ if ($attr["modify"] || $attr["cancel"]) { $endpoint = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_sandbox"] ? "sandbox.google.com/checkout" : "checkout.google.com"; /**/ wp_redirect("https://" . $endpoint . "/"); } else { if ($attr["sp"]) { $attr["uniqid"] = uniqid(); /* Unique ID. */ $attr["referencing"] = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id(); /**/ $attr["sp_ids_exp"] = "sp:" . $attr["ids"] . ":" . $attr["exp"]; /* Combined "sp:ids:expiration hours". */ $attr["sp_access_link"] = c_ws_plugin__optimizemember_sp_access::sp_access_link_gen($attr["ids"], $attr["exp"]); /**/ $xml = '<?xml version="1.0" encoding="UTF-8"?>'; $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">'; $xml .= '<shopping-cart>'; $xml .= '<items>'; /**/ $xml .= '<item>'; /**/ $xml .= '<quantity>1</quantity>'; $xml .= '<item-name>' . esc_html($attr["desc"]) . '</item-name>'; $xml .= '<item-description>(TID:s2-' . esc_html($attr["uniqid"]) . ') ' . esc_html(_x("Grants you immediate access.", "s2member-front", "s2member")) . '</item-description>'; $xml .= '<unit-price currency="' . esc_attr($attr["cc"]) . '">' . esc_html($attr["ra"]) . '</unit-price>'; /**/ $xml .= '<merchant-private-item-data>'; $xml .= '<s2_txn_id>s2-' . esc_html($attr["uniqid"]) . '</s2_txn_id>'; $xml .= '<s2_custom>' . esc_html($attr["custom"]) . '</s2_custom>'; $xml .= '<s2_item_number>' . esc_html($attr["sp_ids_exp"]) . '</s2_item_number>'; $xml .= '<s2_customer_ip>' . esc_html($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>'; $xml .= $attr["referencing"] ? '<s2_referencing>' . esc_html($attr["referencing"]) . '</s2_referencing>' : ''; $xml .= '</merchant-private-item-data>'; /**/ $xml .= '<digital-content>'; $xml .= '<display-disposition>PESSIMISTIC</display-disposition>'; $xml .= '<description>' . esc_html($attr["desc"]) . '</description>'; $xml .= '<url>' . esc_html($attr["sp_access_link"]) . '</url>'; $xml .= '</digital-content>'; /**/ $xml .= '</item>'; /**/ $xml .= '</items>'; $xml .= '</shopping-cart>'; /**/ $xml .= '<checkout-flow-support>'; $xml .= '<merchant-checkout-flow-support>'; $xml .= '<edit-cart-url>' . esc_html(get_page_link($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"])) . '</edit-cart-url>'; $xml .= '<continue-shopping-url>' . esc_html($attr["sp_access_link"]) . '</continue-shopping-url>'; $xml .= '</merchant-checkout-flow-support>'; $xml .= '</checkout-flow-support>'; /**/ $xml .= '</checkout-shopping-cart>'; /**/ $endpoint = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_sandbox"] ? "sandbox.google.com/checkout" : "checkout.google.com"; /**/ if (($xml = c_ws_plugin__optimizemember_utils_urls::remote("https://" . $endpoint . "/api/checkout/v2/merchantCheckout/Merchant/" . $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_merchant_id"], $xml, array_merge(c_ws_plugin__optimizemember_pro_google_utilities::google_api_headers(), array("timeout" => 20)))) && preg_match("/\\<redirect-url\\>(.+?)\\<\\/redirect-url\\>/i", preg_replace("/[\r\n\t]+/", "", $xml), $m) && ($google = $m[1])) { wp_redirect(wp_specialchars_decode($google, ENT_QUOTES)); } else { /* Display error message. */ echo strip_tags($xml); } } else { if ($attr["level"] === "*") { $attr["uniqid"] = uniqid(); /* Unique ID. */ $attr["referencing"] = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id(); /**/ $attr["level_ccaps_eotper"] = $attr["rt"] !== "L" ? $attr["level"] . ":" . $attr["ccaps"] . ":" . $attr["rp"] . " " . $attr["rt"] : $attr["level"] . ":" . $attr["ccaps"]; $attr["level_ccaps_eotper"] = rtrim($attr["level_ccaps_eotper"], ":"); /* Right-trim separators from this string so we don't have trailing colons. */ /**/ $xml = '<?xml version="1.0" encoding="UTF-8"?>'; $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">'; $xml .= '<shopping-cart>'; $xml .= '<items>'; /**/ $xml .= '<item>'; /**/ $xml .= '<quantity>1</quantity>'; $xml .= '<item-name>' . esc_html($attr["desc"]) . '</item-name>'; $xml .= '<item-description>(TID:s2-' . esc_html($attr["uniqid"]) . ') ' . esc_html(_x("Grants you immediate access.", "s2member-front", "s2member")) . '</item-description>'; $xml .= '<unit-price currency="' . esc_attr($attr["cc"]) . '">' . esc_html($attr["ra"]) . '</unit-price>'; /**/ $xml .= '<merchant-private-item-data>'; $xml .= '<s2_txn_id>s2-' . esc_html($attr["uniqid"]) . '</s2_txn_id>'; $xml .= '<s2_custom>' . esc_html($attr["custom"]) . '</s2_custom>'; $xml .= '<s2_customer_ip>' . esc_html($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>'; $xml .= '<s2_item_number>' . esc_html($attr["level_ccaps_eotper"]) . '</s2_item_number>'; $xml .= '<s2_referencing>' . esc_html($attr["referencing"]) . '</s2_referencing>'; $xml .= '</merchant-private-item-data>'; /**/ $xml .= '<digital-content>'; $xml .= '<display-disposition>PESSIMISTIC</display-disposition>'; $xml .= '<description>' . esc_html(sprintf(_x('You now have access to:<br />%s<br />( <a href="%s">please log back in now</a> )', "s2member-front", "s2member"), $attr["desc"], esc_attr(wp_login_url()))) . '</description>'; $xml .= '<url>' . esc_html(wp_login_url()) . '</url>'; $xml .= '</digital-content>'; /**/ $xml .= '</item>'; /**/ $xml .= '</items>'; $xml .= '</shopping-cart>'; /**/ $xml .= '<checkout-flow-support>'; $xml .= '<merchant-checkout-flow-support>'; $xml .= '<edit-cart-url>' . esc_html(get_page_link($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"])) . '</edit-cart-url>'; $xml .= '<continue-shopping-url>' . esc_html(wp_login_url()) . '</continue-shopping-url>'; $xml .= '</merchant-checkout-flow-support>'; $xml .= '</checkout-flow-support>'; /**/ $xml .= '</checkout-shopping-cart>'; /**/ $endpoint = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_sandbox"] ? "sandbox.google.com/checkout" : "checkout.google.com"; /**/ if (($xml = c_ws_plugin__optimizemember_utils_urls::remote("https://" . $endpoint . "/api/checkout/v2/merchantCheckout/Merchant/" . $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_merchant_id"], $xml, array_merge(c_ws_plugin__optimizemember_pro_google_utilities::google_api_headers(), array("timeout" => 20)))) && preg_match("/\\<redirect-url\\>(.+?)\\<\\/redirect-url\\>/i", preg_replace("/[\r\n\t]+/", "", $xml), $m) && ($google = $m[1])) { wp_redirect(wp_specialchars_decode($google, ENT_QUOTES)); } else { /* Display error message. */ echo strip_tags($xml); } } else { if ($attr["rr"] === "BN" || !$attr["tp"] && !$attr["rr"]) { $attr["uniqid"] = uniqid(); /* Unique ID. */ $attr["referencing"] = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id(); /**/ $attr["desc"] = !$attr["desc"] ? $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $attr["level"] . "_label"] : $attr["desc"]; /**/ $attr["level_ccaps_eotper"] = $attr["rt"] !== "L" ? $attr["level"] . ":" . $attr["ccaps"] . ":" . $attr["rp"] . " " . $attr["rt"] : $attr["level"] . ":" . $attr["ccaps"]; $attr["level_ccaps_eotper"] = rtrim($attr["level_ccaps_eotper"], ":"); /* Right-trim separators from this string so we don't have trailing colons. */ /**/ $attr["register_access_link"] = c_ws_plugin__optimizemember_register_access::register_link_gen("google", "s2-" . $attr["uniqid"], $attr["custom"], $attr["level_ccaps_eotper"]); /**/ $xml = '<?xml version="1.0" encoding="UTF-8"?>'; $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">'; $xml .= '<shopping-cart>'; $xml .= '<items>'; /**/ $xml .= '<item>'; /**/ $xml .= '<quantity>1</quantity>'; $xml .= '<item-name>' . esc_html($attr["desc"]) . '</item-name>'; $xml .= '<item-description>(TID:s2-' . esc_html($attr["uniqid"]) . ') ' . esc_html(_x("Grants you immediate access.", "s2member-front", "s2member")) . '</item-description>'; $xml .= '<unit-price currency="' . esc_attr($attr["cc"]) . '">' . esc_html($attr["ra"]) . '</unit-price>'; /**/ $xml .= '<merchant-private-item-data>'; $xml .= '<s2_txn_id>s2-' . esc_html($attr["uniqid"]) . '</s2_txn_id>'; $xml .= '<s2_custom>' . esc_html($attr["custom"]) . '</s2_custom>'; $xml .= '<s2_customer_ip>' . esc_html($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>'; $xml .= '<s2_item_number>' . esc_html($attr["level_ccaps_eotper"]) . '</s2_item_number>'; $xml .= $attr["referencing"] ? '<s2_referencing>' . esc_html($attr["referencing"]) . '</s2_referencing>' : ''; $xml .= '</merchant-private-item-data>'; /**/ $xml .= '<digital-content>'; $xml .= '<display-disposition>PESSIMISTIC</display-disposition>'; /**/ if ($attr["referencing"]) { $xml .= '<description>' . esc_html(sprintf(_x('You\'ve been updated to:<br />%s<br />( <a href="%s">please log back in now</a> )', "s2member-front", "s2member"), $attr["desc"], esc_attr(wp_login_url()))) . '</description>'; $xml .= '<url>' . esc_html(wp_login_url()) . '</url>'; } else { $xml .= '<description>' . esc_html(sprintf(_x('%s<br />( the next step is to Register a Username )', "s2member-front", "s2member"), $attr["desc"])) . '</description>'; $xml .= '<url>' . esc_html($attr["register_access_link"]) . '</url>'; } /**/ $xml .= '</digital-content>'; /**/ $xml .= '</item>'; /**/ $xml .= '</items>'; $xml .= '</shopping-cart>'; /**/ $xml .= '<checkout-flow-support>'; $xml .= '<merchant-checkout-flow-support>'; $xml .= '<edit-cart-url>' . esc_html(get_page_link($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"])) . '</edit-cart-url>'; $xml .= '<continue-shopping-url>' . esc_html($attr["referencing"] ? wp_login_url() : $attr["register_access_link"]) . '</continue-shopping-url>'; $xml .= '</merchant-checkout-flow-support>'; $xml .= '</checkout-flow-support>'; /**/ $xml .= '</checkout-shopping-cart>'; /**/ $endpoint = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_sandbox"] ? "sandbox.google.com/checkout" : "checkout.google.com"; /**/ if (($xml = c_ws_plugin__optimizemember_utils_urls::remote("https://" . $endpoint . "/api/checkout/v2/merchantCheckout/Merchant/" . $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_merchant_id"], $xml, array_merge(c_ws_plugin__optimizemember_pro_google_utilities::google_api_headers(), array("timeout" => 20)))) && preg_match("/\\<redirect-url\\>(.+?)\\<\\/redirect-url\\>/i", preg_replace("/[\r\n\t]+/", "", $xml), $m) && ($google = $m[1])) { wp_redirect(wp_specialchars_decode($google, ENT_QUOTES)); } else { /* Display error message. */ echo strip_tags($xml); } } else { $attr["uniqid"] = uniqid(); /* Unique ID. */ $attr["referencing"] = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id(); /**/ $attr["desc"] = !$attr["desc"] ? $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $attr["level"] . "_label"] : $attr["desc"]; /**/ $attr["level_ccaps_eotper"] = $attr["level"] . ":" . $attr["ccaps"]; /* Actual Subscriptions will always end on their own. */ $attr["level_ccaps_eotper"] = rtrim($attr["level_ccaps_eotper"], ":"); /* Clean any trailing separators from this string. */ /**/ $attr["periodicity"] = c_ws_plugin__optimizemember_pro_google_utilities::google_periodicity($attr["rp"] . " " . $attr["rt"]); /* Google periodicity. */ /**/ $attr["register_access_link"] = c_ws_plugin__optimizemember_register_access::register_link_gen("google", "s2-" . $attr["uniqid"], $attr["custom"], $attr["level_ccaps_eotper"]); /**/ if ($attr["tp"]) { $attr["start_time"] = c_ws_plugin__optimizemember_pro_google_utilities::google_start_time($attr["tp"] . " " . $attr["tt"]); /**/ $xml = '<?xml version="1.0" encoding="UTF-8"?>'; $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">'; $xml .= '<shopping-cart>'; $xml .= '<items>'; /**/ $xml .= '<item>'; /**/ $xml .= '<quantity>1</quantity>'; $xml .= '<item-name>' . esc_html($attr["desc"]) . '</item-name>'; $xml .= $attr["ta"] < 0.01 ? '<item-description>(SID:s2-' . esc_html($attr["uniqid"]) . ') ' . esc_html(_x("100% free trial. NO charge today.", "s2member-front", "s2member")) . '</item-description>' : '<item-description>(SID:s2-' . esc_html($attr["uniqid"]) . ') ' . esc_html(_x("First payment for immediate access.", "s2member-front", "s2member")) . '</item-description>'; $xml .= '<unit-price currency="' . esc_attr($attr["cc"]) . '">' . esc_html($attr["ta"]) . '</unit-price>'; /**/ $xml .= '<merchant-private-item-data>'; $xml .= '<s2_subscr_id>s2-' . esc_html($attr["uniqid"]) . '</s2_subscr_id>'; $xml .= '<s2_custom>' . esc_html($attr["custom"]) . '</s2_custom>'; $xml .= '<s2_customer_ip>' . esc_html($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>'; $xml .= '<s2_item_number>' . esc_html($attr["level_ccaps_eotper"]) . '</s2_item_number>'; $xml .= '<s2_period1>' . esc_html($attr["tp"] . " " . $attr["tt"]) . '</s2_period1>'; $xml .= '<s2_period3>' . esc_html($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>'; $xml .= $attr["rr"] ? '<s2_recurring>' . esc_html($attr["rr"]) . '</s2_recurring>' : ''; $xml .= $attr["referencing"] ? '<s2_referencing>' . esc_html($attr["referencing"]) . '</s2_referencing>' : ''; $xml .= '</merchant-private-item-data>'; /**/ $xml .= '<digital-content>'; $xml .= '<display-disposition>PESSIMISTIC</display-disposition>'; $xml .= '<description>' . esc_html(_x("You'll receive an email confirmation within 15 minutes.", "s2member-front", "s2member")) . '</description>'; $xml .= '</digital-content>'; /**/ $xml .= '</item>'; /**/ $xml .= '<item>'; /**/ $xml .= '<quantity>1</quantity>'; $xml .= '<item-name>' . esc_html($attr["desc"]) . '</item-name>'; $xml .= '<item-description>(SID:s2-' . esc_html($attr["uniqid"]) . ') ' . esc_html(sprintf(_x("Cancel at any time to avoid %s.", "s2member-front", "s2member"), !$attr["rr"] ? _x("this charge", "s2member-front", "s2member") : _x("charges", "s2member-front", "s2member"))) . '</item-description>'; $xml .= '<unit-price currency="' . esc_attr($attr["cc"]) . '">0.00</unit-price>'; /**/ $xml .= '<merchant-private-item-data>'; $xml .= '<s2_subscr_id>s2-' . esc_html($attr["uniqid"]) . '</s2_subscr_id>'; $xml .= '<s2_custom>' . esc_html($attr["custom"]) . '</s2_custom>'; $xml .= '<s2_customer_ip>' . esc_html($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>'; $xml .= '<s2_item_number>' . esc_html($attr["level_ccaps_eotper"]) . '</s2_item_number>'; $xml .= '<s2_period1>' . esc_html($attr["tp"] . " " . $attr["tt"]) . '</s2_period1>'; $xml .= '<s2_period3>' . esc_html($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>'; $xml .= $attr["rr"] ? '<s2_recurring>' . esc_html($attr["rr"]) . '</s2_recurring>' : ''; $xml .= $attr["referencing"] ? '<s2_referencing>' . esc_html($attr["referencing"]) . '</s2_referencing>' : ''; $xml .= '</merchant-private-item-data>'; /**/ $xml .= '<digital-content>'; $xml .= '<display-disposition>PESSIMISTIC</display-disposition>'; /**/ if ($attr["referencing"]) { $xml .= '<description>' . esc_html(sprintf(_x('You\'ve been updated to:<br />%s<br />( <a href="%s">please log back in now</a> )', "s2member-front", "s2member"), $attr["desc"], esc_attr(wp_login_url()))) . '</description>'; $xml .= '<url>' . esc_html(wp_login_url()) . '</url>'; } else { $xml .= '<description>' . esc_html(sprintf(_x('%s<br />( the next step is to Register a Username )', "s2member-front", "s2member"), $attr["desc"])) . '</description>'; $xml .= '<url>' . esc_html($attr["register_access_link"]) . '</url>'; } /**/ $xml .= '</digital-content>'; /**/ $xml .= '<subscription type="google" period="' . esc_attr($attr["periodicity"]) . '" start-date="' . esc_attr(date("Y-m-d", $attr["start_time"]) . "T00:00:00Z") . '">'; /**/ $xml .= '<payments>'; $xml .= '<subscription-payment' . (!$attr["rr"] ? ' times="1"' : '') . '>'; $xml .= '<maximum-charge currency="' . esc_attr($attr["cc"]) . '">' . esc_html($attr["ra"]) . '</maximum-charge>'; $xml .= '</subscription-payment>'; $xml .= '</payments>'; /**/ $xml .= '<recurrent-item>'; /**/ $xml .= '<quantity>1</quantity>'; $xml .= '<item-name>' . esc_html($attr["desc"]) . '</item-name>'; $xml .= '<item-description>(SID:s2-' . esc_html($attr["uniqid"]) . ') ' . esc_html(_x("Covers ongoing access.", "s2member-front", "s2member")) . '</item-description>'; $xml .= '<unit-price currency="' . esc_attr($attr["cc"]) . '">' . esc_html($attr["ra"]) . '</unit-price>'; /**/ $xml .= '<merchant-private-item-data>'; $xml .= '<s2_subscr_payment>1</s2_subscr_payment>'; $xml .= '<s2_subscr_id>s2-' . esc_html($attr["uniqid"]) . '</s2_subscr_id>'; $xml .= '<s2_custom>' . esc_html($attr["custom"]) . '</s2_custom>'; $xml .= '<s2_customer_ip>' . esc_html($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>'; $xml .= '<s2_item_number>' . esc_html($attr["level_ccaps_eotper"]) . '</s2_item_number>'; $xml .= '<s2_period1>' . esc_html($attr["tp"] . " " . $attr["tt"]) . '</s2_period1>'; $xml .= '<s2_period3>' . esc_html($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>'; $xml .= $attr["rr"] ? '<s2_recurring>' . esc_html($attr["rr"]) . '</s2_recurring>' : ''; $xml .= $attr["referencing"] ? '<s2_referencing>' . esc_html($attr["referencing"]) . '</s2_referencing>' : ''; $xml .= '</merchant-private-item-data>'; /**/ $xml .= '<digital-content>'; $xml .= '<display-disposition>PESSIMISTIC</display-disposition>'; $xml .= '<description>' . esc_html($attr["desc"]) . '</description>'; $xml .= '<url>' . esc_html(home_url("/")) . '</url>'; $xml .= '</digital-content>'; /**/ $xml .= '</recurrent-item>'; /**/ $xml .= '</subscription>'; /**/ $xml .= '</item>'; /**/ $xml .= '</items>'; $xml .= '</shopping-cart>'; /**/ $xml .= '<checkout-flow-support>'; $xml .= '<merchant-checkout-flow-support>'; $xml .= '<edit-cart-url>' . esc_html(get_page_link($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"])) . '</edit-cart-url>'; $xml .= '<continue-shopping-url>' . esc_html($attr["referencing"] ? wp_login_url() : $attr["register_access_link"]) . '</continue-shopping-url>'; $xml .= '</merchant-checkout-flow-support>'; $xml .= '</checkout-flow-support>'; /**/ $xml .= '</checkout-shopping-cart>'; } else { if (!$attr["tp"] && $attr["rr"]) { $attr["start_time"] = c_ws_plugin__optimizemember_pro_google_utilities::google_start_time($attr["rp"] . " " . $attr["rt"]); /**/ $xml = '<?xml version="1.0" encoding="UTF-8"?>'; $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">'; $xml .= '<shopping-cart>'; $xml .= '<items>'; /**/ $xml .= '<item>'; /**/ $xml .= '<quantity>1</quantity>'; $xml .= '<item-name>' . esc_html($attr["desc"]) . '</item-name>'; $xml .= '<item-description>(SID:s2-' . esc_html($attr["uniqid"]) . ') ' . esc_html(_x("First payment for immediate access.", "s2member-front", "s2member")) . '</item-description>'; $xml .= '<unit-price currency="' . esc_attr($attr["cc"]) . '">' . esc_html($attr["ra"]) . '</unit-price>'; /**/ $xml .= '<merchant-private-item-data>'; $xml .= '<s2_subscr_id>s2-' . esc_html($attr["uniqid"]) . '</s2_subscr_id>'; $xml .= '<s2_custom>' . esc_html($attr["custom"]) . '</s2_custom>'; $xml .= '<s2_customer_ip>' . esc_html($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>'; $xml .= '<s2_item_number>' . esc_html($attr["level_ccaps_eotper"]) . '</s2_item_number>'; $xml .= '<s2_period1>0 D</s2_period1>'; /* There is no Trial Period. */ $xml .= '<s2_period3>' . esc_html($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>'; $xml .= '<s2_recurring>' . esc_html($attr["rr"]) . '</s2_recurring>'; $xml .= $attr["referencing"] ? '<s2_referencing>' . esc_html($attr["referencing"]) . '</s2_referencing>' : ''; $xml .= '</merchant-private-item-data>'; /**/ $xml .= '<digital-content>'; $xml .= '<display-disposition>PESSIMISTIC</display-disposition>'; $xml .= '<description>' . esc_html(_x("You'll receive an email confirmation within 15 minutes.", "s2member-front", "s2member")) . '</description>'; $xml .= '</digital-content>'; /**/ $xml .= '</item>'; /**/ $xml .= '<item>'; /**/ $xml .= '<quantity>1</quantity>'; $xml .= '<item-name>' . esc_html($attr["desc"]) . '</item-name>'; $xml .= '<item-description>(SID:s2-' . esc_html($attr["uniqid"]) . ') ' . esc_html(_x("Cancel at any time to avoid charges.", "s2member-front", "s2member")) . '</item-description>'; $xml .= '<unit-price currency="' . esc_attr($attr["cc"]) . '">0.00</unit-price>'; /**/ $xml .= '<merchant-private-item-data>'; $xml .= '<s2_subscr_id>s2-' . esc_html($attr["uniqid"]) . '</s2_subscr_id>'; $xml .= '<s2_custom>' . esc_html($attr["custom"]) . '</s2_custom>'; $xml .= '<s2_customer_ip>' . esc_html($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>'; $xml .= '<s2_item_number>' . esc_html($attr["level_ccaps_eotper"]) . '</s2_item_number>'; $xml .= '<s2_period1>0 D</s2_period1>'; /* There is no Trial Period. */ $xml .= '<s2_period3>' . esc_html($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>'; $xml .= '<s2_recurring>' . esc_html($attr["rr"]) . '</s2_recurring>'; $xml .= $attr["referencing"] ? '<s2_referencing>' . esc_html($attr["referencing"]) . '</s2_referencing>' : ''; $xml .= '</merchant-private-item-data>'; /**/ $xml .= '<digital-content>'; $xml .= '<display-disposition>PESSIMISTIC</display-disposition>'; /**/ if ($attr["referencing"]) { $xml .= '<description>' . esc_html(sprintf(_x('You\'ve been updated to:<br />%s<br />( <a href="%s">please log back in now</a> )', "s2member-front", "s2member"), $attr["desc"], esc_attr(wp_login_url()))) . '</description>'; $xml .= '<url>' . esc_html(wp_login_url()) . '</url>'; } else { $xml .= '<description>' . esc_html(sprintf(_x('%s<br />( the next step is to Register a Username )', "s2member-front", "s2member"), $attr["desc"])) . '</description>'; $xml .= '<url>' . esc_html($attr["register_access_link"]) . '</url>'; } /**/ $xml .= '</digital-content>'; /**/ $xml .= '<subscription type="google" period="' . esc_attr($attr["periodicity"]) . '" start-date="' . esc_attr(date("Y-m-d", $attr["start_time"]) . "T00:00:00Z") . '">'; /**/ $xml .= '<payments>'; $xml .= '<subscription-payment>'; $xml .= '<maximum-charge currency="' . esc_attr($attr["cc"]) . '">' . esc_html($attr["ra"]) . '</maximum-charge>'; $xml .= '</subscription-payment>'; $xml .= '</payments>'; /**/ $xml .= '<recurrent-item>'; /**/ $xml .= '<quantity>1</quantity>'; $xml .= '<item-name>' . esc_html($attr["desc"]) . '</item-name>'; $xml .= '<item-description>(SID:s2-' . esc_html($attr["uniqid"]) . ') ' . esc_html(_x("Covers ongoing access.", "s2member-front", "s2member")) . '</item-description>'; $xml .= '<unit-price currency="' . esc_attr($attr["cc"]) . '">' . esc_html($attr["ra"]) . '</unit-price>'; /**/ $xml .= '<merchant-private-item-data>'; $xml .= '<s2_subscr_payment>1</s2_subscr_payment>'; $xml .= '<s2_subscr_id>s2-' . esc_html($attr["uniqid"]) . '</s2_subscr_id>'; $xml .= '<s2_custom>' . esc_html($attr["custom"]) . '</s2_custom>'; $xml .= '<s2_customer_ip>' . esc_html($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>'; $xml .= '<s2_item_number>' . esc_html($attr["level_ccaps_eotper"]) . '</s2_item_number>'; $xml .= '<s2_period1>0 D</s2_period1>'; /* There is no Trial Period. */ $xml .= '<s2_period3>' . esc_html($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>'; $xml .= '<s2_recurring>' . esc_html($attr["rr"]) . '</s2_recurring>'; $xml .= $attr["referencing"] ? '<s2_referencing>' . esc_html($attr["referencing"]) . '</s2_referencing>' : ''; $xml .= '</merchant-private-item-data>'; /**/ $xml .= '<digital-content>'; $xml .= '<display-disposition>PESSIMISTIC</display-disposition>'; $xml .= '<description>' . esc_html($attr["desc"]) . '</description>'; $xml .= '<url>' . esc_html(home_url("/")) . '</url>'; $xml .= '</digital-content>'; /**/ $xml .= '</recurrent-item>'; /**/ $xml .= '</subscription>'; /**/ $xml .= '</item>'; /**/ $xml .= '</items>'; $xml .= '</shopping-cart>'; /**/ $xml .= '<checkout-flow-support>'; $xml .= '<merchant-checkout-flow-support>'; $xml .= '<edit-cart-url>' . esc_html(get_page_link($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"])) . '</edit-cart-url>'; $xml .= '<continue-shopping-url>' . esc_html($attr["referencing"] ? wp_login_url() : $attr["register_access_link"]) . '</continue-shopping-url>'; $xml .= '</merchant-checkout-flow-support>'; $xml .= '</checkout-flow-support>'; /**/ $xml .= '</checkout-shopping-cart>'; } } /**/ $endpoint = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_sandbox"] ? "sandbox.google.com/checkout" : "checkout.google.com"; /**/ if (($xml = c_ws_plugin__optimizemember_utils_urls::remote("https://" . $endpoint . "/api/checkout/v2/merchantCheckout/Merchant/" . $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_merchant_id"], $xml, array_merge(c_ws_plugin__optimizemember_pro_google_utilities::google_api_headers(), array("timeout" => 20)))) && preg_match("/\\<redirect-url\\>(.+?)\\<\\/redirect-url\\>/i", preg_replace("/[\r\n\t]+/", "", $xml), $m) && ($google = $m[1])) { wp_redirect(wp_specialchars_decode($google, ENT_QUOTES)); } else { /* Display error message. */ echo strip_tags($xml); } } } } } /**/ exit; /* Clean exit. */ } }
/** * Handles processing of Pro Forms for Specific Post/Page checkout. * * @package optimizeMember\AuthNet * @since 1.5 * * @attaches-to ``add_action("init");`` * * @return null Or exits script execution after a custom URL redirection. */ public static function authnet_sp_checkout() { if (!empty($_POST["optimizemember_pro_authnet_sp_checkout"]["nonce"]) && ($nonce = $_POST["optimizemember_pro_authnet_sp_checkout"]["nonce"]) && wp_verify_nonce($nonce, "s2member-pro-authnet-sp-checkout")) { $GLOBALS["ws_plugin__optimizemember_pro_authnet_sp_checkout_response"] = array(); /* This holds the global response details. */ $global_response =& $GLOBALS["ws_plugin__optimizemember_pro_authnet_sp_checkout_response"]; /* This is a shorter reference. */ /**/ $post_vars = c_ws_plugin__optimizemember_utils_strings::trim_deep(stripslashes_deep($_POST["optimizemember_pro_authnet_sp_checkout"])); $post_vars["attr"] = unserialize(c_ws_plugin__optimizemember_utils_encryption::decrypt($post_vars["attr"])); /* And Filter. */ $post_vars["attr"] = apply_filters("ws_plugin__optimizemember_pro_authnet_sp_checkout_post_attr", $post_vars["attr"], get_defined_vars()); /**/ $post_vars["recaptcha_challenge_field"] = !$post_vars["recaptcha_challenge_field"] ? trim(stripslashes($_POST["recaptcha_challenge_field"])) : $post_vars["recaptcha_challenge_field"]; $post_vars["recaptcha_response_field"] = !$post_vars["recaptcha_response_field"] ? trim(stripslashes($_POST["recaptcha_response_field"])) : $post_vars["recaptcha_response_field"]; /**/ $post_vars["name"] = trim($post_vars["first_name"] . " " . $post_vars["last_name"]); $post_vars["email"] = apply_filters("user_registration_email", sanitize_email($post_vars["email"]), get_defined_vars()); /**/ if (!c_ws_plugin__optimizemember_pro_authnet_responses::authnet_form_attr_validation_errors($post_vars["attr"])) { if (!($error = c_ws_plugin__optimizemember_pro_authnet_responses::authnet_form_submission_validation_errors("sp-checkout", $post_vars))) { $cp_attr = c_ws_plugin__optimizemember_pro_authnet_utilities::authnet_apply_coupon($post_vars["attr"], $post_vars["coupon"], "attr", array("affiliates-silent-post")); $cost_calculations = c_ws_plugin__optimizemember_pro_authnet_utilities::authnet_cost(null, $cp_attr["ra"], $post_vars["state"], $post_vars["country"], $post_vars["zip"], $cp_attr["cc"], $cp_attr["desc"]); /**/ if (!($authnet = array())) { $authnet["x_type"] = "AUTH_CAPTURE"; $authnet["x_method"] = "CC"; /**/ $authnet["x_email"] = $post_vars["email"]; $authnet["x_first_name"] = $post_vars["first_name"]; $authnet["x_last_name"] = $post_vars["last_name"]; $authnet["x_customer_ip"] = $_SERVER["REMOTE_ADDR"]; /**/ $authnet["x_invoice_num"] = "s2-" . uniqid(); $authnet["x_description"] = $cost_calculations["desc"]; /**/ $authnet["s2_invoice"] = $post_vars["attr"]["sp_ids_exp"]; $authnet["s2_custom"] = $post_vars["attr"]["custom"]; /**/ $authnet["x_tax"] = $cost_calculations["tax"]; $authnet["x_amount"] = $cost_calculations["total"]; /**/ $authnet["x_card_num"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]); $authnet["x_exp_date"] = c_ws_plugin__optimizemember_pro_authnet_utilities::authnet_exp_date($post_vars["card_expiration"]); $authnet["x_card_code"] = $post_vars["card_verification"]; /**/ #if (in_array ($post_vars["card_type"], array ("Maestro", "Solo"))) # if (preg_match ("/^[0-9]{2}\/[0-9]{4}$/", $post_vars["card_start_date_issue_number"])) # $authnet["x_card_start_date"] = preg_replace ("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]); # else /* Otherwise, we assume they provided an issue number instead. */ # $authnet["x_card_issue_number"] = $post_vars["card_start_date_issue_number"]; /**/ $authnet["x_address"] = $post_vars["street"]; $authnet["x_city"] = $post_vars["city"]; $authnet["x_state"] = $post_vars["state"]; $authnet["x_country"] = $post_vars["country"]; $authnet["x_zip"] = $post_vars["zip"]; } /**/ if (($authnet = c_ws_plugin__optimizemember_pro_authnet_utilities::authnet_aim_response($authnet)) && empty($authnet["__error"])) { $new__txn_id = $authnet["transaction_id"]; /**/ if (!($ipn = array())) { $ipn["txn_type"] = "web_accept"; $ipn["txn_id"] = $new__txn_id; $ipn["custom"] = $post_vars["attr"]["custom"]; /**/ $ipn["mc_gross"] = $cost_calculations["total"]; $ipn["mc_currency"] = $cost_calculations["cur"]; $ipn["tax"] = $cost_calculations["tax"]; /**/ $ipn["payer_email"] = $post_vars["email"]; $ipn["first_name"] = $post_vars["first_name"]; $ipn["last_name"] = $post_vars["last_name"]; /**/ if (is_user_logged_in() && ($referencing = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id())) { $ipn["option_name1"] = "Referencing Customer ID"; $ipn["option_selection1"] = $referencing; } else { $ipn["option_name1"] = "Originating Domain"; $ipn["option_selection1"] = $_SERVER["HTTP_HOST"]; } /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"]; /**/ $ipn["item_name"] = $cost_calculations["desc"]; $ipn["item_number"] = $post_vars["attr"]["sp_ids_exp"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=authnet&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); $ipn_q .= "&optimizemember_paypal_proxy_return_url=" . rawurlencode($post_vars["attr"]["success"]); /**/ $ipn["optimizemember_authnet_proxy_return_url"] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20))); } /**/ if ($sp_access_url = c_ws_plugin__optimizemember_sp_access::sp_access_link_gen($post_vars["attr"]["ids"], $post_vars["attr"]["exp"])) { setcookie("optimizemember_sp_tracking", $optimizemember_sp_tracking = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__txn_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie("optimizemember_sp_tracking", $optimizemember_sp_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE["optimizemember_sp_tracking"] = $optimizemember_sp_tracking); /**/ $global_response = array("response" => sprintf(_x('<strong>Thank you.</strong> Your purchase has been approved.<br />— Please <a href="%s" rel="nofollow">click here</a> to proceed.', "s2member-front", "s2member"), esc_attr($sp_access_url))); /**/ if ($post_vars["attr"]["success"] && substr($ipn["optimizemember_authnet_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["optimizemember_authnet_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } else { $global_response = array("response" => _x('<strong>Oops.</strong> Unable to generate Access Link. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true); } } else { $global_response = array("response" => $authnet["__error"], "error" => true); } } else { $global_response = $error; } } } }
/** * optimizeMember's PayPal IPN handler ( inner processing routine ). * * @package optimizeMember\PayPal * @since 110815 * * @param array $vars Required. An array of defined variables passed by {@link optimizeMember\PayPal\c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()}. * @return array|bool The original ``$paypal`` array passed in ( extracted ) from ``$vars``, or false when conditions do NOT apply. * * @todo Optimize with ``empty()`` and ``isset()``. */ public static function cp($vars = array()) { extract($vars); /* Extract all vars passed in from: ``c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()``. */ /**/ if (!empty($paypal["txn_type"]) && preg_match("/^web_accept\$/i", $paypal["txn_type"]) && (!empty($paypal["item_number"]) && preg_match($GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["membership_item_number_wo_level_regex"], $paypal["item_number"])) && (empty($paypal["payment_status"]) || empty($payment_status_issues) || !preg_match($payment_status_issues, $paypal["payment_status"])) && (!empty($paypal["txn_id"]) && ($paypal["subscr_id"] = $paypal["txn_id"])) && !empty($paypal["payer_email"])) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_before_new_ccaps", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if (!get_transient($transient_ipn = "s2m_ipn_" . md5("optimizemember_transient_" . $_paypal_s)) && set_transient($transient_ipn, time(), 31556926 * 10)) { $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `web_accept` ) w/ update vars for Capabilities w/o Level."; /**/ list($paypal["level"], $paypal["ccaps"], $paypal["eotper"]) = preg_split("/\\:/", $paypal["item_number"], 3); /**/ $paypal["ip"] = preg_match("/ip address/i", $paypal["option_name2"]) && $paypal["option_selection2"] ? $paypal["option_selection2"] : ""; $paypal["ip"] = !$paypal["ip"] && preg_match("/^[a-z0-9]+~[0-9\\.]+\$/i", $paypal["invoice"]) ? preg_replace("/^[a-z0-9]+~/i", "", $paypal["invoice"]) : $paypal["ip"]; /**/ if (preg_match("/(referenc|associat|updat|upgrad)/i", $paypal["option_name1"]) && $paypal["option_selection1"]) { if (($user_id = c_ws_plugin__optimizemember_utils_users::get_user_id_with($paypal["txn_id"], $paypal["option_selection1"])) && is_object($user = new WP_User($user_id)) && $user->ID) { if (!$user->has_cap("administrator")) { $processing = $during = true; /* Yes, we ARE processing this. */ /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_before_new_ccaps", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ $fields = get_user_option("optimizemember_custom_fields", $user_id); /* These will be needed in the routines below. */ $user_reg_ip = get_user_option("optimizemember_registration_ip", $user_id); /* Original IP during Registration. */ $user_reg_ip = $paypal["ip"] = $user_reg_ip ? $user_reg_ip : $paypal["ip"]; /* Now merge conditionally. */ /**/ if (is_multisite() && !is_user_member_of_blog($user_id)) { add_existing_user_to_blog(array("user_id" => $user_id, "role" => get_option("default_role"))); $user = new WP_User($user_id); } /**/ if ($paypal["ccaps"] && preg_match("/^-all/", str_replace("+", "", $paypal["ccaps"]))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_optimizemember_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } } /**/ if ($paypal["ccaps"] && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $paypal["ccaps"]))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $paypal["ccaps"]))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_optimizemember_ccap_" . $ccap); } } } /**/ if (!get_user_option("optimizemember_registration_ip", $user_id)) { update_user_option($user_id, "optimizemember_registration_ip", $paypal["ip"]); } /**/ $paypal["optimizemember_log"][] = "optimizeMember Custom Capabilities updated w/ advanced update routines."; /**/ c_ws_plugin__optimizemember_email_configs::email_config() . wp_mail($paypal["payer_email"], apply_filters("ws_plugin__optimizemember_capabilities_email_sbj", _x("Thank you! Your account has been updated.", "s2member-front", "s2member"), get_defined_vars()), apply_filters("ws_plugin__optimizemember_capabilities_email_msg", _x("Thank you! You now have access to:", "s2member-front", "s2member") . "\n" . $paypal["item_name"] . "\n\n" . _x("Please log back in now.", "s2member-front", "s2member") . "\n" . wp_login_url(), get_defined_vars()), "From: \"" . preg_replace('/"/', "'", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["reg_email_from_name"]) . "\" <" . $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["reg_email_from_email"] . ">\r\nContent-Type: text/plain; charset=utf-8") . c_ws_plugin__optimizemember_email_configs::email_config_release(); /**/ $paypal["optimizemember_log"][] = "Capability Confirmation Email sent to Customer, with a URL that provides them with a way to log back in."; /**/ if ($processing && $_GET["optimizemember_paypal_proxy"] && ($url = $_GET["optimizemember_paypal_proxy_return_url"]) && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["subscr_id"])), $url))) { if (($url = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["mc_gross"])), $url)) && ($url = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["txn_id"])), $url))) { if (($url = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_number"])), $url)) && ($url = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_name"])), $url))) { if (($url = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["first_name"])), $url)) && ($url = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["last_name"])), $url))) { if ($url = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($paypal["first_name"] . " " . $paypal["last_name"]))), $url)) { if ($url = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["payer_email"])), $url)) { if (($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->first_name)), $url)) && ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->last_name)), $url))) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($user->first_name . " " . $user->last_name))), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_login)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_reg_ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_id)), $url)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } } /**/ if ($url = trim($url)) { /* Preserve remaining replacements. */ /* Because the parent routine may perform replacements too. */ $paypal["optimizemember_paypal_proxy_return_url"] = $url; } } } } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Capability Return, a Proxy Return URL is ready."; } /**/ if ($processing && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["payment_notification_urls"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["payment_notification_urls"]) as $url) { /**/ if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["subscr_id"])), $url))) { if (($url = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["mc_gross"])), $url)) && ($url = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["txn_id"])), $url))) { if (($url = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_number"])), $url)) && ($url = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_name"])), $url))) { if (($url = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["first_name"])), $url)) && ($url = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["last_name"])), $url))) { if ($url = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($paypal["first_name"] . " " . $paypal["last_name"]))), $url)) { if ($url = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["payer_email"])), $url)) { if (($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->first_name)), $url)) && ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->last_name)), $url))) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($user->first_name . " " . $user->last_name))), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_login)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_reg_ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_id)), $url)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } } /**/ if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__optimizemember_utils_urls::remote($url); } } } } } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Payment Notification URLs have been processed."; } /**/ if ($processing && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["payment_notification_recipients"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { $msg = $sbj = "( optimizeMember / API Notification Email ) - Payment"; $msg .= "\n\n"; /* Spacing in the message body. */ /**/ $msg .= "subscr_id: %%subscr_id%%\n"; $msg .= "amount: %%amount%%\n"; $msg .= "txn_id: %%txn_id%%\n"; $msg .= "item_number: %%item_number%%\n"; $msg .= "item_name: %%item_name%%\n"; $msg .= "first_name: %%first_name%%\n"; $msg .= "last_name: %%last_name%%\n"; $msg .= "full_name: %%full_name%%\n"; $msg .= "payer_email: %%payer_email%%\n"; /**/ $msg .= "user_first_name: %%user_first_name%%\n"; $msg .= "user_last_name: %%user_last_name%%\n"; $msg .= "user_full_name: %%user_full_name%%\n"; $msg .= "user_email: %%user_email%%\n"; $msg .= "user_login: %%user_login%%\n"; $msg .= "user_ip: %%user_ip%%\n"; $msg .= "user_id: %%user_id%%\n"; /**/ if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { $msg .= $var . ": %%" . $var . "%%\n"; } } /**/ $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; /**/ if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["subscr_id"]), $msg))) { if (($msg = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_gross"]), $msg)) && ($msg = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["txn_id"]), $msg))) { if (($msg = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $msg)) && ($msg = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $msg))) { if (($msg = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $msg)) && ($msg = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $msg))) { if ($msg = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $msg)) { if ($msg = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $msg)) { if (($msg = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->first_name), $msg)) && ($msg = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->last_name), $msg))) { if ($msg = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($user->first_name . " " . $user->last_name)), $msg)) { if ($msg = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_email), $msg)) { if ($msg = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_login), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_reg_ip), $msg)) { if ($msg = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_id), $msg)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($msg = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(maybe_serialize($val)), $msg))) { break; } } } /**/ if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { /* Still have a ``$sbj`` and a ``$msg``? */ /**/ foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["payment_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__optimizemember_payment_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_payment_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=utf-8"); } } } } } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Payment Notification Emails have been processed."; } /**/ if ($processing && ($code = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["ccap_tracking_codes"]) && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { if (($code = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $code)) && ($code = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["subscr_id"]), $code))) { if (($code = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_gross"]), $code)) && ($code = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["txn_id"]), $code))) { if (($code = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $code)) && ($code = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $code))) { if (($code = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $code)) && ($code = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $code))) { if ($code = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $code)) { if ($code = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $code)) { if (($code = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->first_name), $code)) && ($code = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->last_name), $code))) { if ($code = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($user->first_name . " " . $user->last_name)), $code)) { if ($code = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_email), $code)) { if ($code = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_login), $code)) { if ($code = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_reg_ip), $code)) { if ($code = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_id), $code)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($code = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(maybe_serialize($val)), $code))) { break; } } } /**/ if ($code = trim(preg_replace("/%%(.+?)%%/i", "", $code))) { $paypal["optimizemember_log"][] = "Storing Payment Tracking Codes into a Transient Queue. These will be processed on-site."; set_transient("s2m_" . md5("optimizemember_transient_ccap_tracking_codes_" . $paypal["txn_id"]), $code, 43200); } } } } } } } } } } } } } } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_new_ccaps", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { $paypal["optimizemember_log"][] = "Unable to add new Capabilities. The existing User ID is associated with an Administrator. Stopping here. Otherwise, an Administrator could lose access."; } } else { $paypal["optimizemember_log"][] = "Unable to add new Capabilities. Could not get the existing User ID from the DB. Please check the `on0` and `os0` variables in your Button Code."; } } else { $paypal["optimizemember_log"][] = "Unable to add new Capabilities. Missing User/Member details. Please check the `on0` and `os0` variables in your Button Code."; } } else { $paypal["optimizemember_log"][] = "Not processing. Duplicate IPN."; $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `web_accept` ) w/ update vars for Capabilities w/o Level."; $paypal["optimizemember_log"][] = "Duplicate IPN. Already processed. This IPN will be ignored."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_after_new_ccaps", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_wa_ccaps_wo_level", $paypal, get_defined_vars()); } else { return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_wa_ccaps_wo_level", false, get_defined_vars()); } }
/** * Checks to see if a Coupon Code was supplied, and if so; what does it provide? * * @package optimizeMember\Stripe * @since 140617 * * @param array $attr An array of Pro Form Attributes. * @param string $coupon_code Optional. A possible Coupon Code supplied by the Customer. * @param string $return Optional. Return type. One of `response|attr`. Defaults to `attr`. * @param array $process Optional. An array of additional processing routines to run here. * One or more of these values: `affiliates-1px-response|affiliates-silent-post|notifications`. * * @return array|string Original array, with prices and description modified when/if a Coupon Code is accepted. * Or, if ``$return === 'response'``, return a string response, indicating status. */ public static function apply_coupon($attr = array(), $coupon_code = '', $return = '', $process = array()) { if (($coupon_code = trim(strtolower($coupon_code))) || ($coupon_code = trim(strtolower($attr['coupon'])))) { if ($attr['accept_coupons'] && $GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_coupon_codes']) { $cs = c_ws_plugin__optimizemember_utils_cur::symbol($attr['cc']); $tx = c_ws_plugin__optimizemember_pro_stripe_utilities::tax_may_apply() ? _x(' + tax', 's2member-front', 's2member') : ''; $ps = _x('%', 'optimizemember-front percentage-symbol', 's2member'); $full_coupon_code = ''; // Initialize. if (strlen($affiliate_suffix_chars = $GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_affiliate_coupon_code_suffix_chars'])) { if (preg_match('/^(.+?)' . preg_quote($affiliate_suffix_chars, '/') . '([0-9]+)$/i', $coupon_code, $m)) { ($full_coupon_code = $m[0]) . ($coupon_code = $m[1]) . ($affiliate_id = $m[2]); } } unset($affiliate_suffix_chars, $m); // Just a little housekeeping here. foreach (c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split('/[' . "\r\n\t" . ']+/', $GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_coupon_codes'])) as $_line) { if (($_line = trim($_line, ' ' . "\r\n\t\v" . '|')) && is_array($_coupon = preg_split('/\\|/', $_line))) { $coupon['code'] = !empty($_coupon[0]) ? trim(strtolower($_coupon[0])) : ''; $coupon['percentage'] = !empty($_coupon[1]) && preg_match('/%/', $_coupon[1]) ? (double) $_coupon[1] : 0; $coupon['flat-rate'] = !empty($_coupon[1]) && !preg_match('/%/', $_coupon[1]) ? (double) $_coupon[1] : 0; $coupon['expired'] = !empty($_coupon[2]) && strtotime($_coupon[2]) < time() ? $_coupon[2] : FALSE; $coupon['directive'] = !empty($_coupon[3]) && ($_coupon[3] = strtolower($_coupon[3])) ? preg_replace('/_/', '-', $_coupon[3]) : 'all'; $coupon['directive'] = preg_match('/^(ta-only|ra-only|all)$/', $coupon['directive']) ? $coupon['directive'] : 'all'; $coupon['singulars'] = !empty($_coupon[4]) && ($_coupon[4] = strtolower($_coupon[4])) && $_coupon[4] !== 'all' ? $_coupon[4] : 'all'; $coupon['singulars'] = $coupon['singulars'] !== 'all' ? preg_split('/[' . "\r\n\t" . '\\s;,]+/', trim(preg_replace('/[^0-9,]/', '', $coupon['singulars']), ',')) : array('all'); unset($_line, $_coupon); // Just a little housekeeping here. Unset these temporary variables. if ($coupon_code === $coupon['code'] && !$coupon['expired']) { if ($coupon['singulars'] === array('all') || in_array($attr['singular'], $coupon['singulars'])) { $coupon_accepted = TRUE; // Yes, this Coupon Code has been accepted. if ($coupon['flat-rate']) { if (($coupon['directive'] === 'ra-only' || $coupon['directive'] === 'all') && $attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'] - $coupon['flat-rate'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . $ra . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . $ra . $tx); } else { if ($coupon['directive'] === 'ta-only' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'] - $coupon['flat-rate'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'ra-only' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'] - $coupon['flat-rate'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'all' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'] - $coupon['flat-rate'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'] - $coupon['flat-rate'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'ra-only' && !$attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'] - $coupon['flat-rate'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); } else { if ($coupon['directive'] === 'all' && !$attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'] - $coupon['flat-rate'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'] - $coupon['flat-rate'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); } else { // Otherwise, we need a default response to display. $response = _x('<div>Sorry, your Coupon is not applicable.</div>', 's2member-front', 's2member'); } } } } } } } else { if ($coupon['percentage']) { if (($coupon['directive'] === 'ra-only' || $coupon['directive'] === 'all') && $attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'] - $p, 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . $ra . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . $ra . $tx); } else { if ($coupon['directive'] === 'ta-only' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'] - $p, 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'ra-only' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'] - $p, 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'all' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'] - $p, 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'] - $p, 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'ra-only' && !$attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'] - $p, 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); } else { if ($coupon['directive'] === 'all' && !$attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'] - $p, 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'] - $p, 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); } else { // Otherwise, we need a default response to display. $response = _x('<div>Sorry, your Coupon is not applicable.</div>', 's2member-front', 's2member'); } } } } } } } else { // Else there was no discount applied at all. $response = sprintf(_x('<div>Coupon: <strong>%s0.00 off</strong>.</div>', 's2member-front', 's2member'), $cs); } } } else { // Otherwise, we need a response that indicates not applicable for this purchase. $response = _x('<div>Sorry, your Coupon cannot be applied to this particular purchase.</div>', 's2member-front', 's2member'); } } else { if ($coupon_code === $coupon['code'] && $coupon['expired']) { $response = sprintf(_x('<div>Sorry, your Coupon <strong>expired</strong>: <em>%s</em>.</div>', 's2member-front', 's2member'), $coupon['expired']); } } } } if (isset($coupon_applies, $full_coupon_code, $desc) && $coupon_applies) { // translators: `%1$s` is new price/description, after coupon applied. `%2$s` is original description. $attr['desc'] = sprintf(_x('%1$s %2$s ~ ORIGINALLY: %3$s', 's2member-front', 's2member'), strtoupper($full_coupon_code), $desc, $attr['desc']); } $attr['ta'] = isset($coupon_applies, $ta) && $coupon_applies ? $ta : $attr['ta']; // Do we have a new Trial Amount? $attr['ra'] = isset($coupon_applies, $ra) && $coupon_applies ? $ra : $attr['ra']; // A new Regular Amount? if (is_array($process) && (in_array('affiliates-silent-post', $process) || in_array('affiliates-1px-response', $process))) { if (isset($coupon_applies) && $coupon_applies && !empty($affiliate_id)) { if (empty($_COOKIE['idev'])) { if ($_urls = $GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_affiliate_coupon_code_tracking_urls']) { foreach (preg_split('/[' . "\r\n\t" . ']+/', $_urls) as $_url) { if ($_url = preg_replace('/%%full_coupon_code%%/i', c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($full_coupon_code)), $_url)) { if ($_url = preg_replace('/%%coupon_code%%/i', c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($coupon_code)), $_url)) { if ($_url = preg_replace('/%%(?:coupon_affiliate_id|affiliate_id)%%/i', c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($affiliate_id)), $_url)) { if ($_url = preg_replace('/%%user_ip%%/i', c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($_SERVER['REMOTE_ADDR'])), $_url)) { if ($_url = trim(preg_replace('/%%(.+?)%%/i', '', $_url))) { if (!($_r = 0) && ($_url = preg_replace('/^silent-php\\|/i', '', $_url, 1, $_r)) && $_r && in_array('affiliates-silent-post', $process)) { c_ws_plugin__optimizemember_utils_urls::remote($_url, FALSE, array('blocking' => FALSE)); } else { if (!($_r = 0) && ($_url = preg_replace('/^img-1px\\|/i', '', $_url, 1, $_r)) && $_r && in_array('affiliates-1px-response', $process)) { if (!empty($response) && $return === 'response') { $response .= '\\n' . '<img src="' . esc_attr($_url) . '" style="width:0; height:0; border:0;" alt="" />'; } } } } } } } } } } } } } unset($_urls, $_url, $_r); // Just a little housekeeping here. Unset these variables. if (empty($response)) { // Is ``$response`` NOT set by now? If it's not, we need a default ``$response``. $response = _x('<div>Sorry, your Coupon is N/A, invalid or expired.</div>', 's2member-front', 's2member'); } } else { // Otherwise, we need a default response to display. $response = _x('<div>Sorry, your Coupon is N/A, invalid or expired.</div>', 's2member-front', 's2member'); } } $attr['_coupon_applies'] = isset($coupon_applies) && $coupon_applies ? '1' : '0'; $attr['_coupon_code'] = isset($coupon_applies) && $coupon_applies ? $coupon_code : ''; $attr['_full_coupon_code'] = isset($coupon_applies) && $coupon_applies && !empty($full_coupon_code) ? $full_coupon_code : (isset($coupon_applies) && $coupon_applies ? $coupon_code : ''); $attr['_coupon_affiliate_id'] = isset($coupon_applies) && $coupon_applies && !empty($affiliate_id) && empty($_COOKIE['idev']) ? $affiliate_id : ''; return $return === 'response' ? !empty($response) ? (string) $response : '' : $attr; }
/** * Checks to see if a Coupon Code was supplied, and if so; what does it provide? * * @package optimizeMember\PayPal * @since 1.5 * * @param array $attr An array of Pro Form Attributes. * @param str $coupon_code Optional. A possible Coupon Code supplied by the Customer. * @param str $return Optional. Return type. One of `response|attr`. Defaults to `attr`. * @param array $process Optional. An array of additional processing routines to run here. * One or more of these values: `affiliates-1px-response|affiliates-silent-post|notifications`. * @return array|str Original array, with prices and description modified when/if a Coupon Code is accepted. * Or, if ``$return === "response"``, return a string response, indicating status. * * @todo See if it's possible to simplify this routine. * @todo Add support for tracking Coupon Code usage. * @todo Add support for a fixed number of uses. */ public static function paypal_apply_coupon($attr = FALSE, $coupon_code = FALSE, $return = FALSE, $process = FALSE) { if (($coupon_code = trim(strtolower($coupon_code))) || ($coupon_code = trim(strtolower($attr["coupon"])))) { if ($attr["accept_coupons"] && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_coupon_codes"]) { $cs = c_ws_plugin__optimizemember_utils_cur::symbol($attr["cc"]); $tx = c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_tax_may_apply() ? _x(" + tax", "s2member-front", "s2member") : ""; $ps = _x("%", "s2member-front percentage-symbol", "s2member"); /**/ if (strlen($affiliate_suffix_chars = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_affiliate_coupon_code_suffix_chars"])) { if (preg_match("/^(.+?)" . preg_quote($affiliate_suffix_chars, "/") . "([0-9]+)\$/i", $coupon_code, $m)) { ($full_coupon_code = $m[0]) . ($coupon_code = $m[1]) . ($affiliate_id = $m[2]); } } unset($affiliate_suffix_chars, $m); /**/ foreach (c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_coupon_codes"])) as $_line) { if (($_line = trim($_line, " \r\n\t\v|")) && is_array($_coupon = preg_split("/\\|/", $_line))) { $coupon["code"] = !empty($_coupon[0]) ? trim(strtolower($_coupon[0])) : ""; /**/ $coupon["percentage"] = !empty($_coupon[1]) && preg_match("/%/", $_coupon[1]) ? (double) $_coupon[1] : 0; $coupon["flat-rate"] = !empty($_coupon[1]) && !preg_match("/%/", $_coupon[1]) ? (double) $_coupon[1] : 0; /**/ $coupon["expired"] = !empty($_coupon[2]) && strtotime($_coupon[2]) < time() ? $_coupon[2] : false; /**/ $coupon["directive"] = !empty($_coupon[3]) && ($_coupon[3] = strtolower($_coupon[3])) ? preg_replace("/_/", "-", $_coupon[3]) : "all"; $coupon["directive"] = preg_match("/^(ta-only|ra-only|all)\$/", $coupon["directive"]) ? $coupon["directive"] : "all"; /**/ $coupon["singulars"] = !empty($_coupon[4]) && ($_coupon[4] = strtolower($_coupon[4])) && $_coupon[4] !== "all" ? $_coupon[4] : "all"; $coupon["singulars"] = $coupon["singulars"] !== "all" ? preg_split("/[\r\n\t\\s;,]+/", trim(preg_replace("/[^0-9,]/", "", $coupon["singulars"]), ",")) : array("all"); /**/ unset($_line, $_coupon); /**/ if ($coupon_code === $coupon["code"] && !$coupon["expired"]) { if ($coupon["singulars"] === array("all") || in_array($attr["singular"], $coupon["singulars"])) { $coupon_accepted = true; /**/ if ($coupon["flat-rate"]) { if (($coupon["directive"] === "ra-only" || $coupon["directive"] === "all") && $attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"] - $coupon["flat-rate"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . $ra . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . $ra . $tx); } else { if ($coupon["directive"] === "ta-only" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"] - $coupon["flat-rate"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "ra-only" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"] - $coupon["flat-rate"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "all" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"] - $coupon["flat-rate"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"] - $coupon["flat-rate"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "ra-only" && !$attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"] - $coupon["flat-rate"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); } else { if ($coupon["directive"] === "all" && !$attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"] - $coupon["flat-rate"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"] - $coupon["flat-rate"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); } else { /* Otherwise, we need a default response to display. */ $response = _x('<div>Sorry, your Coupon is not applicable.</div>', "s2member-front", "s2member"); } } } } } } } else { if ($coupon["percentage"]) { if (($coupon["directive"] === "ra-only" || $coupon["directive"] === "all") && $attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"] - $p, 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . $ra . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . $ra . $tx); } else { if ($coupon["directive"] === "ta-only" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"] - $p, 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "ra-only" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"] - $p, 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "all" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"] - $p, 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"] - $p, 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "ra-only" && !$attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"] - $p, 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); } else { if ($coupon["directive"] === "all" && !$attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"] - $p, 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"] - $p, 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); } else { /* Otherwise, we need a default response to display. */ $response = _x('<div>Sorry, your Coupon is not applicable.</div>', "s2member-front", "s2member"); } } } } } } } else { /* Else there was no discount applied at all. */ $response = sprintf(_x('<div>Coupon: <strong>%s0.00 off</strong>.</div>', "s2member-front", "s2member"), $cs); } } } else { /* Otherwise, we need a response that indicates not applicable for this purchase. */ $response = _x('<div>Sorry, your Coupon cannot be applied to this particular purchase.</div>', "s2member-front", "s2member"); } } else { if ($coupon_code === $coupon["code"] && $coupon["expired"]) { $response = sprintf(_x('<div>Sorry, your Coupon <strong>expired</strong>: <em>%s</em>.</div>', "s2member-front", "s2member"), $coupon["expired"]); } } } } /**/ if (isset($coupon_applies, $desc) && $coupon_applies) { /* translators: `%1$s` is new price/description, after coupon applied. `%2$s` is original description. */ $attr["desc"] = sprintf(_x('%1$s ~ ORIGINALLY: %2$s', "s2member-front", "s2member"), $desc, $attr["desc"]); } /**/ $attr["ta"] = isset($coupon_applies, $ta) && $coupon_applies ? $ta : $attr["ta"]; $attr["ra"] = isset($coupon_applies, $ra) && $coupon_applies ? $ra : $attr["ra"]; /**/ if (is_array($process) && (in_array("affiliates-silent-post", $process) || in_array("affiliates-1px-response", $process))) { if (isset($coupon_applies) && $coupon_applies && !empty($affiliate_id)) { if (empty($_COOKIE["idev"])) { if ($_urls = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_affiliate_coupon_code_tracking_urls"]) { /**/ foreach (preg_split("/[\r\n\t]+/", $_urls) as $_url) { /**/ if ($_url = preg_replace("/%%full_coupon_code%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($full_coupon_code)), $_url)) { if ($_url = preg_replace("/%%coupon_code%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($coupon_code)), $_url)) { if ($_url = preg_replace("/%%affiliate_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($affiliate_id)), $_url)) { if ($_url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($_SERVER["REMOTE_ADDR"])), $_url)) { if ($_url = trim(preg_replace("/%%(.+?)%%/i", "", $_url))) { /**/ if (!($_r = 0) && ($_url = preg_replace("/^silent-php\\|/i", "", $_url, 1, $_r)) && $_r && in_array("affiliates-silent-post", $process)) { c_ws_plugin__optimizemember_utils_urls::remote($_url, false, array("blocking" => false)); } else { if (!($_r = 0) && ($_url = preg_replace("/^img-1px\\|/i", "", $_url, 1, $_r)) && $_r && in_array("affiliates-1px-response", $process)) { if (!empty($response) && $return === "response") { $response .= "\n" . '<img src="' . esc_attr($_url) . '" style="width:0; height:0; border:0;" alt="" />'; } } } } } } } } } } } } } unset($_urls, $_url, $_r); /**/ if (empty($response)) { /* Is ``$response`` NOT set by now? If it's not, we need a default ``$response``. */ $response = _x('<div>Sorry, your Coupon is N/A, invalid or expired.</div>', "s2member-front", "s2member"); } } else { /* Otherwise, we need a default response to display. */ $response = _x('<div>Sorry, your Coupon is N/A, invalid or expired.</div>', "s2member-front", "s2member"); } } /**/ return $return === "response" ? $response : $attr; }
/** * optimizeMember's PayPal IPN handler ( inner processing routine ). * * @package optimizeMember\PayPal * @since 110720 * * @param array $vars Required. An array of defined variables passed by {@link optimizeMember\PayPal\c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()}. * @return array|bool The original ``$paypal`` array passed in ( extracted ) from ``$vars``, or false when conditions do NOT apply. * * @todo Optimize with ``empty()`` and ``isset()``. */ public static function cp($vars = array()) { extract($vars); /* Extract all vars passed in from: ``c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()``. */ /**/ if (!empty($paypal["txn_type"]) && preg_match("/^(subscr_cancel|recurring_payment_profile_cancel)\$/i", $paypal["txn_type"]) && !(preg_match("/^recurring_payment_profile_cancel\$/i", $paypal["txn_type"]) && !empty($paypal["initial_payment_status"]) && preg_match("/^failed\$/i", $paypal["initial_payment_status"])) && ((!empty($paypal["item_number"]) || ($paypal["item_number"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_item_number($paypal))) && preg_match($GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["membership_item_number_w_level_regex"], $paypal["item_number"])) && (!empty($paypal["period1"]) || ($paypal["period1"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period1($paypal)) || ($paypal["period1"] = "0 D")) && (!empty($paypal["period3"]) || ($paypal["period3"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period3($paypal))) && (!empty($paypal["subscr_id"]) || ($paypal["subscr_id"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_subscr_id($paypal))) && (!empty($paypal["item_name"]) || ($paypal["item_name"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_item_name($paypal))) && (!empty($paypal["payer_email"]) || ($paypal["payer_email"] = c_ws_plugin__optimizemember_utils_users::get_user_email_with($paypal["subscr_id"])))) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_before_subscr_cancel", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if (!get_transient($transient_ipn = "s2m_ipn_" . md5("optimizemember_transient_" . $_paypal_s)) && set_transient($transient_ipn, time(), 31556926 * 10)) { $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `subscr_cancel|recurring_payment_profile_cancel` )."; /**/ list($paypal["level"], $paypal["ccaps"]) = preg_split("/\\:/", $paypal["item_number"], 2); /**/ $paypal["ip"] = preg_match("/ip address/i", $paypal["option_name2"]) && $paypal["option_selection2"] ? $paypal["option_selection2"] : ""; $paypal["ip"] = !$paypal["ip"] && preg_match("/^[a-z0-9]+~[0-9\\.]+\$/i", $paypal["invoice"]) ? preg_replace("/^[a-z0-9]+~/i", "", $paypal["invoice"]) : $paypal["ip"]; /**/ if (($user_id = c_ws_plugin__optimizemember_utils_users::get_user_id_with($paypal["subscr_id"])) && is_object($user = new WP_User($user_id)) && $user->ID) { if (!$user->has_cap("administrator")) { $fields = get_user_option("optimizemember_custom_fields", $user_id); /* These will be needed in the routines below. */ $user_reg_ip = get_user_option("optimizemember_registration_ip", $user_id); /* Original IP during Registration. */ $user_reg_ip = $paypal["ip"] = $user_reg_ip ? $user_reg_ip : $paypal["ip"]; /* Now merge conditionally. */ /**/ if (!get_user_option("optimizemember_auto_eot_time", $user_id)) { $processing = $during = true; /* Yes, we ARE processing this. */ /**/ $auto_eot_time = c_ws_plugin__optimizemember_utils_time::auto_eot_time($user_id, $paypal["period1"], $paypal["period3"]); /**/ update_user_option($user_id, "optimizemember_auto_eot_time", $auto_eot_time); /* optimizeMember follows-up later. */ /**/ $paypal["optimizemember_log"][] = "Auto-EOT Time for this account: " . date("D M j, Y g:i a T", $auto_eot_time); /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_cancel", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { $paypal["optimizemember_log"][] = "Ignoring Cancellation. An Auto-EOT Time is already set for this Member. An optimizeMember API Notification will still be processed however."; } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["cancellation_notification_urls"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["cancellation_notification_urls"]) as $url) { /* Handle Cancellation Notifications. */ /**/ if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["subscr_id"])), $url))) { if (($url = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_number"])), $url)) && ($url = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_name"])), $url))) { if (($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->first_name)), $url)) && ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->last_name)), $url))) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($user->first_name . " " . $user->last_name))), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_login)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_reg_ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_id)), $url)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } } /**/ if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__optimizemember_utils_urls::remote($url); } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Cancellation Notification URLs have been processed."; } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["cancellation_notification_recipients"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { $msg = $sbj = "( optimizeMember / API Notification Email ) - Cancellation"; $msg .= "\n\n"; /* Spacing in the message body. */ /**/ $msg .= "subscr_id: %%subscr_id%%\n"; $msg .= "item_number: %%item_number%%\n"; $msg .= "item_name: %%item_name%%\n"; $msg .= "user_first_name: %%user_first_name%%\n"; $msg .= "user_last_name: %%user_last_name%%\n"; $msg .= "user_full_name: %%user_full_name%%\n"; $msg .= "user_email: %%user_email%%\n"; $msg .= "user_login: %%user_login%%\n"; $msg .= "user_ip: %%user_ip%%\n"; $msg .= "user_id: %%user_id%%\n"; /**/ if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { $msg .= $var . ": %%" . $var . "%%\n"; } } /**/ $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; /**/ if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["subscr_id"]), $msg))) { if (($msg = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $msg)) && ($msg = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $msg))) { if (($msg = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->first_name), $msg)) && ($msg = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->last_name), $msg))) { if ($msg = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($user->first_name . " " . $user->last_name)), $msg)) { if ($msg = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_email), $msg)) { if ($msg = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_login), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_reg_ip), $msg)) { if ($msg = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_id), $msg)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($msg = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(maybe_serialize($val)), $msg))) { break; } } } /**/ if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { /* Still have a ``$sbj`` and a ``$msg``? */ /**/ foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["cancellation_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__optimizemember_cancellation_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_cancellation_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=utf-8"); } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Cancellation Notification Emails have been processed."; } } else { $paypal["optimizemember_log"][] = "Ignoring Cancellation. The existing User ID is associated with an Administrator. Stopping here. Otherwise, an Administrator could lose access."; } } else { $paypal["optimizemember_log"][] = "Unable to handle Cancellation. Could not get the existing User ID from the DB."; } } else { $paypal["optimizemember_log"][] = "Not processing. Duplicate IPN."; $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `subscr_cancel|recurring_payment_profile_cancel` )."; $paypal["optimizemember_log"][] = "Duplicate IPN. Already processed. This IPN will be ignored."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_after_subscr_cancel", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_subscr_or_rp_cancellation_w_level", $paypal, get_defined_vars()); } else { return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_subscr_or_rp_cancellation_w_level", false, get_defined_vars()); } }
/** * Handles AliPay IPN URL processing. * * @package optimizeMember\AliPay * @since 1.5 * * @attaches-to ``add_action("init");`` * * @return null Or exits script execution after handling the Notification. */ public static function alipay_notify() { global $current_site, $current_blog; /* For Multisite support. */ /**/ if (!empty($_POST["notify_type"]) && preg_match("/^trade_status_sync\$/i", $_POST["notify_type"]) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_alipay_seller_email"]) { @ignore_user_abort(true); /* Continue processing even if/when connection is broken by the sender. */ /**/ if (is_array($alipay = c_ws_plugin__optimizemember_pro_alipay_utilities::alipay_postvars()) && ($_alipay = $alipay)) { $alipay["optimizemember_log"][] = "IPN received on: " . date("D M j, Y g:i:s a T"); $alipay["optimizemember_log"][] = "optimizeMember POST vars verified through a POST back to AliPay."; /**/ if (!is_array($alipay_already_p = get_transient("s2m_" . md5("optimizemember_pro_alipay_notify_ids"))) || !in_array($alipay["notify_id"], $alipay_already_p)) { $alipay_already_p = is_array($alipay_already_p) ? array_push($alipay_already_p, $alipay["notify_id"]) : array($alipay["notify_id"]); set_transient("s2m_" . md5("optimizemember_pro_alipay_notify_ids"), array_slice(array_unique($alipay_already_p), 0, 1000), 31556926); /**/ if (preg_match("/^(TRADE_FINISHED|TRADE_SUCCESS)\$/i", $alipay["trade_status"]) && !$alipay["refund_status"]) { $alipay["optimizemember_log"][] = "AliPay transaction identified as ( `TRADE_FINISHED|TRADE_SUCCESS` )."; $alipay["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as `txn_type` ( `web_accept` )."; $alipay["optimizemember_log"][] = "Please check PayPal IPN logs for further processing details."; /**/ list($alipay["invoice"], $alipay["item_number"], $alipay["referencing"], $alipay["customer_ip"]) = preg_split("/~/", $alipay["out_trade_no"]); list($alipay["first_name"], $alipay["last_name"]) = preg_split("/@/", $alipay["buyer_email"], 2); /**/ $ipn = array(); /* Reset. */ /**/ $ipn["txn_type"] = "web_accept"; /**/ $ipn["txn_id"] = $alipay["trade_no"]; /**/ $ipn["custom"] = $alipay["extra_common_param"]; /**/ $ipn["mc_gross"] = number_format($alipay["total_fee"], 2, ".", ""); $ipn["mc_currency"] = strtoupper("CNY"); /* Yuan. */ $ipn["tax"] = number_format("0.00", 2, ".", ""); /**/ $ipn["payer_email"] = $alipay["buyer_email"]; $ipn["first_name"] = $alipay["first_name"]; $ipn["last_name"] = $alipay["last_name"]; /**/ $ipn["option_name1"] = $alipay["referencing"] ? "Referencing Customer ID" : "Originating Domain"; $ipn["option_selection1"] = $alipay["referencing"] ? $alipay["referencing"] : $_SERVER["HTTP_HOST"]; /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $alipay["customer_ip"]; /**/ $ipn["item_number"] = $alipay["item_number"]; $ipn["item_name"] = $alipay["body"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=alipay&optimizemember_paypal_proxy_use=standard-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } else { if (preg_match("/^(TRADE_CLOSED|TRADE_SUCCESS)\$/i", $alipay["trade_status"]) && $alipay["refund_status"]) { $alipay["optimizemember_log"][] = "AliPay transaction identified as ( `REFUND_SUCCESS` )."; $alipay["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as `payment_status` ( `refunded` )."; $alipay["optimizemember_log"][] = "Please check PayPal IPN logs for further processing details."; /**/ list($alipay["invoice"], $alipay["item_number"], $alipay["referencing"], $alipay["customer_ip"]) = preg_split("/~/", $alipay["out_trade_no"]); list($alipay["first_name"], $alipay["last_name"]) = preg_split("/@/", $alipay["buyer_email"], 2); /**/ $ipn = array(); /* Reset. */ /**/ $ipn["payment_status"] = "refunded"; /**/ $ipn["parent_txn_id"] = $alipay["trade_no"]; /**/ $ipn["custom"] = $alipay["extra_common_param"]; /**/ $ipn["mc_fee"] = "-" . number_format("0.00", 2, ".", ""); $ipn["mc_gross"] = "-" . number_format(abs($alipay["total_fee"]), 2, ".", ""); $ipn["mc_currency"] = strtoupper("CNY"); /* Yuan. */ $ipn["tax"] = "-" . number_format("0.00", 2, ".", ""); /**/ $ipn["payer_email"] = $alipay["buyer_email"]; $ipn["first_name"] = $alipay["first_name"]; $ipn["last_name"] = $alipay["last_name"]; /**/ $ipn["option_name1"] = $alipay["referencing"] ? "Referencing Customer ID" : "Originating Domain"; $ipn["option_selection1"] = $alipay["referencing"] ? $alipay["referencing"] : $_SERVER["HTTP_HOST"]; /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $alipay["customer_ip"]; /**/ $ipn["item_number"] = $alipay["item_number"]; $ipn["item_name"] = $alipay["body"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=alipay&optimizemember_paypal_proxy_use=standard-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } else { $alipay["optimizemember_log"][] = "Ignoring this IPN request. The status does NOT require any action on the part of optimizeMember."; } } } else { $alipay["optimizemember_log"][] = "Ignoring duplicate IPN. optimizeMember has already processed AliPay Notification ID: " . $alipay["notify_id"] . "."; } } else { $alipay["optimizemember_log"][] = "Unable to verify POST vars. This is most likely related to an invalid AliPay configuration. Please check: optimizeMember -> AliPay Options."; $alipay["optimizemember_log"][] = "If you're absolutely SURE that your AliPay configuration is valid, you may want to run some tests on your server, just to be sure \$_POST variables are populated, and that your server is able to connect to AliPay over an HTTPS connection."; $alipay["optimizemember_log"][] = "optimizeMember uses the WP_Http class for remote connections; which will try to use cURL first, and then fall back on the FOPEN method when cURL is not available. On a Windows server, you may have to disable your cURL extension. Instead, set allow_url_fopen = yes in your php.ini file. The cURL extension (usually) does NOT support SSL connections on a Windows server."; $alipay["optimizemember_log"][] = var_export($_REQUEST, true); /* Recording _POST + _GET vars for analysis and debugging. */ } /* If debugging/logging is enabled; we need to append $alipay to the log file. Logging now supports Multisite Networking as well. */ $logv = c_ws_plugin__optimizemember_utilities::ver_details(); $logm = c_ws_plugin__optimizemember_utilities::mem_details(); $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; $log4 = is_multisite() && !is_main_site() ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; $log2 = is_multisite() && !is_main_site() ? "alipay-ipn-4-" . trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "alipay-ipn.log"; /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["gateway_debug_logs"]) { if (is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["logs_dir"])) { if (is_writable($logs_dir) && c_ws_plugin__optimizemember_utils_logs::archive_oversize_log_files()) { file_put_contents($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export($alipay, true) . "\n\n", FILE_APPEND); } } } /**/ status_header(200); /* 200 OK status header. */ header("Content-Type: text/plain; charset=utf-8"); /* Content-Type text/plain with UTF-8. */ eval('while (@ob_end_clean ());'); /* End/clean all output buffers that may or may not exist. */ /**/ exit("success"); /* Exit now with "success". */ } }
/** * optimizeMember's PayPal IPN handler ( inner processing routine ). * * @package optimizeMember\PayPal * @since 110720 * * @param array $vars Required. An array of defined variables passed by {@link optimizeMember\PayPal\c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()}. * @return array|bool The original ``$paypal`` array passed in ( extracted ) from ``$vars``, or false when conditions do NOT apply. * * @todo Optimize with ``empty()`` and ``isset()``. */ public static function cp($vars = array()) { extract($vars); /* Extract all vars passed in from: ``c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()``. */ /**/ if (!empty($paypal["txn_type"]) && preg_match("/^subscr_modify\$/i", $paypal["txn_type"]) && (!empty($paypal["item_number"]) && preg_match($GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["membership_item_number_w_level_regex"], $paypal["item_number"])) && !empty($paypal["subscr_id"]) && !empty($paypal["payer_email"])) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_before_subscr_modify", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if (!get_transient($transient_ipn = "s2m_ipn_" . md5("optimizemember_transient_" . $_paypal_s)) && set_transient($transient_ipn, time(), 31556926 * 10)) { $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `subscr_modify` )."; /**/ list($paypal["level"], $paypal["ccaps"]) = preg_split("/\\:/", $paypal["item_number"], 2); /**/ $paypal["ip"] = preg_match("/ip address/i", $paypal["option_name2"]) && $paypal["option_selection2"] ? $paypal["option_selection2"] : ""; $paypal["ip"] = !$paypal["ip"] && preg_match("/^[a-z0-9]+~[0-9\\.]+\$/i", $paypal["invoice"]) ? preg_replace("/^[a-z0-9]+~/i", "", $paypal["invoice"]) : $paypal["ip"]; /**/ $paypal["period1"] = preg_match("/^[1-9]/", $paypal["period1"]) ? $paypal["period1"] : "0 D"; /* Defaults to "0 D" ( zero days ). */ $paypal["mc_amount1"] = strlen($paypal["mc_amount1"]) && $paypal["mc_amount1"] > 0 ? $paypal["mc_amount1"] : "0.00"; /* "0.00". */ /**/ $paypal["initial_term"] = preg_match("/^[1-9]/", $paypal["period1"]) ? $paypal["period1"] : "0 D"; /* Defaults to "0 D" ( zero days ). */ $paypal["initial"] = strlen($paypal["mc_amount1"]) && preg_match("/^[1-9]/", $paypal["period1"]) ? $paypal["mc_amount1"] : $paypal["mc_amount3"]; $paypal["regular"] = $paypal["mc_amount3"]; /* This is the Regular Payment Amount that is charged to the Customer. Always required by PayPal. */ $paypal["regular_term"] = $paypal["period3"]; /* This is just set to keep a standard; this way both initial_term & regular_term are available. */ $paypal["recurring"] = $paypal["recurring"] ? $paypal["mc_amount3"] : "0"; /* If non-recurring, this should be zero, otherwise Regular. */ /**/ eval('$ipn_signup_vars = $paypal; unset($ipn_signup_vars["optimizemember_log"]);'); /* Create array of IPN signup vars w/o optimizemember_log. */ /**/ if (($user_id = c_ws_plugin__optimizemember_utils_users::get_user_id_with($paypal["subscr_id"])) && is_object($user = new WP_User($user_id)) && $user->ID) { if (!$user->has_cap("administrator")) { $processing = $modifying = $during = true; /* Yes, we ARE processing this. */ /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_before_subscr_modify", get_defined_vars()); do_action("ws_plugin__optimizemember_during_collective_mods", $user_id, get_defined_vars(), "ipn-upgrade-downgrade", "modification", "optimizemember_level" . $paypal["level"]); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ $fields = get_user_option("optimizemember_custom_fields", $user_id); /* These will be needed in the routines below. */ $user_reg_ip = get_user_option("optimizemember_registration_ip", $user_id); /* Original IP during Registration. */ $user_reg_ip = $paypal["ip"] = $user_reg_ip ? $user_reg_ip : $paypal["ip"]; /* Now merge conditionally. */ /**/ if (is_multisite() && !is_user_member_of_blog($user_id)) { add_existing_user_to_blog(array("user_id" => $user_id, "role" => "optimizemember_level" . $paypal["level"])); $user = new WP_User($user_id); } /**/ $current_role = c_ws_plugin__optimizemember_user_access::user_access_role($user); /**/ if ($current_role !== "optimizemember_level" . $paypal["level"]) { /* Only if we need to. */ $user->set_role("optimizemember_level" . $paypal["level"]); } /* (upgrade/downgrade) */ /**/ if ($paypal["ccaps"] && preg_match("/^-all/", str_replace("+", "", $paypal["ccaps"]))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_optimizemember_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } } /**/ if ($paypal["ccaps"] && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $paypal["ccaps"]))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $paypal["ccaps"]))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_optimizemember_ccap_" . $ccap); } } } /**/ update_user_option($user_id, "optimizemember_subscr_gateway", $paypal["subscr_gateway"]); update_user_option($user_id, "optimizemember_subscr_id", $paypal["subscr_id"]); update_user_option($user_id, "optimizemember_custom", $paypal["custom"]); /**/ if (!get_user_option("optimizemember_registration_ip", $user_id)) { update_user_option($user_id, "optimizemember_registration_ip", $paypal["ip"]); } /**/ update_user_option($user_id, "optimizemember_ipn_signup_vars", $ipn_signup_vars); /**/ delete_user_option($user_id, "optimizemember_file_download_access_log"); /**/ delete_user_option($user_id, "optimizemember_auto_eot_time"); /**/ $pr_times = get_user_option("optimizemember_paid_registration_times", $user_id); $pr_times["level"] = !$pr_times["level"] ? time() : $pr_times["level"]; /* Preserves existing. */ $pr_times["level" . $paypal["level"]] = !$pr_times["level" . $paypal["level"]] ? time() : $pr_times["level" . $paypal["level"]]; update_user_option($user_id, "optimizemember_paid_registration_times", $pr_times); /* Update now. */ /**/ c_ws_plugin__optimizemember_user_notes::clear_user_note_lines($user_id, "/^Demoted by optimizeMember\\:/"); /**/ $paypal["optimizemember_log"][] = "optimizeMember Level/Capabilities updated on Subscription modification."; /**/ c_ws_plugin__optimizemember_email_configs::email_config() . wp_mail($paypal["payer_email"], apply_filters("ws_plugin__optimizemember_modification_email_sbj", _x("Thank you! Your account has been updated.", "s2member-front", "s2member"), get_defined_vars()), apply_filters("ws_plugin__optimizemember_modification_email_msg", _x("Thank you! You've been updated to:", "s2member-front", "s2member") . "\n" . $paypal["item_name"] . "\n\n" . _x("Please log back in now.", "s2member-front", "s2member") . "\n" . wp_login_url(), get_defined_vars()), "From: \"" . preg_replace('/"/', "'", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["reg_email_from_name"]) . "\" <" . $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["reg_email_from_email"] . ">\r\nContent-Type: text/plain; charset=utf-8") . c_ws_plugin__optimizemember_email_configs::email_config_release(); /**/ $paypal["optimizemember_log"][] = "Modification Confirmation Email sent to Customer, with a URL that provides them with a way to log back in."; /**/ if ($processing && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["modification_notification_urls"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["modification_notification_urls"]) as $url) { /**/ if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["subscr_id"])), $url))) { if (($url = preg_replace("/%%initial%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["initial"])), $url)) && ($url = preg_replace("/%%regular%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["regular"])), $url)) && ($url = preg_replace("/%%recurring%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["recurring"])), $url))) { if (($url = preg_replace("/%%initial_term%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["initial_term"])), $url)) && ($url = preg_replace("/%%regular_term%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["regular_term"])), $url))) { if (($url = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_number"])), $url)) && ($url = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_name"])), $url))) { if (($url = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["first_name"])), $url)) && ($url = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["last_name"])), $url))) { if ($url = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($paypal["first_name"] . " " . $paypal["last_name"]))), $url)) { if ($url = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["payer_email"])), $url)) { /**/ if (($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->first_name)), $url)) && ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->last_name)), $url))) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($user->first_name . " " . $user->last_name))), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_login)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_reg_ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_id)), $url)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } } /**/ if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__optimizemember_utils_urls::remote($url); } } } } } } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Modification Notification URLs have been processed."; } /**/ if ($processing && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["modification_notification_recipients"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { $msg = $sbj = "( optimizeMember / API Notification Email ) - Modification"; $msg .= "\n\n"; /* Spacing in the message body. */ /**/ $msg .= "subscr_id: %%subscr_id%%\n"; $msg .= "initial: %%initial%%\n"; $msg .= "regular: %%regular%%\n"; $msg .= "recurring: %%recurring%%\n"; $msg .= "initial_term: %%initial_term%%\n"; $msg .= "regular_term: %%regular_term%%\n"; $msg .= "item_number: %%item_number%%\n"; $msg .= "item_name: %%item_name%%\n"; $msg .= "first_name: %%first_name%%\n"; $msg .= "last_name: %%last_name%%\n"; $msg .= "full_name: %%full_name%%\n"; $msg .= "payer_email: %%payer_email%%\n"; /**/ $msg .= "user_first_name: %%user_first_name%%\n"; $msg .= "user_last_name: %%user_last_name%%\n"; $msg .= "user_full_name: %%user_full_name%%\n"; $msg .= "user_email: %%user_email%%\n"; $msg .= "user_login: %%user_login%%\n"; $msg .= "user_ip: %%user_ip%%\n"; $msg .= "user_id: %%user_id%%\n"; /**/ if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { $msg .= $var . ": %%" . $var . "%%\n"; } } /**/ $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; /**/ if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["subscr_id"]), $msg))) { if (($msg = preg_replace("/%%initial%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["initial"]), $msg)) && ($msg = preg_replace("/%%regular%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["regular"]), $msg)) && ($msg = preg_replace("/%%recurring%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["recurring"]), $msg))) { if (($msg = preg_replace("/%%initial_term%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["initial_term"]), $msg)) && ($msg = preg_replace("/%%regular_term%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["regular_term"]), $msg))) { if (($msg = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $msg)) && ($msg = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $msg))) { if (($msg = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $msg)) && ($msg = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $msg))) { if ($msg = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $msg)) { if ($msg = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $msg)) { /**/ if (($msg = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->first_name), $msg)) && ($msg = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->last_name), $msg))) { if ($msg = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($user->first_name . " " . $user->last_name)), $msg)) { if ($msg = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_email), $msg)) { if ($msg = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_login), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_reg_ip), $msg)) { if ($msg = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_id), $msg)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($msg = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(maybe_serialize($val)), $msg))) { break; } } } /**/ if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { /* Still have a ``$sbj`` and a ``$msg``? */ /**/ foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["modification_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__optimizemember_modification_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_modification_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=utf-8"); } } } } } } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Modification Notification Emails have been processed."; } /**/ if ($processing && ($code = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["modification_tracking_codes"]) && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { if (($code = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $code)) && ($code = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["subscr_id"]), $code))) { if (($code = preg_replace("/%%initial%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["initial"]), $code)) && ($code = preg_replace("/%%regular%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["regular"]), $code)) && ($code = preg_replace("/%%recurring%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["recurring"]), $code))) { if (($code = preg_replace("/%%initial_term%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["initial_term"]), $code)) && ($code = preg_replace("/%%regular_term%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["regular_term"]), $code))) { if (($code = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $code)) && ($code = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $code))) { if (($code = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $code)) && ($code = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $code))) { if ($code = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $code)) { if ($code = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $code)) { if (($code = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->first_name), $code)) && ($code = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->last_name), $code))) { if ($code = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($user->first_name . " " . $user->last_name)), $code)) { if ($code = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_email), $code)) { if ($code = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_login), $code)) { if ($code = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_reg_ip), $code)) { if ($code = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_id), $code)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($code = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(maybe_serialize($val)), $code))) { break; } } } /**/ if ($code = trim(preg_replace("/%%(.+?)%%/i", "", $code))) { $paypal["optimizemember_log"][] = "Storing Modification Tracking Codes into a Transient Queue. These will be processed on-site."; set_transient("s2m_" . md5("optimizemember_transient_modification_tracking_codes_" . $paypal["subscr_id"]), $code, 43200); } } } } } } } } } } } } } } } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_modify", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { $paypal["optimizemember_log"][] = "Unable to modify Subscription. The existing User ID is associated with an Administrator. Stopping here. Otherwise, an Administrator could lose access."; } } else { $paypal["optimizemember_log"][] = "Unable to modify Subscription. Could not get the existing User ID from the DB."; } } else { $paypal["optimizemember_log"][] = "Not processing. Duplicate IPN."; $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `subscr_modify` )."; $paypal["optimizemember_log"][] = "Duplicate IPN. Already processed. This IPN will be ignored."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_after_subscr_modify", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_subscr_modify_w_level", $paypal, get_defined_vars()); } else { return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_subscr_modify_w_level", false, get_defined_vars()); } }
/** * optimizeMember's PayPal IPN handler ( inner processing routine ). * * @package optimizeMember\PayPal * @since 110720 * * @param array $vars Required. An array of defined variables passed by {@link optimizeMember\PayPal\c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()}. * @return array|bool The original ``$paypal`` array passed in ( extracted ) from ``$vars``, or false when conditions do NOT apply. * * @todo Optimize with ``empty()`` and ``isset()``. */ public static function cp($vars = array()) { extract($vars); /* Extract all vars passed in from: ``c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()``. */ /**/ if (!empty($paypal["txn_type"]) && preg_match("/^web_accept\$/i", $paypal["txn_type"]) && (!empty($paypal["item_number"]) && preg_match($GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["sp_access_item_number_regex"], $paypal["item_number"])) && (empty($paypal["payment_status"]) || empty($payment_status_issues) || !preg_match($payment_status_issues, $paypal["payment_status"])) && !empty($paypal["payer_email"]) && !empty($paypal["txn_id"])) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_before_sp_access", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if (!get_transient($transient_ipn = "s2m_ipn_" . md5("optimizemember_transient_" . $_paypal_s)) && set_transient($transient_ipn, time(), 31556926 * 10)) { $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `web_accept` ) for Specific Post/Page Access."; /**/ list(, $paypal["sp_ids"], $paypal["hours"]) = preg_split("/\\:/", $paypal["item_number"], 3); /**/ $paypal["ip"] = preg_match("/ip address/i", $paypal["option_name2"]) && $paypal["option_selection2"] ? $paypal["option_selection2"] : ""; $paypal["ip"] = !$paypal["ip"] && preg_match("/^[a-z0-9]+~[0-9\\.]+\$/i", $paypal["invoice"]) ? preg_replace("/^[a-z0-9]+~/i", "", $paypal["invoice"]) : $paypal["ip"]; /**/ if (($sp_access_url = c_ws_plugin__optimizemember_sp_access::sp_access_link_gen($paypal["sp_ids"], $paypal["hours"])) && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { $processing = $during = true; /* Yes, we ARE processing this. */ /**/ if (preg_match("/(referenc|associat)/i", $paypal["option_name1"]) && $paypal["option_selection1"]) { /* Associating this purchase with a Member? */ if (($user_id = c_ws_plugin__optimizemember_utils_users::get_user_id_with($paypal["option_selection1"], $paypal["option_selection1"])) && is_object($user = new WP_User($user_id)) && $user->ID) { $sp_references = (array) get_user_option("optimizemember_sp_references", $user_id); $_sp_reference = array("time" => time(), "ids" => $paypal["sp_ids"], "hours" => $paypal["hours"], "url" => $sp_access_url); $sp_references = c_ws_plugin__optimizemember_utils_arrays::array_unique(array_merge($sp_references, $_sp_reference)); update_user_option($user_id, "optimizemember_sp_references", $sp_references); /**/ $paypal["optimizemember_log"][] = "Specific Post/Page ~ Sale associated with User ID: " . $user_id . "."; } } /**/ $sbj = preg_replace("/%%sp_access_url%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($sp_access_url), $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"][($_GET["optimizemember_paypal_proxy"] && preg_match("/pro-emails/", $_GET["optimizemember_paypal_proxy_use"]) ? "pro_" : "") . "sp_email_subject"]); $sbj = preg_replace("/%%sp_access_exp%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(c_ws_plugin__optimizemember_utils_time::approx_time_difference(time(), strtotime("+" . $paypal["hours"] . " hours"))), $sbj); /**/ $msg = preg_replace("/%%sp_access_url%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($sp_access_url), $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"][($_GET["optimizemember_paypal_proxy"] && preg_match("/pro-emails/", $_GET["optimizemember_paypal_proxy_use"]) ? "pro_" : "") . "sp_email_message"]); $msg = preg_replace("/%%sp_access_exp%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(c_ws_plugin__optimizemember_utils_time::approx_time_difference(time(), strtotime("+" . $paypal["hours"] . " hours"))), $msg); /**/ $rec = preg_replace("/%%sp_access_url%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($sp_access_url), $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"][($_GET["optimizemember_paypal_proxy"] && preg_match("/pro-emails/", $_GET["optimizemember_paypal_proxy_use"]) ? "pro_" : "") . "sp_email_recipients"]); $rec = preg_replace("/%%sp_access_exp%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(c_ws_plugin__optimizemember_utils_time::approx_time_difference(time(), strtotime("+" . $paypal["hours"] . " hours"))), $rec); /**/ if (($rec = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $rec)) && ($rec = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["txn_id"]), $rec))) { if ($rec = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_gross"]), $rec)) { /* Full amount of the payment, before fee is subtracted. */ if (($rec = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $rec)) && ($rec = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $rec))) { if (($rec = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_dq(c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"])), $rec)) && ($rec = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_dq(c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"])), $rec))) { if ($rec = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_dq(c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"]))), $rec)) { /* **NOTE** c_ws_plugin__optimizemember_utils_strings::esc_dq() is applied here. ( ex. "N\"ame" <email> ). */ if ($rec = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $rec)) { if ($rec = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["ip"]), $rec)) { /**/ if (($sbj = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $sbj)) && ($sbj = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["txn_id"]), $sbj))) { if ($sbj = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_gross"]), $sbj)) { /* Full amount of the payment, before fee is subtracted. */ if (($sbj = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $sbj)) && ($sbj = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $sbj))) { if (($sbj = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $sbj)) && ($sbj = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $sbj))) { if ($sbj = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $sbj)) { if ($sbj = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $sbj)) { if ($sbj = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["ip"]), $sbj)) { /**/ if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["txn_id"]), $msg))) { if ($msg = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_gross"]), $msg)) { /* Full amount of the payment, before fee is subtracted. */ if (($msg = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $msg)) && ($msg = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $msg))) { if (($msg = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $msg)) && ($msg = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $msg))) { if ($msg = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $msg)) { if ($msg = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["ip"]), $msg)) { /**/ if (($rec = trim(preg_replace("/%%(.+?)%%/i", "", $rec))) && ($sbj = trim(preg_replace("/%%(.+?)%%/i", "", $sbj))) && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($rec) as $recipient) { /* Go through a possible list of recipients. */ c_ws_plugin__optimizemember_email_configs::email_config() . wp_mail($recipient, apply_filters("ws_plugin__optimizemember_sp_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_sp_email_msg", $msg, get_defined_vars()), "From: \"" . preg_replace('/"/', "'", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["reg_email_from_name"]) . "\" <" . $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["reg_email_from_email"] . ">\r\nContent-Type: text/plain; charset=utf-8") . c_ws_plugin__optimizemember_email_configs::email_config_release(); } /**/ $paypal["optimizemember_log"][] = "Specific Post/Page Confirmation Email sent to: " . $rec . "."; } } } } } } } } } } } } } } } } } } } } } } /**/ if ($processing && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["sp_sale_notification_urls"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["sp_sale_notification_urls"]) as $url) { /**/ if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%sp_access_url%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(rawurlencode($sp_access_url)), $url))) { if ($url = preg_replace("/%%sp_access_exp%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(c_ws_plugin__optimizemember_utils_time::approx_time_difference(time(), strtotime("+" . $paypal["hours"] . " hours")))), $url)) { if (($url = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["mc_gross"])), $url)) && ($url = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["txn_id"])), $url))) { if (($url = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_number"])), $url)) && ($url = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_name"])), $url))) { if (($url = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["first_name"])), $url)) && ($url = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["last_name"])), $url))) { if ($url = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($paypal["first_name"] . " " . $paypal["last_name"]))), $url)) { if ($url = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["payer_email"])), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["ip"])), $url)) { /**/ if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__optimizemember_utils_urls::remote($url); } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Specific Post/Page ~ Sale Notification URLs have been processed."; } /**/ if ($processing && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["sp_sale_notification_recipients"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { $msg = $sbj = "( optimizeMember / API Notification Email ) - Specific Post/Page ~ Sale"; $msg .= "\n\n"; /* Spacing in the message body. */ /**/ $msg .= "sp_access_url: %%sp_access_url%%\n"; $msg .= "sp_access_exp: %%sp_access_exp%%\n"; $msg .= "amount: %%amount%%\n"; $msg .= "txn_id: %%txn_id%%\n"; $msg .= "item_number: %%item_number%%\n"; $msg .= "item_name: %%item_name%%\n"; $msg .= "first_name: %%first_name%%\n"; $msg .= "last_name: %%last_name%%\n"; $msg .= "full_name: %%full_name%%\n"; $msg .= "payer_email: %%payer_email%%\n"; $msg .= "user_ip: %%user_ip%%\n"; /**/ $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; /**/ if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%sp_access_url%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($sp_access_url), $msg))) { if ($msg = preg_replace("/%%sp_access_exp%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(c_ws_plugin__optimizemember_utils_time::approx_time_difference(time(), strtotime("+" . $paypal["hours"] . " hours"))), $msg)) { if (($msg = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_gross"]), $msg)) && ($msg = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["txn_id"]), $msg))) { if (($msg = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $msg)) && ($msg = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $msg))) { if (($msg = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $msg)) && ($msg = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $msg))) { if ($msg = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $msg)) { if ($msg = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["ip"]), $msg)) { /**/ if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { /* Still have a ``$sbj`` and a ``$msg``? */ /**/ foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["sp_sale_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__optimizemember_sp_sale_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_sp_sale_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=utf-8"); } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Specific Post/Page ~ Sale Notification Emails have been processed."; } /**/ if ($processing && $_GET["optimizemember_paypal_proxy"] && ($url = $_GET["optimizemember_paypal_proxy_return_url"]) && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%sp_access_url%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(rawurlencode($sp_access_url)), $url))) { if ($url = preg_replace("/%%sp_access_exp%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(c_ws_plugin__optimizemember_utils_time::approx_time_difference(time(), strtotime("+" . $paypal["hours"] . " hours")))), $url)) { if (($url = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["mc_gross"])), $url)) && ($url = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["txn_id"])), $url))) { if (($url = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_number"])), $url)) && ($url = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_name"])), $url))) { if (($url = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["first_name"])), $url)) && ($url = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["last_name"])), $url))) { if ($url = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($paypal["first_name"] . " " . $paypal["last_name"]))), $url)) { if ($url = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["payer_email"])), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["ip"])), $url)) { /**/ if ($url = trim($url)) { /* Preserve Remaining replacements. */ /* Because the parent routine may perform replacements too. */ $paypal["optimizemember_paypal_proxy_return_url"] = $url; } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Specific Post/Page Return, a Proxy Return URL is ready."; } /**/ if ($processing && ($code = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["sp_tracking_codes"]) && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { if (($code = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $code)) && ($code = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_gross"]), $code)) && ($code = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["txn_id"]), $code))) { if (($code = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $code)) && ($code = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $code))) { if (($code = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $code)) && ($code = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $code))) { if ($code = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $code)) { if ($code = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $code)) { if ($code = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["ip"]), $code)) { /**/ if ($code = trim(preg_replace("/%%(.+?)%%/i", "", $code))) { $paypal["optimizemember_log"][] = "Storing Specific Post/Page Tracking Codes into a Transient Queue. These will be processed on-site."; set_transient("s2m_" . md5("optimizemember_transient_sp_tracking_codes_" . $paypal["txn_id"]), $code, 43200); } } } } } } } } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_sp_access", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { $paypal["optimizemember_log"][] = "Unable to generate Access Link for Specific Post/Page Access. Does your Leading Post/Page still exist?"; } } else { $paypal["optimizemember_log"][] = "Not processing. Duplicate IPN."; $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `web_accept` ) for Specific Post/Page Access."; $paypal["optimizemember_log"][] = "Duplicate IPN. Already processed. This IPN will be ignored."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_after_sp_access", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_web_accept_sp", $paypal, get_defined_vars()); } else { return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_web_accept_sp", false, get_defined_vars()); } }
/** * Get ``$_POST`` or ``$_REQUEST`` vars from Google. * * @package optimizeMember\Google * @since 1.5 * * @return array|bool An array of verified ``$_POST`` or ``$_REQUEST`` variables, else false. * * @todo Continue optimizing this routine with ``empty()`` and ``isset()``. * @todo Candidate for the use of ``ifsetor()``? */ public static function google_postvars() { if (!empty($_REQUEST["optimizemember_pro_google_notify"]) && !empty($_REQUEST["serial-number"])) { $postback["_type"] = "notification-history-request"; $postback["serial-number"] = trim(stripslashes((string) $_REQUEST["serial-number"])); /**/ $endpoint = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_sandbox"] ? "sandbox.google.com/checkout" : "checkout.google.com"; /**/ if (($response = c_ws_plugin__optimizemember_utils_urls::remote("https://" . $endpoint . "/api/checkout/v2/reportsForm/Merchant/" . $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_google_merchant_id"], $postback, array_merge(c_ws_plugin__optimizemember_pro_google_utilities::google_api_headers(), array("timeout" => 20)))) && wp_parse_str($response, $postvars) !== "nill" && !empty($postvars["_type"])) { return c_ws_plugin__optimizemember_utils_strings::trim_deep($postvars); } else { /* Nope. Return false. */ return false; } } else { /* Nope. */ return false; } }
/** * Handles processing of Pro Form checkouts. * * @package optimizeMember\Stripe * @since 140617 * * @attaches-to ``add_action('init');`` */ public static function stripe_checkout() { if (!empty($_POST['optimizemember_pro_stripe_checkout']['nonce']) && ($nonce = $_POST['optimizemember_pro_stripe_checkout']['nonce']) && wp_verify_nonce($nonce, 'optimizemember-pro-stripe-checkout')) { $GLOBALS['ws_plugin__optimizemember_pro_stripe_checkout_response'] = array(); // This holds the global response details. $global_response =& $GLOBALS['ws_plugin__optimizemember_pro_stripe_checkout_response']; $post_vars = c_ws_plugin__optimizemember_utils_strings::trim_deep(stripslashes_deep($_POST['optimizemember_pro_stripe_checkout'])); $post_vars['attr'] = !empty($post_vars['attr']) ? (array) unserialize(c_ws_plugin__optimizemember_utils_encryption::decrypt($post_vars['attr'])) : array(); $post_vars['attr'] = apply_filters('ws_plugin__optimizemember_pro_stripe_checkout_post_attr', $post_vars['attr'], get_defined_vars()); $post_vars['name'] = trim($post_vars['first_name'] . ' ' . $post_vars['last_name']); $post_vars['email'] = apply_filters('user_registration_email', sanitize_email(@$post_vars['email']), get_defined_vars()); $post_vars['username'] = is_multisite() ? strtolower(@$post_vars['username']) : @$post_vars['username']; // Force lowercase. $post_vars['username'] = preg_replace('/\\s+/', '', sanitize_user($post_vars['_o_username'] = $post_vars['username'], is_multisite())); $post_vars['recaptcha_challenge_field'] = isset($_POST['recaptcha_challenge_field']) ? trim(stripslashes($_POST['recaptcha_challenge_field'])) : ''; $post_vars['recaptcha_response_field'] = isset($_POST['recaptcha_response_field']) ? trim(stripslashes($_POST['recaptcha_response_field'])) : ''; if (!c_ws_plugin__optimizemember_pro_stripe_responses::stripe_form_attr_validation_errors($post_vars['attr'])) { if (!($form_submission_validation_errors = c_ws_plugin__optimizemember_pro_stripe_responses::stripe_form_submission_validation_errors('checkout', $post_vars))) { unset($_POST['optimizemember_pro_stripe_checkout']['card_token']); // These are good one-time only. unset($_POST['optimizemember_pro_stripe_checkout']['card_token_summary']); $cp_attr = c_ws_plugin__optimizemember_pro_stripe_utilities::apply_coupon($post_vars['attr'], $post_vars['coupon'], 'attr', array('affiliates-silent-post')); $cost_calculations = c_ws_plugin__optimizemember_pro_stripe_utilities::cost($cp_attr['ta'], $cp_attr['ra'], $post_vars['state'], $post_vars['country'], $post_vars['zip'], $cp_attr['cc'], $cp_attr['desc']); if ($cost_calculations['total'] <= 0 && $post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0) { $post_vars['attr']['tp'] = '0'; // Ditch the trial period completely. $cost_calculations['sub_total'] = $cost_calculations['trial_sub_total']; // Use as regular sub-total (ditch trial sub-total). $cost_calculations['tax'] = $cost_calculations['trial_tax']; // Use as regular tax (ditch trial tax). $cost_calculations['tax_per'] = $cost_calculations['trial_tax_per']; // Use as regular tax (ditch trial tax). $cost_calculations['total'] = $cost_calculations['trial_total']; // Use as regular total (ditch trial). $cost_calculations['trial_sub_total'] = '0.00'; // Ditch the initial total (using as grand total). $cost_calculations['trial_tax'] = '0.00'; // Ditch this calculation now also. $cost_calculations['trial_tax_per'] = ''; // Ditch this calculation now also. $cost_calculations['trial_total'] = '0.00'; // Ditch this calculation now also. } $use_subscription = $post_vars['attr']['rr'] === 'BN' || !$post_vars['attr']['tp'] && !$post_vars['attr']['rr'] ? FALSE : TRUE; $is_independent_ccaps_sale = $post_vars['attr']['level'] === '*' ? TRUE : FALSE; // Selling Independent Custom Capabilities? if ($use_subscription && $cost_calculations['trial_total'] <= 0 && $cost_calculations['total'] <= 0) { if (!$post_vars['attr']['rr'] && $post_vars['attr']['rt'] !== 'L') { if (substr_count($post_vars['attr']['level_ccaps_eotper'], ':') === 1) { $post_vars['attr']['level_ccaps_eotper'] .= ':' . $post_vars['attr']['rp'] . ' ' . $post_vars['attr']['rt']; } else { if (substr_count($post_vars['attr']['level_ccaps_eotper'], ':') === 0) { $post_vars['attr']['level_ccaps_eotper'] .= '::' . $post_vars['attr']['rp'] . ' ' . $post_vars['attr']['rt']; } } } else { if ($post_vars['attr']['rr'] && $post_vars['attr']['rrt'] && $post_vars['attr']['rt'] !== 'L') { if (substr_count($post_vars['attr']['level_ccaps_eotper'], ':') === 1) { $post_vars['attr']['level_ccaps_eotper'] .= ':' . $post_vars['attr']['rp'] * $post_vars['attr']['rrt'] . ' ' . $post_vars['attr']['rt']; } else { if (substr_count($post_vars['attr']['level_ccaps_eotper'], ':') === 0) { $post_vars['attr']['level_ccaps_eotper'] .= '::' . $post_vars['attr']['rp'] * $post_vars['attr']['rrt'] . ' ' . $post_vars['attr']['rt']; } } } } } if ($use_subscription && is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID)) { $plan_attr = $cp_attr; // For the subscription plan. $plan_attr['ta'] = $cost_calculations['trial_total']; $plan_attr['ra'] = $cost_calculations['total']; $plan_attr['desc'] = $cost_calculations['desc']; update_user_meta($user_id, 'first_name', $post_vars['first_name']); update_user_meta($user_id, 'last_name', $post_vars['last_name']); $period1 = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period1($post_vars['attr']['tp'] . ' ' . $post_vars['attr']['tt']); $period3 = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period3($post_vars['attr']['rp'] . ' ' . $post_vars['attr']['rt']); $start_time = $post_vars['attr']['tp'] ? c_ws_plugin__optimizemember_pro_stripe_utilities::start_time($period1) : c_ws_plugin__optimizemember_pro_stripe_utilities::start_time($period3); // Or next billing cycle. if (!$global_response) { if ($post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0 || !$post_vars['attr']['tp'] && $cost_calculations['total'] > 0) { if (!is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::get_customer($user_id, $user->user_email, $post_vars['first_name'], $post_vars['last_name']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::set_customer_card_token($stripe_customer->id, $post_vars['card_token']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_charge = c_ws_plugin__optimizemember_pro_stripe_utilities::create_customer_charge($stripe_customer->id, $post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0 ? $cost_calculations['trial_total'] : $cost_calculations['total'], $cost_calculations['cur'], $cost_calculations['desc']))) { $global_response = array('response' => $stripe_charge, 'error' => TRUE); } else { $new__txn_cid = $stripe_customer->id; $new__txn_id = $stripe_charge->id; } } } } } if (!$global_response) { if ($cost_calculations['total'] > 0) { if (!is_object($stripe_plan = c_ws_plugin__optimizemember_pro_stripe_utilities::get_plan($plan_attr))) { $global_response = array('response' => $stripe_plan, 'error' => TRUE); } else { if ((!isset($stripe_customer) || !is_object($stripe_customer)) && !is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::get_customer($user_id, $user->user_email, $post_vars['first_name'], $post_vars['last_name']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if ((!isset($stripe_customer) || !is_object($stripe_customer)) && !is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::set_customer_card_token($stripe_customer->id, $post_vars['card_token']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_subscription = c_ws_plugin__optimizemember_pro_stripe_utilities::create_customer_subscription($stripe_customer->id, $stripe_plan->id))) { $global_response = array('response' => $stripe_subscription, 'error' => TRUE); } else { $new__subscr_cid = $stripe_customer->id; $new__subscr_id = $stripe_subscription->id; } } } } if ($global_response && !empty($new__txn_id)) { $global_response = array(); $stripe_subscription_failed_charge_succeeded = TRUE; } } } if (!$global_response) { $old__subscr_cid = get_user_option('optimizemember_subscr_cid'); $old__subscr_id = get_user_option('optimizemember_subscr_id'); $old__subscr_or_wp_id = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id(); if (empty($new__subscr_cid)) { $new__subscr_cid = strtoupper('free-' . uniqid()); } if (empty($new__subscr_id)) { $new__subscr_id = strtoupper('free-' . uniqid()); } $ipn['txn_type'] = 'subscr_signup'; $ipn['subscr_cid'] = $new__subscr_cid; $ipn['subscr_id'] = $new__subscr_id; $ipn['custom'] = $post_vars['attr']['custom']; $ipn['txn_cid'] = !empty($new__txn_cid) ? $new__txn_cid : $new__subscr_cid; $ipn['txn_id'] = !empty($new__txn_id) ? $new__txn_id : $new__subscr_id; $ipn['period1'] = $period1; $ipn['period3'] = $period3; $ipn['mc_amount1'] = $cost_calculations['trial_total']; $ipn['mc_amount3'] = $cost_calculations['total']; $ipn['mc_gross'] = preg_match('/^[1-9]/', $ipn['period1']) ? $ipn['mc_amount1'] : $ipn['mc_amount3']; $ipn['mc_currency'] = $cost_calculations['cur']; $ipn['tax'] = $cost_calculations['tax']; $ipn['recurring'] = $post_vars['attr']['rr'] ? '1' : ''; $ipn['payer_email'] = $user->user_email; $ipn['first_name'] = $post_vars['first_name']; $ipn['last_name'] = $post_vars['last_name']; $ipn['option_name1'] = 'Referencing Customer ID'; $ipn['option_selection1'] = $old__subscr_or_wp_id; $ipn['option_name2'] = 'Customer IP Address'; $ipn['option_selection2'] = $_SERVER['REMOTE_ADDR']; $ipn['item_name'] = $cost_calculations['desc']; $ipn['item_number'] = $post_vars['attr']['level_ccaps_eotper']; $ipn['optimizemember_paypal_proxy'] = 'stripe'; $ipn['optimizemember_paypal_proxy_use'] = 'pro-emails'; $ipn['optimizemember_paypal_proxy_use'] .= $post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0 && $ipn['mc_gross'] > 0 ? ',subscr-signup-as-subscr-payment' : ''; $ipn['optimizemember_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']); $ipn['optimizemember_paypal_proxy_verification'] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); $ipn['optimizemember_paypal_proxy_return_url'] = $post_vars['attr']['success']; $ipn['optimizemember_stripe_proxy_return_url'] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url('/?optimizemember_paypal_notify=1'), $ipn, array('timeout' => 20))); if (!empty($stripe_subscription_failed_charge_succeeded)) { update_user_option($user_id, 'optimizemember_auto_eot_time', $start_time); } if ($old__subscr_cid && $old__subscr_id && apply_filters('optimizemember_pro_cancels_old_rp_before_new_rp', TRUE, get_defined_vars())) { c_ws_plugin__optimizemember_pro_stripe_utilities::cancel_customer_subscription($old__subscr_cid, $old__subscr_id, FALSE); } c_ws_plugin__optimizemember_list_servers::process_list_servers_against_current_user((bool) @$post_vars['custom_fields']['opt_in'], TRUE, TRUE); setcookie('optimizemember_tracking', $optimizemember_tracking = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__subscr_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie('optimizemember_tracking', $optimizemember_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['optimizemember_tracking'] = $optimizemember_tracking); $global_response = array('response' => sprintf(_x('<strong>Thank you.</strong> Your account has been updated :-)', 's2member-front', 's2member'), esc_attr(wp_login_url()))); if ($post_vars['attr']['success'] && substr($ipn['optimizemember_stripe_proxy_return_url'], 0, 2) === substr($post_vars['attr']['success'], 0, 2) && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $ipn['optimizemember_stripe_proxy_return_url'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, 's2p-v')) . exit; } } } else { if ($use_subscription && !is_user_logged_in()) { $plan_attr = $cp_attr; // For the subscription plan. $plan_attr['ta'] = $cost_calculations['trial_total']; $plan_attr['ra'] = $cost_calculations['total']; $plan_attr['desc'] = $cost_calculations['desc']; $period1 = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period1($post_vars['attr']['tp'] . ' ' . $post_vars['attr']['tt']); $period3 = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period3($post_vars['attr']['rp'] . ' ' . $post_vars['attr']['rt']); $start_time = $post_vars['attr']['tp'] ? c_ws_plugin__optimizemember_pro_stripe_utilities::start_time($period1) : c_ws_plugin__optimizemember_pro_stripe_utilities::start_time($period3); // Or next billing cycle. if (!$global_response) { if ($post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0 || !$post_vars['attr']['tp'] && $cost_calculations['total'] > 0) { if (!is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::get_customer(0, $post_vars['email'], $post_vars['first_name'], $post_vars['last_name']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::set_customer_card_token($stripe_customer->id, $post_vars['card_token']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_charge = c_ws_plugin__optimizemember_pro_stripe_utilities::create_customer_charge($stripe_customer->id, $post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0 ? $cost_calculations['trial_total'] : $cost_calculations['total'], $cost_calculations['cur'], $cost_calculations['desc']))) { $global_response = array('response' => $stripe_charge, 'error' => TRUE); } else { $new__txn_cid = $stripe_customer->id; $new__txn_id = $stripe_charge->id; } } } } } if (!$global_response) { if ($cost_calculations['total'] > 0) { if (!is_object($stripe_plan = c_ws_plugin__optimizemember_pro_stripe_utilities::get_plan($plan_attr))) { $global_response = array('response' => $stripe_plan, 'error' => TRUE); } else { if ((!isset($stripe_customer) || !is_object($stripe_customer)) && !is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::get_customer(0, $post_vars['email'], $post_vars['first_name'], $post_vars['last_name']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if ((!isset($stripe_customer) || !is_object($stripe_customer)) && !is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::set_customer_card_token($stripe_customer->id, $post_vars['card_token']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_subscription = c_ws_plugin__optimizemember_pro_stripe_utilities::create_customer_subscription($stripe_customer->id, $stripe_plan->id))) { $global_response = array('response' => $stripe_subscription, 'error' => TRUE); } else { $new__subscr_cid = $stripe_customer->id; $new__subscr_id = $stripe_subscription->id; } } } } if ($global_response && !empty($new__txn_id)) { $global_response = array(); $stripe_subscription_failed_charge_succeeded = TRUE; } } } if (!$global_response) { if (empty($new__subscr_cid)) { $new__subscr_cid = strtoupper('free-' . uniqid()); } if (empty($new__subscr_id)) { $new__subscr_id = strtoupper('free-' . uniqid()); } $ipn['txn_type'] = 'subscr_signup'; $ipn['subscr_cid'] = $new__subscr_cid; $ipn['subscr_id'] = $new__subscr_id; $ipn['custom'] = $post_vars['attr']['custom']; $ipn['txn_cid'] = !empty($new__txn_cid) ? $new__txn_cid : $new__subscr_cid; $ipn['txn_id'] = !empty($new__txn_id) ? $new__txn_id : $new__subscr_id; $ipn['period1'] = $period1; $ipn['period3'] = $period3; $ipn['mc_amount1'] = $cost_calculations['trial_total']; $ipn['mc_amount3'] = $cost_calculations['total']; $ipn['mc_gross'] = preg_match('/^[1-9]/', $ipn['period1']) ? $ipn['mc_amount1'] : $ipn['mc_amount3']; $ipn['mc_currency'] = $cost_calculations['cur']; $ipn['tax'] = $cost_calculations['tax']; $ipn['recurring'] = $post_vars['attr']['rr'] ? '1' : ''; $ipn['payer_email'] = $post_vars['email']; $ipn['first_name'] = $post_vars['first_name']; $ipn['last_name'] = $post_vars['last_name']; $ipn['option_name1'] = 'Originating Domain'; $ipn['option_selection1'] = $_SERVER['HTTP_HOST']; $ipn['option_name2'] = 'Customer IP Address'; $ipn['option_selection2'] = $_SERVER['REMOTE_ADDR']; $ipn['item_name'] = $cost_calculations['desc']; $ipn['item_number'] = $post_vars['attr']['level_ccaps_eotper']; $ipn['optimizemember_paypal_proxy'] = 'stripe'; $ipn['optimizemember_paypal_proxy_use'] = 'pro-emails'; $ipn['optimizemember_paypal_proxy_use'] .= $post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0 && $ipn['mc_gross'] > 0 ? ',subscr-signup-as-subscr-payment' : ''; $ipn['optimizemember_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']); $ipn['optimizemember_paypal_proxy_verification'] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); $ipn['optimizemember_paypal_proxy_return_url'] = $post_vars['attr']['success']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_user_pass1'] = $post_vars['password1']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_first_name'] = $post_vars['first_name']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_last_name'] = $post_vars['last_name']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_opt_in'] = @$post_vars['custom_fields']['opt_in']; if ($GLOBALS['WS_PLUGIN__']['optimizemember']['o']['custom_reg_fields']) { foreach (json_decode($GLOBALS['WS_PLUGIN__']['optimizemember']['o']['custom_reg_fields'], TRUE) as $field) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (isset($post_vars['custom_fields'][$field_var])) { $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_' . $field_var] = $post_vars['custom_fields'][$field_var]; } } } $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_gateway'] = 'stripe'; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_cid'] = $new__subscr_cid; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_id'] = $new__subscr_id; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_level'] = $post_vars['attr']['level']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_ccaps'] = $post_vars['attr']['ccaps']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_custom'] = $post_vars['attr']['custom']; @(list($level, $ccaps, $eotper) = preg_split('/\\:/', $post_vars['attr']['level_ccaps_eotper'], 3)); if (!empty($eotper)) { $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_auto_eot_time'] = date('Y-m-d H:i:s', c_ws_plugin__optimizemember_utils_time::auto_eot_time('', '', '', $eotper)); } $create_user['user_email'] = $post_vars['email']; // Copy this into a separate array for `wp_create_user()`. $create_user['user_login'] = $post_vars['username']; // Copy this into a separate array for `wp_create_user()`. $create_user['user_pass'] = wp_generate_password(); // Which may fire `c_ws_plugin__optimizemember_registrations::generate_password()`. $has_custom_password = $post_vars['password1'] && $post_vars['password1'] === $create_user['user_pass']; if ((is_multisite() && ($new__user_id = c_ws_plugin__optimizemember_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)) { update_user_option($new__user_id, 'default_password_nag', $has_custom_password ? FALSE : TRUE, TRUE); wp_new_user_notification($new__user_id, $create_user['user_pass']); if (!empty($stripe_subscription_failed_charge_succeeded)) { update_user_option($new__user_id, 'optimizemember_auto_eot_time', $start_time); } $ipn['optimizemember_stripe_proxy_return_url'] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url('/?optimizemember_paypal_notify=1'), $ipn, array('timeout' => 20))); setcookie('optimizemember_tracking', $optimizemember_tracking = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__subscr_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie('optimizemember_tracking', $optimizemember_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['optimizemember_tracking'] = $optimizemember_tracking); if ($has_custom_password) { $global_response = array('response' => sprintf(_x('<strong>Thank you.</strong> Your account has been approved.<br />— Please <a href="%s" rel="nofollow">login</a>.', 's2member-front', 's2member'), esc_attr(wp_login_url()))); } else { $global_response = array('response' => _x('<strong>Thank you.</strong> Your account has been approved.<br />— You\'ll receive an email momentarily.', 's2member-front', 's2member')); } if ($post_vars['attr']['success'] && substr($ipn['optimizemember_stripe_proxy_return_url'], 0, 2) === substr($post_vars['attr']['success'], 0, 2) && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $ipn['optimizemember_stripe_proxy_return_url'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, 's2p-v')) . exit; } } else { c_ws_plugin__optimizemember_utils_urls::remote(site_url('/?optimizemember_paypal_notify=1'), $ipn, array('timeout' => 20)); $global_response = array('response' => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } } else { if (!$use_subscription && is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID)) { update_user_meta($user_id, 'first_name', $post_vars['first_name']); update_user_meta($user_id, 'last_name', $post_vars['last_name']); if (!$global_response) { if ($cost_calculations['total'] > 0) { if (!is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::get_customer($user_id, $user->user_email, $post_vars['first_name'], $post_vars['last_name']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::set_customer_card_token($stripe_customer->id, $post_vars['card_token']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_charge = c_ws_plugin__optimizemember_pro_stripe_utilities::create_customer_charge($stripe_customer->id, $cost_calculations['total'], $cost_calculations['cur'], $cost_calculations['desc']))) { $global_response = array('response' => $stripe_charge, 'error' => TRUE); } else { $new__txn_cid = $stripe_customer->id; $new__txn_id = $stripe_charge->id; } } } } } if (!$global_response) { $old__subscr_cid = get_user_option('optimizemember_subscr_cid'); $old__subscr_id = get_user_option('optimizemember_subscr_id'); $old__subscr_or_wp_id = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id(); if (empty($new__txn_cid)) { $new__txn_cid = strtoupper('free-' . uniqid()); } if (empty($new__txn_id)) { $new__txn_id = strtoupper('free-' . uniqid()); } $ipn['txn_type'] = 'web_accept'; $ipn['txn_cid'] = $new__txn_cid; $ipn['txn_id'] = $new__txn_id; $ipn['custom'] = $post_vars['attr']['custom']; $ipn['mc_gross'] = $cost_calculations['total']; $ipn['mc_currency'] = $cost_calculations['cur']; $ipn['tax'] = $cost_calculations['tax']; $ipn['payer_email'] = $user->user_email; $ipn['first_name'] = $post_vars['first_name']; $ipn['last_name'] = $post_vars['last_name']; $ipn['option_name1'] = 'Referencing Customer ID'; $ipn['option_selection1'] = $old__subscr_or_wp_id; $ipn['option_name2'] = 'Customer IP Address'; $ipn['option_selection2'] = $_SERVER['REMOTE_ADDR']; $ipn['item_name'] = $cost_calculations['desc']; $ipn['item_number'] = $post_vars['attr']['level_ccaps_eotper']; $ipn['optimizemember_paypal_proxy'] = 'stripe'; $ipn['optimizemember_paypal_proxy_use'] = 'pro-emails'; $ipn['optimizemember_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']); $ipn['optimizemember_paypal_proxy_verification'] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); $ipn['optimizemember_paypal_proxy_return_url'] = $post_vars['attr']['success']; $ipn['optimizemember_stripe_proxy_return_url'] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url('/?optimizemember_paypal_notify=1'), $ipn, array('timeout' => 20))); if (!$is_independent_ccaps_sale) { // Independent? if ($old__subscr_cid && $old__subscr_id && apply_filters('optimizemember_pro_cancels_old_rp_before_new_rp', TRUE, get_defined_vars())) { c_ws_plugin__optimizemember_pro_stripe_utilities::cancel_customer_subscription($old__subscr_cid, $old__subscr_id, FALSE); } } c_ws_plugin__optimizemember_list_servers::process_list_servers_against_current_user((bool) @$post_vars['custom_fields']['opt_in'], TRUE, TRUE); setcookie('optimizemember_tracking', $optimizemember_tracking = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__txn_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie('optimizemember_tracking', $optimizemember_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['optimizemember_tracking'] = $optimizemember_tracking); $global_response = array('response' => sprintf(_x('<strong>Thank you.</strong> Your account has been updated :-)', 's2member-front', 's2member'), esc_attr(wp_login_url()))); if ($post_vars['attr']['success'] && substr($ipn['optimizemember_stripe_proxy_return_url'], 0, 2) === substr($post_vars['attr']['success'], 0, 2) && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $ipn['optimizemember_stripe_proxy_return_url'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, 's2p-v')) . exit; } } } else { if (!$use_subscription && !is_user_logged_in()) { if (!$global_response) { if ($cost_calculations['total'] > 0) { if (!is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::get_customer(0, $post_vars['email'], $post_vars['first_name'], $post_vars['last_name']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::set_customer_card_token($stripe_customer->id, $post_vars['card_token']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_charge = c_ws_plugin__optimizemember_pro_stripe_utilities::create_customer_charge($stripe_customer->id, $cost_calculations['total'], $cost_calculations['cur'], $cost_calculations['desc']))) { $global_response = array('response' => $stripe_charge, 'error' => TRUE); } else { $new__txn_cid = $stripe_customer->id; $new__txn_id = $stripe_charge->id; } } } } } if (!$global_response) { if (empty($new__txn_cid)) { $new__txn_cid = strtoupper('free-' . uniqid()); } if (empty($new__txn_id)) { $new__txn_id = strtoupper('free-' . uniqid()); } $ipn['txn_type'] = 'web_accept'; $ipn['txn_cid'] = $new__txn_cid; $ipn['txn_id'] = $new__txn_id; $ipn['custom'] = $post_vars['attr']['custom']; $ipn['mc_gross'] = $cost_calculations['total']; $ipn['mc_currency'] = $cost_calculations['cur']; $ipn['tax'] = $cost_calculations['tax']; $ipn['payer_email'] = $post_vars['email']; $ipn['first_name'] = $post_vars['first_name']; $ipn['last_name'] = $post_vars['last_name']; $ipn['option_name1'] = 'Originating Domain'; $ipn['option_selection1'] = $_SERVER['HTTP_HOST']; $ipn['option_name2'] = 'Customer IP Address'; $ipn['option_selection2'] = $_SERVER['REMOTE_ADDR']; $ipn['item_name'] = $cost_calculations['desc']; $ipn['item_number'] = $post_vars['attr']['level_ccaps_eotper']; $ipn['optimizemember_paypal_proxy'] = 'stripe'; $ipn['optimizemember_paypal_proxy_use'] = 'pro-emails'; $ipn['optimizemember_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']); $ipn['optimizemember_paypal_proxy_verification'] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); $ipn['optimizemember_paypal_proxy_return_url'] = $post_vars['attr']['success']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_user_pass1'] = $post_vars['password1']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_first_name'] = $post_vars['first_name']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_last_name'] = $post_vars['last_name']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_opt_in'] = @$post_vars['custom_fields']['opt_in']; if ($GLOBALS['WS_PLUGIN__']['']['o']['custom_reg_fields']) { foreach (json_decode($GLOBALS['WS_PLUGIN__']['optimizemember']['o']['custom_reg_fields'], TRUE) as $field) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (isset($post_vars['custom_fields'][$field_var])) { $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_' . $field_var] = $post_vars['custom_fields'][$field_var]; } } } $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_gateway'] = 'stripe'; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_cid'] = $new__txn_cid; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_id'] = $new__txn_id; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_level'] = $post_vars['attr']['level']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_ccaps'] = $post_vars['attr']['ccaps']; $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_custom'] = $post_vars['attr']['custom']; @(list($level, $ccaps, $eotper) = preg_split('/\\:/', $post_vars['attr']['level_ccaps_eotper'], 3)); if (!empty($eotper)) { $GLOBALS['ws_plugin__optimizemember_registration_vars']['ws_plugin__optimizemember_custom_reg_field_optimizemember_auto_eot_time'] = date('Y-m-d H:i:s', c_ws_plugin__optimizemember_utils_time::auto_eot_time('', '', '', $eotper)); } $create_user['user_email'] = $post_vars['email']; // Copy this into a separate array for `wp_create_user()`. $create_user['user_login'] = $post_vars['username']; // Copy this into a separate array for `wp_create_user()`. $create_user['user_pass'] = wp_generate_password(); // Which may fire `c_ws_plugin__optimizemember_registrations::generate_password()`. $has_custom_password = $post_vars['password1'] && $post_vars['password1'] === $create_user['user_pass']; if ((is_multisite() && ($new__user_id = c_ws_plugin__optimizemember_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)) { update_user_option($new__user_id, 'default_password_nag', $has_custom_password ? FALSE : TRUE, TRUE); wp_new_user_notification($new__user_id, $create_user['user_pass']); $ipn['optimizemember_stripe_proxy_return_url'] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url('/?optimizemember_paypal_notify=1'), $ipn, array('timeout' => 20))); setcookie('optimizemember_tracking', $optimizemember_tracking = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__txn_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie('optimizemember_tracking', $optimizemember_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['optimizemember_tracking'] = $optimizemember_tracking); if ($has_custom_password) { $global_response = array('response' => sprintf(_x('<strong>Thank you.</strong> Your account has been approved.<br />— Please <a href="%s" rel="nofollow">login</a>.', 'optimizemember-front', 's2member'), esc_attr(wp_login_url()))); } else { $global_response = array('response' => _x('<strong>Thank you.</strong> Your account has been approved.<br />— You\'ll receive an email momentarily.', 's2member-front', 's2member')); } if ($post_vars['attr']['success'] && substr($ipn['optimizemember_stripe_proxy_return_url'], 0, 2) === substr($post_vars['attr']['success'], 0, 2) && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $ipn['optimizemember_stripe_proxy_return_url'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, 's2p-v')) . exit; } } else { c_ws_plugin__optimizemember_utils_urls::remote(site_url('/?optimizemember_paypal_notify=1'), $ipn, array('timeout' => 20)); $global_response = array('response' => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } } else { $global_response = array('response' => _x('<strong>Unknown error.</strong> Please contact Support for assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } } } } else { // Input form field validation errors. $global_response = $form_submission_validation_errors; } } } }
/** * optimizeMember's PayPal IPN handler ( inner processing routine ). * * @package optimizeMember\PayPal * @since 110720 * * @param array $vars Required. An array of defined variables passed by {@link optimizeMember\PayPal\c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()}. * @return array|bool The original ``$paypal`` array passed in ( extracted ) from ``$vars``, or false when conditions do NOT apply. * * @todo Optimize with ``empty()`` and ``isset()``. */ public static function cp($vars = array()) { extract($vars); /* Extract all vars passed in from: ``c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()``. */ /**/ if ((!empty($paypal["txn_type"]) && preg_match("/^new_case\$/i", $paypal["txn_type"]) && !empty($paypal["case_type"]) && preg_match("/^chargeback\$/i", $paypal["case_type"]) || !empty($paypal["payment_status"]) && preg_match("/^(refunded|reversed|reversal)\$/i", $paypal["payment_status"])) && ((!empty($paypal["item_number"]) || ($paypal["item_number"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_item_number($paypal))) && preg_match($GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["sp_access_item_number_regex"], $paypal["item_number"])) && (!empty($paypal["item_name"]) || ($paypal["item_name"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_item_name($paypal)) || ($paypal["item_name"] = $_SERVER["HTTP_HOST"])) && !empty($paypal["payer_email"]) && !empty($paypal["parent_txn_id"])) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_before_sp_refund_reversal", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if (!get_transient($transient_ipn = "s2m_ipn_" . md5("optimizemember_transient_" . $_paypal_s)) && set_transient($transient_ipn, time(), 31556926 * 10)) { $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `[empty or irrelevant]` ) w/ `payment_status` ( `refunded|reversed|reversal` ) - or - `new_case` w/ `case_type` ( `chargeback` )."; /**/ $paypal["ip"] = preg_match("/ip address/i", $paypal["option_name2"]) && $paypal["option_selection2"] ? $paypal["option_selection2"] : ""; $paypal["ip"] = !$paypal["ip"] && preg_match("/^[a-z0-9]+~[0-9\\.]+\$/i", $paypal["invoice"]) ? preg_replace("/^[a-z0-9]+~/i", "", $paypal["invoice"]) : $paypal["ip"]; /**/ $processing = $during = true; /* Yes, we ARE processing this. */ /* Refunds and chargeback reversals. This is excluded from the processing check. In other words, optimizeMember sends `Refund/Reversal` Notifications ANYTIME a Refund/Reversal occurs; even if optimizeMember did not process it otherwise. Since this routine ignores the processing check, it is *possible* that Refund/Reversal Notification URLs will be contacted more than once. If you're writing scripts that depend on Refund/Reversal Notifications, please keep this in mind. */ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["sp_ref_rev_notification_urls"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["sp_ref_rev_notification_urls"]) as $url) { /**/ if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%parent_txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["parent_txn_id"])), $url))) { if (($url = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_number"])), $url)) && ($url = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_name"])), $url))) { if (($url = preg_replace("/%%-amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["mc_gross"])), $url)) && ($url = preg_replace("/%%-fee%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["mc_fee"])), $url))) { if (($url = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["first_name"])), $url)) && ($url = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["last_name"])), $url))) { if ($url = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($paypal["first_name"] . " " . $paypal["last_name"]))), $url)) { if ($url = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["payer_email"])), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["ip"])), $url)) { /**/ if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__optimizemember_utils_urls::remote($url); } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Specific Post/Page ~ Refund/Reversal Notification URLs have been processed."; } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["sp_ref_rev_notification_recipients"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { $msg = $sbj = "( optimizeMember / API Notification Email ) - Specific Post/Page ~ Refund/Reversal"; $msg .= "\n\n"; /* Spacing in the message body. */ /**/ $msg .= "parent_txn_id: %%parent_txn_id%%\n"; $msg .= "item_number: %%item_number%%\n"; $msg .= "item_name: %%item_name%%\n"; $msg .= "-amount: %%-amount%%\n"; $msg .= "-fee: %%-fee%%\n"; $msg .= "first_name: %%first_name%%\n"; $msg .= "last_name: %%last_name%%\n"; $msg .= "full_name: %%full_name%%\n"; $msg .= "payer_email: %%payer_email%%\n"; $msg .= "user_ip: %%user_ip%%\n"; /**/ $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; /**/ if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%parent_txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["parent_txn_id"]), $msg))) { if (($msg = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $msg)) && ($msg = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $msg))) { if (($msg = preg_replace("/%%-amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_gross"]), $msg)) && ($msg = preg_replace("/%%-fee%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_fee"]), $msg))) { if (($msg = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $msg)) && ($msg = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $msg))) { if ($msg = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $msg)) { if ($msg = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["ip"]), $msg)) { /**/ if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { /* Still have a ``$sbj`` and a ``$msg``? */ /**/ foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["sp_ref_rev_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__optimizemember_sp_ref_rev_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_sp_ref_rev_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=utf-8"); } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Specific Post/Page ~ Refund/Reversal Notification Emails have been processed."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_sp_refund_reversal", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { $paypal["optimizemember_log"][] = "Not processing. Duplicate IPN."; $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `[empty or irrelevant]` ) w/ `payment_status` ( `refunded|reversed|reversal` ) - or - `new_case` w/ `case_type` ( `chargeback` )."; $paypal["optimizemember_log"][] = "Duplicate IPN. Already processed. This IPN will be ignored."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_after_sp_refund_reversal", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_sp_refund_reversal", $paypal, get_defined_vars()); } else { return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_sp_refund_reversal", false, get_defined_vars()); } }
/** * Configures all new Users. * * The Hook `user_register` is also fired by calling: * ``c_ws_plugin__optimizemember_registrations::ms_create_existing_user()`` and/or ``wpmu_create_user()``. * * This function also receives hand-offs from optimizeMember's handlers for these two Hooks: * `wpmu_activate_user` and `wpmu_activate_blog`. * * @package optimizeMember\Registrations * @since 3.5 * * @attaches-to ``add_action("user_register");`` * * @param int|str $user_id A numeric WordPress User ID. * @param str $password Optional in most cases. A User's plain text Password. If unspecified, attempts are made to collect the plain text Password from other sources. * @param array $meta Optional in most cases. Defaults to false. An array of meta data for a User/Member. * @return null No return value. Returns `null` in possible every scenario. * * @todo Impossible to delete cookies when fired inside: `/wp-activate.php`? */ public static function configure_user_registration($user_id = FALSE, $password = FALSE, $meta = FALSE) { global $wpdb; /* Global database object reference. */ global $pagenow; /* We need this to detect the current administration page. */ global $current_site, $current_blog; /* Adds support for Multisite Networking. */ static $email_config, $processed; /* Static vars prevent duplicate processing. */ /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_before_configure_user_registration", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ /* With Multisite Networking, we need this to run on `user_register` ahead of `wpmu_activate_[user|blog]`. */ if (!isset($email_config) && ($email_config = true)) { /* Anytime this routine is fired; we configure email. */ c_ws_plugin__optimizemember_email_configs::email_config(); } /* Configures `From:` email header. */ /**/ $_p = isset($_POST) ? $_POST : null; $rvs = isset($GLOBALS["ws_plugin__optimizemember_registration_vars"]) ? $GLOBALS["ws_plugin__optimizemember_registration_vars"] : null; /**/ if (!$processed) { /**/ if (is_array($_p) || is_array($meta) || is_array($rvs)) { /**/ if (!(is_multisite() && is_blog_admin() && $pagenow === "user-new.php" && isset($_p["noconfirmation"]) && is_super_admin() && !is_array($meta))) { if (!(preg_match("/\\/wp-activate\\.php/", $_SERVER["REQUEST_URI"]) && !is_array($meta))) { if (!(c_ws_plugin__optimizemember_utils_conds::bp_is_installed() && bp_is_activation_page() && !is_array($meta))) { if (!(c_ws_plugin__optimizemember_utils_conds::pro_is_installed() && c_ws_plugin__optimizemember_pro_remote_ops::is_remote_op("create_user") && !is_array($rvs))) { /**/ if ($user_id && is_object($user = new WP_User($user_id)) && !empty($user->ID) && ($user_id = $user->ID) && ($processed = true)) { settype($_p, "array") . settype($meta, "array") . settype($rvs, "array"); /**/ $_p = c_ws_plugin__optimizemember_utils_strings::trim_deep(stripslashes_deep($_p)); $meta = c_ws_plugin__optimizemember_utils_strings::trim_deep(stripslashes_deep($meta)); $rvs = c_ws_plugin__optimizemember_utils_strings::trim_deep($rvs); /**/ foreach ($_p as $_key => $_value) { /* Scan ``$_p`` vars; adding `custom_reg_field` keys. */ if (preg_match("/^ws_plugin__optimizemember_user_new_/", $_key)) { /* Look for keys. */ if ($_key = str_replace("_user_new_", "_custom_reg_field_", $_key)) { $_p[$_key] = $_value; } } } /* Add each of these key conversions. */ unset($_key, $_value); /**/ if (!is_admin() && (isset($_p["ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_gateway"]) || isset($_p["ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_id"]) || isset($_p["ws_plugin__optimizemember_custom_reg_field_optimizemember_custom"]) || isset($_p["ws_plugin__optimizemember_custom_reg_field_optimizemember_ccaps"]) || isset($_p["ws_plugin__optimizemember_custom_reg_field_optimizemember_auto_eot_time"]) || isset($_p["ws_plugin__optimizemember_custom_reg_field_optimizemember_notes"]))) { exit(_x("optimizeMember security violation. You attempted to POST administrative variables that will NOT be trusted in a NON-administrative zone!", "s2member-front", "s2member")); } /**/ $_pmr = array_merge($_p, $meta, $rvs); /* Merge all of these arrays together now, in this specific order. */ unset($_p, $meta, $rvs); /* These variables can all be unset now; we have them all in the ``$_pmr`` array. */ /**/ $custom_reg_display_name = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_display_name"]; /* Can be configured by the site owner. */ /**/ if (!is_admin() && (!c_ws_plugin__optimizemember_utils_conds::pro_is_installed() || !c_ws_plugin__optimizemember_pro_remote_ops::is_remote_op("create_user")) && ($reg_cookies = c_ws_plugin__optimizemember_register_access::reg_cookies_ok()) && extract($reg_cookies)) { /* This routine could be processed through `/wp-login.php?action=register`, `/wp-activate.php`, or `/activate` via BuddyPress`. This may also be processed through a standard BuddyPress installation, or another plugin calling `user_register`. If processed through `/wp-activate.php`, it could've originated inside the admin, via `/user-new.php`. */ /**/ $processed = "yes"; /* Mark this as yes. */ /**/ $current_role = c_ws_plugin__optimizemember_user_access::user_access_role($user); @(list($level, $ccaps, $eotper) = preg_split("/\\:/", $item_number, 3)); $role = "optimizemember_level" . $level; /* Membership Level. */ /**/ $email = $user->user_email; $login = $user->user_login; $ip = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_registration_ip"]; $ip = !$ip ? $_SERVER["REMOTE_ADDR"] : $ip; /* Else use environment variable. */ $cv = preg_split("/\\|/", $custom); /**/ if (!($auto_eot_time = "") && $eotper) { /* If a specific EOT Period is included. */ $auto_eot_time = c_ws_plugin__optimizemember_utils_time::auto_eot_time("", "", "", $eotper); } /**/ $notes = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_notes"]; /**/ $opt_in = !$GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_opt_in"] ? true : false; $opt_in = !$opt_in && !empty($_pmr["ws_plugin__optimizemember_custom_reg_field_opt_in"]) ? true : $opt_in; /**/ if (!($fname = $user->first_name)) { if (!empty($_pmr["ws_plugin__optimizemember_custom_reg_field_first_name"])) { $fname = (string) $_pmr["ws_plugin__optimizemember_custom_reg_field_first_name"]; } } /**/ if (!$fname) { /* Also try BuddyPress. */ if (!empty($_pmr["field_1"])) { /* BuddyPress? */ $fname = trim(preg_replace("/ (.*)\$/", "", (string) $_pmr["field_1"])); } } /**/ if (!($lname = $user->last_name)) { if (!empty($_pmr["ws_plugin__optimizemember_custom_reg_field_last_name"])) { $lname = (string) $_pmr["ws_plugin__optimizemember_custom_reg_field_last_name"]; } } /**/ if (!$lname) { /* Also try BuddyPress. */ if (!empty($_pmr["field_1"]) && preg_match("/^(.+?) (.+)\$/", (string) $_pmr["field_1"])) { $lname = trim(preg_replace("/^(.+?) (.+)\$/", "\$2", (string) $_pmr["field_1"])); } } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_names"] && !$fname) { if ($login) { /* Username and empty Last Name. */ eval('$fname = trim ($login); $lname = "";'); } } /**/ $name = trim($fname . " " . $lname); /* Both names. */ /**/ if (!($pass = $password)) { /* Try optimizeMember's generator. */ if (!empty($GLOBALS["ws_plugin__optimizemember_generate_password_return"])) { $pass = (string) $GLOBALS["ws_plugin__optimizemember_generate_password_return"]; } } /**/ if (!$pass) { /* Also try BuddyPress Password. */ if (!empty($_pmr["signup_password"])) { /* BuddyPress? */ $pass = (string) $_pmr["signup_password"]; } } /**/ if ($pass) { !headers_sent() ? delete_user_setting("default_password_nag", $user_id) : null; update_user_option($user_id, "default_password_nag", false, true); } /**/ update_user_option($user_id, "optimizemember_registration_ip", $ip); update_user_option($user_id, "optimizemember_auto_eot_time", $auto_eot_time); update_user_option($user_id, "optimizemember_subscr_gateway", $subscr_gateway); update_user_option($user_id, "optimizemember_subscr_id", $subscr_id); update_user_option($user_id, "optimizemember_custom", $custom); update_user_option($user_id, "optimizemember_notes", $notes); /**/ if (!$user->first_name && $fname) { update_user_meta($user_id, "first_name", $fname); } /**/ if (!$user->last_name && $lname) { update_user_meta($user_id, "last_name", $lname); } /**/ if (!$user->display_name || $user->display_name === $user->user_login) { if ($custom_reg_display_name === "full" && $name) { wp_update_user(array("ID" => $user_id, "display_name" => $name)); } else { if ($custom_reg_display_name === "first" && $fname) { wp_update_user(array("ID" => $user_id, "display_name" => $fname)); } else { if ($custom_reg_display_name === "last" && $lname) { wp_update_user(array("ID" => $user_id, "display_name" => $lname)); } else { if ($custom_reg_display_name === "login" && $login) { wp_update_user(array("ID" => $user_id, "display_name" => $login)); } } } } } /**/ if (is_multisite()) { if (!is_main_site() && strtotime($user->user_registered) >= strtotime("-10 seconds")) { remove_user_from_blog($user_id, $current_site->blog_id); } /* No Main Site Role. */ /**/ if (!get_user_meta($user_id, "optimizemember_originating_blog", true)) { /* Recorded yet? */ update_user_meta($user_id, "optimizemember_originating_blog", $current_blog->blog_id); } } /**/ if ($current_role !== $role) { /* Only if NOT the current Role. */ $user->set_role($role); } /* optimizeMember. */ /**/ if ($ccaps && preg_match("/^-all/", str_replace("+", "", $ccaps))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_optimizemember_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } } /**/ if ($ccaps && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_optimizemember_ccap_" . $ccap); } } } /**/ if (!($fields = array()) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_fields"]) { foreach (json_decode($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_fields"], true) as $field) { $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"])); $field_id_class = preg_replace("/_/", "-", $field_var); /**/ if (isset($_pmr["ws_plugin__optimizemember_custom_reg_field_" . $field_var])) { $fields[$field_var] = $_pmr["ws_plugin__optimizemember_custom_reg_field_" . $field_var]; } } } /**/ if (!empty($fields)) { /* Only if NOT empty. */ update_user_option($user_id, "optimizemember_custom_fields", $fields); } /**/ if ($level > 0) { $pr_times = get_user_option("optimizemember_paid_registration_times", $user_id); $pr_times["level"] = empty($pr_times["level"]) ? time() : $pr_times["level"]; $pr_times["level" . $level] = empty($pr_times["level" . $level]) ? time() : $pr_times["level" . $level]; update_user_option($user_id, "optimizemember_paid_registration_times", $pr_times); /* Update now. */ } /**/ if (($transient = "s2m_" . md5("optimizemember_transient_ipn_signup_vars_" . $subscr_id)) && is_array($ipn_signup_vars = get_transient($transient))) { update_user_option($user_id, "optimizemember_ipn_signup_vars", $ipn_signup_vars); /* For future reference. */ delete_transient($transient); /* This can be deleted now. */ } if (($transient = "s2m_" . md5("optimizemember_transient_ipn_subscr_payment_" . $subscr_id)) && is_array($subscr_payment = get_transient($transient)) && !empty($subscr_payment["subscr_gateway"])) { $proxy = array("optimizemember_paypal_notify" => "1", "optimizemember_paypal_proxy" => stripslashes((string) $subscr_payment["subscr_gateway"]), "optimizemember_paypal_proxy_verification" => c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); c_ws_plugin__optimizemember_utils_urls::remote(add_query_arg(urlencode_deep($proxy), site_url("/")), stripslashes_deep($subscr_payment), array("timeout" => 20)); delete_transient($transient); /* This can be deleted now. */ } if (($transient = "s2m_" . md5("optimizemember_transient_ipn_subscr_eot_" . $subscr_id)) && is_array($subscr_eot = get_transient($transient)) && !empty($subscr_eot["subscr_gateway"])) { $proxy = array("optimizemember_paypal_notify" => "1", "optimizemember_paypal_proxy" => stripslashes((string) $subscr_eot["subscr_gateway"]), "optimizemember_paypal_proxy_verification" => c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); c_ws_plugin__optimizemember_utils_urls::remote(add_query_arg(urlencode_deep($proxy), site_url("/")), stripslashes_deep($subscr_eot), array("timeout" => 20)); delete_transient($transient); /* This can be deleted now. */ } /**/ if (!headers_sent()) { /* Only if headers are NOT yet sent. Here we establish both Signup and Payment Tracking Cookies. */ @setcookie("optimizemember_tracking", $optimizemember_tracking = c_ws_plugin__optimizemember_utils_encryption::encrypt($subscr_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie("optimizemember_tracking", $optimizemember_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE["optimizemember_tracking"] = $optimizemember_tracking); } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_configure_user_registration_front_side_paid", get_defined_vars()); do_action("ws_plugin__optimizemember_during_configure_user_registration_front_side", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { if (!is_admin() && (!c_ws_plugin__optimizemember_utils_conds::pro_is_installed() || !c_ws_plugin__optimizemember_pro_remote_ops::is_remote_op("create_user"))) { /* This routine could be processed through `/wp-login.php?action=register`, `/wp-activate.php`, or `/activate` via BuddyPress`. This may also be processed through a standard BuddyPress installation, or another plugin calling `user_register`. If processed through `/wp-activate.php`, it could've originated inside the admin, via `/user-new.php`. */ /**/ $processed = "yes"; /* Mark this as yes. */ /**/ $current_role = c_ws_plugin__optimizemember_user_access::user_access_role($user); $role = ""; /* Initialize ``$role`` to an empty string here, before processing. */ $role = !$role && ($level = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_level"]) > 0 ? "optimizemember_level" . $level : $role; $role = !$role && ($level = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_level"]) === "0" ? "subscriber" : $role; $role = !$role && $current_role ? $current_role : $role; /* Use existing Role? */ $role = !$role ? get_option("default_role") : $role; /* Otherwise default. */ /**/ $level = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_level"]; $level = !$level && preg_match("/^(administrator|editor|author|contributor)\$/i", $role) ? $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"] : $level; $level = !$level && preg_match("/^optimizemember_level[1-9][0-9]*\$/i", $role) ? preg_replace("/^optimizemember_level/", "", $role) : $level; $level = !$level && preg_match("/^subscriber\$/i", $role) ? "0" : $level; $level = !$level ? "0" : $level; /**/ $ccaps = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_ccaps"]; /**/ $email = $user->user_email; $login = $user->user_login; $ip = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_registration_ip"]; $ip = !$ip ? $_SERVER["REMOTE_ADDR"] : $ip; /* Else use environment variable. */ $custom = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_custom"]; $subscr_id = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_id"]; $subscr_gateway = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_gateway"]; $cv = preg_split("/\\|/", (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_custom"]); /**/ $auto_eot_time = ($eot = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_auto_eot_time"]) ? strtotime($eot) : ""; $notes = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_notes"]; /**/ $opt_in = !$GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_opt_in"] ? true : false; $opt_in = !$opt_in && !empty($_pmr["ws_plugin__optimizemember_custom_reg_field_opt_in"]) ? true : $opt_in; /**/ if (!($fname = $user->first_name)) { if (!empty($_pmr["ws_plugin__optimizemember_custom_reg_field_first_name"])) { $fname = (string) $_pmr["ws_plugin__optimizemember_custom_reg_field_first_name"]; } } /**/ if (!$fname) { /* Also try BuddyPress. */ if (!empty($_pmr["field_1"])) { /* BuddyPress? */ $fname = trim(preg_replace("/ (.*)\$/", "", (string) $_pmr["field_1"])); } } /**/ if (!($lname = $user->last_name)) { if (!empty($_pmr["ws_plugin__optimizemember_custom_reg_field_last_name"])) { $lname = (string) $_pmr["ws_plugin__optimizemember_custom_reg_field_last_name"]; } } /**/ if (!$lname) { /* Also try BuddyPress. */ if (!empty($_pmr["field_1"]) && preg_match("/^(.+?) (.+)\$/", (string) $_pmr["field_1"])) { $lname = trim(preg_replace("/^(.+?) (.+)\$/", "\$2", (string) $_pmr["field_1"])); } } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_names"] && !$fname) { if ($login) { /* Username and empty Last Name. */ eval('$fname = trim ($login); $lname = "";'); } } /**/ $name = trim($fname . " " . $lname); /* Both names. */ /**/ if (!($pass = $password)) { /* Try optimizeMember's generator. */ if (!empty($GLOBALS["ws_plugin__optimizemember_generate_password_return"])) { $pass = (string) $GLOBALS["ws_plugin__optimizemember_generate_password_return"]; } } /**/ if (!$pass) { /* Also try BuddyPress Password. */ if (!empty($_pmr["signup_password"])) { /* BuddyPress? */ $pass = (string) $_pmr["signup_password"]; } } /**/ if ($pass) { !headers_sent() ? delete_user_setting("default_password_nag", $user_id) : null; update_user_option($user_id, "default_password_nag", false, true); } /**/ update_user_option($user_id, "optimizemember_registration_ip", $ip); update_user_option($user_id, "optimizemember_auto_eot_time", $auto_eot_time); update_user_option($user_id, "optimizemember_subscr_gateway", $subscr_gateway); update_user_option($user_id, "optimizemember_subscr_id", $subscr_id); update_user_option($user_id, "optimizemember_custom", $custom); update_user_option($user_id, "optimizemember_notes", $notes); /**/ if (!$user->first_name && $fname) { update_user_meta($user_id, "first_name", $fname); } /**/ if (!$user->last_name && $lname) { update_user_meta($user_id, "last_name", $lname); } /**/ if (!$user->display_name || $user->display_name === $user->user_login) { if ($custom_reg_display_name === "full" && $name) { wp_update_user(array("ID" => $user_id, "display_name" => $name)); } else { if ($custom_reg_display_name === "first" && $fname) { wp_update_user(array("ID" => $user_id, "display_name" => $fname)); } else { if ($custom_reg_display_name === "last" && $lname) { wp_update_user(array("ID" => $user_id, "display_name" => $lname)); } else { if ($custom_reg_display_name === "login" && $login) { wp_update_user(array("ID" => $user_id, "display_name" => $login)); } } } } } /**/ if (is_multisite()) { if (!is_main_site() && strtotime($user->user_registered) >= strtotime("-10 seconds")) { remove_user_from_blog($user_id, $current_site->blog_id); } /**/ if (!get_user_meta($user_id, "optimizemember_originating_blog", true)) { update_user_meta($user_id, "optimizemember_originating_blog", $current_blog->blog_id); } } /**/ if ($current_role !== $role) { /* Only if NOT the current Role. */ $user->set_role($role); } /* optimizeMember. */ /**/ if ($ccaps && preg_match("/^-all/", str_replace("+", "", $ccaps))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_optimizemember_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } } /**/ if ($ccaps && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_optimizemember_ccap_" . $ccap); } } } /**/ if (!($fields = array()) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_fields"]) { foreach (json_decode($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_fields"], true) as $field) { $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"])); $field_id_class = preg_replace("/_/", "-", $field_var); /**/ if (isset($_pmr["ws_plugin__optimizemember_custom_reg_field_" . $field_var])) { $fields[$field_var] = $_pmr["ws_plugin__optimizemember_custom_reg_field_" . $field_var]; } } } /**/ if (!empty($fields)) { /* Only if NOT empty. */ update_user_option($user_id, "optimizemember_custom_fields", $fields); } /**/ if ($level > 0) { $pr_times = get_user_option("optimizemember_paid_registration_times", $user_id); $pr_times["level"] = empty($pr_times["level"]) ? time() : $pr_times["level"]; $pr_times["level" . $level] = empty($pr_times["level" . $level]) ? time() : $pr_times["level" . $level]; update_user_option($user_id, "optimizemember_paid_registration_times", $pr_times); /* Update now. */ } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_configure_user_registration_front_side_free", get_defined_vars()); do_action("ws_plugin__optimizemember_during_configure_user_registration_front_side", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { if (is_blog_admin() && $pagenow === "user-new.php" || c_ws_plugin__optimizemember_utils_conds::pro_is_installed() && c_ws_plugin__optimizemember_pro_remote_ops::is_remote_op("create_user")) { /* Can only be processed through `/user-new.php` in the Admin panel, or through Remote Op: `create_user`. */ /**/ $processed = "yes"; /* Mark this as yes, to indicate that a routine was processed. */ /**/ $current_role = c_ws_plugin__optimizemember_user_access::user_access_role($user); $role = ""; /* Initialize $role to an empty string here, before processing. */ $role = !$role && ($level = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_level"]) > 0 ? "optimizemember_level" . $level : $role; $role = !$role && ($level = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_level"]) === "0" ? "subscriber" : $role; $role = !$role && $current_role ? $current_role : $role; /* Use existing Role? */ $role = !$role ? get_option("default_role") : $role; /* Otherwise default. */ /**/ $level = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_level"]; $level = !$level && preg_match("/^(administrator|editor|author|contributor)\$/i", $role) ? $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"] : $level; $level = !$level && preg_match("/^optimizemember_level[1-9][0-9]*\$/i", $role) ? preg_replace("/^optimizemember_level/", "", $role) : $level; $level = !$level && preg_match("/^subscriber\$/i", $role) ? "0" : $level; $level = !$level ? "0" : $level; /**/ $ccaps = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_ccaps"]; /**/ $email = $user->user_email; $login = $user->user_login; $ip = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_registration_ip"]; $custom = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_custom"]; $subscr_id = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_id"]; $subscr_gateway = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_subscr_gateway"]; $cv = preg_split("/\\|/", (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_custom"]); /**/ $auto_eot_time = ($eot = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_auto_eot_time"]) ? strtotime($eot) : ""; $notes = (string) @$_pmr["ws_plugin__optimizemember_custom_reg_field_optimizemember_notes"]; /**/ $opt_in = !empty($_pmr["ws_plugin__optimizemember_custom_reg_field_opt_in"]) ? true : false; /**/ if (!($fname = $user->first_name)) { /* `Users -> Add New`. */ if (!empty($_pmr["ws_plugin__optimizemember_custom_reg_field_first_name"])) { $fname = (string) $_pmr["ws_plugin__optimizemember_custom_reg_field_first_name"]; } } /**/ if (!($lname = $user->last_name)) { /* `Users -> Add New`. */ if (!empty($_pmr["ws_plugin__optimizemember_custom_reg_field_last_name"])) { $lname = (string) $_pmr["ws_plugin__optimizemember_custom_reg_field_last_name"]; } } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_names"] && !$fname) { if ($login) { /* Username and empty Last Name. */ eval('$fname = trim ($login); $lname = "";'); } } /**/ $name = trim($fname . " " . $lname); /* Both names. */ /**/ if (!($pass = $password)) { /* Try optimizeMember's generator. */ if (!empty($GLOBALS["ws_plugin__optimizemember_generate_password_return"])) { $pass = (string) $GLOBALS["ws_plugin__optimizemember_generate_password_return"]; } } /**/ if (!$pass) { /* Also try the `Users -> Add New` form. */ if (!empty($_pmr["pass1"])) { /* Field in `/user-new.php`. */ $pass = (string) $_pmr["pass1"]; } } /**/ if ($pass) { !headers_sent() ? delete_user_setting("default_password_nag", $user_id) : null; update_user_option($user_id, "default_password_nag", false, true); } /**/ update_user_option($user_id, "optimizemember_registration_ip", $ip); update_user_option($user_id, "optimizemember_auto_eot_time", $auto_eot_time); update_user_option($user_id, "optimizemember_subscr_gateway", $subscr_gateway); update_user_option($user_id, "optimizemember_subscr_id", $subscr_id); update_user_option($user_id, "optimizemember_custom", $custom); update_user_option($user_id, "optimizemember_notes", $notes); /**/ if (!$user->first_name && $fname) { update_user_meta($user_id, "first_name", $fname); } /**/ if (!$user->last_name && $lname) { update_user_meta($user_id, "last_name", $lname); } /**/ if (!$user->display_name || $user->display_name === $user->user_login) { if ($custom_reg_display_name === "full" && $name) { wp_update_user(array("ID" => $user_id, "display_name" => $name)); } else { if ($custom_reg_display_name === "first" && $fname) { wp_update_user(array("ID" => $user_id, "display_name" => $fname)); } else { if ($custom_reg_display_name === "last" && $lname) { wp_update_user(array("ID" => $user_id, "display_name" => $lname)); } else { if ($custom_reg_display_name === "login" && $login) { wp_update_user(array("ID" => $user_id, "display_name" => $login)); } } } } } /**/ if (is_multisite()) { if (!is_main_site() && strtotime($user->user_registered) >= strtotime("-10 seconds")) { remove_user_from_blog($user_id, $current_site->blog_id); } /* No Main Site Role. */ /**/ if (!get_user_meta($user_id, "optimizemember_originating_blog", true)) { /* Recorded yet? */ update_user_meta($user_id, "optimizemember_originating_blog", $current_blog->blog_id); } } /**/ if ($current_role !== $role) { /* Only if NOT the current Role. */ $user->set_role($role); } /* optimizeMember. */ /**/ if ($ccaps && preg_match("/^-all/", str_replace("+", "", $ccaps))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_optimizemember_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } } /**/ if ($ccaps && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_optimizemember_ccap_" . $ccap); } } } /**/ if (!($fields = array()) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_fields"]) { foreach (json_decode($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_fields"], true) as $field) { $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"])); $field_id_class = preg_replace("/_/", "-", $field_var); /**/ if (isset($_pmr["ws_plugin__optimizemember_custom_reg_field_" . $field_var])) { $fields[$field_var] = $_pmr["ws_plugin__optimizemember_custom_reg_field_" . $field_var]; } } } /**/ if (!empty($fields)) { /* Only if NOT empty. */ update_user_option($user_id, "optimizemember_custom_fields", $fields); } /**/ if ($level > 0) { $pr_times = get_user_option("optimizemember_paid_registration_times", $user_id); $pr_times["level"] = empty($pr_times["level"]) ? time() : $pr_times["level"]; $pr_times["level" . $level] = empty($pr_times["level" . $level]) ? time() : $pr_times["level" . $level]; update_user_option($user_id, "optimizemember_paid_registration_times", $pr_times); /* Update now. */ } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_configure_user_registration_admin_side", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } } } /**/ if ($processed === "yes") { if ($urls = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["registration_notification_urls"]) { /**/ foreach (preg_split("/[\r\n\t]+/", $urls) as $url) { /* Notify each of the URLs. */ /**/ if ($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) { if ($url = preg_replace("/%%role%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($role)), $url)) { if ($url = preg_replace("/%%level%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($level)), $url)) { if ($url = preg_replace("/%%ccaps%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($ccaps)), $url)) { if ($url = preg_replace("/%%auto_eot_time%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($auto_eot_time)), $url)) { if ($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($fname)), $url)) { if ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($lname)), $url)) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($name)), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($login)), $url)) { if ($url = preg_replace("/%%user_pass%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($pass)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($user_id)), $url)) { foreach ($fields as $var => $val) { /* Custom Fields. */ if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode(maybe_serialize($val))), $url))) { break; } } /**/ if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__optimizemember_utils_urls::remote($url); } } } } } } } } } } } } } } } } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["registration_notification_recipients"]) { $email_configs_were_on = c_ws_plugin__optimizemember_email_configs::email_config_status(); c_ws_plugin__optimizemember_email_configs::email_config_release(); /**/ $msg = $sbj = "( optimizeMember / API Notification Email ) - Registration"; $msg .= "\n\n"; /* Spacing in the message body. */ /**/ $msg .= "role: %%role%%\n"; $msg .= "level: %%level%%\n"; $msg .= "ccaps: %%ccaps%%\n"; $msg .= "auto_eot_time: %%auto_eot_time%%\n"; $msg .= "user_first_name: %%user_first_name%%\n"; $msg .= "user_last_name: %%user_last_name%%\n"; $msg .= "user_full_name: %%user_full_name%%\n"; $msg .= "user_email: %%user_email%%\n"; $msg .= "user_login: %%user_login%%\n"; $msg .= "user_pass: %%user_pass%%\n"; $msg .= "user_ip: %%user_ip%%\n"; $msg .= "user_id: %%user_id%%\n"; /**/ foreach ($fields as $var => $val) { $msg .= $var . ": %%" . $var . "%%\n"; } /**/ $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; /**/ if ($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) { if ($msg = preg_replace("/%%role%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($role), $msg)) { if ($msg = preg_replace("/%%level%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($level), $msg)) { if ($msg = preg_replace("/%%ccaps%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($ccaps), $msg)) { if ($msg = preg_replace("/%%auto_eot_time%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($auto_eot_time), $msg)) { if ($msg = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($fname), $msg)) { if ($msg = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($lname), $msg)) { if ($msg = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($name), $msg)) { if ($msg = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($email), $msg)) { if ($msg = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($login), $msg)) { if ($msg = preg_replace("/%%user_pass%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($pass), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($ip), $msg)) { if ($msg = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs($user_id), $msg)) { foreach ($fields as $var => $val) { /* Custom Fields. */ if (!($msg = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(maybe_serialize($val)), $msg))) { break; } } /**/ if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { /* Still have a ``$sbj`` and a ``$msg``? */ /**/ foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["registration_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__optimizemember_registration_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_registration_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=utf-8"); } } } } } } } } } } } } } } } /**/ if ($email_configs_were_on) { /* Back on? */ c_ws_plugin__optimizemember_email_configs::email_config(); } } /**/ if (!empty($GLOBALS["ws_plugin__optimizemember_registration_return_url"]) && ($url = $GLOBALS["ws_plugin__optimizemember_registration_return_url"])) { /**/ if ($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) { if ($url = preg_replace("/%%role%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($role)), $url)) { if ($url = preg_replace("/%%level%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($level)), $url)) { if ($url = preg_replace("/%%ccaps%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($ccaps)), $url)) { if ($url = preg_replace("/%%auto_eot_time%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($auto_eot_time)), $url)) { if ($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($fname)), $url)) { if ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($lname)), $url)) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($name)), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($login)), $url)) { if ($url = preg_replace("/%%user_pass%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($pass)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($user_id)), $url)) { foreach ($fields as $var => $val) { /* Custom Fields. */ if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode(maybe_serialize($val))), $url))) { break; } } /**/ if ($url = trim($url)) { /* Preserve remaining Replacements; because the parent routine may perform replacements too. */ $GLOBALS["ws_plugin__optimizemember_registration_return_url"] = $url; } } } } } } } } } } } } } } } /**/ c_ws_plugin__optimizemember_list_servers::process_list_servers($role, $level, $login, $pass, $email, $fname, $lname, $ip, $opt_in, true, $user_id); /* Suppress errors here in case this routine is fired in unexpected locations; or with odd output buffering techniques. @todo It may also be impossible to delete cookies when fired inside: `/wp-activate.php`. */ if (!headers_sent()) { @setcookie("optimizemember_subscr_gateway", "", time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie("optimizemember_subscr_gateway", "", time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); @setcookie("optimizemember_subscr_id", "", time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie("optimizemember_subscr_id", "", time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); @setcookie("optimizemember_custom", "", time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie("optimizemember_custom", "", time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); @setcookie("optimizemember_item_number", "", time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie("optimizemember_item_number", "", time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_configure_user_registration", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } } } } } } } } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_after_configure_user_registration", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ return; /* Return for uniformity. */ }
/** * Handles processing of Pro Forms for Specific Post/Page checkout. * * @package optimizeMember\PayPal * @since 1.5 * * @attaches-to ``add_action("init");`` * * @return null Or exits script execution after a custom URL redirection; or upon Express Checkout redirection. */ public static function sp_checkout() { if (!empty($_POST["optimizemember_pro_paypal_sp_checkout"]["nonce"]) && ($nonce = $_POST["optimizemember_pro_paypal_sp_checkout"]["nonce"]) && wp_verify_nonce($nonce, "s2member-pro-paypal-sp-checkout") || !empty($_GET["optimizemember_paypal_xco"]) && $_GET["optimizemember_paypal_xco"] === "optimizemember_pro_paypal_sp_checkout_return" && !empty($_GET["token"]) && ($_GET["token"] = esc_html($_GET["token"])) && (empty($_GET["PayerID"]) || ($_GET["PayerID"] = esc_html($_GET["PayerID"]))) && ($xco_post_vars = get_transient("s2m_" . md5("optimizemember_transient_express_checkout_" . $_GET["token"])))) { $GLOBALS["ws_plugin__optimizemember_pro_paypal_sp_checkout_response"] = array(); /* This holds the global response details. */ $global_response =& $GLOBALS["ws_plugin__optimizemember_pro_paypal_sp_checkout_response"]; /* This is a shorter reference. */ /**/ $post_vars = $xco_post_vars ? $xco_post_vars : $_POST["optimizemember_pro_paypal_sp_checkout"]; $post_vars = c_ws_plugin__optimizemember_utils_strings::trim_deep(stripslashes_deep($post_vars)); $post_vars["attr"] = !$xco_post_vars ? unserialize(c_ws_plugin__optimizemember_utils_encryption::decrypt($post_vars["attr"])) : $post_vars["attr"]; $post_vars["attr"] = !$xco_post_vars ? apply_filters("ws_plugin__optimizemember_pro_paypal_sp_checkout_post_attr", $post_vars["attr"], get_defined_vars()) : $post_vars["attr"]; /**/ if ($xco_post_vars) { /* No need to re-validate this upon return from Express Checkout. */ $post_vars["attr"]["captcha"] = "0"; } /**/ $post_vars["recaptcha_challenge_field"] = !$post_vars["recaptcha_challenge_field"] ? trim(stripslashes($_POST["recaptcha_challenge_field"])) : $post_vars["recaptcha_challenge_field"]; $post_vars["recaptcha_response_field"] = !$post_vars["recaptcha_response_field"] ? trim(stripslashes($_POST["recaptcha_response_field"])) : $post_vars["recaptcha_response_field"]; /**/ $post_vars["name"] = trim($post_vars["first_name"] . " " . $post_vars["last_name"]); $post_vars["email"] = apply_filters("user_registration_email", sanitize_email($post_vars["email"]), get_defined_vars()); /**/ !empty($_GET["token"]) ? delete_transient("s2m_" . md5("optimizemember_transient_express_checkout_" . $_GET["token"])) : null; /**/ if (!c_ws_plugin__optimizemember_pro_paypal_responses::paypal_form_attr_validation_errors($post_vars["attr"])) { if (!($error = c_ws_plugin__optimizemember_pro_paypal_responses::paypal_form_submission_validation_errors("sp-checkout", $post_vars))) { $cp_attr = c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_apply_coupon($post_vars["attr"], $post_vars["coupon"], "attr", array("affiliates-silent-post")); $cp_2gbp_attr = c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_maestro_solo_2gbp($cp_attr, $post_vars["card_type"]); $cost_calculations = c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_cost(null, $cp_2gbp_attr["ra"], $post_vars["state"], $post_vars["country"], $post_vars["zip"], $cp_2gbp_attr["cc"], $cp_2gbp_attr["desc"]); /**/ if (empty($_GET["optimizemember_paypal_xco"]) && $post_vars["card_type"] === "PayPal") { $return_url = $cancel_url = is_ssl() ? "https://" : "http://"; $return_url = $cancel_url = ($return_url = $cancel_url) . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; $return_url = $cancel_url = remove_query_arg(array("token", "PayerID"), $return_url = $cancel_url); $return_url = add_query_arg("optimizemember_paypal_xco", urlencode("optimizemember_pro_paypal_sp_checkout_return"), $return_url); $cancel_url = add_query_arg("optimizemember_paypal_xco", urlencode("optimizemember_pro_paypal_sp_checkout_cancel"), $cancel_url); /**/ $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID) ? $user : false; /**/ $post_vars["attr"]["invoice"] = uniqid() . "~" . $_SERVER["REMOTE_ADDR"]; /* Unique invoice w/ IP address too. */ /**/ if (!($paypal_set_xco = array())) { $paypal_set_xco["METHOD"] = "SetExpressCheckout"; /**/ $paypal_set_xco["RETURNURL"] = $return_url; $paypal_set_xco["CANCELURL"] = $cancel_url; /**/ $paypal_set_xco["PAGESTYLE"] = $post_vars["attr"]["ps"]; $paypal_set_xco["LOCALECODE"] = $post_vars["attr"]["lc"]; $paypal_set_xco["NOSHIPPING"] = $post_vars["attr"]["ns"]; $paypal_set_xco["SOLUTIONTYPE"] = "Sole"; $paypal_set_xco["LANDINGPAGE"] = "Billing"; $paypal_set_xco["ALLOWNOTE"] = "0"; /**/ $paypal_set_xco["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; $paypal_set_xco["MAXAMT"] = $cost_calculations["total"]; /**/ $paypal_set_xco["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"]; $paypal_set_xco["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"]; $paypal_set_xco["PAYMENTREQUEST_0_INVNUM"] = $post_vars["attr"]["invoice"]; /**/ $paypal_set_xco["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"]; $paypal_set_xco["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"]; $paypal_set_xco["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"]; $paypal_set_xco["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"]; /**/ $paypal_set_xco["L_PAYMENTREQUEST_0_QTY0"] = "1"; /* Always (1). */ $paypal_set_xco["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"]; $paypal_set_xco["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["sp_ids_exp"]; $paypal_set_xco["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"]; /**/ $paypal_set_xco["PAYMENTREQUEST_0_SHIPTONAME"] = $post_vars["name"]; $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOSTREET"] = $post_vars["street"]; $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOCITY"] = $post_vars["city"]; $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOSTATE"] = $post_vars["state"]; $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE"] = $post_vars["country"]; $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOZIP"] = $post_vars["zip"]; /**/ $paypal_set_xco["EMAIL"] = $post_vars["email"]; } /**/ if (($paypal_set_xco = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal_set_xco)) && empty($paypal_set_xco["__error"])) { set_transient("s2m_" . md5("optimizemember_transient_express_checkout_" . $paypal_set_xco["TOKEN"]), $post_vars, 10800); /**/ $endpoint = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["paypal_sandbox"] ? "www.sandbox.paypal.com" : "www.paypal.com"; /**/ wp_redirect(add_query_arg("token", urlencode($paypal_set_xco["TOKEN"]), "https://" . $endpoint . "/cgi-bin/webscr?cmd=_express-checkout")); /**/ exit; /* Clean exit. */ } else { $global_response = array("response" => $paypal_set_xco["__error"], "error" => true); } } else { if (empty($post_vars["attr"]["invoice"])) { /* Only if it's empty. */ $post_vars["attr"]["invoice"] = uniqid() . "~" . $_SERVER["REMOTE_ADDR"]; } /**/ if (!($paypal = array())) { if ($_GET["optimizemember_paypal_xco"] === "optimizemember_pro_paypal_sp_checkout_return" && !empty($_GET["token"]) && ($paypal_xco_details = array("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($paypal_xco_details = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal_xco_details)) && empty($paypal_xco_details["__error"])) { $paypal["METHOD"] = "DoExpressCheckoutPayment"; /**/ $paypal["TOKEN"] = $paypal_xco_details["TOKEN"]; $paypal["PAYERID"] = $paypal_xco_details["PAYERID"]; /**/ $paypal["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; /**/ $paypal["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"]; $paypal["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"]; $paypal["PAYMENTREQUEST_0_INVNUM"] = $post_vars["attr"]["invoice"]; /**/ $paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"]; $paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"]; $paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"]; $paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"]; /**/ $paypal["L_PAYMENTREQUEST_0_QTY0"] = "1"; /* Always (1). */ $paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"]; $paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["sp_ids_exp"]; $paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"]; } else { $paypal["METHOD"] = "DoDirectPayment"; $paypal["PAYMENTACTION"] = "Sale"; /**/ $paypal["EMAIL"] = $post_vars["email"]; $paypal["FIRSTNAME"] = $post_vars["first_name"]; $paypal["LASTNAME"] = $post_vars["last_name"]; $paypal["IPADDRESS"] = $_SERVER["REMOTE_ADDR"]; /**/ $paypal["DESC"] = $cost_calculations["desc"]; $paypal["CUSTOM"] = $post_vars["attr"]["custom"]; $paypal["INVNUM"] = $post_vars["attr"]["invoice"]; /**/ $paypal["CURRENCYCODE"] = $cost_calculations["cur"]; $paypal["ITEMAMT"] = $cost_calculations["sub_total"]; $paypal["TAXAMT"] = $cost_calculations["tax"]; $paypal["AMT"] = $cost_calculations["total"]; /**/ $paypal["L_QTY0"] = "1"; /* Always (1). */ $paypal["L_NAME0"] = $cost_calculations["desc"]; $paypal["L_NUMBER0"] = $post_vars["attr"]["sp_ids_exp"]; $paypal["L_AMT0"] = $cost_calculations["sub_total"]; /**/ $paypal["CREDITCARDTYPE"] = $post_vars["card_type"]; $paypal["ACCT"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]); $paypal["EXPDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_expiration"]); $paypal["CVV2"] = $post_vars["card_verification"]; /**/ if (in_array($post_vars["card_type"], array("Maestro", "Solo"))) { if (preg_match("/^[0-9]{2}\\/[0-9]{4}\$/", $post_vars["card_start_date_issue_number"])) { $paypal["STARTDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]); } else { /* Otherwise, we assume they provided an Issue Number instead. */ $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"]; } } /**/ $paypal["STREET"] = $post_vars["street"]; $paypal["CITY"] = $post_vars["city"]; $paypal["STATE"] = $post_vars["state"]; $paypal["COUNTRYCODE"] = $post_vars["country"]; $paypal["ZIP"] = $post_vars["zip"]; } } /**/ if (($paypal = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal)) && empty($paypal["__error"])) { $new__txn_id = !empty($paypal["PAYMENTINFO_0_TRANSACTIONID"]) ? $paypal["PAYMENTINFO_0_TRANSACTIONID"] : false; $new__txn_id = !$new__txn_id && !empty($paypal["TRANSACTIONID"]) ? $paypal["TRANSACTIONID"] : $new__txn_id; /**/ if (!($ipn = array())) { $ipn["txn_type"] = "web_accept"; $ipn["txn_id"] = $new__txn_id; $ipn["custom"] = $post_vars["attr"]["custom"]; $ipn["invoice"] = $post_vars["attr"]["invoice"]; /**/ $ipn["mc_gross"] = $cost_calculations["total"]; $ipn["mc_currency"] = $cost_calculations["cur"]; $ipn["tax"] = $cost_calculations["tax"]; /**/ $ipn["payer_email"] = $post_vars["email"]; $ipn["first_name"] = $post_vars["first_name"]; $ipn["last_name"] = $post_vars["last_name"]; /**/ if (is_user_logged_in() && ($referencing = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id())) { $ipn["option_name1"] = "Referencing Customer ID"; $ipn["option_selection1"] = $referencing; } else { $ipn["option_name1"] = "Originating Domain"; $ipn["option_selection1"] = $_SERVER["HTTP_HOST"]; } /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"]; /**/ $ipn["item_name"] = $cost_calculations["desc"]; $ipn["item_number"] = $post_vars["attr"]["sp_ids_exp"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=paypal&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); $ipn_q .= "&optimizemember_paypal_proxy_return_url=" . rawurlencode($post_vars["attr"]["success"]); /**/ $ipn["optimizemember_paypal_proxy_return_url"] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20))); } /**/ if ($sp_access_url = c_ws_plugin__optimizemember_sp_access::sp_access_link_gen($post_vars["attr"]["ids"], $post_vars["attr"]["exp"])) { setcookie("optimizemember_sp_tracking", $optimizemember_sp_tracking = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__txn_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie("optimizemember_sp_tracking", $optimizemember_sp_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE["optimizemember_sp_tracking"] = $optimizemember_sp_tracking); /**/ $global_response = array("response" => sprintf(_x('<strong>Thank you.</strong> Your purchase has been approved.<br />— Please <a href="%s" rel="nofollow">click here</a> to proceed.', "s2member-front", "s2member"), esc_attr($sp_access_url))); /**/ if ($post_vars["attr"]["success"] && substr($ipn["optimizemember_paypal_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["optimizemember_paypal_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } else { $global_response = array("response" => _x('<strong>Oops.</strong> Unable to generate Access Link. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true); } } else { $global_response = array("response" => $paypal["__error"], "error" => true); } } } else { $global_response = $error; } } } }
/** * Handles ClickBank® IPN URL processing. * * @package optimizeMember\ClickBank * @since 1.5 * * @attaches-to ``add_action("init");`` * * @return null Or exits script execution after handling the Notification. */ public static function clickbank_notify() { global $current_site, $current_blog; if (!empty($_GET["optimizemember_pro_clickbank_notify"]) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_clickbank_username"]) { @ignore_user_abort(true); // Continue processing even if/when connection is broken by the sender. if (is_array($clickbank = c_ws_plugin__optimizemember_pro_clickbank_utilities::clickbank_postvars()) && ($_clickbank = $clickbank)) { $clickbank["optimizemember_log"][] = "IPN received on: " . date("D M j, Y g:i:s a T"); $clickbank["optimizemember_log"][] = "optimizeMember POST vars verified with ClickBank®."; $s2vars = c_ws_plugin__optimizemember_pro_clickbank_utilities::clickbank_parse_s2vars($clickbank["cvendthru"], $clickbank["ctransaction"]); if (isset($s2vars["s2_p1"], $s2vars["s2_p3"]) && $s2vars["s2_p1"] === "0 D") { $s2vars["s2_p1"] = $s2vars["s2_p3"]; } $clickbank["s2vars"] = $s2vars; if (strcasecmp($clickbank["ccustfirstname"] . " " . $clickbank["ccustlastname"], $clickbank["ccustfullname"]) !== 0 && preg_match("/(?:[^ ]+)(?: +)(?:[^ ]+)/", $clickbank["ccustfullname"])) { list($clickbank["ccustfirstname"], $clickbank["ccustlastname"]) = preg_split("/ +/", $clickbank["ccustfullname"], 2); } if (preg_match("/^(?:TEST_)?SALE\$/i", $clickbank["ctransaction"]) && preg_match("/^STANDARD\$/i", $clickbank["cprodtype"])) { $clickbank["optimizemember_log"][] = "ClickBank® transaction identified as ( `SALE/STANDARD` )."; $clickbank["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal® processor as `txn_type` ( `web_accept` )."; $clickbank["optimizemember_log"][] = "Please check PayPal® IPN logs for further processing details."; $processing = $processed = true; $ipn = array(); // Reset. $ipn["txn_type"] = "web_accept"; $ipn["txn_id"] = $clickbank["ctransreceipt"]; $ipn["custom"] = $s2vars["s2_custom"]; $ipn["mc_gross"] = number_format($clickbank["corderamount"] / 100, 2, ".", ""); $ipn["mc_currency"] = strtoupper($clickbank["ccurrency"]); $ipn["tax"] = number_format("0.00", 2, ".", ""); $ipn["payer_email"] = $clickbank["ccustemail"]; $ipn["first_name"] = ucwords(strtolower($clickbank["ccustfirstname"])); $ipn["last_name"] = ucwords(strtolower($clickbank["ccustlastname"])); $ipn["option_name1"] = $s2vars["s2_referencing"] ? "Referencing Customer ID" : "Originating Domain"; $ipn["option_selection1"] = $s2vars["s2_referencing"] ? $s2vars["s2_referencing"] : $_SERVER["HTTP_HOST"]; $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $s2vars["s2_customer_ip"]; $ipn["item_number"] = $s2vars["s2_invoice"]; $ipn["item_name"] = $s2vars["s2_desc"]; $ipn["optimizemember_paypal_proxy"] = "clickbank"; $ipn["optimizemember_paypal_proxy_use"] = "standard-emails"; $ipn["optimizemember_paypal_proxy_verification"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1"), $ipn, array("timeout" => 20)); } else { if (preg_match("/^(?:TEST_)?SALE\$/i", $clickbank["ctransaction"]) && preg_match("/^RECURRING\$/i", $clickbank["cprodtype"])) { $clickbank["optimizemember_log"][] = "ClickBank® transaction identified as ( `SALE/RECURRING` )."; $clickbank["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal® processor as `txn_type` ( `subscr_signup` )."; $clickbank["optimizemember_log"][] = "Please check PayPal® IPN logs for further processing details."; $processing = $processed = true; $ipn = array(); // Reset. $ipn["txn_type"] = "subscr_signup"; $ipn["subscr_id"] = $s2vars["s2_subscr_id"]; $ipn["recurring"] = $clickbank["cfuturepayments"] > 1 ? "1" : "0"; $ipn["txn_id"] = $clickbank["ctransreceipt"]; $ipn["custom"] = $s2vars["s2_custom"]; $ipn["period1"] = $s2vars["s2_p1"]; $ipn["period3"] = $s2vars["s2_p3"]; $ipn["mc_amount1"] = number_format($clickbank["corderamount"] / 100, 2, ".", ""); $ipn["mc_amount3"] = number_format($clickbank["crebillamnt"] / 100, 2, ".", ""); $ipn["mc_gross"] = preg_match("/^[1-9]/", $ipn["period1"]) ? $ipn["mc_amount1"] : $ipn["mc_amount3"]; $ipn["mc_currency"] = strtoupper($clickbank["ccurrency"]); $ipn["tax"] = number_format("0.00", 2, ".", ""); $ipn["payer_email"] = $clickbank["ccustemail"]; $ipn["first_name"] = ucwords(strtolower($clickbank["ccustfirstname"])); $ipn["last_name"] = ucwords(strtolower($clickbank["ccustlastname"])); $ipn["option_name1"] = $s2vars["s2_referencing"] ? "Referencing Customer ID" : "Originating Domain"; $ipn["option_selection1"] = $s2vars["s2_referencing"] ? $s2vars["s2_referencing"] : $_SERVER["HTTP_HOST"]; $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $s2vars["s2_customer_ip"]; $ipn["item_number"] = $s2vars["s2_invoice"]; $ipn["item_name"] = $s2vars["s2_desc"]; $ipn["optimizemember_paypal_proxy"] = "clickbank"; $ipn["optimizemember_paypal_proxy_use"] = "standard-emails"; $ipn["optimizemember_paypal_proxy_use"] .= $ipn["mc_gross"] > 0 ? ",subscr-signup-as-subscr-payment" : ""; $ipn["optimizemember_paypal_proxy_verification"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1"), $ipn, array("timeout" => 20)); } else { if (preg_match("/^(?:TEST_)?BILL\$/i", $clickbank["ctransaction"]) && preg_match("/^RECURRING\$/i", $clickbank["cprodtype"])) { $clickbank["optimizemember_log"][] = "ClickBank® transaction identified as ( `BILL/RECURRING` )."; $clickbank["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal® processor as `txn_type` ( `subscr_payment` )."; $clickbank["optimizemember_log"][] = "Please check PayPal® IPN logs for further processing details."; $processing = $processed = true; $ipn = array(); // Reset. $ipn["txn_type"] = "subscr_payment"; $ipn["subscr_id"] = $s2vars["s2_subscr_id"]; $ipn["txn_id"] = $clickbank["ctransreceipt"]; $ipn["custom"] = $s2vars["s2_custom"]; $ipn["mc_gross"] = number_format($clickbank["corderamount"] / 100, 2, ".", ""); $ipn["mc_currency"] = strtoupper($clickbank["ccurrency"]); $ipn["tax"] = number_format("0.00", 2, ".", ""); $ipn["payer_email"] = $clickbank["ccustemail"]; $ipn["first_name"] = ucwords(strtolower($clickbank["ccustfirstname"])); $ipn["last_name"] = ucwords(strtolower($clickbank["ccustlastname"])); $ipn["option_name1"] = $s2vars["s2_referencing"] ? "Referencing Customer ID" : "Originating Domain"; $ipn["option_selection1"] = $s2vars["s2_referencing"] ? $s2vars["s2_referencing"] : $_SERVER["HTTP_HOST"]; $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $s2vars["s2_customer_ip"]; $ipn["item_number"] = $s2vars["s2_invoice"]; $ipn["item_name"] = $s2vars["s2_desc"]; $ipn["optimizemember_paypal_proxy"] = "clickbank"; $ipn["optimizemember_paypal_proxy_use"] = "standard-emails"; $ipn["optimizemember_paypal_proxy_verification"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1"), $ipn, array("timeout" => 20)); } else { if (preg_match("/^(?:TEST_)?(?:RFND|CGBK|INSF)\$/i", $clickbank["ctransaction"])) { $clickbank["optimizemember_log"][] = "ClickBank® transaction identified as ( `RFND|CGBK|INSF` )."; $clickbank["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal® processor as `payment_status` ( `refunded|reversed` )."; $clickbank["optimizemember_log"][] = "Please check PayPal® IPN logs for further processing details."; $processing = $processed = true; $ipn = array(); // Reset. $ipn["payment_status"] = preg_match("/^(?:TEST_)?RFND\$/", $clickbank["ctransaction"]) ? "refunded" : "reversed"; $ipn["parent_txn_id"] = preg_match("/^RECURRING\$/i", $clickbank["cprodtype"]) && $s2vars["s2_subscr_id"] ? $s2vars["s2_subscr_id"] : $clickbank["ctransreceipt"]; $ipn["custom"] = $s2vars["s2_custom"]; $ipn["mc_fee"] = "-" . number_format("0.00", 2, ".", ""); $ipn["mc_gross"] = "-" . number_format(abs($clickbank["corderamount"]) / 100, 2, ".", ""); $ipn["mc_currency"] = strtoupper($clickbank["ccurrency"]); $ipn["tax"] = "-" . number_format("0.00", 2, ".", ""); $ipn["payer_email"] = $clickbank["ccustemail"]; $ipn["first_name"] = ucwords(strtolower($clickbank["ccustfirstname"])); $ipn["last_name"] = ucwords(strtolower($clickbank["ccustlastname"])); $ipn["option_name1"] = $s2vars["s2_referencing"] ? "Referencing Customer ID" : "Originating Domain"; $ipn["option_selection1"] = $s2vars["s2_referencing"] ? $s2vars["s2_referencing"] : $_SERVER["HTTP_HOST"]; $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $s2vars["s2_customer_ip"]; $ipn["item_number"] = $s2vars["s2_invoice"]; $ipn["item_name"] = $s2vars["s2_desc"]; $ipn["optimizemember_paypal_proxy"] = "clickbank"; $ipn["optimizemember_paypal_proxy_use"] = "standard-emails"; $ipn["optimizemember_paypal_proxy_verification"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1"), $ipn, array("timeout" => 20)); } } } } if (preg_match("/^(?:TEST_)?(?:SALE|BILL)\$/i", $clickbank["ctransaction"]) && preg_match("/^RECURRING\$/i", $clickbank["cprodtype"]) && (preg_match("/^COMPLETED\$/i", $clickbank["crebillstatus"]) || $clickbank["cfuturepayments"] <= 0) || preg_match("/^(?:TEST_)?CANCEL-REBILL\$/i", $clickbank["ctransaction"]) && preg_match("/^RECURRING\$/i", $clickbank["cprodtype"])) { $clickbank["optimizemember_log"][] = "ClickBank® transaction identified as ( `RECURRING/COMPLETED` or `CANCEL-REBILL` )."; $clickbank["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal® processor as `txn_type` ( `subscr_cancel` )."; $clickbank["optimizemember_log"][] = "Please check PayPal® IPN logs for further processing details."; $processing = $processed = true; $ipn = array(); // Reset. $ipn["txn_type"] = "subscr_cancel"; $ipn["subscr_id"] = $s2vars["s2_subscr_id"]; $ipn["custom"] = $s2vars["s2_custom"]; $ipn["period1"] = $s2vars["s2_p1"]; $ipn["period3"] = $s2vars["s2_p3"]; $ipn["payer_email"] = $clickbank["ccustemail"]; $ipn["first_name"] = ucwords(strtolower($clickbank["ccustfirstname"])); $ipn["last_name"] = ucwords(strtolower($clickbank["ccustlastname"])); $ipn["option_name1"] = $s2vars["s2_referencing"] ? "Referencing Customer ID" : "Originating Domain"; $ipn["option_selection1"] = $s2vars["s2_referencing"] ? $s2vars["s2_referencing"] : $_SERVER["HTTP_HOST"]; $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $s2vars["s2_customer_ip"]; $ipn["item_number"] = $s2vars["s2_invoice"]; $ipn["item_name"] = $s2vars["s2_desc"]; $ipn["optimizemember_paypal_proxy"] = "clickbank"; $ipn["optimizemember_paypal_proxy_use"] = "standard-emails"; $ipn["optimizemember_paypal_proxy_verification"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1"), $ipn, array("timeout" => 20)); } if (!$processed) { // If nothing was processed, here we add a message to the logs indicating the IPN was ignored. $clickbank["optimizemember_log"][] = "Ignoring this IPN request. The transaction does NOT require any action on the part of optimizeMember."; } } else { $clickbank["optimizemember_log"][] = "Unable to verify POST vars. This is most likely related to an invalid ClickBank® configuration. Please check: optimizeMember -› ClickBank® Options."; $clickbank["optimizemember_log"][] = "If you're absolutely SURE that your ClickBank® configuration is valid, you may want to run some tests on your server, just to be sure \$_POST variables are populated, and that your server is able to connect to ClickBank® over an HTTPS connection."; $clickbank["optimizemember_log"][] = "optimizeMember uses the WP_Http class for remote connections; which will try to use cURL first, and then fall back on the FOPEN method when cURL is not available. On a Windows® server, you may have to disable your cURL extension. Instead, set allow_url_fopen = yes in your php.ini file. The cURL extension (usually) does NOT support SSL connections on a Windows® server."; $clickbank["optimizemember_log"][] = var_export($_REQUEST, true); // Recording _POST + _GET vars for analysis and debugging. } /* If debugging/logging is enabled; we need to append $clickbank to the log file. Logging now supports Multisite Networking as well. */ $logt = c_ws_plugin__optimizemember_utilities::time_details(); $logv = c_ws_plugin__optimizemember_utilities::ver_details(); $logm = c_ws_plugin__optimizemember_utilities::mem_details(); $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; $log4 = is_multisite() && !is_main_site() ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; $log2 = is_multisite() && !is_main_site() ? "clickbank-ipn-4-" . trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "clickbank-ipn.log"; if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["gateway_debug_logs"]) { if (is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["logs_dir"])) { if (is_writable($logs_dir) && c_ws_plugin__optimizemember_utils_logs::archive_oversize_log_files()) { file_put_contents($logs_dir . "/" . $log2, "LOG ENTRY: " . $logt . "\n" . $logv . "\n" . $logm . "\n" . $log4 . "\n" . c_ws_plugin__optimizemember_utils_logs::conceal_private_info(var_export($clickbank, true)) . "\n\n", FILE_APPEND); } } } status_header(200); // Send a 200 OK status header. header("Content-Type: text/plain; charset=UTF-8"); // Content-Type text/plain with UTF-8. while (@ob_end_clean()) { } // Clean any existing output buffers. exit; // Exit now. } }
/** * Processed by WP_Cron; this handles Auto-EOTs *( EOT = End Of Term )*. * * If you have a HUGE userbase, increase the max EOTs per process. * But NOTE, this runs ``$per_process`` *( per Blog )* on a Multisite Network. * To increase, use: ``add_filter ("ws_plugin__optimizemember_auto_eot_system_per_process");``. * * This function makes an important Hook available: `ws_plugin__optimizemember_after_auto_eot_system`. * This Hook is used by some of optimizeMember Pro's Gateway integrations; allowing CRON processing * to run for important communications; which poll Payment Gateway APIs for possible EOTs. * * @package optimizeMember\Auto_EOT_System * @since 3.5 * * @param int $per_process Number of database records to process each time. * Can also be Filtered with `ws_plugin__optimizemember_auto_eot_system_per_process`. * @return null */ public static function auto_eot_system($per_process = 3) { global $wpdb; /* Need global DB obj. */ global $current_site, $current_blog; /* Multisite. */ /**/ include_once ABSPATH . "wp-admin/includes/admin.php"; /**/ @set_time_limit(0); /* Make time for processing a larger userbase. */ @ini_set("memory_limit", apply_filters("admin_memory_limit", WP_MAX_MEMORY_LIMIT)); /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_before_auto_eot_system", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["auto_eot_system_enabled"]) { $per_process = apply_filters("ws_plugin__optimizemember_auto_eot_system_per_process", $per_process, get_defined_vars()); /**/ if (is_array($eots = $wpdb->get_results("SELECT `user_id` AS `ID` FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = '" . $wpdb->prefix . "optimizemember_auto_eot_time' AND `meta_value` != '' AND `meta_value` <= '" . $wpdb->escape(strtotime("now")) . "' LIMIT " . $per_process))) { foreach ($eots as $eot) { if (($user_id = $eot->ID) && is_object($user = new WP_User($user_id)) && $user->ID) { delete_user_option($user_id, "optimizemember_auto_eot_time"); /* Always delete. */ /**/ if (!$user->has_cap("administrator")) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_eot_behavior"] === "demote") { $eot_del_type = "auto-eot-cancellation-expiration-demotion"; /**/ $custom = get_user_option("optimizemember_custom", $user_id); $subscr_id = get_user_option("optimizemember_subscr_id", $user_id); $fields = get_user_option("optimizemember_custom_fields", $user_id); $user_reg_ip = get_user_option("optimizemember_registration_ip", $user_id); /**/ $demotion_role = c_ws_plugin__optimizemember_option_forces::force_demotion_role("subscriber"); $existing_role = c_ws_plugin__optimizemember_user_access::user_access_role($user); /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_auto_eot_system_during_before_demote", get_defined_vars()); do_action("ws_plugin__optimizemember_during_collective_mods", $user_id, get_defined_vars(), $eot_del_type, "modification", $demotion_role); do_action("ws_plugin__optimizemember_during_collective_eots", $user_id, get_defined_vars(), $eot_del_type, "modification"); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if ($existing_role !== $demotion_role) { /* Only if NOT the existing Role. */ $user->set_role($demotion_role); } /* Give User the demotion Role. */ /**/ foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_optimizemember_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } /**/ delete_user_option($user_id, "optimizemember_custom"); delete_user_option($user_id, "optimizemember_subscr_id"); delete_user_option($user_id, "optimizemember_subscr_gateway"); /**/ delete_user_option($user_id, "optimizemember_ipn_signup_vars"); if (!apply_filters("ws_plugin__optimizemember_preserve_paid_registration_times", true, get_defined_vars())) { delete_user_option($user_id, "optimizemember_paid_registration_times"); } /**/ delete_user_option($user_id, "optimizemember_last_status_scan"); delete_user_option($user_id, "optimizemember_first_payment_txn_id"); delete_user_option($user_id, "optimizemember_last_payment_time"); delete_user_option($user_id, "optimizemember_auto_eot_time"); /**/ delete_user_option($user_id, "optimizemember_file_download_access_log"); /**/ c_ws_plugin__optimizemember_user_notes::append_user_notes($user_id, "Demoted by optimizeMember: " . date("D M j, Y g:i a T")); /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["eot_del_notification_urls"] && is_array($cv = preg_split("/\\|/", $custom))) { foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["eot_del_notification_urls"]) as $url) { /* Handle EOT Notifications. */ /**/ if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%eot_del_type%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode("auto-eot-cancellation-expiration-demotion")), $url)) && ($url = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($subscr_id)), $url))) { if (($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->first_name)), $url)) && ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->last_name)), $url))) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($user->first_name . " " . $user->last_name))), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_login)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_reg_ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_id)), $url)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } } /**/ if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__optimizemember_utils_urls::remote($url); } } } } } } } } } } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["eot_del_notification_recipients"] && is_array($cv = preg_split("/\\|/", $custom))) { $email_configs_were_on = c_ws_plugin__optimizemember_email_configs::email_config_status(); c_ws_plugin__optimizemember_email_configs::email_config_release(); /**/ $msg = $sbj = "( optimizeMember / API Notification Email ) - EOT/Deletion"; $msg .= "\n\n"; /* Spacing in the message body. */ /**/ $msg .= "eot_del_type: %%eot_del_type%%\n"; $msg .= "subscr_id: %%subscr_id%%\n"; $msg .= "user_first_name: %%user_first_name%%\n"; $msg .= "user_last_name: %%user_last_name%%\n"; $msg .= "user_full_name: %%user_full_name%%\n"; $msg .= "user_email: %%user_email%%\n"; $msg .= "user_login: %%user_login%%\n"; $msg .= "user_ip: %%user_ip%%\n"; $msg .= "user_id: %%user_id%%\n"; /**/ if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { $msg .= $var . ": %%" . $var . "%%\n"; } } /**/ $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; /**/ if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%eot_del_type%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds("auto-eot-cancellation-expiration-demotion"), $msg)) && ($msg = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($subscr_id), $msg))) { if (($msg = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->first_name), $msg)) && ($msg = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->last_name), $msg))) { if ($msg = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($user->first_name . " " . $user->last_name)), $msg)) { if ($msg = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_email), $msg)) { if ($msg = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_login), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_reg_ip), $msg)) { if ($msg = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_id), $msg)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($msg = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(maybe_serialize($val)), $msg))) { break; } } } /**/ if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { /* Still have a ``$sbj`` and a ``$msg``? */ /**/ foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["eot_del_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__optimizemember_eot_del_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_eot_del_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=utf-8"); } } } } } } } } } /**/ if ($email_configs_were_on) { /* Back on? */ c_ws_plugin__optimizemember_email_configs::email_config(); } } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_auto_eot_system_during_demote", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_eot_behavior"] === "delete") { $eot_del_type = $GLOBALS["ws_plugin__optimizemember_eot_del_type"] = "auto-eot-cancellation-expiration-deletion"; /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_auto_eot_system_during_before_delete", get_defined_vars()); do_action("ws_plugin__optimizemember_during_collective_eots", $user_id, get_defined_vars(), $eot_del_type, "removal-deletion"); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if (is_multisite()) { remove_user_from_blog($user_id, $current_blog->blog_id); /* This will automatically trigger `eot_del_notification_urls` as well. */ c_ws_plugin__optimizemember_user_deletions::handle_ms_user_deletions($user_id, $current_blog->blog_id, "s2says"); } else { /* Otherwise, we can actually delete them. */ /* This will automatically trigger `eot_del_notification_urls` as well. */ wp_delete_user($user_id); } /* `c_ws_plugin__optimizemember_user_deletions::handle_user_deletions()` */ /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_auto_eot_system_during_delete", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_auto_eot_system", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } } } } } /**/ c_ws_plugin__optimizemember_utils_logs::cleanup_expired_s2m_transients(); /* Cleanup. */ /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_after_auto_eot_system", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ return; /* Return for uniformity. */ }
/** * Handles processing of Pro Form cancellations. * * @package optimizeMember\AuthNet * @since 1.5 * * @attaches-to ``add_action("init");`` * * @return null Or exits script execution after a custom URL redirection. */ public static function authnet_cancellation() { if (!empty($_POST["optimizemember_pro_authnet_cancellation"]["nonce"]) && ($nonce = $_POST["optimizemember_pro_authnet_cancellation"]["nonce"]) && wp_verify_nonce($nonce, "s2member-pro-authnet-cancellation")) { $GLOBALS["ws_plugin__optimizemember_pro_authnet_cancellation_response"] = array(); /* This holds the global response details. */ $global_response =& $GLOBALS["ws_plugin__optimizemember_pro_authnet_cancellation_response"]; /* This is a shorter reference. */ /**/ $post_vars = c_ws_plugin__optimizemember_utils_strings::trim_deep(stripslashes_deep($_POST["optimizemember_pro_authnet_cancellation"])); $post_vars["attr"] = unserialize(c_ws_plugin__optimizemember_utils_encryption::decrypt($post_vars["attr"])); /* And run a Filter. */ $post_vars["attr"] = apply_filters("ws_plugin__optimizemember_pro_authnet_cancellation_post_attr", $post_vars["attr"], get_defined_vars()); /**/ $post_vars["recaptcha_challenge_field"] = !$post_vars["recaptcha_challenge_field"] ? trim(stripslashes($_POST["recaptcha_challenge_field"])) : $post_vars["recaptcha_challenge_field"]; $post_vars["recaptcha_response_field"] = !$post_vars["recaptcha_response_field"] ? trim(stripslashes($_POST["recaptcha_response_field"])) : $post_vars["recaptcha_response_field"]; /**/ if (!c_ws_plugin__optimizemember_pro_authnet_responses::authnet_form_attr_validation_errors($post_vars["attr"])) { if (!($error = c_ws_plugin__optimizemember_pro_authnet_responses::authnet_form_submission_validation_errors("cancellation", $post_vars))) { if (is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID)) { if (($authnet = array("x_method" => "status")) && ($authnet["x_subscription_id"] = $cur__subscr_id = get_user_option("optimizemember_subscr_id"))) { if (($authnet = c_ws_plugin__optimizemember_pro_authnet_utilities::authnet_arb_response($authnet)) && empty($authnet["__error"]) && $authnet["subscription_status"]) { if (preg_match("/^(active|suspended)\$/i", $authnet["subscription_status"])) { if (!($ipn = array())) { /* With Authorize.Net, we need their IPN signup vars. */ if (is_array($ipn_signup_vars = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_vars())) { $ipn["txn_type"] = "subscr_cancel"; $ipn["subscr_id"] = $ipn_signup_vars["subscr_id"]; $ipn["custom"] = $ipn_signup_vars["custom"]; /**/ $ipn["period1"] = $ipn_signup_vars["period1"]; $ipn["period3"] = $ipn_signup_vars["period3"]; /**/ $ipn["payer_email"] = $ipn_signup_vars["payer_email"]; $ipn["first_name"] = $ipn_signup_vars["first_name"]; $ipn["last_name"] = $ipn_signup_vars["last_name"]; /**/ $ipn["option_name1"] = $ipn_signup_vars["option_name1"]; $ipn["option_selection1"] = $ipn_signup_vars["option_selection1"]; /**/ $ipn["option_name2"] = $ipn_signup_vars["option_name2"]; $ipn["option_selection2"] = $ipn_signup_vars["option_selection2"]; /**/ $ipn["item_name"] = $ipn_signup_vars["item_name"]; $ipn["item_number"] = $ipn_signup_vars["item_number"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=authnet&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } } /**/ if ($authnet = array("x_method" => "cancel", "x_subscription_id" => $cur__subscr_id)) { c_ws_plugin__optimizemember_pro_authnet_utilities::authnet_arb_response($authnet); /**/ $global_response = array("response" => _x('<strong>Billing termination confirmed.</strong> Your account has been cancelled.', "s2member-front", "s2member")); /**/ if ($post_vars["attr"]["success"] && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $post_vars["attr"]["success"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } } else { $global_response = array("response" => _x('<strong>Billing terminated.</strong> Your account has been cancelled.', "s2member-front", "s2member")); /**/ if ($post_vars["attr"]["success"] && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $post_vars["attr"]["success"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } } else { $global_response = array("response" => _x('<strong>Billing terminated.</strong> Your account has been cancelled.', "s2member-front", "s2member")); /**/ if ($post_vars["attr"]["success"] && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $post_vars["attr"]["success"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } } else { $global_response = array("response" => _x('<strong>Billing terminated.</strong> Your account has been cancelled.', "s2member-front", "s2member")); /**/ if ($post_vars["attr"]["success"] && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $post_vars["attr"]["success"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } } else { $global_response = array("response" => _x('You\'re <strong>NOT</strong> logged in.', "s2member-front", "s2member"), "error" => true); } } else { $global_response = $error; } } } }
/** * Connect to and process cancellations/refunds/chargebacks/etc via Payflow. * * optimizeMember's Auto EOT System must be enabled for this to work properly. * * If you have a HUGE userbase, increase the max IPNs per process. * But NOTE, this runs ``$per_process`` *( per Blog )* on a Multisite Network. * To increase, use: ``add_filter ("ws_plugin__optimizemember_pro_payflow_ipns_per_process");``. * * @package optimizeMember\PayPal * @since 120514 * * @attaches-to ``add_action("ws_plugin__optimizemember_after_auto_eot_system");`` * * @param array $vars Expects an array of defined variables to be passed in by the Action Hook. * @return null */ public static function payflow_service($vars = FALSE) { global $wpdb; /* Need global DB obj. */ global $current_site, $current_blog; /* For Multisite support. */ /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["paypal_payflow_api_username"]) { $scan_time = apply_filters("ws_plugin__optimizemember_pro_payflow_status_scan_time", strtotime("-1 day"), get_defined_vars()); $per_process = apply_filters("ws_plugin__optimizemember_pro_payflow_ipns_per_process", $vars["per_process"], get_defined_vars()); /**/ if (is_array($objs = $wpdb->get_results("SELECT `user_id` AS `ID` FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = '" . $wpdb->prefix . "optimizemember_subscr_gateway' AND `meta_value` = 'paypal' AND `user_id` NOT IN(SELECT `user_id` FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = '" . $wpdb->prefix . "optimizemember_last_status_scan' AND `meta_value` > '" . esc_sql($scan_time) . "')"))) { foreach ($objs as $obj) { if (($user_id = $obj->ID) && ($counter = (int) $counter + 1)) { unset($paypal, $subscr_id, $ipn_sv, $processing, $processed, $ipn, $ipn_q, $log4, $_log4, $log2, $logs_dir); /**/ if (($subscr_id = get_user_option("optimizemember_subscr_id", $user_id)) && !get_user_option("optimizemember_auto_eot_time", $user_id)) { if (is_array($ipn_sv = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_vars(false, $subscr_id)) && ($paypal = c_ws_plugin__optimizemember_pro_paypal_utilities::payflow_get_profile($subscr_id)) && is_array($paypal["ipn_signup_vars"] = $ipn_sv)) { if (preg_match("/expired/i", $paypal["STATUS"])) { $paypal["optimizemember_log"][] = "Payflow IPN via polling, processed on: " . date("D M j, Y g:i:s a T"); /**/ $paypal["optimizemember_log"][] = "Payflow transaction identified as ( `SUBSCRIPTION EXPIRATION` )."; $paypal["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as `txn_type` ( `subscr_eot` )."; $paypal["optimizemember_log"][] = "Please check PayPal IPN logs for further processing details."; /**/ $processing = $processed = true; $ipn = array(); /* Reset. */ /**/ $ipn["txn_type"] = "subscr_eot"; $ipn["subscr_id"] = $paypal["ipn_signup_vars"]["subscr_id"]; /**/ $ipn["custom"] = $paypal["ipn_signup_vars"]["custom"]; /**/ $ipn["period1"] = $paypal["ipn_signup_vars"]["period1"]; $ipn["period3"] = $paypal["ipn_signup_vars"]["period3"]; /**/ $ipn["payer_email"] = $paypal["ipn_signup_vars"]["payer_email"]; $ipn["first_name"] = $paypal["ipn_signup_vars"]["first_name"]; $ipn["last_name"] = $paypal["ipn_signup_vars"]["last_name"]; /**/ $ipn["option_name1"] = $paypal["ipn_signup_vars"]["option_name1"]; $ipn["option_selection1"] = $paypal["ipn_signup_vars"]["option_selection1"]; /**/ $ipn["option_name2"] = $paypal["ipn_signup_vars"]["option_name2"]; $ipn["option_selection2"] = $paypal["ipn_signup_vars"]["option_selection2"]; /**/ $ipn["item_number"] = $paypal["ipn_signup_vars"]["item_number"]; $ipn["item_name"] = $paypal["ipn_signup_vars"]["item_name"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=paypal&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } else { if (preg_match("/(suspended|canceled|terminated|deactivated)/i", $paypal["STATUS"])) { $paypal["optimizemember_log"][] = "Payflow IPN via polling, processed on: " . date("D M j, Y g:i:s a T"); /**/ $paypal["optimizemember_log"][] = "Payflow transaction identified as ( `SUBSCRIPTION " . strtoupper($paypal["STATUS"]) . "` )."; $paypal["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as `txn_type` ( `subscr_cancel` )."; $paypal["optimizemember_log"][] = "Please check PayPal IPN logs for further processing details."; /**/ $processing = $processed = true; $ipn = array(); /* Reset. */ /**/ $ipn["txn_type"] = "subscr_cancel"; $ipn["subscr_id"] = $paypal["ipn_signup_vars"]["subscr_id"]; /**/ $ipn["custom"] = $paypal["ipn_signup_vars"]["custom"]; /**/ $ipn["period1"] = $paypal["ipn_signup_vars"]["period1"]; $ipn["period3"] = $paypal["ipn_signup_vars"]["period3"]; /**/ $ipn["payer_email"] = $paypal["ipn_signup_vars"]["payer_email"]; $ipn["first_name"] = $paypal["ipn_signup_vars"]["first_name"]; $ipn["last_name"] = $paypal["ipn_signup_vars"]["last_name"]; /**/ $ipn["option_name1"] = $paypal["ipn_signup_vars"]["option_name1"]; $ipn["option_selection1"] = $paypal["ipn_signup_vars"]["option_selection1"]; /**/ $ipn["option_name2"] = $paypal["ipn_signup_vars"]["option_name2"]; $ipn["option_selection2"] = $paypal["ipn_signup_vars"]["option_selection2"]; /**/ $ipn["item_number"] = $paypal["ipn_signup_vars"]["item_number"]; $ipn["item_name"] = $paypal["ipn_signup_vars"]["item_name"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=paypal&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } else { if (!$processed) { /* If nothing was processed, here we add a message to the logs indicating the status; which is being ignored. */ $paypal["optimizemember_log"][] = "Ignoring this status ( `" . $paypal["STATUS"] . "` ). It does NOT require any action on the part of optimizeMember."; } } } /**/ $logv = c_ws_plugin__optimizemember_utilities::ver_details(); $logm = c_ws_plugin__optimizemember_utilities::mem_details(); $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; $log4 = is_multisite() && !is_main_site() ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; $log2 = is_multisite() && !is_main_site() ? "paypal-payflow-ipn-4-" . trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "paypal-payflow-ipn.log"; /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["gateway_debug_logs"]) { if (is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["logs_dir"])) { if (is_writable($logs_dir) && c_ws_plugin__optimizemember_utils_logs::archive_oversize_log_files()) { file_put_contents($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export($paypal, true) . "\n\n", FILE_APPEND); } } } } } /**/ update_user_option($user_id, "optimizemember_last_status_scan", time()); /**/ if ($counter >= $per_process) { /* Only this many. */ break; } /* Break the loop now. */ } } } } /**/ return; /* Return for uniformity. */ }
/** * Connect to and process DataLink information for ccBill. * * optimizeMember's Auto EOT System must be enabled for this to work properly. * * If you have a HUGE userbase, increase the max IPNs per process. * But NOTE, this runs ``$per_process`` *( per Blog )* on a Multisite Network. * To increase, use: ``add_filter ("ws_plugin__optimizemember_pro_ccbill_datalink_ipns_per_process");``. * * @package optimizeMember\ccBill * @since 1.5 * * @attaches-to ``add_action("ws_plugin__optimizemember_after_auto_eot_system");`` * * @param array $vars Expects an array of defined variables passed in by the Action Hook. * @return null */ public static function ccbill_datalink($vars = FALSE) { global $wpdb; global $current_site, $current_blog; /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_id"]) { $mst_time_10m_ago = time() - 6 * 3600 - 600; $datalink = "https://datalink.ccbill.com/data/main.cgi"; /**/ if (!($last = get_transient("s2m_" . md5("optimizemember_pro_ccbill_last_datalink"))) || $last < $mst_time_10m_ago - 86400) { $start = $last && $last >= $mst_time_10m_ago - (86400 + 43200) ? $last : $mst_time_10m_ago - 86400; $end = $last = $start + 86400 <= $mst_time_10m_ago ? $start + 86400 : $mst_time_10m_ago; /**/ $dl_types = "REBILL" . ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_dl_cancellations"] || apply_filters("ws_plugin__optimizemember_pro_ccbill_datalink_pulls_cancellations", false) ? ",CANCELLATION" : "") . ",EXPIRE,REFUND,CHARGEBACK"; $qvrs = array("startTime" => date("YmdHis", $start), "endTime" => date("YmdHis", $end), "transactionTypes" => $dl_types, "clientAccnum" => $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_id"], "clientSubacc" => $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_sid"], "username" => $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_dl_user"], "password" => $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_dl_pass"]); /**/ if (($unprocessed_ipn_lines = trim(c_ws_plugin__optimizemember_utils_urls::remote($datalink = add_query_arg(urlencode_deep($qvrs), $datalink)))) && !preg_match("/^Error\\:/i", $unprocessed_ipn_lines)) { $ccbill["optimizemember_log"][] = "Storing last DataLink time: " . date("D M j, Y g:i:s a T", $last); /**/ set_transient("s2m_" . md5("optimizemember_pro_ccbill_last_datalink"), $last, 31556926); /**/ $ccbill["optimizemember_log"][] = "Storing new DataLink IPNs into a Transient Queue."; $ccbill["optimizemember_log"][] = $datalink; $ccbill["optimizemember_log"][] = $unprocessed_ipn_lines; /**/ set_transient("s2m_" . md5("optimizemember_pro_ccbill_datalink_ipns"), trim(trim(get_transient("s2m_" . md5("optimizemember_pro_ccbill_datalink_ipns"))) . "\n" . $unprocessed_ipn_lines), 31556926); } else { if (!preg_match("/^Error\\:/i", $unprocessed_ipn_lines)) { $ccbill["optimizemember_log"][] = "Storing last DataLink time: " . date("D M j, Y g:i:s a T", $last); /**/ set_transient("s2m_" . md5("optimizemember_pro_ccbill_last_datalink"), $last, 31556926); /**/ $ccbill["optimizemember_log"][] = "No new Datalink IPNs at this time: " . date("D M j, Y g:i:s a T"); $ccbill["optimizemember_log"][] = $datalink; $ccbill["optimizemember_log"][] = $unprocessed_ipn_lines; } else { $ccbill["optimizemember_log"][] = "Storing last DataLink time: " . date("D M j, Y g:i:s a T", $last); /**/ set_transient("s2m_" . md5("optimizemember_pro_ccbill_last_datalink"), $last, 31556926); /**/ $ccbill["optimizemember_log"][] = "Recording DataLink error at: " . date("D M j, Y g:i:s a T"); $ccbill["optimizemember_log"][] = "Recording server IP address: " . $_SERVER["SERVER_ADDR"]; $ccbill["optimizemember_log"][] = $datalink; $ccbill["optimizemember_log"][] = $unprocessed_ipn_lines; } } /**/ $logv = c_ws_plugin__optimizemember_utilities::ver_details(); $logm = c_ws_plugin__optimizemember_utilities::mem_details(); $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; $log4 = is_multisite() && !is_main_site() ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; $log2 = is_multisite() && !is_main_site() ? "ccbill-dl-4-" . trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "ccbill-dl.log"; /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["gateway_debug_logs"]) { if (is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["logs_dir"])) { if (is_writable($logs_dir) && c_ws_plugin__optimizemember_utils_logs::archive_oversize_log_files()) { file_put_contents($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export($ccbill, true) . "\n\n", FILE_APPEND); } } } } else { if ($unprocessed_ipn_lines = trim(get_transient("s2m_" . md5("optimizemember_pro_ccbill_datalink_ipns")))) { $per_process = apply_filters("ws_plugin__optimizemember_pro_ccbill_datalink_ipns_per_process", $vars["per_process"], get_defined_vars()); /**/ foreach ($unprocessed_lines = preg_split("/[\r\n]+/", $unprocessed_ipn_lines) as $line => $unprocessed_line) { unset($ccbill, $processing, $processed, $ipn, $ipn_q, $log4, $_log4, $log2, $logs_dir); /**/ if (($unprocessed_line = trim($unprocessed_line)) && ($counter = (int) $counter + 1)) { $ccbill["optimizemember_log"][] = "DataLink IPN processed on: " . date("D M j, Y g:i:s a T"); /**/ $ccbill["dl_ipn"] = c_ws_plugin__optimizemember_utils_strings::trim_dq_deep(preg_split("/\",\"/", $unprocessed_line)); /**/ if (is_array($ccbill["dl_ipn_signup_vars"] = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_vars(false, $ccbill["dl_ipn"][3]))) { if (preg_match("/^REBILL\$/i", $ccbill["dl_ipn"][0])) { $ccbill["optimizemember_log"][] = "ccBill transaction identified as (SUBSCRIPTION PAYMENT)."; $ccbill["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as txn_type (subscr_payment)."; $ccbill["optimizemember_log"][] = "Please check PayPal IPN logs for further processing details."; /**/ $processing = $processed = true; $ipn = array(); /**/ $ipn["txn_type"] = "subscr_payment"; $ipn["subscr_id"] = $ccbill["dl_ipn_signup_vars"]["subscr_id"]; /**/ $ipn["custom"] = $ccbill["dl_ipn_signup_vars"]["custom"]; /**/ $ipn["txn_id"] = $ccbill["dl_ipn"][5]; /**/ $ipn["mc_gross"] = number_format($ccbill["dl_ipn"][6], 2, ".", ""); $ipn["mc_currency"] = strtoupper("USD"); $ipn["tax"] = number_format("0.00", 2, ".", ""); /**/ $ipn["payer_email"] = $ccbill["dl_ipn_signup_vars"]["payer_email"]; $ipn["first_name"] = $ccbill["dl_ipn_signup_vars"]["first_name"]; $ipn["last_name"] = $ccbill["dl_ipn_signup_vars"]["last_name"]; /**/ $ipn["option_name1"] = $ccbill["dl_ipn_signup_vars"]["option_name1"]; $ipn["option_selection1"] = $ccbill["dl_ipn_signup_vars"]["option_selection1"]; /**/ $ipn["option_name2"] = $ccbill["dl_ipn_signup_vars"]["option_name2"]; $ipn["option_selection2"] = $ccbill["dl_ipn_signup_vars"]["option_selection2"]; /**/ $ipn["item_number"] = $ccbill["dl_ipn_signup_vars"]["item_number"]; $ipn["item_name"] = $ccbill["dl_ipn_signup_vars"]["item_name"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=ccbill&optimizemember_paypal_proxy_use=standard-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } else { if (preg_match("/^CANCELLATION\$/i", $ccbill["dl_ipn"][0])) { $ccbill["optimizemember_log"][] = "ccBill transaction identified as (SUBSCRIPTION CANCELLATION)."; $ccbill["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as txn_type (subscr_cancel)."; $ccbill["optimizemember_log"][] = "Please check PayPal IPN logs for further processing details."; /**/ $processing = $processed = true; $ipn = array(); /**/ $ipn["txn_type"] = "subscr_cancel"; $ipn["subscr_id"] = $ccbill["dl_ipn_signup_vars"]["subscr_id"]; /**/ $ipn["custom"] = $ccbill["dl_ipn_signup_vars"]["custom"]; /**/ $ipn["period1"] = $ccbill["dl_ipn_signup_vars"]["period1"]; $ipn["period3"] = $ccbill["dl_ipn_signup_vars"]["period3"]; /**/ $ipn["payer_email"] = $ccbill["dl_ipn_signup_vars"]["payer_email"]; $ipn["first_name"] = $ccbill["dl_ipn_signup_vars"]["first_name"]; $ipn["last_name"] = $ccbill["dl_ipn_signup_vars"]["last_name"]; /**/ $ipn["option_name1"] = $ccbill["dl_ipn_signup_vars"]["option_name1"]; $ipn["option_selection1"] = $ccbill["dl_ipn_signup_vars"]["option_selection1"]; /**/ $ipn["option_name2"] = $ccbill["dl_ipn_signup_vars"]["option_name2"]; $ipn["option_selection2"] = $ccbill["dl_ipn_signup_vars"]["option_selection2"]; /**/ $ipn["item_number"] = $ccbill["dl_ipn_signup_vars"]["item_number"]; $ipn["item_name"] = $ccbill["dl_ipn_signup_vars"]["item_name"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=ccbill&optimizemember_paypal_proxy_use=standard-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } else { if (preg_match("/^EXPIRE\$/i", $ccbill["dl_ipn"][0])) { $ccbill["optimizemember_log"][] = "ccBill transaction identified as (SUBSCRIPTION EXPIRATION)."; $ccbill["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as txn_type (subscr_eot)."; $ccbill["optimizemember_log"][] = "Please check PayPal IPN logs for further processing details."; /**/ $processing = $processed = true; $ipn = array(); /**/ $ipn["txn_type"] = "subscr_eot"; $ipn["subscr_id"] = $ccbill["dl_ipn_signup_vars"]["subscr_id"]; /**/ $ipn["custom"] = $ccbill["dl_ipn_signup_vars"]["custom"]; /**/ $ipn["period1"] = $ccbill["dl_ipn_signup_vars"]["period1"]; $ipn["period3"] = $ccbill["dl_ipn_signup_vars"]["period3"]; /**/ $ipn["payer_email"] = $ccbill["dl_ipn_signup_vars"]["payer_email"]; $ipn["first_name"] = $ccbill["dl_ipn_signup_vars"]["first_name"]; $ipn["last_name"] = $ccbill["dl_ipn_signup_vars"]["last_name"]; /**/ $ipn["option_name1"] = $ccbill["dl_ipn_signup_vars"]["option_name1"]; $ipn["option_selection1"] = $ccbill["dl_ipn_signup_vars"]["option_selection1"]; /**/ $ipn["option_name2"] = $ccbill["dl_ipn_signup_vars"]["option_name2"]; $ipn["option_selection2"] = $ccbill["dl_ipn_signup_vars"]["option_selection2"]; /**/ $ipn["item_number"] = $ccbill["dl_ipn_signup_vars"]["item_number"]; $ipn["item_name"] = $ccbill["dl_ipn_signup_vars"]["item_name"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=ccbill&optimizemember_paypal_proxy_use=standard-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } else { if (preg_match("/^(REFUND|CHARGEBACK)\$/i", $ccbill["dl_ipn"][0])) { $ccbill["optimizemember_log"][] = "ccBill transaction identified as (REFUND|CHARGEBACK)."; $ccbill["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as payment_status (refunded|reversed)."; $ccbill["optimizemember_log"][] = "Please check PayPal IPN logs for further processing details."; /**/ $processing = $processed = true; $ipn = array(); /**/ $ipn["custom"] = $ccbill["dl_ipn_signup_vars"]["custom"]; /**/ $ipn["parent_txn_id"] = $ccbill["dl_ipn_signup_vars"]["subscr_id"]; /**/ $ipn["payment_status"] = preg_match("/^CHARGEBACK\$/i", $ccbill["dl_ipn"][0]) ? "reversed" : "refunded"; $ipn["mc_fee"] = "-" . number_format("0.00", 2, ".", ""); $ipn["mc_gross"] = "-" . number_format($ccbill["dl_ipn"][5], 2, ".", ""); $ipn["mc_currency"] = strtoupper("USD"); $ipn["tax"] = "-" . number_format("0.00", 2, ".", ""); /**/ $ipn["payer_email"] = $ccbill["dl_ipn_signup_vars"]["payer_email"]; $ipn["first_name"] = $ccbill["dl_ipn_signup_vars"]["first_name"]; $ipn["last_name"] = $ccbill["dl_ipn_signup_vars"]["last_name"]; /**/ $ipn["option_name1"] = $ccbill["dl_ipn_signup_vars"]["option_name1"]; $ipn["option_selection1"] = $ccbill["dl_ipn_signup_vars"]["option_selection1"]; /**/ $ipn["option_name2"] = $ccbill["dl_ipn_signup_vars"]["option_name2"]; $ipn["option_selection2"] = $ccbill["dl_ipn_signup_vars"]["option_selection2"]; /**/ $ipn["item_number"] = $ccbill["dl_ipn_signup_vars"]["item_number"]; $ipn["item_name"] = $ccbill["dl_ipn_signup_vars"]["item_name"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=ccbill&optimizemember_paypal_proxy_use=standard-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } else { if (!$processed) { /* Here we add a message to the logs indicating the IPN was ignored; no action taken. */ $ccbill["optimizemember_log"][] = "Ignoring this DataLink IPN. It does NOT require any action on the part of optimizeMember."; } } } } } } else { if (!$processed) { /* Here we add a message to the logs indicating that no IPN vars are available. */ $ccbill["optimizemember_log"][] = "Ignoring this DataLink IPN. No IPN signup vars for Subscr. ID: " . $ccbill["dl_ipn"][3] . "."; } } /**/ $logv = c_ws_plugin__optimizemember_utilities::ver_details(); $logm = c_ws_plugin__optimizemember_utilities::mem_details(); $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; $log4 = is_multisite() && !is_main_site() ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; $log2 = is_multisite() && !is_main_site() ? "ccbill-dl-ipn-4-" . trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "ccbill-dl-ipn.log"; /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["gateway_debug_logs"]) { if (is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["logs_dir"])) { if (is_writable($logs_dir) && c_ws_plugin__optimizemember_utils_logs::archive_oversize_log_files()) { file_put_contents($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export($ccbill, true) . "\n\n", FILE_APPEND); } } } } /**/ unset($unprocessed_lines[$line]); /* Remove this line and update the list of unprocessed IPN lines. */ set_transient("s2m_" . md5("optimizemember_pro_ccbill_datalink_ipns"), implode("\n", $unprocessed_lines), 31556926); /**/ if ($counter >= $per_process) { break; } /* Break the loop now. */ } } } } /**/ return; /* Return for uniformity. */ }
/** * Handles Stripe Webhook/IPN event processing. * * @package optimizeMember\Stripe * @since 140617 * * @attaches-to ``add_action('init');`` */ public static function stripe_notify() { global $current_site, $current_blog; if (!empty($_GET['optimizemember_pro_stripe_notify']) && $GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_stripe_api_secret_key']) { $stripe = array(); // Initialize array of Webhook/IPN event data and s2Member log details. @ignore_user_abort(TRUE); // Continue processing even if/when connection is broken. require_once dirname(__FILE__) . '/stripe-sdk/lib/Stripe.php'; Stripe::setApiKey($GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_stripe_api_secret_key']); if (is_object($event = c_ws_plugin__optimizemember_pro_stripe_utilities::get_event()) && ($stripe['event'] = $event)) { switch ($event->type) { case 'invoice.payment_succeeded': // Subscription payments. if (!empty($event->data->object) && ($stripe_invoice = $event->data->object) instanceof Stripe_Invoice && !empty($stripe_invoice->customer) && !empty($stripe_invoice->subscription) && ($stripe_invoice_total = number_format(c_ws_plugin__optimizemember_pro_stripe_utilities::cents_to_dollar_amount($stripe_invoice->total, $stripe_invoice->currency), 2, '.', '')) && is_object($stripe_subscription = c_ws_plugin__optimizemember_pro_stripe_utilities::get_customer_subscription($stripe_invoice->customer, $stripe_invoice->subscription)) && ($ipn_signup_vars = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_vars(0, $stripe_subscription->id))) { $processing = TRUE; $ipn['txn_type'] = 'subscr_payment'; $ipn['txn_id'] = $stripe_invoice->id; $ipn['txn_cid'] = $ipn_signup_vars['subscr_cid']; $ipn['subscr_cid'] = $ipn_signup_vars['subscr_cid']; $ipn['subscr_id'] = $ipn_signup_vars['subscr_id']; $ipn['custom'] = $ipn_signup_vars['custom']; $ipn['mc_gross'] = $stripe_invoice_total; $ipn['mc_currency'] = strtoupper($stripe_invoice->currency); $ipn['tax'] = number_format(0, 2, '.', ''); $ipn['period1'] = $ipn_signup_vars['period1']; $ipn['period3'] = $ipn_signup_vars['period3']; $ipn['payer_email'] = $ipn_signup_vars['payer_email']; $ipn['first_name'] = $ipn_signup_vars['first_name']; $ipn['last_name'] = $ipn_signup_vars['last_name']; $ipn['option_name1'] = $ipn_signup_vars['option_name1']; $ipn['option_selection1'] = $ipn_signup_vars['option_selection1']; $ipn['option_name2'] = $ipn_signup_vars['option_name2']; $ipn['option_selection2'] = $ipn_signup_vars['option_selection2']; $ipn['item_name'] = $ipn_signup_vars['item_name']; $ipn['item_number'] = $ipn_signup_vars['item_number']; $ipn['optimizemember_paypal_proxy'] = 'stripe'; $ipn['optimizemember_paypal_proxy_use'] = 'pro-emails'; $ipn['optimizemember_paypal_proxy_verification'] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); c_ws_plugin__optimizemember_utils_urls::remote(site_url('/?optimizemember_paypal_notify=1'), $ipn, array('timeout' => 20)); $stripe['optimizemember_log'][] = 'Stripe Webhook/IPN event type identified as: `' . $event->type . '` on: ' . date('D M j, Y g:i:s a T'); if ($maybe_end_subscription = self::_maybe_end_subscription_after_payment($stripe_invoice->customer, $stripe_subscription)) { $stripe['optimizemember_log'][] = $maybe_end_subscription; } $stripe['optimizemember_log'][] = 'Webhook/IPN event `' . $event->type . '` reformulated. Piping through optimizeMember\'s core gateway processor as `txn_type` (`' . $ipn['txn_type'] . '`).'; $stripe['optimizemember_log'][] = 'Please check core IPN logs for further processing details.'; } break; // Break switch handler. // Break switch handler. case 'invoice.payment_failed': // Subscription payment failures. if (!empty($event->data->object) && ($stripe_invoice = $event->data->object) instanceof Stripe_Invoice && !empty($stripe_invoice->customer) && !empty($stripe_invoice->subscription) && ($stripe_invoice_total = number_format(c_ws_plugin__optimizemember_pro_stripe_utilities::cents_to_dollar_amount($stripe_invoice->total, $stripe_invoice->currency), 2, '.', '')) && is_object($stripe_subscription = c_ws_plugin__optimizemember_pro_stripe_utilities::get_customer_subscription($stripe_invoice->customer, $stripe_invoice->subscription)) && ($ipn_signup_vars = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_vars(0, $stripe_subscription->id))) { $processing = TRUE; $stripe['optimizemember_log'][] = 'Stripe Webhook/IPN event type identified as: `' . $event->type . '` on: ' . date('D M j, Y g:i:s a T'); if ($maybe_end_subscription = self::_maybe_end_subscription_after_payment($stripe_invoice->customer, $stripe_subscription)) { $stripe['optimizemember_log'][] = $maybe_end_subscription; } $stripe['optimizemember_log'][] = 'Ignoring `' . $event->type . '`. optimizeMember does NOT respond to individual payment failures; only to subscription cancellations.'; $stripe['optimizemember_log'][] = 'You may control the behavior(s) associated w/ subscription payment failures from your Stripe Dashboard please.'; } break; // Break switch handler. // Break switch handler. case 'customer.deleted': // Customer deletions. if (!empty($event->data->object) && ($stripe_customer = $event->data->object) instanceof Stripe_Customer && ($ipn_signup_vars = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_vars(0, $stripe_customer->id))) { $processing = TRUE; $ipn['txn_type'] = 'subscr_eot'; $ipn['subscr_cid'] = $ipn_signup_vars['subscr_cid']; $ipn['subscr_id'] = $ipn_signup_vars['subscr_id']; $ipn['custom'] = $ipn_signup_vars['custom']; $ipn['period1'] = $ipn_signup_vars['period1']; $ipn['period3'] = $ipn_signup_vars['period3']; $ipn['payer_email'] = $ipn_signup_vars['payer_email']; $ipn['first_name'] = $ipn_signup_vars['first_name']; $ipn['last_name'] = $ipn_signup_vars['last_name']; $ipn['option_name1'] = $ipn_signup_vars['option_name1']; $ipn['option_selection1'] = $ipn_signup_vars['option_selection1']; $ipn['option_name2'] = $ipn_signup_vars['option_name2']; $ipn['option_selection2'] = $ipn_signup_vars['option_selection2']; $ipn['item_name'] = $ipn_signup_vars['item_name']; $ipn['item_number'] = $ipn_signup_vars['item_number']; $ipn['optimizemember_paypal_proxy'] = 'stripe'; $ipn['optimizemember_paypal_proxy_use'] = 'pro-emails'; $ipn['optimizemember_paypal_proxy_verification'] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); c_ws_plugin__optimizemember_utils_urls::remote(site_url('/?optimizemember_paypal_notify=1'), $ipn, array('timeout' => 20)); $stripe['optimizemember_log'][] = 'Stripe Webhook/IPN event type identified as: `' . $event->type . '` on: ' . date('D M j, Y g:i:s a T'); $stripe['optimizemember_log'][] = 'Webhook/IPN event `' . $event->type . '` reformulated. Piping through optimizeMember\'s core gateway processor as `txn_type` (`' . $ipn['txn_type'] . '`).'; $stripe['optimizemember_log'][] = 'Please check core IPN logs for further processing details.'; } break; // Break switch handler. // Break switch handler. case 'customer.subscription.deleted': // Customer subscription deletion. if (!empty($event->data->object) && ($stripe_subscription = $event->data->object) instanceof Stripe_Subscription && ($ipn_signup_vars = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_vars(0, $stripe_subscription->id))) { $processing = TRUE; $ipn['txn_type'] = 'subscr_eot'; $ipn['subscr_cid'] = $ipn_signup_vars['subscr_cid']; $ipn['subscr_id'] = $ipn_signup_vars['subscr_id']; $ipn['custom'] = $ipn_signup_vars['custom']; $ipn['period1'] = $ipn_signup_vars['period1']; $ipn['period3'] = $ipn_signup_vars['period3']; $ipn['payer_email'] = $ipn_signup_vars['payer_email']; $ipn['first_name'] = $ipn_signup_vars['first_name']; $ipn['last_name'] = $ipn_signup_vars['last_name']; $ipn['option_name1'] = $ipn_signup_vars['option_name1']; $ipn['option_selection1'] = $ipn_signup_vars['option_selection1']; $ipn['option_name2'] = $ipn_signup_vars['option_name2']; $ipn['option_selection2'] = $ipn_signup_vars['option_selection2']; $ipn['item_name'] = $ipn_signup_vars['item_name']; $ipn['item_number'] = $ipn_signup_vars['item_number']; $ipn['optimizemember_paypal_proxy'] = 'stripe'; $ipn['optimizemember_paypal_proxy_use'] = 'pro-emails'; $ipn['optimizemember_paypal_proxy_verification'] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); c_ws_plugin__optimizemember_utils_urls::remote(site_url('/?optimizemember_paypal_notify=1'), $ipn, array('timeout' => 20)); $stripe['optimizemember_log'][] = 'Stripe Webhook/IPN event type identified as: `' . $event->type . '` on: ' . date('D M j, Y g:i:s a T'); $stripe['optimizemember_log'][] = 'Webhook/IPN event `' . $event->type . '` reformulated. Piping through optimizeMember\'s core gateway processor as `txn_type` (`' . $ipn['txn_type'] . '`).'; $stripe['optimizemember_log'][] = 'Please check core IPN logs for further processing details.'; } break; // Break switch handler. } if (empty($processing)) { $stripe['optimizemember_log'][] = 'Ignoring this Webhook/IPN. The event does NOT require any action on the part of OptimizeMember.'; } } else { $stripe['optimizemember_log'][] = 'Unable to verify Webhook/IPN event ID. This is most likely related to an invalid Stripe configuration. Please check: optimizeMember -› Stripe Options.'; $stripe['optimizemember_log'][] = 'If you\'re absolutely SURE that your Stripe configuration is valid, you may want to run some tests on your server, just to be sure \\$_POST variables (and php://input) are populated; and that your server is able to connect to Stripe over an HTTPS connection.'; $stripe['optimizemember_log'][] = 'optimizeMember uses the Stripe SDK for remote connections; which relies upon the cURL extension for PHP. Please make sure that your installation of PHP has the cURL extension; and that it\'s configured together with OpenSSL for HTTPS communication.'; $stripe['optimizemember_log'][] = var_export($_REQUEST, TRUE) . "\n" . var_export(json_decode(@file_get_contents('php://input')), TRUE); } $logt = c_ws_plugin__optimizemember_utilities::time_details(); $logv = c_ws_plugin__optimizemember_utilities::ver_details(); $logm = c_ws_plugin__optimizemember_utilities::mem_details(); $log4 = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\n" . 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT']; $log4 = is_multisite() && !is_main_site() ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; $log2 = is_multisite() && !is_main_site() ? 'stripe-ipn-4-' . trim(preg_replace('/[^a-z0-9]/i', '-', !empty($_log4) ? $_log4 : ''), '-') . '.log' : 'stripe-ipn.log'; if ($GLOBALS['WS_PLUGIN__']['optimizemember']['o']['gateway_debug_logs']) { if (is_dir($logs_dir = $GLOBALS['WS_PLUGIN__']['optimizemember']['c']['logs_dir'])) { if (is_writable($logs_dir) && c_ws_plugin__optimizemember_utils_logs::archive_oversize_log_files()) { file_put_contents($logs_dir . '/' . $log2, 'LOG ENTRY: ' . $logt . "\n" . $logv . "\n" . $logm . "\n" . $log4 . "\n" . c_ws_plugin__optimizemember_utils_logs::conceal_private_info(var_export($stripe, TRUE)) . "\n\n", FILE_APPEND); } } } status_header(200); // Send a 200 OK status header. header('Content-Type: text/plain; charset=UTF-8'); // Content-Type text/plain with UTF-8. while (@ob_end_clean()) { } // Clean any existing output buffers. exit; // Exit now. } }
/** * optimizeMember's PayPal IPN handler ( inner processing routine ). * * @package optimizeMember\PayPal * @since 110720 * * @param array $vars Required. An array of defined variables passed by {@link optimizeMember\PayPal\c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()}. * @return array|bool The original ``$paypal`` array passed in ( extracted ) from ``$vars``, or false when conditions do NOT apply. * * @todo Optimize with ``empty()`` and ``isset()``. */ public static function cp($vars = array()) { extract($vars); /* Extract all vars passed in from: ``c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()``. */ /**/ if (!empty($paypal["txn_type"]) && preg_match("/^(subscr_payment|recurring_payment)\$/i", $paypal["txn_type"]) && ((!empty($paypal["item_number"]) || ($paypal["item_number"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_item_number($paypal))) && preg_match($GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["membership_item_number_w_level_regex"], $paypal["item_number"])) && (!empty($paypal["subscr_id"]) || ($paypal["subscr_id"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_subscr_id($paypal))) && (empty($paypal["payment_status"]) || empty($payment_status_issues) || !preg_match($payment_status_issues, $paypal["payment_status"])) && (!empty($paypal["item_name"]) || ($paypal["item_name"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_item_name($paypal))) && (!empty($paypal["payer_email"]) || ($paypal["payer_email"] = c_ws_plugin__optimizemember_utils_users::get_user_email_with($paypal["subscr_id"]))) && !empty($paypal["txn_id"]) && !empty($paypal["mc_gross"])) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_before_subscr_payment", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if (!get_transient($transient_ipn = "s2m_ipn_" . md5("optimizemember_transient_" . $_paypal_s)) && set_transient($transient_ipn, time(), 31556926 * 10)) { $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as " . ($identified_as = "( `subscr_payment|recurring_payment` )") . "."; $paypal["optimizemember_log"][] = "Sleeping for 5 seconds. Waiting for a possible ( `subscr_signup|subscr_modify|recurring_payment_profile_created` )."; sleep(5); /* Sleep here for a moment. PayPal sometimes sends a subscr_payment before the subscr_signup, subscr_modify. */ /* It is NOT a big deal if they do. However, optimizeMember goes to sleep here, just to help keep the log files in a logical order. */ $paypal["optimizemember_log"][] = "Awake. It's " . date("D M j, Y g:i:s a T") . ". optimizeMember `txn_type` identified as " . $identified_as . "."; /**/ list($paypal["level"], $paypal["ccaps"]) = preg_split("/\\:/", $paypal["item_number"], 2); /**/ $paypal["ip"] = preg_match("/ip address/i", $paypal["option_name2"]) && $paypal["option_selection2"] ? $paypal["option_selection2"] : ""; $paypal["ip"] = !$paypal["ip"] && preg_match("/^[a-z0-9]+~[0-9\\.]+\$/i", $paypal["invoice"]) ? preg_replace("/^[a-z0-9]+~/i", "", $paypal["invoice"]) : $paypal["ip"]; /**/ if (($user_id = c_ws_plugin__optimizemember_utils_users::get_user_id_with($paypal["subscr_id"])) && is_object($user = new WP_User($user_id)) && $user->ID) { $processing = $during = true; /* Yes, we ARE processing this. */ /**/ $pr_times = get_user_option("optimizemember_paid_registration_times", $user_id); $pr_times["level"] = !$pr_times["level"] ? time() : $pr_times["level"]; /* Preserves existing. */ $pr_times["level" . $paypal["level"]] = !$pr_times["level" . $paypal["level"]] ? time() : $pr_times["level" . $paypal["level"]]; update_user_option($user_id, "optimizemember_paid_registration_times", $pr_times); /* Update now. */ /**/ if (!get_user_option("optimizemember_first_payment_txn_id", $user_id)) { /* 1st payment? */ update_user_option($user_id, "optimizemember_first_payment_txn_id", $paypal["txn_id"]); } /**/ update_user_option($user_id, "optimizemember_last_payment_time", time()); /* Also update last payment time. */ /**/ $paypal["optimizemember_log"][] = "Updated Payment Times for this Member."; /* Flag this action in the log. */ /**/ $fields = get_user_option("optimizemember_custom_fields", $user_id); /* These will be needed in the routines below. */ $user_reg_ip = get_user_option("optimizemember_registration_ip", $user_id); /* Original IP during Registration. */ $user_reg_ip = $paypal["ip"] = $user_reg_ip ? $user_reg_ip : $paypal["ip"]; /* Now merge conditionally. */ /**/ if ($processing && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["payment_notification_urls"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["payment_notification_urls"]) as $url) { /**/ if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["subscr_id"])), $url))) { if (($url = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["mc_gross"])), $url)) && ($url = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["txn_id"])), $url))) { if (($url = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_number"])), $url)) && ($url = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_name"])), $url))) { if (($url = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["first_name"])), $url)) && ($url = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["last_name"])), $url))) { if ($url = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($paypal["first_name"] . " " . $paypal["last_name"]))), $url)) { if ($url = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["payer_email"])), $url)) { if (($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->first_name)), $url)) && ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->last_name)), $url))) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($user->first_name . " " . $user->last_name))), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_login)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_reg_ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_id)), $url)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } } /**/ if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__optimizemember_utils_urls::remote($url); } } } } } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Payment Notification URLs have been processed."; } /**/ if ($processing && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["payment_notification_recipients"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { $msg = $sbj = "( optimizeMember / API Notification Email ) - Payment"; $msg .= "\n\n"; /* Spacing in the message body. */ /**/ $msg .= "subscr_id: %%subscr_id%%\n"; $msg .= "amount: %%amount%%\n"; $msg .= "txn_id: %%txn_id%%\n"; $msg .= "item_number: %%item_number%%\n"; $msg .= "item_name: %%item_name%%\n"; $msg .= "first_name: %%first_name%%\n"; $msg .= "last_name: %%last_name%%\n"; $msg .= "full_name: %%full_name%%\n"; $msg .= "payer_email: %%payer_email%%\n"; /**/ $msg .= "user_first_name: %%user_first_name%%\n"; $msg .= "user_last_name: %%user_last_name%%\n"; $msg .= "user_full_name: %%user_full_name%%\n"; $msg .= "user_email: %%user_email%%\n"; $msg .= "user_login: %%user_login%%\n"; $msg .= "user_ip: %%user_ip%%\n"; $msg .= "user_id: %%user_id%%\n"; /**/ if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { $msg .= $var . ": %%" . $var . "%%\n"; } } /**/ $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; /**/ if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["subscr_id"]), $msg))) { if (($msg = preg_replace("/%%amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_gross"]), $msg)) && ($msg = preg_replace("/%%txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["txn_id"]), $msg))) { if (($msg = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $msg)) && ($msg = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $msg))) { if (($msg = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $msg)) && ($msg = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $msg))) { if ($msg = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $msg)) { if ($msg = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $msg)) { if (($msg = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->first_name), $msg)) && ($msg = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->last_name), $msg))) { if ($msg = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($user->first_name . " " . $user->last_name)), $msg)) { if ($msg = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_email), $msg)) { if ($msg = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_login), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_reg_ip), $msg)) { if ($msg = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_id), $msg)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($msg = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(maybe_serialize($val)), $msg))) { break; } } } /**/ if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { /* Still have a ``$sbj`` and a ``$msg``? */ /**/ foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["payment_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__optimizemember_payment_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_payment_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=utf-8"); } } } } } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Payment Notification Emails have been processed."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_payment", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { $paypal["optimizemember_log"][] = "Skipping this IPN response, for now. The Subscr. ID is not associated with a registered Member."; /**/ $ipn = array("txn_type" => "subscr_payment"); /* Create a simulated IPN response for txn_type=subscr_payment. */ /**/ foreach ($paypal as $var => $val) { if (in_array($var, array("subscr_gateway", "subscr_id", "txn_id", "custom", "invoice", "mc_gross", "mc_currency", "tax", "payer_email", "first_name", "last_name", "item_name", "item_number", "option_name1", "option_selection1", "option_name2", "option_selection2"))) { $ipn[$var] = $val; } } /**/ $paypal["optimizemember_log"][] = "Re-generating. This IPN will go into a Transient Queue; and be re-processed during registration."; /**/ set_transient("s2m_" . md5("optimizemember_transient_ipn_subscr_payment_" . $paypal["subscr_id"]), $ipn, 43200); } } else { $paypal["optimizemember_log"][] = "Not processing. Duplicate IPN."; $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as ( `subscr_payment|recurring_payment` )."; $paypal["optimizemember_log"][] = "Duplicate IPN. Already processed. This IPN will be ignored."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_after_subscr_payment", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_subscr_or_rp_payment_w_level", $paypal, get_defined_vars()); } else { return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_subscr_or_rp_payment_w_level", false, get_defined_vars()); } }
/** * Calls upon the PayPal PayFlow API, and returns the response. * * @package optimizeMember\PayPal * @since 120514 * * @param array $post_vars An array of variables to send through the PayPal PayFlow API call. * @return array An array of variables returned by the PayPal PayFlow API. */ public static function paypal_payflow_api_response($post_vars = FALSE) { global $current_site, $current_blog; /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_before_paypal_payflow_api_response", get_defined_vars()); unset($__refs, $__v); /**/ $url = "https://" . ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["paypal_sandbox"] ? "pilot-payflowpro.paypal.com" : "payflowpro.paypal.com"); /**/ $post_vars = apply_filters("ws_plugin__optimizemember_paypal_payflow_api_post_vars", $post_vars, get_defined_vars()); $post_vars = is_array($post_vars) ? $post_vars : array(); /**/ $post_vars["VERBOSITY"] = "MEDIUM"; $post_vars["USER"] = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["paypal_payflow_api_username"]; $post_vars["PARTNER"] = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["paypal_payflow_api_partner"]; $post_vars["VENDOR"] = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["paypal_payflow_api_vendor"]; $post_vars["PWD"] = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["paypal_payflow_api_password"]; /**/ foreach ($post_vars as $_key => &$_value) { $_value = c_ws_plugin__optimizemember_paypal_utilities::paypal_payflow_api_nv_cleanup($_key, $_value); } unset($_key, $_value); /**/ $input_time = date("D M j, Y g:i:s a T"); /**/ $nvp_post_vars = ""; foreach ($post_vars as $_key => $_value) { $nvp_post_vars .= ($nvp_post_vars ? "&" : "") . $_key . "[" . strlen($_value) . "]=" . $_value; } unset($_key, $_value); /**/ $nvp = trim(c_ws_plugin__optimizemember_utils_urls::remote($url, $nvp_post_vars, array("timeout" => 20, "headers" => array("Content-Type" => "text/namevalue")))); /**/ $output_time = date("D M j, Y g:i:s a T"); /**/ wp_parse_str($nvp, $response); $response = c_ws_plugin__optimizemember_utils_strings::trim_deep($response); /**/ if ($response["RESULT"] !== "0") { if (strlen($response["RESPMSG"])) { /* translators: Exclude `%2$s`. These are English details returned by PayPal. Replace `%2$s` with: `Unable to process, please try again`, or something to that affect. Or, if you prefer, you could Filter ``$response["__error"]`` with `ws_plugin__optimizemember_paypal_payflow_api_response`. */ $response["__error"] = sprintf(_x('Error #%1$s. %2$s.', "s2member-front", "s2member"), $response["RESULT"], rtrim($response["RESPMSG"], ".")); } else { $response["__error"] = _x("Error. Please contact Support for assistance.", "s2member-front", "s2member"); } } else { if (isset($response["TRXRESULT"]) && $response["TRXRESULT"] !== "0") { if (strlen($response["TRXRESPMSG"])) { /* translators: Exclude `%2$s`. These are English details returned by PayPal. Replace `%2$s` with: `Unable to process, please try again`, or something to that affect. Or, if you prefer, you could Filter ``$response["__error"]`` with `ws_plugin__optimizemember_paypal_payflow_api_response`. */ $response["__error"] = sprintf(_x('Error #%1$s. %2$s.', "s2member-front", "s2member"), $response["TRXRESULT"], rtrim($response["TRXRESPMSG"], ".")); } else { $response["__error"] = _x("Error. Please contact Support for assistance.", "s2member-front", "s2member"); } } } /**/ $logv = c_ws_plugin__optimizemember_utilities::ver_details(); $logm = c_ws_plugin__optimizemember_utilities::mem_details(); $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; $log4 = is_multisite() && !is_main_site() ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; $log2 = is_multisite() && !is_main_site() ? "paypal-payflow-api-4-" . trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "paypal-payflow-api.log"; /**/ if (isset($post_vars["ACCT"]) && strlen($post_vars["ACCT"]) > 4) { $post_vars["ACCT"] = str_repeat("*", strlen($post_vars["ACCT"]) - 4) . substr($post_vars["ACCT"], -4); } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["gateway_debug_logs"]) { if (is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["logs_dir"])) { if (is_writable($logs_dir) && c_ws_plugin__optimizemember_utils_logs::archive_oversize_log_files()) { if ($log = "-------- Input vars: ( " . $input_time . " ) --------\n" . $nvp_post_vars . "\n" . var_export($post_vars, true) . "\n") { if ($log .= "-------- Output string/vars: ( " . $output_time . " ) --------\n" . $nvp . "\n" . var_export($response, true)) { file_put_contents($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . $log . "\n\n", FILE_APPEND); } } } } } /**/ return apply_filters("ws_plugin__optimizemember_paypal_payflow_api_response", c_ws_plugin__optimizemember_paypal_utilities::_paypal_payflow_api_response_filters($response), get_defined_vars()); }
/** * Deprecated in optimizeMember v3.5+. * * Needed by the optimizeMember Pro upgrader prior to optimizeMember Pro v1.5+. * * @package optimizeMember * @since 3.0 * * @deprecated Starting with optimizeMember v3.5+, please use: * ``c_ws_plugin__optimizemember_utils_urls::remote()`` * * @see optimizeMember\Utilities\c_ws_plugin__optimizemember_utils_urls::remote() */ function ws_plugin__optimizemember_remote($url = FALSE, $post_vars = FALSE, $args = array()) { return c_ws_plugin__optimizemember_utils_urls::remote($url, $post_vars, $args); }
/** * optimizeMember's PayPal IPN handler ( inner processing routine ). * * @package optimizeMember\PayPal * @since 110720 * * @param array $vars Required. An array of defined variables passed by {@link optimizeMember\PayPal\c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()}. * @return array|bool The original ``$paypal`` array passed in ( extracted ) from ``$vars``, or false when conditions do NOT apply. * * @todo Optimize with ``empty()`` and ``isset()``. */ public static function cp($vars = array()) { extract($vars); /* Extract all vars passed in from: ``c_ws_plugin__optimizemember_paypal_notify_in::paypal_notify()``. */ /**/ if ((!empty($paypal["txn_type"]) && preg_match("/^(subscr_eot|recurring_payment_expired|recurring_payment_suspended_due_to_max_failed_payment)\$/i", $paypal["txn_type"]) && ($recurring = true) || !empty($paypal["txn_type"]) && preg_match("/^recurring_payment_profile_cancel\$/i", $paypal["txn_type"]) && !empty($paypal["initial_payment_status"]) && preg_match("/^failed\$/i", $paypal["initial_payment_status"]) && ($recurring = true) || !empty($paypal["txn_type"]) && preg_match("/^new_case\$/i", $paypal["txn_type"]) && !empty($paypal["case_type"]) && preg_match("/^chargeback\$/i", $paypal["case_type"]) && !($recurring = false) || !empty($paypal["payment_status"]) && preg_match("/^(refunded|reversed|reversal)\$/i", $paypal["payment_status"]) && !($recurring = false)) && (!empty($paypal["subscr_id"]) || ($paypal["subscr_id"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_subscr_id($paypal)) || !empty($paypal["parent_txn_id"]) && ($paypal["subscr_id"] = $paypal["parent_txn_id"])) && (!empty($paypal["period1"]) || ($paypal["period1"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period1($paypal, false)) || empty($recurring) || ($paypal["period1"] = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_var("period1", false, $paypal["subscr_id"])) || ($paypal["period1"] = "0 D")) && (!empty($paypal["period3"]) || ($paypal["period3"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period3($paypal, false)) || empty($recurring) || ($paypal["period3"] = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_var("period3", false, $paypal["subscr_id"])) || ($paypal["period3"] = "1 D")) && ((!empty($paypal["item_number"]) || ($paypal["item_number"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_item_number($paypal)) || ($paypal["item_number"] = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_var("item_number", false, $paypal["subscr_id"])) || ($paypal["item_number"] = "1")) && preg_match($GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["membership_item_number_w_level_regex"], $paypal["item_number"])) && (!empty($paypal["item_name"]) || ($paypal["item_name"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_item_name($paypal)) || ($paypal["item_name"] = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_var("item_name", false, $paypal["subscr_id"])) || ($paypal["item_name"] = $_SERVER["HTTP_HOST"])) && (!empty($paypal["payer_email"]) || ($paypal["payer_email"] = c_ws_plugin__optimizemember_utils_users::get_user_ipn_signup_var("payer_email", false, $paypal["subscr_id"])) || ($paypal["payer_email"] = c_ws_plugin__optimizemember_utils_users::get_user_email_with($paypal["subscr_id"])))) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_before_subscr_eot", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if (!get_transient($transient_ipn = "s2m_ipn_" . md5("optimizemember_transient_" . $_paypal_s)) && set_transient($transient_ipn, time(), 31556926 * 10)) { $is_refund = preg_match("/^refunded\$/i", $paypal["payment_status"]) && $paypal["parent_txn_id"]; $is_reversal = preg_match("/^(reversed|reversal)\$/i", $paypal["payment_status"]) && $paypal["parent_txn_id"]; $is_reversal = !$is_reversal ? preg_match("/^new_case\$/i", $paypal["txn_type"]) && preg_match("/^chargeback\$/i", $paypal["case_type"]) : $is_reversal; $is_refund_or_reversal = $is_refund || $is_reversal; /* If either of the previous tests above evaluated to true; then it's obviously a Refund and/or a Reversal. */ $is_delayed_eot = !$is_refund_or_reversal && preg_match("/^(subscr_eot|recurring_payment_expired)\$/i", $paypal["txn_type"]) && preg_match("/^I-/i", $paypal["subscr_id"]); /**/ if ($is_refund_or_reversal) { $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as " . ($identified_as = "( `[empty or irrelevant]` ) w/ `payment_status` ( `refunded|reversed|reversal` ) - or - `new_case` w/ `case_type` ( `chargeback` )") . "."; } else { $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as " . ($identified_as = "( `subscr_eot|recurring_payment_expired|recurring_payment_suspended_due_to_max_failed_payment` ) - or - `recurring_payment_profile_cancel` w/ `initial_payment_status` ( `failed` )") . "."; } /**/ $paypal["optimizemember_log"][] = "Sleeping for 5 seconds. Waiting for a possible ( `subscr_signup|subscr_modify|recurring_payment_profile_created` )."; sleep(5); /* Sleep here for a moment. PayPal sometimes sends a subscr_eot before the subscr_signup, subscr_modify. */ /* It is NOT a big deal if they do. However, optimizeMember goes to sleep here, just to help keep the log files in a logical order. */ $paypal["optimizemember_log"][] = "Awake. It's " . date("D M j, Y g:i:s a T") . ". optimizeMember `txn_type` identified as " . $identified_as . "."; /**/ $paypal["ip"] = preg_match("/ip address/i", $paypal["option_name2"]) && $paypal["option_selection2"] ? $paypal["option_selection2"] : ""; $paypal["ip"] = !$paypal["ip"] && preg_match("/^[a-z0-9]+~[0-9\\.]+\$/i", $paypal["invoice"]) ? preg_replace("/^[a-z0-9]+~/i", "", $paypal["invoice"]) : $paypal["ip"]; /**/ if (($user_id = c_ws_plugin__optimizemember_utils_users::get_user_id_with($paypal["subscr_id"])) && is_object($user = new WP_User($user_id)) && !empty($user->ID)) { $fields = get_user_option("optimizemember_custom_fields", $user_id); /* These will be needed below. */ $user_reg_ip = get_user_option("optimizemember_registration_ip", $user_id); /* Needed below. */ $user_reg_ip = $paypal["ip"] = $user_reg_ip ? $user_reg_ip : $paypal["ip"]; /**/ if (!$is_refund_or_reversal && !$is_delayed_eot && !get_user_option("optimizemember_auto_eot_time", $user_id) || $is_refund_or_reversal && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["triggers_immediate_eot"] === "refunds,reversals" || $is_reversal && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["triggers_immediate_eot"] === "reversals" || $is_refund && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["triggers_immediate_eot"] === "refunds") { if (!$user->has_cap("administrator")) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["auto_eot_system_enabled"]) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_eot_behavior"] === "demote") { $processing = $during = true; /* Yes, we ARE processing this. */ /**/ $eot_del_type = $is_refund_or_reversal ? "ipn-refund-reversal-demotion" : "ipn-cancellation-expiration-demotion"; /**/ $demotion_role = c_ws_plugin__optimizemember_option_forces::force_demotion_role("subscriber"); $existing_role = c_ws_plugin__optimizemember_user_access::user_access_role($user); /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_eot_before_demote", get_defined_vars()); do_action("ws_plugin__optimizemember_during_collective_mods", $user_id, get_defined_vars(), $eot_del_type, "modification", $demotion_role); do_action("ws_plugin__optimizemember_during_collective_eots", $user_id, get_defined_vars(), $eot_del_type, "modification"); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if ($existing_role !== $demotion_role) { /* Only if NOT the existing Role. */ $user->set_role($demotion_role); } /* Give User the demotion Role. */ /**/ foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_optimizemember_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } /**/ delete_user_option($user_id, "optimizemember_custom"); delete_user_option($user_id, "optimizemember_subscr_id"); delete_user_option($user_id, "optimizemember_subscr_gateway"); /**/ delete_user_option($user_id, "optimizemember_ipn_signup_vars"); if (!apply_filters("ws_plugin__optimizemember_preserve_paid_registration_times", true, get_defined_vars())) { delete_user_option($user_id, "optimizemember_paid_registration_times"); } /**/ delete_user_option($user_id, "optimizemember_last_status_scan"); delete_user_option($user_id, "optimizemember_first_payment_txn_id"); delete_user_option($user_id, "optimizemember_last_payment_time"); delete_user_option($user_id, "optimizemember_auto_eot_time"); /**/ delete_user_option($user_id, "optimizemember_file_download_access_log"); /**/ c_ws_plugin__optimizemember_user_notes::append_user_notes($user_id, "Demoted by optimizeMember: " . date("D M j, Y g:i a T")); /**/ $paypal["optimizemember_log"][] = "Member Level/Capabilities demoted to: " . ucwords(preg_replace("/_/", " ", $demotion_role)) . "."; /**/ if ($processing && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["eot_del_notification_urls"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["eot_del_notification_urls"]) as $url) { /* Handle EOT Notifications. */ /**/ if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%eot_del_type%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($eot_del_type)), $url)) && ($url = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["subscr_id"])), $url))) { if (($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->first_name)), $url)) && ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->last_name)), $url))) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($user->first_name . " " . $user->last_name))), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user->user_login)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_reg_ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_id)), $url)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } } /**/ if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__optimizemember_utils_urls::remote($url); } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "EOT/Deletion Notification URLs have been processed."; } /**/ if ($processing && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["eot_del_notification_recipients"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { $msg = $sbj = "( optimizeMember / API Notification Email ) - EOT/Deletion"; $msg .= "\n\n"; /* Spacing in the message body. */ /**/ $msg .= "eot_del_type: %%eot_del_type%%\n"; $msg .= "subscr_id: %%subscr_id%%\n"; $msg .= "user_first_name: %%user_first_name%%\n"; $msg .= "user_last_name: %%user_last_name%%\n"; $msg .= "user_full_name: %%user_full_name%%\n"; $msg .= "user_email: %%user_email%%\n"; $msg .= "user_login: %%user_login%%\n"; $msg .= "user_ip: %%user_ip%%\n"; $msg .= "user_id: %%user_id%%\n"; /**/ if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { $msg .= $var . ": %%" . $var . "%%\n"; } } /**/ $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; /**/ if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%eot_del_type%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($eot_del_type), $msg)) && ($msg = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["subscr_id"]), $msg))) { if (($msg = preg_replace("/%%user_first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->first_name), $msg)) && ($msg = preg_replace("/%%user_last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->last_name), $msg))) { if ($msg = preg_replace("/%%user_full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($user->first_name . " " . $user->last_name)), $msg)) { if ($msg = preg_replace("/%%user_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_email), $msg)) { if ($msg = preg_replace("/%%user_login%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user->user_login), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_reg_ip), $msg)) { if ($msg = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_id), $msg)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($msg = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(maybe_serialize($val)), $msg))) { break; } } } /**/ if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { /* Still have a ``$sbj`` and a ``$msg``? */ /**/ foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["eot_del_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__optimizemember_eot_del_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_eot_del_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=utf-8"); } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "EOT/Deletion Notification Emails have been processed."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_eot_demote", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_eot_behavior"] === "delete") { $processing = $during = true; /* Yes, we ARE processing this. */ /**/ $eot_del_type = $GLOBALS["ws_plugin__optimizemember_eot_del_type"] = $is_refund_or_reversal ? "ipn-refund-reversal-deletion" : "ipn-cancellation-expiration-deletion"; /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_eot_before_delete", get_defined_vars()); do_action("ws_plugin__optimizemember_during_collective_eots", $user_id, get_defined_vars(), $eot_del_type, "removal-deletion"); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if (is_multisite()) { remove_user_from_blog($user_id, $current_blog->blog_id); /* This will automatically trigger `eot_del_notification_urls` as well. */ c_ws_plugin__optimizemember_user_deletions::handle_ms_user_deletions($user_id, $current_blog->blog_id, "s2says"); } else { /* Otherwise, we can actually delete them. */ /* This will automatically trigger `eot_del_notification_urls` as well. */ wp_delete_user($user_id); } /* `c_ws_plugin__optimizemember_user_deletions::handle_user_deletions()` */ /**/ $paypal["optimizemember_log"][] = "This Member's account has been " . (is_multisite() ? "removed" : "deleted") . "."; /**/ $paypal["optimizemember_log"][] = "EOT/Deletion Notification URLs have been processed."; /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_eot_delete", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_eot", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { $processing = $during = true; /* Yes, we ARE processing this. */ /**/ update_user_option($user_id, "optimizemember_auto_eot_time", $auto_eot_time = strtotime("now")); /**/ $paypal["optimizemember_log"][] = "Auto-EOT is currently disabled. Skipping immediate EOT ( demote|delete ), for now."; $paypal["optimizemember_log"][] = "Recording the Auto-EOT Time for this Member's account: " . date("D M j, Y g:i a T", $auto_eot_time); /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_eot_disabled", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } } else { $paypal["optimizemember_log"][] = "Unable to ( demote|delete ) Member. The existing User ID is associated with an Administrator. Stopping here. Otherwise, an Administrator could lose access."; } } else { if ($is_delayed_eot && !get_user_option("optimizemember_auto_eot_time", $user_id)) { if (!$user->has_cap("administrator")) { $processing = $during = true; /* Yes, we ARE processing this. */ /**/ $auto_eot_time = c_ws_plugin__optimizemember_utils_time::auto_eot_time($user_id, $paypal["period1"], $paypal["period3"], "", time()); /* We assume the last payment was today, because this is how newer PayPal accounts function with respect to EOT handling. Newer PayPal accounts ( i.e. Subscription IDs starting with `I-`, will have their EOT triggered upon the last payment. */ update_user_option($user_id, "optimizemember_auto_eot_time", $auto_eot_time); /* optimizeMember will follow-up on this later. */ /**/ $paypal["optimizemember_log"][] = "Auto-EOT Time for this account ( delayed ), set to: " . date("D M j, Y g:i a T", $auto_eot_time); /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_eot_delayed", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } else { $paypal["optimizemember_log"][] = "Ignoring Delayed EOT. The existing User ID is associated with an Administrator. Stopping here. Otherwise, an Administrator could lose access."; } } else { if (!$is_refund_or_reversal || $is_delayed_eot) { $paypal["optimizemember_log"][] = "Skipping ( demote|delete ) Member, for now. An Auto-EOT Time is already set for this account. When an Auto-EOT Time has been recorded, optimizeMember will handle EOT ( demote|delete ) events using it's own Auto-EOT System - internally."; } else { if ($is_reversal) { $paypal["optimizemember_log"][] = "Skipping ( demote|delete ) Member. Your configuration dictates that optimizeMember should NOT take any immediate action on an EOT associated with a Chargeback Reversal. An optimizeMember API Notification will still be processed however."; } else { if ($is_refund) { $paypal["optimizemember_log"][] = "Skipping ( demote|delete ) Member. Your configuration dictates that optimizeMember should NOT take any immediate action on an EOT associated with a Refund. An optimizeMember API Notification will still be processed however."; } } } } } } else { if ($is_delayed_eot) { $paypal["optimizemember_log"][] = "Skipping this IPN response, for now. The Subscr. ID is not associated with a registered Member."; /**/ $ipn = array("txn_type" => "subscr_eot"); /* Create a simulated IPN response for txn_type=subscr_eot. */ /**/ foreach ($paypal as $var => $val) { if (in_array($var, array("subscr_gateway", "subscr_id", "custom", "invoice", "payer_email", "first_name", "last_name", "item_name", "item_number", "option_name1", "option_selection1", "option_name2", "option_selection2"))) { $ipn[$var] = $val; } } /**/ $paypal["optimizemember_log"][] = "Re-generating. This IPN will go into a Transient Queue; and be re-processed during registration."; /**/ set_transient("s2m_" . md5("optimizemember_transient_ipn_subscr_eot_" . $paypal["subscr_id"]), $ipn, 43200); } else { $paypal["optimizemember_log"][] = "Unable to ( demote|delete ) Member. Could not get the existing User ID from the DB. It's possible that it was ALREADY processed through another IPN, removed manually by a Site Administrator, or by optimizeMember's Auto-EOT Sys."; } } /* Refunds and chargeback reversals. This is excluded from the processing check, because a Member *could* have already been (demoted|deleted). In other words, optimizeMember sends `Refund/Reversal` Notifications ANYTIME a Refund/Reversal occurs; even if optimizeMember did not process it otherwise. Since this routine ignores the processing check, it is *possible* that Refund/Reversal Notification URLs will be contacted more than once. If you're writing scripts that depend on Refund/Reversal Notifications, please keep this in mind. */ if ($is_refund_or_reversal) { $fields = $user_id ? get_user_option("optimizemember_custom_fields", $user_id) : array(); /* These will be needed below. */ $user_reg_ip = $user_id ? get_user_option("optimizemember_registration_ip", $user_id) : ""; /* Needed below. */ $user_reg_ip = $paypal["ip"] = $user_reg_ip ? $user_reg_ip : $paypal["ip"]; /* Now merge conditionally. */ /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["ref_rev_notification_urls"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["ref_rev_notification_urls"]) as $url) { /**/ if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["subscr_id"])), $url)) && ($url = preg_replace("/%%parent_txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["parent_txn_id"])), $url))) { if (($url = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_number"])), $url)) && ($url = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["item_name"])), $url))) { if (($url = preg_replace("/%%-amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["mc_gross"])), $url)) && ($url = preg_replace("/%%-fee%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["mc_fee"])), $url))) { if (($url = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["first_name"])), $url)) && ($url = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["last_name"])), $url))) { if ($url = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(trim($paypal["first_name"] . " " . $paypal["last_name"]))), $url)) { if ($url = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($paypal["payer_email"])), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_reg_ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($user_id)), $url)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } } /**/ if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__optimizemember_utils_urls::remote($url); } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Refund/Reversal Notification URLs have been processed."; } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["ref_rev_notification_recipients"] && is_array($cv = preg_split("/\\|/", $paypal["custom"]))) { $msg = $sbj = "( optimizeMember / API Notification Email ) - Refund/Reversal"; $msg .= "\n\n"; /* Spacing in the message body. */ /**/ $msg .= "subscr_id: %%subscr_id%%\n"; $msg .= "parent_txn_id: %%parent_txn_id%%\n"; $msg .= "item_number: %%item_number%%\n"; $msg .= "item_name: %%item_name%%\n"; $msg .= "-amount: %%-amount%%\n"; $msg .= "-fee: %%-fee%%\n"; $msg .= "first_name: %%first_name%%\n"; $msg .= "last_name: %%last_name%%\n"; $msg .= "full_name: %%full_name%%\n"; $msg .= "payer_email: %%payer_email%%\n"; $msg .= "user_ip: %%user_ip%%\n"; $msg .= "user_id: %%user_id%%\n"; /**/ if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { $msg .= $var . ": %%" . $var . "%%\n"; } } /**/ $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; /**/ if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%subscr_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["subscr_id"]), $msg)) && ($msg = preg_replace("/%%parent_txn_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["parent_txn_id"]), $msg))) { if (($msg = preg_replace("/%%item_number%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_number"]), $msg)) && ($msg = preg_replace("/%%item_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["item_name"]), $msg))) { if (($msg = preg_replace("/%%-amount%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_gross"]), $msg)) && ($msg = preg_replace("/%%-fee%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["mc_fee"]), $msg))) { if (($msg = preg_replace("/%%first_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["first_name"]), $msg)) && ($msg = preg_replace("/%%last_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["last_name"]), $msg))) { if ($msg = preg_replace("/%%full_name%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(trim($paypal["first_name"] . " " . $paypal["last_name"])), $msg)) { if ($msg = preg_replace("/%%payer_email%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($paypal["payer_email"]), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_reg_ip), $msg)) { if ($msg = preg_replace("/%%user_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds($user_id), $msg)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { /* Custom Registration/Profile Fields. */ if (!($msg = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(maybe_serialize($val)), $msg))) { break; } } } /**/ if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { /* Still have a ``$sbj`` and a ``$msg``? */ /**/ foreach (c_ws_plugin__optimizemember_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["ref_rev_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__optimizemember_ref_rev_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__optimizemember_ref_rev_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=utf-8"); } } } } } } } } } } /**/ $paypal["optimizemember_log"][] = "Refund/Reversal Notification Emails have been processed."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_during_subscr_eot_refund_reversal", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ } } else { $paypal["optimizemember_log"][] = "Not processing. Duplicate IPN."; $paypal["optimizemember_log"][] = "optimizeMember `txn_type` identified as a type of EOT."; $paypal["optimizemember_log"][] = "Duplicate IPN. Already processed. This IPN will be ignored."; } /**/ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_paypal_notify_after_subscr_eot", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_subscr_or_rp_eots_w_level", $paypal, get_defined_vars()); } else { return apply_filters("c_ws_plugin__optimizemember_paypal_notify_in_subscr_or_rp_eots_w_level", false, get_defined_vars()); } }
/** * Handles processing of Pro Form cancellations. * * @package optimizeMember\PayPal * @since 1.5 * * @attaches-to ``add_action("init");`` * * @return null Or exits script execution after a custom URL redirection. */ public static function paypal_cancellation() { if (!empty($_POST["optimizemember_pro_paypal_cancellation"]["nonce"]) && ($nonce = $_POST["optimizemember_pro_paypal_cancellation"]["nonce"]) && wp_verify_nonce($nonce, "s2member-pro-paypal-cancellation")) { $GLOBALS["ws_plugin__optimizemember_pro_paypal_cancellation_response"] = array(); /* This holds the global response details. */ $global_response =& $GLOBALS["ws_plugin__optimizemember_pro_paypal_cancellation_response"]; /* This is a shorter reference. */ /**/ $post_vars = c_ws_plugin__optimizemember_utils_strings::trim_deep(stripslashes_deep($_POST["optimizemember_pro_paypal_cancellation"])); $post_vars["attr"] = unserialize(c_ws_plugin__optimizemember_utils_encryption::decrypt($post_vars["attr"])); /* And run a Filter. */ $post_vars["attr"] = apply_filters("ws_plugin__optimizemember_pro_paypal_cancellation_post_attr", $post_vars["attr"], get_defined_vars()); /**/ $post_vars["recaptcha_challenge_field"] = !$post_vars["recaptcha_challenge_field"] ? trim(stripslashes($_POST["recaptcha_challenge_field"])) : $post_vars["recaptcha_challenge_field"]; $post_vars["recaptcha_response_field"] = !$post_vars["recaptcha_response_field"] ? trim(stripslashes($_POST["recaptcha_response_field"])) : $post_vars["recaptcha_response_field"]; /**/ if (!c_ws_plugin__optimizemember_pro_paypal_responses::paypal_form_attr_validation_errors($post_vars["attr"])) { if (!($error = c_ws_plugin__optimizemember_pro_paypal_responses::paypal_form_submission_validation_errors("cancellation", $post_vars))) { if (is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID)) { if ($cur__subscr_id = get_user_option("optimizemember_subscr_id")) { if (($paypal = c_ws_plugin__optimizemember_pro_paypal_utilities::payflow_get_profile($cur__subscr_id)) && $paypal["TENDER"] !== "P") { if (preg_match("/^(Active|ActiveProfile|Suspended|SuspendedProfile)\$/i", $paypal["STATUS"])) { if (!($ipn = array())) { $ipn["txn_type"] = "subscr_cancel"; $ipn["subscr_id"] = $paypal["PROFILEID"]; $ipn["custom"] = get_user_option("optimizemember_custom"); /**/ $ipn["period1"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period1($paypal); $ipn["period3"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period3($paypal); /**/ $ipn["payer_email"] = $paypal["EMAIL"]; $ipn["first_name"] = $paypal["FIRSTNAME"]; $ipn["last_name"] = $paypal["LASTNAME"]; /**/ $ipn["option_name1"] = "Referencing Customer ID"; $ipn["option_selection1"] = $paypal["PROFILEID"]; /**/ $ipn["option_name2"] = "Customer IP Address"; /* IP Address. */ $ipn["option_selection2"] = get_user_option("optimizemember_registration_ip"); /**/ $ipn["item_name"] = $paypal["DESC"] ? $paypal["DESC"] : $paypal["PROFILENAME"]; $ipn["item_number"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_item_number($paypal); /**/ $ipn_q = "&optimizemember_paypal_proxy=paypal&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } /**/ c_ws_plugin__optimizemember_pro_paypal_utilities::payflow_cancel_profile($paypal["PROFILEID"]); /**/ $global_response = array("response" => _x('<strong>Billing termination confirmed.</strong> Your account has been cancelled.', "s2member-front", "s2member")); /**/ if ($post_vars["attr"]["success"] && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $post_vars["attr"]["success"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } else { if (preg_match("/^(Pending|PendingProfile)\$/i", $paypal["STATUS"])) { $global_response = array("response" => _x('<strong>Unable to cancel at this time.</strong> Your account is pending other changes. Please try again in 15 minutes.', "s2member-front", "s2member"), "error" => true); } else { $global_response = array("response" => _x('<strong>Billing terminated.</strong> Your account has been cancelled.', "s2member-front", "s2member")); /**/ if ($post_vars["attr"]["success"] && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $post_vars["attr"]["success"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } } } else { if ($paypal && $paypal["TENDER"] === "P") { $global_response = array("response" => sprintf(_x('Please <a href="%s" rel="nofollow">log in at PayPal</a> to cancel your Subscription.', "s2member-front", "s2member"), esc_attr("https://" . ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["paypal_sandbox"] ? "www.sandbox.paypal.com" : "www.paypal.com") . "/cgi-bin/webscr?cmd=_subscr-find&alias=" . urlencode($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["paypal_business"]))), "error" => true); } else { $global_response = array("response" => _x('<strong>Billing terminated.</strong> Your account has been cancelled.', "s2member-front", "s2member")); /**/ if ($post_vars["attr"]["success"] && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $post_vars["attr"]["success"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } } } else { $global_response = array("response" => _x('<strong>Billing terminated.</strong> Your account has been cancelled.', "s2member-front", "s2member")); /**/ if ($post_vars["attr"]["success"] && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $post_vars["attr"]["success"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } } else { $global_response = array("response" => _x('You\'re <strong>NOT</strong> logged in.', "s2member-front", "s2member"), "error" => true); } } else { $global_response = $error; } } } }
/** * Handles Authorize.Net IPN URL processing. * * @package optimizeMember\AuthNet * @since 1.5 * * @attaches-to ``add_action("init");`` * * @return null Or exits script execution after handling IPN processing. */ public static function authnet_notify() { global $current_site, $current_blog; /* For Multisite support. */ /**/ if (!empty($_GET["optimizemember_pro_authnet_notify"]) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_authnet_api_login_id"]) { @ignore_user_abort(true); /* Continue processing even if/when connection is broken by the sender. */ /**/ if (is_array($authnet = c_ws_plugin__optimizemember_pro_authnet_utilities::authnet_postvars()) && ($_authnet = $authnet)) { $authnet["optimizemember_log"][] = "IPN received on: " . date("D M j, Y g:i:s a T"); $authnet["optimizemember_log"][] = "optimizeMember POST vars verified with Authorize.Net."; /**/ if ($authnet["x_subscription_id"] && $authnet["x_subscription_paynum"] && $authnet["x_response_code"] === "1") { if (($_authnet = c_ws_plugin__optimizemember_pro_authnet_utilities::authnet_parse_arb_desc($authnet)) && ($authnet = $_authnet)) { $authnet["optimizemember_log"][] = "Authorize.Net transaction identified as ( `ARB / PAYMENT #" . $authnet["x_subscription_paynum"] . "` )."; $authnet["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as `txn_type` ( `subscr_payment` )."; $authnet["optimizemember_log"][] = "Please check PayPal IPN logs for further processing details."; /**/ $processing = $processed = true; $ipn = array(); /* Reset. */ /**/ $ipn["txn_type"] = "subscr_payment"; $ipn["subscr_id"] = $authnet["x_subscription_id"]; $ipn["txn_id"] = $authnet["x_trans_id"]; /**/ $ipn["custom"] = $authnet["s2_custom"]; /**/ $ipn["mc_gross"] = number_format($authnet["x_amount"], 2, ".", ""); $ipn["mc_currency"] = strtoupper("USD"); /* Auth.Net uses USD. */ $ipn["tax"] = number_format($authnet["x_tax"], 2, ".", ""); /**/ $ipn["payer_email"] = $authnet["x_email"]; $ipn["first_name"] = $authnet["x_first_name"]; $ipn["last_name"] = $authnet["x_last_name"]; /**/ $ipn["option_name1"] = "Referencing Customer ID"; $ipn["option_selection1"] = $authnet["x_subscription_id"]; /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = null; /**/ $ipn["item_number"] = $authnet["s2_invoice"]; $ipn["item_name"] = $authnet["x_description"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=authnet&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); /**/ c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); } else { $authnet["optimizemember_log"][] = "Authorize.Net transaction identified as ( `ARB / PAYMENT #" . $authnet["x_subscription_paynum"] . "` )."; $authnet["optimizemember_log"][] = "Ignoring this IPN. The transaction does NOT contain a valid reference value/desc."; } } else { if ($authnet["x_subscription_id"] && $authnet["x_subscription_paynum"] && preg_match("/^(2|3)\$/", $authnet["x_response_code"])) { if (($_authnet = c_ws_plugin__optimizemember_pro_authnet_utilities::authnet_parse_arb_desc($authnet)) && ($authnet = $_authnet)) { $authnet["optimizemember_log"][] = "Authorize.Net transaction identified as ( `ARB / FAILED PAYMENT` )."; $authnet["optimizemember_log"][] = "optimizeMember does NOT respond to individual failed payment notifications."; $authnet["optimizemember_log"][] = "When multiple consecutive payments fail, optimizeMember is notified via ARB services."; $authnet["optimizemember_log"][] = "This does not require any action ( at the moment ) on the part of optimizeMember."; } else { $authnet["optimizemember_log"][] = "Authorize.Net transaction identified as ( `ARB / FAILED PAYMENT` )."; $authnet["optimizemember_log"][] = "Ignoring this IPN. The transaction does NOT contain a valid reference value/desc."; } } else { if (!$processed) { /* If nothing was processed, here we add a message to the logs indicating the IPN was ignored. */ $authnet["optimizemember_log"][] = "Ignoring this IPN. The transaction does NOT require any action on the part of optimizeMember."; } } } } else { $authnet["optimizemember_log"][] = "Unable to verify POST vars. This is most likely related to an invalid Authorize.Net configuration. Please check: optimizeMember -> Authorize.Net Options."; $authnet["optimizemember_log"][] = "If you're absolutely SURE that your Authorize.Net configuration is valid, you may want to run some tests on your server, just to be sure \$_POST variables are populated, and that your server is able to connect to Authorize.Net over an HTTPS connection."; $authnet["optimizemember_log"][] = "optimizeMember uses the WP_Http class for remote connections; which will try to use cURL first, and then fall back on the FOPEN method when cURL is not available. On a Windows server, you may have to disable your cURL extension. Instead, set allow_url_fopen = yes in your php.ini file. The cURL extension (usually) does NOT support SSL connections on a Windows server."; $authnet["optimizemember_log"][] = var_export($_REQUEST, true); /* Recording _POST + _GET vars for analysis and debugging. */ } /* If debugging/logging is enabled; we need to append $authnet to the log file. Logging now supports Multisite Networking as well. */ $logv = c_ws_plugin__optimizemember_utilities::ver_details(); $logm = c_ws_plugin__optimizemember_utilities::mem_details(); $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; $log4 = is_multisite() && !is_main_site() ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; $log2 = is_multisite() && !is_main_site() ? "authnet-ipn-4-" . trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "authnet-ipn.log"; /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["gateway_debug_logs"]) { if (is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["logs_dir"])) { if (is_writable($logs_dir) && c_ws_plugin__optimizemember_utils_logs::archive_oversize_log_files()) { file_put_contents($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export($authnet, true) . "\n\n", FILE_APPEND); } } } /**/ status_header(200); /* Send a 200 OK status header. */ header("Content-Type: text/plain; charset=utf-8"); /* Content-Type text/plain with UTF-8. */ eval('while (@ob_end_clean ());'); /* End/clean all output buffers that may or may not exist. */ /**/ exit; /* Exit now. */ } }
/** * Handles processing of Pro Form checkouts. * * @package optimizeMember\PayPal * @since 1.5 * * @attaches-to ``add_action("init");`` * * @return null Or exits script execution after a custom URL redirection; or upon Express Checkout redirection. */ public static function paypal_checkout() { if (!empty($_POST["optimizemember_pro_paypal_checkout"]["nonce"]) && ($nonce = $_POST["optimizemember_pro_paypal_checkout"]["nonce"]) && wp_verify_nonce($nonce, "s2member-pro-paypal-checkout") || !empty($_GET["optimizemember_paypal_xco"]) && $_GET["optimizemember_paypal_xco"] === "optimizemember_pro_paypal_checkout_return" && !empty($_GET["token"]) && ($_GET["token"] = esc_html($_GET["token"])) && (empty($_GET["PayerID"]) || ($_GET["PayerID"] = esc_html($_GET["PayerID"]))) && ($xco_post_vars = get_transient("s2m_" . md5("optimizemember_transient_express_checkout_" . $_GET["token"])))) { $GLOBALS["ws_plugin__optimizemember_pro_paypal_checkout_response"] = array(); /* This holds the global response details. */ $global_response =& $GLOBALS["ws_plugin__optimizemember_pro_paypal_checkout_response"]; /* This is a shorter reference. */ /**/ $post_vars = $xco_post_vars ? $xco_post_vars : $_POST["optimizemember_pro_paypal_checkout"]; $post_vars = c_ws_plugin__optimizemember_utils_strings::trim_deep(stripslashes_deep($post_vars)); /* And Filter. */ $post_vars["attr"] = !$xco_post_vars ? unserialize(c_ws_plugin__optimizemember_utils_encryption::decrypt($post_vars["attr"])) : $post_vars["attr"]; $post_vars["attr"] = !$xco_post_vars ? apply_filters("ws_plugin__optimizemember_pro_paypal_checkout_post_attr", $post_vars["attr"], get_defined_vars()) : $post_vars["attr"]; /**/ if ($xco_post_vars) { /* No need to re-validate this upon return from Express Checkout. */ $post_vars["attr"]["captcha"] = "0"; } /**/ $post_vars["recaptcha_challenge_field"] = !$post_vars["recaptcha_challenge_field"] ? trim(stripslashes($_POST["recaptcha_challenge_field"])) : $post_vars["recaptcha_challenge_field"]; $post_vars["recaptcha_response_field"] = !$post_vars["recaptcha_response_field"] ? trim(stripslashes($_POST["recaptcha_response_field"])) : $post_vars["recaptcha_response_field"]; /**/ $post_vars["name"] = trim($post_vars["first_name"] . " " . $post_vars["last_name"]); $post_vars["email"] = apply_filters("user_registration_email", sanitize_email($post_vars["email"]), get_defined_vars()); $post_vars["username"] = preg_replace("/\\s+/", "", sanitize_user($post_vars["username"], is_multisite())); /**/ !empty($_GET["token"]) ? delete_transient("s2m_" . md5("optimizemember_transient_express_checkout_" . $_GET["token"])) : null; /**/ if (!c_ws_plugin__optimizemember_pro_paypal_responses::paypal_form_attr_validation_errors($post_vars["attr"])) { if (!($error = c_ws_plugin__optimizemember_pro_paypal_responses::paypal_form_submission_validation_errors("checkout", $post_vars))) { $cp_attr = c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_apply_coupon($post_vars["attr"], $post_vars["coupon"], "attr", array("affiliates-silent-post")); $cp_2gbp_attr = c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_maestro_solo_2gbp($cp_attr, $post_vars["card_type"]); $cost_calculations = c_ws_plugin__optimizemember_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"]); /**/ $use_recurring_profile = $post_vars["attr"]["rr"] === "BN" || !$post_vars["attr"]["tp"] && !$post_vars["attr"]["rr"] ? false : true; $is_independent_ccaps_sale = $post_vars["attr"]["level"] === "*" ? true : false; /* Selling Independent Custom Capabilities? */ /**/ if (empty($_GET["optimizemember_paypal_xco"]) && $post_vars["card_type"] === "PayPal") { $return_url = $cancel_url = is_ssl() ? "https://" : "http://"; $return_url = $cancel_url = ($return_url = $cancel_url) . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; $return_url = $cancel_url = remove_query_arg(array("token", "PayerID"), $return_url = $cancel_url); $return_url = add_query_arg("optimizemember_paypal_xco", urlencode("optimizemember_pro_paypal_checkout_return"), $return_url); $cancel_url = add_query_arg("optimizemember_paypal_xco", urlencode("optimizemember_pro_paypal_checkout_cancel"), $cancel_url); /**/ $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID) ? $user : false; /**/ if (!($paypal_set_xco = array())) { $paypal_set_xco["METHOD"] = "SetExpressCheckout"; /**/ $paypal_set_xco["RETURNURL"] = $return_url; $paypal_set_xco["CANCELURL"] = $cancel_url; /**/ $paypal_set_xco["PAGESTYLE"] = $post_vars["attr"]["ps"]; $paypal_set_xco["LOCALECODE"] = $post_vars["attr"]["lc"]; $paypal_set_xco["NOSHIPPING"] = $post_vars["attr"]["ns"]; $paypal_set_xco["SOLUTIONTYPE"] = "Sole"; $paypal_set_xco["LANDINGPAGE"] = "Billing"; $paypal_set_xco["ALLOWNOTE"] = "0"; /**/ if ($use_recurring_profile) { $paypal_set_xco["L_BILLINGTYPE0"] = "RecurringPayments"; $paypal_set_xco["L_BILLINGAGREEMENTDESCRIPTION0"] = $cost_calculations["desc"]; if ($post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0) { $paypal_set_xco["MAXAMT"] = $cost_calculations["trial_total"]; } else { $paypal_set_xco["MAXAMT"] = $cost_calculations["total"]; } } else { $paypal_set_xco["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; $paypal_set_xco["MAXAMT"] = $cost_calculations["total"]; /**/ $paypal_set_xco["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"]; $paypal_set_xco["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"]; /**/ $paypal_set_xco["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"]; $paypal_set_xco["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"]; $paypal_set_xco["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"]; $paypal_set_xco["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"]; /**/ $paypal_set_xco["L_PAYMENTREQUEST_0_QTY0"] = "1"; /* Always (1). */ $paypal_set_xco["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"]; $paypal_set_xco["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"]; $paypal_set_xco["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"]; } /**/ $paypal_set_xco["PAYMENTREQUEST_0_SHIPTONAME"] = $post_vars["name"]; $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOSTREET"] = $post_vars["street"]; $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOCITY"] = $post_vars["city"]; $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOSTATE"] = $post_vars["state"]; $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE"] = $post_vars["country"]; $paypal_set_xco["PAYMENTREQUEST_0_SHIPTOZIP"] = $post_vars["zip"]; /**/ $paypal_set_xco["EMAIL"] = $user ? $user->user_email : $post_vars["email"]; } /**/ if (($paypal_set_xco = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal_set_xco)) && empty($paypal_set_xco["__error"])) { set_transient("s2m_" . md5("optimizemember_transient_express_checkout_" . $paypal_set_xco["TOKEN"]), $post_vars, 10800); /**/ $endpoint = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["paypal_sandbox"] ? "www.sandbox.paypal.com" : "www.paypal.com"; /**/ wp_redirect(add_query_arg("token", urlencode($paypal_set_xco["TOKEN"]), "https://" . $endpoint . "/cgi-bin/webscr?cmd=_express-checkout")); /**/ exit; /* Clean exit. */ } else { $global_response = array("response" => $paypal_set_xco["__error"], "error" => true); } } else { if ($use_recurring_profile && is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID)) { if (!($cur__subscr_id = get_user_option("optimizemember_subscr_id")) || !($paypal = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response(array("METHOD" => "GetRecurringPaymentsProfileDetails", "PROFILEID" => $cur__subscr_id))) || !empty($paypal["__error"]) || !preg_match("/^(Pending|PendingProfile)\$/i", $paypal["STATUS"])) { $period1 = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period1($post_vars["attr"]["tp"] . " " . $post_vars["attr"]["tt"]); $period3 = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period3($post_vars["attr"]["rp"] . " " . $post_vars["attr"]["rt"]); /**/ $start_time = $post_vars["attr"]["tp"] ? c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_start_time($period1) : c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_start_time($period3); /* Or next billing cycle. */ /**/ $reference = $start_time . ":" . $period1 . ":" . $period3 . "~" . $_SERVER["HTTP_HOST"] . "~" . $post_vars["attr"]["level_ccaps_eotper"]; /**/ update_user_meta($user_id, "first_name", $post_vars["first_name"]) . update_user_meta($user_id, "last_name", $post_vars["last_name"]); /**/ if (!($paypal = array())) { $paypal["METHOD"] = "CreateRecurringPaymentsProfile"; /**/ $paypal["EMAIL"] = $user->user_email; $paypal["FIRSTNAME"] = $post_vars["first_name"]; $paypal["LASTNAME"] = $post_vars["last_name"]; $paypal["SUBSCRIBERNAME"] = $post_vars["name"]; /**/ $paypal["DESC"] = $cost_calculations["desc"]; $paypal["PROFILEREFERENCE"] = $reference; /**/ if (!$post_vars["attr"]["tp"] || $post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0) { $paypal["INITAMT"] = $post_vars["attr"]["tp"] ? $cost_calculations["trial_total"] : $cost_calculations["total"]; $paypal["FAILEDINITAMTACTION"] = "CancelOnFailure"; } /**/ $paypal["CURRENCYCODE"] = $cost_calculations["cur"]; $paypal["AMT"] = $cost_calculations["sub_total"]; $paypal["TAXAMT"] = $cost_calculations["tax"]; /**/ $paypal["MAXFAILEDPAYMENTS"] = $post_vars["attr"]["rra"]; $paypal["AUTOBILLOUTAMT"] = apply_filters("ws_plugin__optimizemember_pro_paypal_auto_bill_op", "AddToNextBilling", get_defined_vars()); /**/ $paypal["PROFILESTARTDATE"] = date("Y-m-d", $start_time) . "T00:00:00Z"; /**/ $paypal["BILLINGPERIOD"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_term($post_vars["attr"]["rt"]); $paypal["TOTALBILLINGCYCLES"] = $post_vars["attr"]["rr"] ? $post_vars["attr"]["rrt"] ? $post_vars["attr"]["rrt"] : "0" : "1"; $paypal["BILLINGFREQUENCY"] = $post_vars["attr"]["rp"]; /**/ if ($_GET["optimizemember_paypal_xco"] === "optimizemember_pro_paypal_checkout_return" && !empty($_GET["token"]) && ($paypal_xco_details = array("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($paypal_xco_details = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal_xco_details)) && empty($paypal_xco_details["__error"])) { $paypal["TOKEN"] = $paypal_xco_details["TOKEN"]; } else { $paypal["CREDITCARDTYPE"] = $post_vars["card_type"]; $paypal["ACCT"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]); $paypal["EXPDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_expiration"]); $paypal["CVV2"] = $post_vars["card_verification"]; /**/ if (in_array($post_vars["card_type"], array("Maestro", "Solo"))) { if (preg_match("/^[0-9]{2}\\/[0-9]{4}\$/", $post_vars["card_start_date_issue_number"])) { $paypal["STARTDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]); } else { /* Otherwise, we assume they provided an Issue Number instead. */ $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"]; } } /**/ $paypal["STREET"] = $post_vars["street"]; $paypal["CITY"] = $post_vars["city"]; $paypal["STATE"] = $post_vars["state"]; $paypal["COUNTRYCODE"] = $post_vars["country"]; $paypal["ZIP"] = $post_vars["zip"]; } } /**/ if (($paypal = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal)) && empty($paypal["__error"])) { $old__subscr_or_wp_id = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id(); $old__subscr_id = get_user_option("optimizemember_subscr_id"); $new__subscr_id = $paypal["PROFILEID"]; /**/ if (!($ipn = array())) { $ipn["txn_type"] = "subscr_signup"; $ipn["subscr_id"] = $new__subscr_id; $ipn["custom"] = $post_vars["attr"]["custom"]; /**/ $ipn["txn_id"] = $new__subscr_id; /**/ $ipn["period1"] = $period1; $ipn["period3"] = $period3; /**/ $ipn["mc_amount1"] = $cost_calculations["trial_total"]; $ipn["mc_amount3"] = $cost_calculations["total"]; /**/ $ipn["mc_gross"] = preg_match("/^[1-9]/", $ipn["period1"]) ? $ipn["mc_amount1"] : $ipn["mc_amount3"]; /**/ $ipn["mc_currency"] = $cost_calculations["cur"]; $ipn["tax"] = $cost_calculations["tax"]; /**/ $ipn["recurring"] = $post_vars["attr"]["rr"] ? "1" : ""; /**/ $ipn["payer_email"] = $user->user_email; $ipn["first_name"] = $post_vars["first_name"]; $ipn["last_name"] = $post_vars["last_name"]; /**/ $ipn["option_name1"] = "Referencing Customer ID"; $ipn["option_selection1"] = $old__subscr_or_wp_id; /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"]; /**/ $ipn["item_name"] = $cost_calculations["desc"]; $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=paypal&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= $ipn["mc_gross"] > 0 ? ",subscr-signup-as-subscr-payment" : ""; /* Use as first payment? */ $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); $ipn_q .= "&optimizemember_paypal_proxy_return_url=" . rawurlencode($post_vars["attr"]["success"]); /**/ $ipn["optimizemember_paypal_proxy_return_url"] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20))); } /**/ if (!($paypal = array()) && ($paypal["PROFILEID"] = $old__subscr_id)) { $paypal["METHOD"] = "ManageRecurringPaymentsProfileStatus"; $paypal["ACTION"] = "Cancel"; /**/ c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal); } /**/ setcookie("optimizemember_tracking", $optimizemember_tracking = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__subscr_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie("optimizemember_tracking", $optimizemember_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE["optimizemember_tracking"] = $optimizemember_tracking); /**/ $global_response = array("response" => sprintf(_x('<strong>Thank you.</strong> Your account has been updated.<br />— Please <a href="%s" rel="nofollow">log back in</a> now.', "s2member-front", "s2member"), esc_attr(wp_login_url()))); /**/ if ($post_vars["attr"]["success"] && substr($ipn["optimizemember_paypal_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["optimizemember_paypal_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } else { $global_response = array("response" => $paypal["__error"], "error" => true); } } else { $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); } } else { if ($use_recurring_profile && !is_user_logged_in()) { $period1 = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period1($post_vars["attr"]["tp"] . " " . $post_vars["attr"]["tt"]); $period3 = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_period3($post_vars["attr"]["rp"] . " " . $post_vars["attr"]["rt"]); /**/ $start_time = $post_vars["attr"]["tp"] ? c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_start_time($period1) : c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_start_time($period3); /* Or next billing cycle. */ /**/ $reference = $start_time . ":" . $period1 . ":" . $period3 . "~" . $_SERVER["HTTP_HOST"] . "~" . $post_vars["attr"]["level_ccaps_eotper"]; /**/ if (!($paypal = array())) { $paypal["METHOD"] = "CreateRecurringPaymentsProfile"; /**/ $paypal["EMAIL"] = $post_vars["email"]; $paypal["FIRSTNAME"] = $post_vars["first_name"]; $paypal["LASTNAME"] = $post_vars["last_name"]; $paypal["SUBSCRIBERNAME"] = $post_vars["name"]; /**/ $paypal["DESC"] = $cost_calculations["desc"]; $paypal["PROFILEREFERENCE"] = $reference; /**/ if (!$post_vars["attr"]["tp"] || $post_vars["attr"]["tp"] && $cost_calculations["trial_total"] > 0) { $paypal["INITAMT"] = $post_vars["attr"]["tp"] ? $cost_calculations["trial_total"] : $cost_calculations["total"]; $paypal["FAILEDINITAMTACTION"] = "CancelOnFailure"; } /**/ $paypal["CURRENCYCODE"] = $cost_calculations["cur"]; $paypal["AMT"] = $cost_calculations["sub_total"]; $paypal["TAXAMT"] = $cost_calculations["tax"]; /**/ $paypal["MAXFAILEDPAYMENTS"] = $post_vars["attr"]["rra"]; $paypal["AUTOBILLOUTAMT"] = apply_filters("ws_plugin__optimizemember_pro_paypal_auto_bill_op", "AddToNextBilling", get_defined_vars()); /**/ $paypal["PROFILESTARTDATE"] = date("Y-m-d", $start_time) . "T00:00:00Z"; /**/ $paypal["BILLINGPERIOD"] = c_ws_plugin__optimizemember_paypal_utilities::paypal_pro_term($post_vars["attr"]["rt"]); $paypal["TOTALBILLINGCYCLES"] = $post_vars["attr"]["rr"] ? $post_vars["attr"]["rrt"] ? $post_vars["attr"]["rrt"] : "0" : "1"; $paypal["BILLINGFREQUENCY"] = $post_vars["attr"]["rp"]; /**/ if ($_GET["optimizemember_paypal_xco"] === "optimizemember_pro_paypal_checkout_return" && !empty($_GET["token"]) && ($paypal_xco_details = array("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($paypal_xco_details = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal_xco_details)) && empty($paypal_xco_details["__error"])) { $paypal["TOKEN"] = $paypal_xco_details["TOKEN"]; } else { $paypal["CREDITCARDTYPE"] = $post_vars["card_type"]; $paypal["ACCT"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]); $paypal["EXPDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_expiration"]); $paypal["CVV2"] = $post_vars["card_verification"]; /**/ if (in_array($post_vars["card_type"], array("Maestro", "Solo"))) { if (preg_match("/^[0-9]{2}\\/[0-9]{4}\$/", $post_vars["card_start_date_issue_number"])) { $paypal["STARTDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]); } else { /* Otherwise, we assume they provided an Issue Number instead. */ $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"]; } } /**/ $paypal["STREET"] = $post_vars["street"]; $paypal["CITY"] = $post_vars["city"]; $paypal["STATE"] = $post_vars["state"]; $paypal["COUNTRYCODE"] = $post_vars["country"]; $paypal["ZIP"] = $post_vars["zip"]; } } /**/ if (($paypal = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal)) && empty($paypal["__error"])) { $new__subscr_id = $paypal["PROFILEID"]; /**/ if (!($ipn = array())) { $ipn["txn_type"] = "subscr_signup"; $ipn["subscr_id"] = $new__subscr_id; $ipn["custom"] = $post_vars["attr"]["custom"]; /**/ $ipn["txn_id"] = $new__subscr_id; /**/ $ipn["period1"] = $period1; $ipn["period3"] = $period3; /**/ $ipn["mc_amount1"] = $cost_calculations["trial_total"]; $ipn["mc_amount3"] = $cost_calculations["total"]; /**/ $ipn["mc_gross"] = preg_match("/^[1-9]/", $ipn["period1"]) ? $ipn["mc_amount1"] : $ipn["mc_amount3"]; /**/ $ipn["mc_currency"] = $cost_calculations["cur"]; $ipn["tax"] = $cost_calculations["tax"]; /**/ $ipn["recurring"] = $post_vars["attr"]["rr"] ? "1" : ""; /**/ $ipn["payer_email"] = $post_vars["email"]; $ipn["first_name"] = $post_vars["first_name"]; $ipn["last_name"] = $post_vars["last_name"]; /**/ $ipn["option_name1"] = "Originating Domain"; $ipn["option_selection1"] = $_SERVER["HTTP_HOST"]; /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"]; /**/ $ipn["item_name"] = $cost_calculations["desc"]; $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=paypal&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= $ipn["mc_gross"] > 0 ? ",subscr-signup-as-subscr-payment" : ""; /* Use as first payment? */ $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); $ipn_q .= "&optimizemember_paypal_proxy_return_url=" . rawurlencode($post_vars["attr"]["success"]); } /**/ if (!($create_user = array())) { $_POST["ws_plugin__optimizemember_custom_reg_field_user_pass1"] = $post_vars["password1"]; /* Fake this for registration configuration. */ $_POST["ws_plugin__optimizemember_custom_reg_field_first_name"] = $post_vars["first_name"]; /* Fake this for registration configuration. */ $_POST["ws_plugin__optimizemember_custom_reg_field_last_name"] = $post_vars["last_name"]; /* Fake this for registration configuration. */ $_POST["ws_plugin__optimizemember_custom_reg_field_opt_in"] = $post_vars["custom_fields"]["opt_in"]; /* Fake this too. */ /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_fields"]) { foreach (json_decode($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_fields"], true) as $field) { $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"])); $field_id_class = preg_replace("/_/", "-", $field_var); /**/ if (isset($post_vars["custom_fields"][$field_var])) { $_POST["ws_plugin__optimizemember_custom_reg_field_" . $field_var] = $post_vars["custom_fields"][$field_var]; } } } /**/ $_COOKIE["optimizemember_subscr_gateway"] = c_ws_plugin__optimizemember_utils_encryption::encrypt("paypal"); /* Fake this for registration configuration. */ $_COOKIE["optimizemember_subscr_id"] = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__subscr_id); /* Fake this for registration configuration. */ $_COOKIE["optimizemember_custom"] = c_ws_plugin__optimizemember_utils_encryption::encrypt($post_vars["attr"]["custom"]); /* Fake this for registration configuration. */ $_COOKIE["optimizemember_item_number"] = c_ws_plugin__optimizemember_utils_encryption::encrypt($post_vars["attr"]["level_ccaps_eotper"]); /* Fake this too. */ /**/ $create_user["user_login"] = $post_vars["username"]; /* Copy this into a separate array for `wp_create_user()`. */ $create_user["user_pass"] = wp_generate_password(); /* Which may fire `c_ws_plugin__optimizemember_registrations::generate_password()`. */ $create_user["user_email"] = $post_vars["email"]; /* Copy this into a separate array for `wp_create_user()`. */ } /**/ if ($post_vars["password1"] && $post_vars["password1"] === $create_user["user_pass"]) { if ((is_multisite() && ($new__user_id = c_ws_plugin__optimizemember_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)) { wp_new_user_notification($new__user_id, $create_user["user_pass"]); /**/ $ipn["optimizemember_paypal_proxy_return_url"] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20))); /**/ $global_response = array("response" => sprintf(_x('<strong>Thank you.</strong> Your account has been approved.<br />— Please <a href="%s" rel="nofollow">login</a>.', "s2member-front", "s2member"), esc_attr(wp_login_url()))); /**/ if ($post_vars["attr"]["success"] && substr($ipn["optimizemember_paypal_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["optimizemember_paypal_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } else { c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); /**/ $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true); } } else { if ((is_multisite() && ($new__user_id = c_ws_plugin__optimizemember_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)) { update_user_option($new__user_id, "default_password_nag", true, true); /* Password nag. */ wp_new_user_notification($new__user_id, $create_user["user_pass"]); /**/ $ipn["optimizemember_paypal_proxy_return_url"] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20))); /**/ $global_response = array("response" => _x('<strong>Thank you.</strong> Your account has been approved.<br />— You\'ll receive an email momentarily.', "s2member-front", "s2member")); /**/ if ($post_vars["attr"]["success"] && substr($ipn["optimizemember_paypal_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["optimizemember_paypal_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } else { c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); /**/ $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true); } } } else { $global_response = array("response" => $paypal["__error"], "error" => true); } } else { if (!$use_recurring_profile && is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID)) { if ($is_independent_ccaps_sale || !($cur__subscr_id = get_user_option("optimizemember_subscr_id")) || !($paypal = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response(array("METHOD" => "GetRecurringPaymentsProfileDetails", "PROFILEID" => $cur__subscr_id))) || !empty($paypal["__error"]) || !preg_match("/^(Pending|PendingProfile)\$/i", $paypal["STATUS"])) { update_user_meta($user_id, "first_name", $post_vars["first_name"]) . update_user_meta($user_id, "last_name", $post_vars["last_name"]); /**/ if (!($paypal = array())) { if ($_GET["optimizemember_paypal_xco"] === "optimizemember_pro_paypal_checkout_return" && !empty($_GET["token"]) && ($paypal_xco_details = array("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($paypal_xco_details = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal_xco_details)) && empty($paypal_xco_details["__error"])) { $paypal["METHOD"] = "DoExpressCheckoutPayment"; /**/ $paypal["TOKEN"] = $paypal_xco_details["TOKEN"]; $paypal["PAYERID"] = $paypal_xco_details["PAYERID"]; /**/ $paypal["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; /**/ $paypal["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"]; $paypal["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"]; /**/ $paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"]; $paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"]; $paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"]; $paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"]; /**/ $paypal["L_PAYMENTREQUEST_0_QTY0"] = "1"; /* Always (1). */ $paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"]; $paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"]; $paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"]; } else { $paypal["METHOD"] = "DoDirectPayment"; $paypal["PAYMENTACTION"] = "Sale"; /**/ $paypal["EMAIL"] = $user->user_email; $paypal["FIRSTNAME"] = $post_vars["first_name"]; $paypal["LASTNAME"] = $post_vars["last_name"]; $paypal["IPADDRESS"] = $_SERVER["REMOTE_ADDR"]; /**/ $paypal["DESC"] = $cost_calculations["desc"]; $paypal["CUSTOM"] = $post_vars["attr"]["custom"]; /**/ $paypal["CURRENCYCODE"] = $cost_calculations["cur"]; $paypal["ITEMAMT"] = $cost_calculations["sub_total"]; $paypal["TAXAMT"] = $cost_calculations["tax"]; $paypal["AMT"] = $cost_calculations["total"]; /**/ $paypal["L_QTY0"] = "1"; /* Always (1). */ $paypal["L_NAME0"] = $cost_calculations["desc"]; $paypal["L_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"]; $paypal["L_AMT0"] = $cost_calculations["sub_total"]; /**/ $paypal["CREDITCARDTYPE"] = $post_vars["card_type"]; $paypal["ACCT"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]); $paypal["EXPDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_expiration"]); $paypal["CVV2"] = $post_vars["card_verification"]; /**/ if (in_array($post_vars["card_type"], array("Maestro", "Solo"))) { if (preg_match("/^[0-9]{2}\\/[0-9]{4}\$/", $post_vars["card_start_date_issue_number"])) { $paypal["STARTDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]); } else { /* Otherwise, we assume they provided an Issue Number instead. */ $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"]; } } /**/ $paypal["STREET"] = $post_vars["street"]; $paypal["CITY"] = $post_vars["city"]; $paypal["STATE"] = $post_vars["state"]; $paypal["COUNTRYCODE"] = $post_vars["country"]; $paypal["ZIP"] = $post_vars["zip"]; } } /**/ if (($paypal = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal)) && empty($paypal["__error"])) { $old__subscr_id = get_user_option("optimizemember_subscr_id"); $old__subscr_or_wp_id = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id(); $new__subscr_id = $new__txn_id = !empty($paypal["PAYMENTINFO_0_TRANSACTIONID"]) ? $paypal["PAYMENTINFO_0_TRANSACTIONID"] : false; $new__subscr_id = $new__txn_id = !$new__subscr_id && !empty($paypal["TRANSACTIONID"]) ? $paypal["TRANSACTIONID"] : $new__subscr_id; /**/ if (!($ipn = array())) { $ipn["txn_type"] = "web_accept"; $ipn["txn_id"] = $new__subscr_id; $ipn["custom"] = $post_vars["attr"]["custom"]; /**/ $ipn["mc_gross"] = $cost_calculations["total"]; $ipn["mc_currency"] = $cost_calculations["cur"]; $ipn["tax"] = $cost_calculations["tax"]; /**/ $ipn["payer_email"] = $user->user_email; $ipn["first_name"] = $post_vars["first_name"]; $ipn["last_name"] = $post_vars["last_name"]; /**/ $ipn["option_name1"] = "Referencing Customer ID"; $ipn["option_selection1"] = $old__subscr_or_wp_id; /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"]; /**/ $ipn["item_name"] = $cost_calculations["desc"]; $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=paypal&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); $ipn_q .= "&optimizemember_paypal_proxy_return_url=" . rawurlencode($post_vars["attr"]["success"]); /**/ $ipn["optimizemember_paypal_proxy_return_url"] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20))); } /**/ if (!$is_independent_ccaps_sale) { /* Independent? */ if (!($paypal = array()) && ($paypal["PROFILEID"] = $old__subscr_id)) { $paypal["METHOD"] = "ManageRecurringPaymentsProfileStatus"; $paypal["ACTION"] = "Cancel"; /**/ c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal); } } /**/ setcookie("optimizemember_tracking", $optimizemember_tracking = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__subscr_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie("optimizemember_tracking", $optimizemember_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE["optimizemember_tracking"] = $optimizemember_tracking); /**/ $global_response = array("response" => sprintf(_x('<strong>Thank you.</strong> Your account has been updated.<br />— Please <a href="%s" rel="nofollow">log back in</a> now.', "s2member-front", "s2member"), esc_attr(wp_login_url()))); /**/ if ($post_vars["attr"]["success"] && substr($ipn["optimizemember_paypal_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["optimizemember_paypal_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } else { $global_response = array("response" => $paypal["__error"], "error" => true); } } else { $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); } } else { if (!$use_recurring_profile && !is_user_logged_in()) { if (!($paypal = array())) { if ($_GET["optimizemember_paypal_xco"] === "optimizemember_pro_paypal_checkout_return" && !empty($_GET["token"]) && ($paypal_xco_details = array("METHOD" => "GetExpressCheckoutDetails", "TOKEN" => $_GET["token"])) && ($paypal_xco_details = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal_xco_details)) && empty($paypal_xco_details["__error"])) { $paypal["METHOD"] = "DoExpressCheckoutPayment"; /**/ $paypal["TOKEN"] = $paypal_xco_details["TOKEN"]; $paypal["PAYERID"] = $paypal_xco_details["PAYERID"]; /**/ $paypal["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; /**/ $paypal["PAYMENTREQUEST_0_DESC"] = $cost_calculations["desc"]; $paypal["PAYMENTREQUEST_0_CUSTOM"] = $post_vars["attr"]["custom"]; /**/ $paypal["PAYMENTREQUEST_0_CURRENCYCODE"] = $cost_calculations["cur"]; $paypal["PAYMENTREQUEST_0_ITEMAMT"] = $cost_calculations["sub_total"]; $paypal["PAYMENTREQUEST_0_TAXAMT"] = $cost_calculations["tax"]; $paypal["PAYMENTREQUEST_0_AMT"] = $cost_calculations["total"]; /**/ $paypal["L_PAYMENTREQUEST_0_QTY0"] = "1"; /* Always (1). */ $paypal["L_PAYMENTREQUEST_0_NAME0"] = $cost_calculations["desc"]; $paypal["L_PAYMENTREQUEST_0_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"]; $paypal["L_PAYMENTREQUEST_0_AMT0"] = $cost_calculations["sub_total"]; } else { $paypal["METHOD"] = "DoDirectPayment"; $paypal["PAYMENTACTION"] = "Sale"; /**/ $paypal["EMAIL"] = $post_vars["email"]; $paypal["FIRSTNAME"] = $post_vars["first_name"]; $paypal["LASTNAME"] = $post_vars["last_name"]; $paypal["IPADDRESS"] = $_SERVER["REMOTE_ADDR"]; /**/ $paypal["DESC"] = $cost_calculations["desc"]; $paypal["CUSTOM"] = $post_vars["attr"]["custom"]; /**/ $paypal["CURRENCYCODE"] = $cost_calculations["cur"]; $paypal["ITEMAMT"] = $cost_calculations["sub_total"]; $paypal["TAXAMT"] = $cost_calculations["tax"]; $paypal["AMT"] = $cost_calculations["total"]; /**/ $paypal["L_QTY0"] = "1"; /* Always (1). */ $paypal["L_NAME0"] = $cost_calculations["desc"]; $paypal["L_NUMBER0"] = $post_vars["attr"]["level_ccaps_eotper"]; $paypal["L_AMT0"] = $cost_calculations["sub_total"]; /**/ $paypal["CREDITCARDTYPE"] = $post_vars["card_type"]; $paypal["ACCT"] = preg_replace("/[^0-9]/", "", $post_vars["card_number"]); $paypal["EXPDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_expiration"]); $paypal["CVV2"] = $post_vars["card_verification"]; /**/ if (in_array($post_vars["card_type"], array("Maestro", "Solo"))) { if (preg_match("/^[0-9]{2}\\/[0-9]{4}\$/", $post_vars["card_start_date_issue_number"])) { $paypal["STARTDATE"] = preg_replace("/[^0-9]/", "", $post_vars["card_start_date_issue_number"]); } else { /* Otherwise, we assume they provided an Issue Number instead. */ $paypal["ISSUENUMBER"] = $post_vars["card_start_date_issue_number"]; } } /**/ $paypal["STREET"] = $post_vars["street"]; $paypal["CITY"] = $post_vars["city"]; $paypal["STATE"] = $post_vars["state"]; $paypal["COUNTRYCODE"] = $post_vars["country"]; $paypal["ZIP"] = $post_vars["zip"]; } } /**/ if (($paypal = c_ws_plugin__optimizemember_paypal_utilities::paypal_api_response($paypal)) && empty($paypal["__error"])) { $new__subscr_id = !empty($paypal["PAYMENTINFO_0_TRANSACTIONID"]) ? $paypal["PAYMENTINFO_0_TRANSACTIONID"] : false; $new__subscr_id = !$new__subscr_id && !empty($paypal["TRANSACTIONID"]) ? $paypal["TRANSACTIONID"] : $new__subscr_id; /**/ if (!($ipn = array())) { $ipn["txn_type"] = "web_accept"; $ipn["txn_id"] = $new__subscr_id; $ipn["custom"] = $post_vars["attr"]["custom"]; /**/ $ipn["mc_gross"] = $cost_calculations["total"]; $ipn["mc_currency"] = $cost_calculations["cur"]; $ipn["tax"] = $cost_calculations["tax"]; /**/ $ipn["payer_email"] = $post_vars["email"]; $ipn["first_name"] = $post_vars["first_name"]; $ipn["last_name"] = $post_vars["last_name"]; /**/ $ipn["option_name1"] = "Originating Domain"; $ipn["option_selection1"] = $_SERVER["HTTP_HOST"]; /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $_SERVER["REMOTE_ADDR"]; /**/ $ipn["item_name"] = $cost_calculations["desc"]; $ipn["item_number"] = $post_vars["attr"]["level_ccaps_eotper"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=paypal&optimizemember_paypal_proxy_use=pro-emails"; $ipn_q .= "&optimizemember_paypal_proxy_verification=" . urlencode(c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen()); $ipn_q .= "&optimizemember_paypal_proxy_return_url=" . rawurlencode($post_vars["attr"]["success"]); } /**/ if (!($create_user = array())) { $_POST["ws_plugin__optimizemember_custom_reg_field_user_pass1"] = $post_vars["password1"]; /* Fake this for registration configuration. */ $_POST["ws_plugin__optimizemember_custom_reg_field_first_name"] = $post_vars["first_name"]; /* Fake this for registration configuration. */ $_POST["ws_plugin__optimizemember_custom_reg_field_last_name"] = $post_vars["last_name"]; /* Fake this for registration configuration. */ $_POST["ws_plugin__optimizemember_custom_reg_field_opt_in"] = $post_vars["custom_fields"]["opt_in"]; /* Fake this too. */ /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_fields"]) { foreach (json_decode($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["custom_reg_fields"], true) as $field) { $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"])); $field_id_class = preg_replace("/_/", "-", $field_var); /**/ if (isset($post_vars["custom_fields"][$field_var])) { $_POST["ws_plugin__optimizemember_custom_reg_field_" . $field_var] = $post_vars["custom_fields"][$field_var]; } } } /**/ $_COOKIE["optimizemember_subscr_gateway"] = c_ws_plugin__optimizemember_utils_encryption::encrypt("paypal"); /* Fake this for registration configuration. */ $_COOKIE["optimizemember_subscr_id"] = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__subscr_id); /* Fake this for registration configuration. */ $_COOKIE["optimizemember_custom"] = c_ws_plugin__optimizemember_utils_encryption::encrypt($post_vars["attr"]["custom"]); /* Fake this for registration configuration. */ $_COOKIE["optimizemember_item_number"] = c_ws_plugin__optimizemember_utils_encryption::encrypt($post_vars["attr"]["level_ccaps_eotper"]); /* Fake this too. */ /**/ $create_user["user_login"] = $post_vars["username"]; /* Copy this into a separate array for `wp_create_user()`. */ $create_user["user_pass"] = wp_generate_password(); /* Which may fire `c_ws_plugin__optimizemember_registrations::generate_password()`. */ $create_user["user_email"] = $post_vars["email"]; /* Copy this into a separate array for `wp_create_user()`. */ } /**/ if ($post_vars["password1"] && $post_vars["password1"] === $create_user["user_pass"]) { if ((is_multisite() && ($new__user_id = c_ws_plugin__optimizemember_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)) { wp_new_user_notification($new__user_id, $create_user["user_pass"]); /**/ $ipn["optimizemember_paypal_proxy_return_url"] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20))); /**/ $global_response = array("response" => sprintf(_x('<strong>Thank you.</strong> Your account has been approved.<br />— Please <a href="%s" rel="nofollow">login</a>.', "s2member-front", "s2member"), esc_attr(wp_login_url()))); /**/ if ($post_vars["attr"]["success"] && substr($ipn["optimizemember_paypal_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["optimizemember_paypal_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } else { c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); /**/ $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true); } } else { if ((is_multisite() && ($new__user_id = c_ws_plugin__optimizemember_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)) { update_user_option($new__user_id, "default_password_nag", true, true); /* Password nag. */ wp_new_user_notification($new__user_id, $create_user["user_pass"]); /**/ $ipn["optimizemember_paypal_proxy_return_url"] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20))); /**/ $global_response = array("response" => _x('<strong>Thank you.</strong> Your account has been approved.<br />— You\'ll receive an email momentarily.', "s2member-front", "s2member")); /**/ if ($post_vars["attr"]["success"] && substr($ipn["optimizemember_paypal_proxy_return_url"], 0, 2) === substr($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace(array("%%s_response%%", "%%response%%"), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response["response"])), urlencode($global_response["response"])), $ipn["optimizemember_paypal_proxy_return_url"])) && ($custom_success_url = trim(preg_replace("/%%(.+?)%%/i", "", $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, "s2p-v")) . exit; } } else { c_ws_plugin__optimizemember_utils_urls::remote(site_url("/?optimizemember_paypal_notify=1" . $ipn_q), $ipn, array("timeout" => 20)); /**/ $global_response = array("response" => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true); } } } else { $global_response = array("response" => $paypal["__error"], "error" => true); } } else { $global_response = array("response" => _x('<strong>Unknown error.</strong> Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true); } } } } } } else { $global_response = $error; } } } }
/** * Handles processing of Pro Forms for Specific Post/Page checkout. * * @package optimizeMember\Stripe * @since 140617 * * @attaches-to ``add_action('init');`` * * @return null Or exits script execution after a custom URL redirection. */ public static function stripe_sp_checkout() { if (!empty($_POST['optimizemember_pro_stripe_sp_checkout']['nonce']) && ($nonce = $_POST['optimizemember_pro_stripe_sp_checkout']['nonce']) && wp_verify_nonce($nonce, 'optimizemember-pro-stripe-sp-checkout')) { $GLOBALS['ws_plugin__optimizemember_pro_stripe_sp_checkout_response'] = array(); // This holds the global response details. $global_response =& $GLOBALS['ws_plugin__optimizemember_pro_stripe_sp_checkout_response']; $post_vars = c_ws_plugin__optimizemember_utils_strings::trim_deep(stripslashes_deep($_POST['optimizemember_pro_stripe_sp_checkout'])); $post_vars['attr'] = !empty($post_vars['attr']) ? (array) unserialize(c_ws_plugin__optimizemember_utils_encryption::decrypt($post_vars['attr'])) : array(); $post_vars['attr'] = apply_filters('ws_plugin__optimizemember_pro_stripe_sp_checkout_post_attr', $post_vars['attr'], get_defined_vars()); $post_vars['name'] = trim($post_vars['first_name'] . ' ' . $post_vars['last_name']); $post_vars['email'] = apply_filters('user_registration_email', sanitize_email($post_vars['email']), get_defined_vars()); $post_vars['recaptcha_challenge_field'] = isset($_POST['recaptcha_challenge_field']) ? trim(stripslashes($_POST['recaptcha_challenge_field'])) : ''; $post_vars['recaptcha_response_field'] = isset($_POST['recaptcha_response_field']) ? trim(stripslashes($_POST['recaptcha_response_field'])) : ''; if (!c_ws_plugin__optimizemember_pro_stripe_responses::stripe_form_attr_validation_errors($post_vars['attr'])) { if (!($form_submission_validation_errors = c_ws_plugin__optimizemember_pro_stripe_responses::stripe_form_submission_validation_errors('sp-checkout', $post_vars))) { unset($_POST['optimizemember_pro_stripe_sp_checkout']['card_token']); // These are good one-time only. unset($_POST['optimizemember_pro_stripe_sp_checkout']['card_token_summary']); $cp_attr = c_ws_plugin__optimizemember_pro_stripe_utilities::apply_coupon($post_vars['attr'], $post_vars['coupon'], 'attr', array('affiliates-silent-post')); $cost_calculations = c_ws_plugin__optimizemember_pro_stripe_utilities::cost(NULL, $cp_attr['ra'], $post_vars['state'], $post_vars['country'], $post_vars['zip'], $cp_attr['cc'], $cp_attr['desc']); if (!$global_response) { if ($cost_calculations['total'] > 0) { if (!is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::get_customer(get_current_user_id(), $post_vars['email'], $post_vars['first_name'], $post_vars['last_name']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_customer = c_ws_plugin__optimizemember_pro_stripe_utilities::set_customer_card_token($stripe_customer->id, $post_vars['card_token']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_charge = c_ws_plugin__optimizemember_pro_stripe_utilities::create_customer_charge($stripe_customer->id, $cost_calculations['total'], $cost_calculations['cur'], $cost_calculations['desc']))) { $global_response = array('response' => $stripe_charge, 'error' => TRUE); } else { $new__txn_cid = $stripe_customer->id; $new__txn_id = $stripe_charge->id; } } } } } if (!$global_response) { if (empty($new__txn_cid)) { $new__txn_cid = strtoupper('free-' . uniqid()); } if (empty($new__txn_id)) { $new__txn_id = strtoupper('free-' . uniqid()); } $ipn['txn_type'] = 'web_accept'; $ipn['txn_cid'] = $new__txn_cid; $ipn['txn_id'] = $new__txn_id; $ipn['custom'] = $post_vars['attr']['custom']; $ipn['mc_gross'] = $cost_calculations['total']; $ipn['mc_currency'] = $cost_calculations['cur']; $ipn['tax'] = $cost_calculations['tax']; $ipn['payer_email'] = $post_vars['email']; $ipn['first_name'] = $post_vars['first_name']; $ipn['last_name'] = $post_vars['last_name']; if (is_user_logged_in() && ($referencing = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id())) { $ipn['option_name1'] = 'Referencing Customer ID'; $ipn['option_selection1'] = $referencing; } else { $ipn['option_name1'] = 'Originating Domain'; $ipn['option_selection1'] = $_SERVER['HTTP_HOST']; } $ipn['option_name2'] = 'Customer IP Address'; $ipn['option_selection2'] = $_SERVER['REMOTE_ADDR']; $ipn['item_name'] = $cost_calculations['desc']; $ipn['item_number'] = $post_vars['attr']['sp_ids_exp']; $ipn['optimizemember_paypal_proxy'] = 'stripe'; $ipn['optimizemember_paypal_proxy_use'] = 'pro-emails'; $ipn['optimizemember_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']); $ipn['optimizemember_paypal_proxy_verification'] = c_ws_plugin__optimizemember_paypal_utilities::paypal_proxy_key_gen(); $ipn['optimizemember_paypal_proxy_return_url'] = $post_vars['attr']['success']; $ipn['optimizemember_stripe_proxy_return_url'] = trim(c_ws_plugin__optimizemember_utils_urls::remote(site_url('/?optimizemember_paypal_notify=1'), $ipn, array('timeout' => 20))); setcookie('optimizemember_sp_tracking', $optimizemember_sp_tracking = c_ws_plugin__optimizemember_utils_encryption::encrypt($new__txn_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie('optimizemember_sp_tracking', $optimizemember_sp_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['optimizemember_sp_tracking'] = $optimizemember_sp_tracking); if ($sp_access_url = c_ws_plugin__optimizemember_sp_access::sp_access_link_gen($post_vars['attr']['ids'], $post_vars['attr']['exp'])) { $global_response = array('response' => sprintf(_x('<strong>Thank you.</strong> Your purchase has been approved.<br />— Please <a href="%s" rel="nofollow">click here</a> to proceed.', 's2member-front', 'optimizemember'), esc_attr($sp_access_url))); if ($post_vars['attr']['success'] && substr($ipn['optimizemember_stripe_proxy_return_url'], 0, 2) === substr($post_vars['attr']['success'], 0, 2) && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__optimizemember_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $ipn['optimizemember_stripe_proxy_return_url'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__optimizemember_utils_urls::add_optimizemember_sig($custom_success_url, 's2p-v')) . exit; } } else { $global_response = array('response' => _x('<strong>Oops.</strong> Unable to generate Access Link. Please contact Support for assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } } else { // Input form field validation errors. $global_response = $form_submission_validation_errors; } } } }