/** * Handles ccBill IPN URL processing. * * @package optimizeMember\ccBill * @since 1.5 * * @attaches-to ``add_action("init");`` * * @return null Or exits script execution after handling the Notification. */ public static function ccbill_notify() { global $current_site, $current_blog; /* For Multisite support. */ /**/ if (isset($_GET["optimizemember_pro_ccbill_notify"]) && strlen($_GET["optimizemember_pro_ccbill_notify"]) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_id"]) { @ignore_user_abort(true); /* Continue processing even if/when connection is broken by the sender. */ /**/ if (is_array($ccbill = c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_postvars()) && ($_ccbill = $ccbill)) { $ccbill["optimizemember_log"][] = "IPN received on: " . date("D M j, Y g:i:s a T"); $ccbill["optimizemember_log"][] = "optimizeMember POST vars verified with ccBill."; /**/ if (!$ccbill["denialId"] && $ccbill["subscription_id"] && !$ccbill["recurringPeriod"]) { $ccbill["optimizemember_log"][] = "ccBill transaction identified as ( `NON-RECURRING/BUY-NOW` )."; $ccbill["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as `txn_type` ( `web_accept` )."; $ccbill["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"] = $ccbill["subscription_id"]; /**/ $ipn["custom"] = $ccbill["s2_custom"]; /**/ $ipn["mc_gross"] = number_format($ccbill["initialPrice"], 2, ".", ""); $ipn["mc_currency"] = c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_currency_code($ccbill["currencyCode"]); $ipn["tax"] = number_format("0.00", 2, ".", ""); /**/ $ipn["payer_email"] = $ccbill["email"]; $ipn["first_name"] = $ccbill["customer_fname"]; $ipn["last_name"] = $ccbill["customer_lname"]; /**/ $ipn["option_name1"] = $ccbill["s2_referencing"] ? "Referencing Customer ID" : "Originating Domain"; $ipn["option_selection1"] = $ccbill["s2_referencing"] ? $ccbill["s2_referencing"] : $_SERVER["HTTP_HOST"]; /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $ccbill["s2_customer_ip"]; /**/ $ipn["item_number"] = $ccbill["s2_invoice"]; $ipn["item_name"] = $ccbill["s2_desc"]; /**/ $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 (!$ccbill["denialId"] && $ccbill["subscription_id"] && $ccbill["recurringPeriod"]) { $ccbill["optimizemember_log"][] = "ccBill transaction identified as ( `RECURRING/SUBSCRIPTION` )."; $ccbill["optimizemember_log"][] = "IPN reformulated. Piping through optimizeMember's core/standard PayPal processor as `txn_type` ( `subscr_signup` )."; $ccbill["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"] = $ccbill["subscription_id"]; $ipn["recurring"] = "1"; /* Yes, recurring. */ /**/ $ipn["txn_id"] = $ccbill["subscription_id"]; /**/ $ipn["custom"] = $ccbill["s2_custom"]; /**/ $ipn["period1"] = $ccbill["s2_p1"]; $ipn["period3"] = $ccbill["s2_p3"]; /**/ $ipn["mc_amount1"] = number_format($ccbill["initialPrice"], 2, ".", ""); $ipn["mc_amount3"] = number_format($ccbill["recurringPrice"], 2, ".", ""); /**/ $ipn["mc_gross"] = preg_match("/^[1-9]/", $ipn["period1"]) ? $ipn["mc_amount1"] : $ipn["mc_amount3"]; /**/ $ipn["mc_currency"] = c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_currency_code($ccbill["currencyCode"]); $ipn["tax"] = number_format("0.00", 2, ".", ""); /**/ $ipn["payer_email"] = $ccbill["email"]; $ipn["first_name"] = $ccbill["customer_fname"]; $ipn["last_name"] = $ccbill["customer_lname"]; /**/ $ipn["option_name1"] = $ccbill["s2_referencing"] ? "Referencing Customer ID" : "Originating Domain"; $ipn["option_selection1"] = $ccbill["s2_referencing"] ? $ccbill["s2_referencing"] : $_SERVER["HTTP_HOST"]; /**/ $ipn["option_name2"] = "Customer IP Address"; $ipn["option_selection2"] = $ccbill["s2_customer_ip"]; /**/ $ipn["item_number"] = $ccbill["s2_invoice"]; $ipn["item_name"] = $ccbill["s2_desc"]; /**/ $ipn_q = "&optimizemember_paypal_proxy=ccbill&optimizemember_paypal_proxy_use=standard-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()); /**/ 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 IPN was ignored. */ $ccbill["optimizemember_log"][] = "Ignoring this IPN request. The transaction does NOT require any action on the part of optimizeMember."; } } } } else { $ccbill["optimizemember_log"][] = "Unable to verify POST vars. This is most likely related to an invalid ccBill configuration. Please check: optimizeMember -> ccBill Options."; $ccbill["optimizemember_log"][] = "If you're absolutely SURE that your ccBill 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 ccBill over an HTTPS connection."; $ccbill["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."; $ccbill["optimizemember_log"][] = var_export($_REQUEST, true); /* Recording _POST + _GET vars for analysis and debugging. */ } /* If debugging/logging is enabled; we need to append $ccbill 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() ? "ccbill-ipn-4-" . trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "ccbill-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); } } } /**/ 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. */ } }
/** * Shortcode `[optimizeMember-Pro-ccBill-Button /]`. * * @package optimizeMember\ccBill * @since 1.5 * * @attaches-to ``add_shortcode("optimizeMember-Pro-ccBill-Button");`` * * @param array $attr An array of Attributes. * @param str $content Content inside the Shortcode. * @param str $shortcode The actual Shortcode name itself. * @return str The resulting ccBill Button Code, HTML markup. */ public static function sc_ccbill_button($attr = FALSE, $content = FALSE, $shortcode = FALSE) { c_ws_plugin__optimizemember_no_cache::no_cache_constants(true); /**/ $attr = c_ws_plugin__optimizemember_utils_strings::trim_qts_deep((array) $attr); /**/ $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" => "2.95", "rp" => "1", "rt" => "M", "rr" => "1", "modify" => "0", "cancel" => "0", "sp" => "0", "image" => "default", "sub_account" => "", "form" => "", "output" => "anchor"), $attr); /**/ $attr["tt"] = strtoupper($attr["tt"]); $attr["rt"] = strtoupper($attr["rt"]); $attr["ccaps"] = strtolower($attr["ccaps"]); $attr["rr"] = $attr["rt"] === "L" ? "0" : $attr["rr"]; $attr["rr"] = $attr["level"] === "*" ? "0" : $attr["rr"]; /**/ if ($attr["rr"] && ($attr["ta"] <= 0 || $attr["tp"] <= 0 || !$attr["tt"])) { eval('$attr["ta"] = $attr["ra"]; $attr["tp"] = $attr["rp"]; $attr["tt"] = $attr["rt"];'); } /**/ if ($attr["modify"] || $attr["cancel"]) { $default_image = $GLOBALS["WS_PLUGIN__"]["optimizemember_pro"]["c"]["dir_url"] . "/images/ccbill-edit-button.png"; /**/ $code = trim(c_ws_plugin__optimizemember_utilities::evl(file_get_contents(dirname(dirname(dirname(dirname(__FILE__)))) . "/templates/buttons/ccbill-cancellation-button.php"))); $code = preg_replace("/%%images%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($GLOBALS["WS_PLUGIN__"]["optimizemember_pro"]["c"]["dir_url"] . "/images")), $code); $code = preg_replace("/%%wpurl%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr(site_url())), $code); /**/ $code = $_code = $attr["image"] && $attr["image"] !== "default" ? preg_replace('/ src\\="(.*?)"/', ' src="' . c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($attr["image"])) . '"', $code) : preg_replace('/ src\\="(.*?)"/', ' src="' . c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($default_image)) . '"', $code); /**/ $code = $attr["output"] === "anchor" ? $code : $code; if ($attr["output"] === "url" && preg_match('/ href\\="(.*?)"/', $code, $m) && ($href = $m[1])) { $code = $url = c_ws_plugin__optimizemember_utils_urls::n_amps($href); } /**/ unset($href, $url, $m); } else { if ($attr["sp"]) { $default_image = $GLOBALS["WS_PLUGIN__"]["optimizemember_pro"]["c"]["dir_url"] . "/images/ccbill-button.png"; /**/ $attr["sp_ids_exp"] = "sp:" . $attr["ids"] . ":" . $attr["exp"]; /**/ $code = trim(c_ws_plugin__optimizemember_utilities::evl(file_get_contents(dirname(dirname(dirname(dirname(__FILE__)))) . "/templates/buttons/ccbill-sp-checkout-button.php"))); $code = preg_replace("/%%images%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($GLOBALS["WS_PLUGIN__"]["optimizemember_pro"]["c"]["dir_url"] . "/images")), $code); $code = preg_replace("/%%wpurl%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr(site_url())), $code); /**/ $vars = array("clientAccnum" => $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_id"], "clientSubacc" => $attr["sub_account"] ? $attr["sub_account"] : $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_sid"], "formName" => $attr["form"] ? $attr["form"] : $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_form_name"], "formPrice" => $attr["ra"], "formPeriod" => round($attr["exp"] / 24), "currencyCode" => c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_currency_numr($attr["cc"]), "s2_desc" => $attr["desc"], "s2_invoice" => $attr["sp_ids_exp"], "s2_custom" => $attr["custom"], "s2_customer_ip" => $_SERVER["REMOTE_ADDR"]); /**/ if ($referencing = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id()) { $vars["s2_referencing"] = $referencing; } /**/ $code = preg_replace("/%%url%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($url = c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_link_gen($vars))), $code); /**/ $code = $_code = $attr["image"] && $attr["image"] !== "default" ? preg_replace('/ src\\="(.*?)"/', ' src="' . c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($attr["image"])) . '"', $code) : preg_replace('/ src\\="(.*?)"/', ' src="' . c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($default_image)) . '"', $code); /**/ $code = $attr["output"] === "anchor" ? $code : $code; $code = $attr["output"] === "url" ? $url : $code; /**/ unset($href, $url, $m); } else { if ($attr["level"] === "*") { $default_image = $GLOBALS["WS_PLUGIN__"]["optimizemember_pro"]["c"]["dir_url"] . "/images/ccbill-button.png"; /**/ $attr["level_ccaps_eotper"] = !$attr["rr"] && $attr["rt"] !== "L" ? $attr["level"] . ":" . $attr["ccaps"] . ":" . $attr["rp"] . " " . $attr["rt"] : $attr["level"] . ":" . $attr["ccaps"]; $attr["level_ccaps_eotper"] = rtrim($attr["level_ccaps_eotper"], ":"); /**/ $code = trim(c_ws_plugin__optimizemember_utilities::evl(file_get_contents(dirname(dirname(dirname(dirname(__FILE__)))) . "/templates/buttons/ccbill-ccaps-checkout-button.php"))); $code = preg_replace("/%%images%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($GLOBALS["WS_PLUGIN__"]["optimizemember_pro"]["c"]["dir_url"] . "/images")), $code); $code = preg_replace("/%%wpurl%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr(site_url())), $code); /**/ $vars = array("clientAccnum" => $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_id"], "clientSubacc" => $attr["sub_account"] ? $attr["sub_account"] : $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_sid"], "formName" => $attr["form"] ? $attr["form"] : $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_form_name"], "formPrice" => $attr["ra"], "formPeriod" => c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_per_term_2_days($attr["rp"], $attr["rt"]), "currencyCode" => c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_currency_numr($attr["cc"]), "s2_desc" => $attr["desc"], "s2_invoice" => $attr["level_ccaps_eotper"], "s2_custom" => $attr["custom"], "s2_customer_ip" => $_SERVER["REMOTE_ADDR"]); /**/ if ($referencing = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id()) { $vars["s2_referencing"] = $referencing; } /**/ $code = preg_replace("/%%url%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($url = c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_link_gen($vars))), $code); /**/ $code = $_code = $attr["image"] && $attr["image"] !== "default" ? preg_replace('/ src\\="(.*?)"/', ' src="' . c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($attr["image"])) . '"', $code) : preg_replace('/ src\\="(.*?)"/', ' src="' . c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($default_image)) . '"', $code); /**/ $code = $attr["output"] === "anchor" ? $code : $code; $code = $attr["output"] === "url" ? $url : $code; /**/ unset($href, $url, $m); } else { $default_image = $GLOBALS["WS_PLUGIN__"]["optimizemember_pro"]["c"]["dir_url"] . "/images/ccbill-button.png"; /**/ $attr["desc"] = !$attr["desc"] ? $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $attr["level"] . "_label"] : $attr["desc"]; /**/ $attr["level_ccaps_eotper"] = !$attr["rr"] && $attr["rt"] !== "L" ? $attr["level"] . ":" . $attr["ccaps"] . ":" . $attr["rp"] . " " . $attr["rt"] : $attr["level"] . ":" . $attr["ccaps"]; $attr["level_ccaps_eotper"] = rtrim($attr["level_ccaps_eotper"], ":"); /**/ $code = trim(c_ws_plugin__optimizemember_utilities::evl(file_get_contents(dirname(dirname(dirname(dirname(__FILE__)))) . "/templates/buttons/ccbill-checkout-button.php"))); /* * Custom button */ if (!empty($content)) { $code = preg_replace('/%%button_markup%%/', $content, $code); } else { $code = preg_replace("/%%button_markup%%/", '<a href="%%url%%"><img src="%%images%%/ccbill-button.png" style="width:auto; height:auto; border:0;" alt="ccBill" /></a>', $code); } $code = preg_replace("/%%images%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($GLOBALS["WS_PLUGIN__"]["optimizemember_pro"]["c"]["dir_url"] . "/images")), $code); $code = preg_replace("/%%wpurl%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr(site_url())), $code); /**/ if (!$attr["rr"]) { $vars = array("clientAccnum" => $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_id"], "clientSubacc" => $attr["sub_account"] ? $attr["sub_account"] : $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_sid"], "formName" => $attr["form"] ? $attr["form"] : $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_form_name"], "formPrice" => $attr["ra"], "formPeriod" => c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_per_term_2_days($attr["rp"], $attr["rt"]), "currencyCode" => c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_currency_numr($attr["cc"]), "s2_p1" => "0 D", "s2_p3" => $attr["rp"] . " " . $attr["rt"], "s2_desc" => $attr["desc"], "s2_invoice" => $attr["level_ccaps_eotper"], "s2_custom" => $attr["custom"], "s2_customer_ip" => $_SERVER["REMOTE_ADDR"]); } else { /* Otherwise, we need to include both an Initial and Regular/Recurring period. This will ALWAYS recur. */ $vars = array("clientAccnum" => $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_id"], "clientSubacc" => $attr["sub_account"] ? $attr["sub_account"] : $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_client_sid"], "formName" => $attr["form"] ? $attr["form"] : $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_ccbill_form_name"], "formPrice" => $attr["ta"], "formPeriod" => c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_per_term_2_days($attr["tp"], $attr["tt"]), "formRecurringPrice" => $attr["ra"], "formRecurringPeriod" => c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_per_term_2_days($attr["rp"], $attr["rt"]), "formRebills" => "99", "currencyCode" => c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_currency_numr($attr["cc"]), "s2_p1" => $attr["tp"] . " " . $attr["tt"], "s2_p3" => $attr["rp"] . " " . $attr["rt"], "s2_desc" => $attr["desc"], "s2_invoice" => $attr["level_ccaps_eotper"], "s2_custom" => $attr["custom"], "s2_customer_ip" => $_SERVER["REMOTE_ADDR"]); } /**/ if ($referencing = c_ws_plugin__optimizemember_utils_users::get_user_subscr_or_wp_id()) { $vars["s2_referencing"] = $referencing; } /**/ $code = preg_replace("/%%url%%/", c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($url = c_ws_plugin__optimizemember_pro_ccbill_utilities::ccbill_link_gen($vars))), $code); /* * Only when there is no custom button */ if (empty($content)) { $code = $_code = $attr["image"] && $attr["image"] !== "default" ? preg_replace('/ src\\="(.*?)"/', ' src="' . c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($attr["image"])) . '"', $code) : preg_replace('/ src\\="(.*?)"/', ' src="' . c_ws_plugin__optimizemember_utils_strings::esc_ds(esc_attr($default_image)) . '"', $code); } /**/ $code = $attr["output"] === "anchor" ? $code : $code; $code = $attr["output"] === "url" ? $url : $code; /**/ unset($href, $url, $m); } } } /**/ $code = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', $code); return $code; }