/** * Initialize GeoLocation based on IP and store it in a session. */ public static function init_geolocation() { $geodata = ProSites_Helper_Session::session('geodata'); if (empty($geodata)) { $geodata = ProSites_Helper_Geolocation::getIPInfo(); ProSites_Helper_Session::session('geodata', $geodata); } return $geodata; }
private static function validate_imsi($imsi) { $eu_countries = array_keys(ProSites_Helper_Geolocation::get_EU_countries()); $data = false; // If its a valid MCC and MNC $operator = self::check_mnc($imsi); if ($operator) { $mcc_list = self::get_mcc_list(); $data = new stdClass(); $data->mcc = self::get_mcc($imsi); $data->country_name = $mcc_list[$data->mcc]['country']; $data->country_code = $mcc_list[$data->mcc]['country_code']; $data->operator_code = $operator[0]; $data->operator = $operator[1]; $data->is_EU = in_array($data->country_code, $eu_countries); return $data; } else { return false; } }
public static function render_checkout_page($content, $blog_id, $domain = false, $selected_period = 'price_1', $selected_level = false) { global $psts, $current_prosite_blog, $wpdb; // Prepare for location based TAX (Taxamo does its own checking client side) ProSites_Helper_Geolocation::init_geolocation(); // Reposition coupon based on option $coupons_enabled = $psts->get_setting('coupons_enabled'); $coupons_enabled = 'enabled' === $coupons_enabled ? true : false; if ($coupons_enabled && ('option2' == $psts->get_setting('pricing_table_coupon_position', 'option1') || 'option2' == $psts->get_setting('pricing_table_period_position', 'option1'))) { add_filter('prosites_inner_pricing_table_post', array(get_class(), 'render_standalone_coupon')); } // Add period selector above table based on option if ('option2' == $psts->get_setting('pricing_table_period_position', 'option1')) { add_filter('prosites_inner_pricing_table_pre', array(get_class(), 'render_standalone_periods')); } $session_data = ProSites_Helper_Session::session(); // If its in session, get it if (isset($session_data['new_blog_details']) && isset($session_data['new_blog_details']['level'])) { $selected_period = 'price_' . (int) $session_data['new_blog_details']['period']; $selected_level = (int) $session_data['new_blog_details']['level']; } // User is not logged in and this is not a new registration. // Get them to sign up! (or login) if (empty($blog_id) && !isset($session_data['new_blog_details']) && empty($current_prosite_blog)) { self::$new_signup = true; } // Get blog_id from the session... if (isset($session_data['new_blog_details']) && isset($session_data['new_blog_details']['blog_id'])) { $blog_id = $session_data['new_blog_details']['blog_id']; } // Or if we're at checkout and already have a blog (1 blog only!) $blog_id = empty($blog_id) && !empty($current_prosite_blog) ? $current_prosite_blog : $blog_id; //If no blog id, get it from pro sites table, using activation key if (empty($blog_id) && !empty($session_data['activation_key'])) { $blog_id = $wpdb->get_var("SELECT blog_id FROM {$wpdb->base_prefix}pro_sites WHERE identifier='" . $session_data['activation_key'] . "'"); } self::$default_period = apply_filters('prosites_render_checkout_page_period', $selected_period, $blog_id); self::$selected_level = apply_filters('prosites_render_checkout_page_level', $selected_level, $blog_id); // Are the tables enabled? $plans_table_enabled = $psts->get_setting('plans_table_enabled', 'enabled'); $plans_table_enabled = 'enabled' === $plans_table_enabled ? true : false; $features_table_enabled = $psts->get_setting('comparison_table_enabled'); $features_table_enabled = 'enabled' === $features_table_enabled ? true : false; // $columns = self::get_pricing_columns( $plans_table_enabled, $features_table_enabled ); $columns = self::get_pricing_columns(true, $features_table_enabled); $content .= apply_filters('prosites_inner_pricing_table_pre', self::render_tables_wrapper('pre'), $blog_id); if ($plans_table_enabled) { $content .= self::render_pricing_columns($columns, $blog_id); } else { $content .= self::render_pricing_grid($columns, $blog_id); } $content .= apply_filters('prosites_inner_pricing_table_post', self::render_tables_wrapper('post'), $blog_id); $content = apply_filters('prosites_post_pricing_table_content', $content, $blog_id); if (self::$new_signup && !is_user_logged_in()) { $content .= self::render_login(); } // Signup registration $content .= ProSites_View_Front_Registration::render_signup_form(); $content .= ProSites_View_Front_Gateway::render_checkout(array(), $blog_id, $domain); return apply_filters('prosites_render_checkout_page', $content, $blog_id, $domain); // Reset self::$new_signup = false; }
public static function eu_tax_warning_notice($content) { global $psts; $token = $psts->get_setting('taxamo_token'); $taxamo_enabled = $psts->get_setting('taxamo_status', 0); $geodata = ProSites_Helper_Geolocation::get_geodata(); if ((empty($token) || empty($taxamo_enabled)) && $geodata->is_EU) { return $content . '<div class="tax-checkout-warning">' . __('It appears that you are in an European Union country. Unfortunately we do not currently support sites for EU countries.', 'psts') . '</div>'; } return $content; }
public static function record_transaction($transaction) { global $psts; $token = $psts->get_setting('taxamo_private_token'); if ($token && isset($transaction->billing_country_code) && ProSites_Helper_Geolocation::is_EU($transaction->billing_country_code)) { $taxamo = new Taxamo(new APIClient($token, 'https://api.taxamo.com')); // Convert to Taxamo types (because of Swagger lib) $t = new Input_transaction(); // Add easy items (and avoid custom ones) $t_types = array_keys(get_object_vars($t)); foreach ($transaction as $key => $value) { if (!is_object($value) && in_array($key, $t_types)) { $t->{$key} = $value; } } // Convert line items $lines = array(); foreach ($transaction->transaction_lines as $line) { $l = new Input_transaction_line(); foreach ($line as $key => $value) { if (!is_object($value)) { $l->{$key} = $value; } } $lines[] = $l; } $t->transaction_lines = $lines; // //// Evidence $t->evidence = new Evidence(); foreach ($transaction->evidence as $ek => $ev) { $t->evidence->{$ek} = new Evidence_schema(); foreach ($ev as $k => $v) { $t->evidence->{$ek}->{$k} = $v; } } $resp = $taxamo->createTransaction(array('transaction' => $t)); if (isset($resp) && isset($resp->transaction) && isset($resp->transaction->key)) { $taxamo->confirmTransaction($resp->transaction->key, null); } } }