diff --git a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php index 436c9d693..59a22aa58 100644 --- a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php +++ b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php @@ -8,11 +8,34 @@ class Angelleye_PayPal_Express_Checkout_Helper { public $setting; public $function_helper; public $posted; + public $version; - public function __construct($version) { + /** + * The single instance of the class + * @var Angelleye_PayPal_Express_Checkout_Helper + */ + protected static $_instance = null; + + /** + * Main WC_Emails Instance. + * + * Ensures only one instance of Angelleye_PayPal_Express_Checkout_Helper is loaded or can be loaded. + * + * @since 2.1 + * @static + * @return WC_Emails Main instance + */ + public static function instance() { + if (is_null(self::$_instance)) { + self::$_instance = new self(); + } + return self::$_instance; + } + + public function __construct() { try { global $wpdb; - $this->version = $version; + $this->version = VERSION_PFW; $this->setting = AngellEYE_Utility::angelleye_get_pre_option(false, 'woocommerce_paypal_express_settings'); $this->setting = !empty($this->setting) ? $this->setting : array(); $this->enabled = !empty($this->setting['enabled']) ? $this->setting['enabled'] : 'no'; @@ -41,7 +64,7 @@ public function __construct($version) { $this->testmode = 'yes' === $this->testmode_value; $this->billing_address_value = !empty($this->setting['billing_address']) ? $this->setting['billing_address'] : 'no'; $this->disallowed_funding_methods = !empty($this->setting['disallowed_funding_methods']) ? $this->setting['disallowed_funding_methods'] : array(); - if(!in_array('card', $this->disallowed_funding_methods)) { + if (!in_array('card', $this->disallowed_funding_methods)) { $this->disallowed_card_types = !empty($this->setting['disallowed_card_types']) ? $this->setting['disallowed_card_types'] : array(); $this->disallowed_funding_methods = array_merge($this->disallowed_card_types, $this->disallowed_funding_methods); } @@ -67,12 +90,12 @@ public function __construct($version) { } else { $this->is_paypal_credit_enable = false; } - if(substr(get_option("woocommerce_default_country"), 0, 2) == 'US') { + if (substr(get_option("woocommerce_default_country"), 0, 2) == 'US') { $this->is_us = true; } else { $this->is_us = false; } - if($this->is_paypal_credit_enable == true) { + if ($this->is_paypal_credit_enable == true) { $this->allowed_funding_methods = !empty($this->setting['allowed_funding_methods']) ? $this->setting['allowed_funding_methods'] : array( 'credit', 'card', 'elv', 'venmo' ); @@ -80,7 +103,7 @@ public function __construct($version) { $this->allowed_funding_methods = !empty($this->setting['allowed_funding_methods']) ? $this->setting['allowed_funding_methods'] : array( 'card', 'elv', 'venmo' ); - if( !empty($this->allowed_funding_methods['credit']) ) { + if (!empty($this->allowed_funding_methods['credit'])) { unset($this->allowed_funding_methods['credit']); } } @@ -163,7 +186,6 @@ public function __construct($version) { $this->is_order_completed = true; } add_filter('woocommerce_locate_template', array($this, 'angelleye_woocommerce_locate_template'), 10, 3); - } catch (Exception $ex) { } @@ -176,13 +198,13 @@ public function buy_now_button() { if ($this->enabled == 'yes' && $this->show_on_product_page == 'yes' && $is_ec_button_enable_product_level == 'yes') { $ec_html_button = ''; $_product = wc_get_product($product->get_id()); - if ( $_product->is_type('variation') || $_product->is_type('variable') || $_product->is_type('simple') ) { + if ($_product->is_type('variation') || $_product->is_type('variable') || $_product->is_type('simple')) { if ($_product->is_type('simple') && (version_compare(WC_VERSION, '3.0', '<') == false)) { ?> is_type('simple') && ($_product->get_price() == 0 || $_product->get_price() == '')) { + if ($_product->is_type('simple') && ($_product->get_price() == 0 || $_product->get_price() == '')) { return false; } $button_dynamic_class = 'single_variation_wrap_angelleye_' . $product->get_id(); @@ -308,14 +330,14 @@ public function ec_set_checkout_post_data() { } else { if ($this->angelleye_is_need_to_set_billing_address() == true) { $_POST['billing_' . $field] = wc_clean(stripslashes($value)); - } elseif(empty($post_data)) { + } elseif (empty($post_data)) { $_POST['billing_' . $field] = wc_clean(stripslashes($value)); } $_POST['shipping_' . $field] = wc_clean(stripslashes($value)); } } } - + $_POST['order_comments'] = isset($post_data['order_comments']) ? wc_clean($post_data['order_comments']) : ''; if (!empty($post_data)) { foreach ($post_data as $key => $value) { @@ -323,7 +345,7 @@ public function ec_set_checkout_post_data() { $_POST[$key] = is_string($value) ? wc_clean(stripslashes($value)) : $value; } } - } + } $this->chosen = true; } catch (Exception $ex) { @@ -363,36 +385,36 @@ public function ec_formatted_address($type) {
- WC()->checkout->get_value($type . '_first_name'), - 'last_name' => WC()->checkout->get_value($type . '_last_name'), - 'company' => WC()->checkout->get_value($type . '_company'), - 'address_1' => WC()->checkout->get_value($type . '_address_1'), - 'address_2' => WC()->checkout->get_value($type . '_address_2'), - 'city' => WC()->checkout->get_value($type . '_city'), - 'state' => WC()->checkout->get_value($type . '_state'), - 'postcode' => WC()->checkout->get_value($type . '_postcode'), - 'country' => WC()->checkout->get_value($type . '_country'), - ); - - $shipping_details = $this->ec_get_session_data('shipping_details'); - $email = WC()->checkout->get_value($type . '_email'); - if(empty($email)) { - $email = !empty($shipping_details['email']) ? $shipping_details['email'] : ''; - } - $phone = WC()->checkout->get_value($type . '_phone'); - if(empty($phone)) { - $phone = !empty($shipping_details['phone']) ? $shipping_details['phone'] : ''; - } - $formatted_address = WC()->countries->get_formatted_address($address); - $formatted_address = str_replace('
-
', '
', $formatted_address); - echo $formatted_address; - if (!empty($shipping_details)) { - echo!empty($email) ? '

' . $email . '

' : ''; - echo!empty($phone) ? '

' . $phone . '

' : ''; - } - ?> + WC()->checkout->get_value($type . '_first_name'), + 'last_name' => WC()->checkout->get_value($type . '_last_name'), + 'company' => WC()->checkout->get_value($type . '_company'), + 'address_1' => WC()->checkout->get_value($type . '_address_1'), + 'address_2' => WC()->checkout->get_value($type . '_address_2'), + 'city' => WC()->checkout->get_value($type . '_city'), + 'state' => WC()->checkout->get_value($type . '_state'), + 'postcode' => WC()->checkout->get_value($type . '_postcode'), + 'country' => WC()->checkout->get_value($type . '_country'), + ); + + $shipping_details = $this->ec_get_session_data('shipping_details'); + $email = WC()->checkout->get_value($type . '_email'); + if (empty($email)) { + $email = !empty($shipping_details['email']) ? $shipping_details['email'] : ''; + } + $phone = WC()->checkout->get_value($type . '_phone'); + if (empty($phone)) { + $phone = !empty($shipping_details['phone']) ? $shipping_details['phone'] : ''; + } + $formatted_address = WC()->countries->get_formatted_address($address); + $formatted_address = str_replace('
-
', '
', $formatted_address); + echo $formatted_address; + if (!empty($shipping_details)) { + echo!empty($email) ? '

' . $email . '

' : ''; + echo!empty($phone) ? '

' . $phone . '

' : ''; + } + ?>
@@ -485,25 +507,25 @@ public function ec_enqueue_scripts_product_page($is_mini_cart = false) { if (is_order_received_page()) { return false; } - if(is_product() == false && 0 >= WC()->cart->total) { - if($this->show_on_cart == 'no' && $this->show_on_minicart == 'no') { + if (is_product() == false && 0 >= WC()->cart->total) { + if ($this->show_on_cart == 'no' && $this->show_on_minicart == 'no') { return false; } } - if($this->button_layout == 'vertical') { + if ($this->button_layout == 'vertical') { $this->button_label = ''; $this->button_tagline = ''; $this->button_fundingicons = ''; - if( $this->button_size == 'small' ) { + if ($this->button_size == 'small') { $this->button_size = 'medium'; } - } - if($this->button_label == 'credit') { + } + if ($this->button_label == 'credit') { $this->button_color = ''; $this->button_fundingicons = ''; } $js_value = array('is_page_name' => '', 'enable_in_context_checkout_flow' => ( $this->enable_in_context_checkout_flow == 'yes' ? 'yes' : 'no')); - if ($this->angelleye_is_in_context_enable() == true ) { + if ($this->angelleye_is_in_context_enable() == true) { $cancel_url = !empty($this->cancel_page) ? get_permalink($this->cancel_page) : wc_get_cart_url(); $allowed_funding_methods_json = json_encode(array_values(array_diff($this->allowed_funding_methods, $this->disallowed_funding_methods))); $disallowed_funding_methods_json = json_encode($this->disallowed_funding_methods); @@ -537,7 +559,7 @@ public function ec_enqueue_scripts_product_page($is_mini_cart = false) { 'enable_google_analytics_click' => $this->enable_google_analytics_click, 'set_express_checkout' => add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/'))), 'zcommit' => $this->angelleye_ec_force_to_display_checkout_page_js() == true ? 'false' : 'true' - ) + ) ); } @@ -569,15 +591,10 @@ public function top_cart_button() { public function mini_cart_button() { if (AngellEYE_Utility::is_express_checkout_credentials_is_set()) { - $this->woocommerce_before_cart(); - $mini_cart_button_html = ''; $mini_cart_button_html .= $this->woocommerce_paypal_express_checkout_button_angelleye($return = true, 'mini'); $mini_cart_button_html .= "
"; - - - echo apply_filters('angelleye_ec_mini_cart_button_html', $mini_cart_button_html); } } @@ -599,7 +616,7 @@ public function woocommerce_paypal_express_checkout_button_angelleye($return = f $class_top = 'paypal_checkout_button_top'; $class_cc_top = 'paypal_checkout_button_cc_top'; $angelleye_smart_button = 'angelleye_smart_button_top'; - } elseif($possition == 'mini') { + } elseif ($possition == 'mini') { $class_top = 'paypal_checkout_button_top'; $class_cc_top = 'paypal_checkout_button_cc_top'; $angelleye_smart_button = 'angelleye_smart_button_mini'; @@ -607,7 +624,7 @@ public function woocommerce_paypal_express_checkout_button_angelleye($return = f $class_top = 'paypal_checkout_button_bottom'; $class_cc_top = 'paypal_checkout_button_cc_bottom'; $angelleye_smart_button = 'angelleye_smart_button_bottom'; - $angelleye_proceed_to_checkout_button_separator = '
' . __( '— OR —', 'paypal-for-woocommerce' ) . '
'; + $angelleye_proceed_to_checkout_button_separator = '
' . __('— OR —', 'paypal-for-woocommerce') . '
'; $cart_button_html .= apply_filters('angelleye_proceed_to_checkout_button_separator', $angelleye_proceed_to_checkout_button_separator); } if ($this->enable_in_context_checkout_flow == 'no') { @@ -634,9 +651,8 @@ public function woocommerce_paypal_express_checkout_button_angelleye($return = f $cart_button_html .= $paypal_credit_button_markup; } } else { - + $cart_button_html .= "
"; - } if ($this->enable_tokenized_payments == 'yes') { $cart_button_html .= $this->function_helper->angelleye_ec_save_payment_method_checkbox(); @@ -664,7 +680,7 @@ public function checkout_message() { if (WC()->cart->total > 0) { $ec_top_checkout_button = ''; wp_enqueue_script('angelleye_button'); - echo '
'; + $ec_top_checkout_button .= '
'; do_action('angelleye_ec_checkout_page_before_checkout_button', $this); $ec_top_checkout_button .= '
'; if ($this->enable_in_context_checkout_flow == 'no') { @@ -708,12 +724,11 @@ public function checkout_message() { $ec_top_checkout_button .= '
'; $ec_top_checkout_button .= '

' . $this->angelleye_skip_text . '

'; $ec_top_checkout_button .= '
'; - + $ec_top_checkout_button .= '
'; + $ec_top_checkout_button .= '
'; + $ec_top_checkout_button .= '
'; echo apply_filters('angelleye_ec_checkout_page_buy_now_nutton', $ec_top_checkout_button); do_action('angelleye_ec_checkout_page_after_checkout_button', $this); - echo '
'; - echo ''; - echo '
'; } } @@ -747,7 +762,7 @@ public function woocommerce_before_cart() { WC()->cart->calculate_totals(); $payment_gateways_count = 0; echo ""; - if ( $this->enabled == 'yes' && 0 < WC()->cart->total) { + if ($this->enabled == 'yes' && 0 < WC()->cart->total) { $payment_gateways = WC()->payment_gateways->get_available_payment_gateways(); unset($payment_gateways['paypal_pro']); unset($payment_gateways['paypal_pro_payflow']); @@ -790,7 +805,7 @@ public function angelleye_woocommerce_coupons_enabled($is_coupons_enabled) { } public function maybe_add_shipping_information($packages) { - if ( ! is_ajax() ) { + if (!is_ajax()) { if ($this->function_helper->ec_is_express_checkout() || $this->ec_get_session_data('shipping_details')) { $destination = $this->ec_get_session_data('shipping_details'); if (!empty($destination)) { @@ -834,7 +849,7 @@ public function angelleye_ajax_generate_cart() { wp_die(__('Cheatin’ huh?', 'paypal-for-woocommerce')); } WC()->shipping->reset_shipping(); - $product_id = absint( wp_unslash( $_POST['product_id'])); + $product_id = absint(wp_unslash($_POST['product_id'])); $url = esc_url_raw(add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))); if (!empty($_POST['wc-paypal_express-new-payment-method']) && $_POST['wc-paypal_express-new-payment-method'] == 'true') { $url = add_query_arg('ec_save_to_account', 'true', $url); @@ -851,8 +866,8 @@ public function angelleye_ajax_generate_cart() { $qty = !isset($_POST['qty']) ? 1 : absint($_POST['qty']); if ($product->is_type('variable')) { $attributes = array_map('wc_clean', json_decode(stripslashes($_POST['attributes']), true)); - if(!empty($_POST['variation_id'])) { - $variation_id = absint( wp_unslash( $_POST['variation_id'] ) ); + if (!empty($_POST['variation_id'])) { + $variation_id = absint(wp_unslash($_POST['variation_id'])); } else { if (version_compare(WC_VERSION, '3.0', '<')) { $variation_id = $product->get_matching_variation($attributes); @@ -862,12 +877,12 @@ public function angelleye_ajax_generate_cart() { } } $bool = $this->angelleye_is_product_already_in_cart($product->get_id(), $qty, $variation_id, $attributes); - if($bool == false) { + if ($bool == false) { WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); } } elseif ($product->is_type('simple')) { $bool = $this->angelleye_is_product_already_in_cart($product->get_id(), $qty); - if( $bool == false ) { + if ($bool == false) { WC()->cart->add_to_cart($product->get_id(), $qty); } } @@ -876,7 +891,7 @@ public function angelleye_ajax_generate_cart() { if (ob_get_length()) { ob_end_clean(); } - ob_start(); + ob_start(); wp_send_json(array('url' => $url)); } catch (Exception $ex) { if (ob_get_length()) { @@ -884,7 +899,7 @@ public function angelleye_ajax_generate_cart() { } ob_start(); wp_send_json(array('url' => $url)); - } + } } public function angelleye_in_content_js($url) { @@ -1029,8 +1044,6 @@ public function angelleye_is_in_context_enable() { return false; } - - /** * frontend_scripts function. * @@ -1085,26 +1098,26 @@ public function add_body_classes($classes) { $classes[] = 'has_paypal_express_checkout'; return $classes; } - + public function angelleye_is_product_already_in_cart($product_id = 0, $quantity = 1, $variation_id = 0, $variation = array(), $cart_item_data = array()) { - $product_id = absint( $product_id ); - $variation_id = absint( $variation_id ); - if ( 'product_variation' === get_post_type( $product_id ) ) { + $product_id = absint($product_id); + $variation_id = absint($variation_id); + if ('product_variation' === get_post_type($product_id)) { $variation_id = $product_id; - $product_id = wp_get_post_parent_id( $variation_id ); + $product_id = wp_get_post_parent_id($variation_id); } - $product_data = wc_get_product( $variation_id ? $variation_id : $product_id ); - $quantity = apply_filters( 'woocommerce_add_to_cart_quantity', $quantity, $product_id ); - if ( $quantity <= 0 || ! $product_data || 'trash' === $product_data->get_status() ) { + $product_data = wc_get_product($variation_id ? $variation_id : $product_id); + $quantity = apply_filters('woocommerce_add_to_cart_quantity', $quantity, $product_id); + if ($quantity <= 0 || !$product_data || 'trash' === $product_data->get_status()) { return false; } - $cart_item_data = (array) apply_filters( 'woocommerce_add_cart_item_data', $cart_item_data, $product_id, $variation_id, $quantity ); - $cart_id = WC()->cart->generate_cart_id( $product_id, $variation_id, $variation, $cart_item_data ); - $cart_item_key = WC()->cart->find_product_in_cart( $cart_id ); - if ( $product_data->is_sold_individually() ) { - $quantity = apply_filters( 'woocommerce_add_to_cart_sold_individually_quantity', 1, $quantity, $product_id, $variation_id, $cart_item_data ); - $found_in_cart = apply_filters( 'woocommerce_add_to_cart_sold_individually_found_in_cart', $cart_item_key && WC()->cart->cart_contents[ $cart_item_key ]['quantity'] > 0, $product_id, $variation_id, $cart_item_data, $cart_id ); - if ( $found_in_cart ) { + $cart_item_data = (array) apply_filters('woocommerce_add_cart_item_data', $cart_item_data, $product_id, $variation_id, $quantity); + $cart_id = WC()->cart->generate_cart_id($product_id, $variation_id, $variation, $cart_item_data); + $cart_item_key = WC()->cart->find_product_in_cart($cart_id); + if ($product_data->is_sold_individually()) { + $quantity = apply_filters('woocommerce_add_to_cart_sold_individually_quantity', 1, $quantity, $product_id, $variation_id, $cart_item_data); + $found_in_cart = apply_filters('woocommerce_add_to_cart_sold_individually_found_in_cart', $cart_item_key && WC()->cart->cart_contents[$cart_item_key]['quantity'] > 0, $product_id, $variation_id, $cart_item_data, $cart_id); + if ($found_in_cart) { return true; } else { return false; @@ -1112,23 +1125,23 @@ public function angelleye_is_product_already_in_cart($product_id = 0, $quantity } return false; } - + public function angelleye_add_header_meta() { - if ($this->enable_in_context_checkout_flow === 'yes' && $this->enabled == 'yes' ) { + if ($this->enable_in_context_checkout_flow === 'yes' && $this->enabled == 'yes') { echo ''; echo ''; } } - + public function angelleye_display_custom_message_review_page() { - if( !empty($this->order_review_page_custom_message)) { + if (!empty($this->order_review_page_custom_message)) { $paypal_express_checkout = WC()->session->get('paypal_express_checkout'); if (!is_admin() && is_main_query() && in_the_loop() && is_page() && is_checkout() && !empty($paypal_express_checkout)) { echo ''; } } } - + public function angelleye_ec_force_to_display_checkout_page_js() { $this->enable_guest_checkout = get_option('woocommerce_enable_guest_checkout') == 'yes' ? true : false; $this->must_create_account = $this->enable_guest_checkout || is_user_logged_in() ? false : true; @@ -1160,30 +1173,29 @@ public function angelleye_ec_force_to_display_checkout_page_js() { } return apply_filters('angelleye_ec_force_to_display_checkout_page', $force_to_display_checkout_page); } - + public function angelleye_woocommerce_locate_template($template, $template_name, $template_path) { - if( $template_name != 'cart/proceed-to-checkout-button.php' ) { + if ($template_name != 'cart/proceed-to-checkout-button.php') { return $template; } $change_proceed_checkout_button_text = get_option('change_proceed_checkout_button_text'); - if( empty($change_proceed_checkout_button_text) ) { + if (empty($change_proceed_checkout_button_text)) { return $template; } global $woocommerce; $_template = $template; - if ( ! $template_path ) { + if (!$template_path) { $template_path = $woocommerce->template_url; } $plugin_path = PAYPAL_FOR_WOOCOMMERCE_DIR_PATH . '/template/'; $template = locate_template(array($template_path . $template_name, $template_name)); - if ( ! $template && file_exists( $plugin_path . $template_name ) ) { + if (!$template && file_exists($plugin_path . $template_name)) { $template = $plugin_path . $template_name; } - if ( ! $template ) { + if (!$template) { $template = $_template; } return $template; } - } diff --git a/paypal-for-woocommerce.php b/paypal-for-woocommerce.php index a30ac5fe2..d9ed2cebb 100644 --- a/paypal-for-woocommerce.php +++ b/paypal-for-woocommerce.php @@ -291,7 +291,7 @@ public function init(){ include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-pro-angelleye.php'); include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-braintree-angelleye.php'); include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-credit-cards-rest-angelleye.php'); - new Angelleye_PayPal_Express_Checkout_Helper(VERSION_PFW); + Angelleye_PayPal_Express_Checkout_Helper::instance(); add_filter( 'woocommerce_payment_gateways', array($this, 'angelleye_add_paypal_pro_gateway'),1000 ); }