Angelleye_PayPal_Express_Checkout_Helper

The PayPal for WooCommerce Angelleye PayPal Express Checkout Helper class.

Defined (1)

The class is defined in the following location(s).

/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php  
  1. class Angelleye_PayPal_Express_Checkout_Helper { 
  2.  
  3. public $setting; 
  4. public $function_helper; 
  5.  
  6. public function __construct($version) { 
  7. try { 
  8. global $wpdb; 
  9. $this->version = $version; 
  10. $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'woocommerce_paypal_express_settings')); 
  11. $this->setting = isset($row->option_value) ? maybe_unserialize($row->option_value) : array(); 
  12. $paypal_pro_row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'woocommerce_paypal_pro_settings')); 
  13. $this->paypal_pro_setting = isset($paypal_pro_row->option_value) ? maybe_unserialize($paypal_pro_row->option_value) : array(); 
  14. $this->paypal_pro_enabled = !empty($this->paypal_pro_setting['enabled']) ? $this->paypal_pro_setting['enabled'] : 'no'; 
  15. $paypal_flow_row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'woocommerce_paypal_pro_payflow_settings')); 
  16. $this->paypal_flow_setting = isset($paypal_flow_row->option_value) ? maybe_unserialize($paypal_flow_row->option_value) : array(); 
  17. $this->paypal_flow_enabled = !empty($this->paypal_flow_setting['enabled']) ? $this->paypal_flow_setting['enabled'] : 'no'; 
  18. $this->enable_tokenized_payments = !empty($this->setting['enable_tokenized_payments']) ? $this->setting['enable_tokenized_payments'] : 'no'; 
  19. $this->save_abandoned_checkout_value = !empty($this->setting['save_abandoned_checkout']) ? $this->setting['enable_tokenized_payments'] : 'no'; 
  20. $this->save_abandoned_checkout = 'yes' === $this->save_abandoned_checkout_value; 
  21. $this->checkout_with_pp_button_type = !empty($this->setting['checkout_with_pp_button_type']) ? $this->setting['checkout_with_pp_button_type'] : 'paypalimage'; 
  22. $this->pp_button_type_text_button = !empty($this->setting['pp_button_type_text_button']) ? $this->setting['pp_button_type_text_button'] : 'Proceed to Checkout'; 
  23. $this->pp_button_type_my_custom = !empty($this->setting['pp_button_type_my_custom']) ? $this->setting['pp_button_type_my_custom'] : WC_Gateway_PayPal_Express_AngellEYE::angelleye_get_paypalimage(); 
  24. $this->show_on_product_page = !empty($this->setting['show_on_product_page']) ? $this->setting['show_on_product_page'] : 'no'; 
  25. $this->enabled = !empty($this->setting['enabled']) ? $this->setting['enabled'] : 'no'; 
  26. $this->show_on_checkout = !empty($this->setting['show_on_checkout']) ? $this->setting['show_on_checkout'] : 'top'; 
  27. $this->button_position = !empty($this->setting['button_position']) ? $this->setting['button_position'] : 'bottom'; 
  28. $this->show_on_cart = !empty($this->setting['show_on_cart']) ? $this->setting['show_on_cart'] : 'yes'; 
  29. $this->prevent_to_add_additional_item_value = !empty($this->setting['prevent_to_add_additional_item']) ? $this->setting['prevent_to_add_additional_item'] : 'no'; 
  30. $this->prevent_to_add_additional_item = 'yes' === $this->prevent_to_add_additional_item_value; 
  31. $this->testmode_value = !empty($this->setting['testmode']) ? $this->setting['testmode'] : 'yes'; 
  32. $this->testmode = 'yes' === $this->testmode_value; 
  33. $this->cancel_page = !empty($this->setting['cancel_page']) ? $this->setting['cancel_page'] : ''; 
  34. if( $this->testmode == false ) { 
  35. $this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product(); 
  36. if (substr(get_option("woocommerce_default_country"), 0, 2) == 'US' || substr(get_option("woocommerce_default_country"), 0, 2) == 'GB') { 
  37. $this->is_us_or_uk = true; 
  38. } else { 
  39. $this->is_us_or_uk = false; 
  40. $this->show_paypal_credit = !empty($this->setting['show_paypal_credit']) ? $this->setting['show_paypal_credit'] : 'yes'; 
  41. if ($this->is_us_or_uk == false) { 
  42. $this->show_paypal_credit = 'no'; 
  43. if ($this->testmode == true) { 
  44. $this->API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp"; 
  45. $this->PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token="; 
  46. $this->api_username = !empty($this->setting['sandbox_api_username']) ? $this->setting['sandbox_api_username'] : ''; 
  47. $this->api_password = !empty($this->setting['sandbox_api_password']) ? $this->setting['sandbox_api_password'] : ''; 
  48. $this->api_signature = !empty($this->setting['sandbox_api_signature']) ? $this->setting['sandbox_api_signature'] : ''; 
  49. } else { 
  50. $this->API_Endpoint = "https://api-3t.paypal.com/nvp"; 
  51. $this->PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token="; 
  52. $this->api_username = !empty($this->setting['api_username']) ? $this->setting['api_username'] : ''; 
  53. $this->api_password = !empty($this->setting['api_password']) ? $this->setting['api_password'] : ''; 
  54. $this->api_signature = !empty($this->setting['api_signature']) ? $this->setting['api_signature'] : ''; 
  55. $this->angelleye_skip_text = !empty($this->setting['angelleye_skip_text']) ? $this->setting['angelleye_skip_text'] : 'Skip the forms and pay faster with PayPal!'; 
  56. add_action('woocommerce_after_add_to_cart_button', array($this, 'buy_now_button')); 
  57. if($this->save_abandoned_checkout == false) { 
  58. add_action('woocommerce_after_checkout_validation', array($this, 'angelleye_paypal_express_checkout_redirect_to_paypal'), 99); 
  59. add_action('woocommerce_add_to_cart_redirect', array($this, 'add_to_cart_redirect')); 
  60. add_action('woocommerce_checkout_billing', array($this, 'ec_set_checkout_post_data')); 
  61. add_action('woocommerce_available_payment_gateways', array($this, 'ec_disable_gateways')); 
  62. add_filter('body_class', array($this, 'ec_add_body_class')); 
  63. add_action('woocommerce_checkout_fields', array($this, 'ec_display_checkout_fields')); 
  64. add_action('woocommerce_before_checkout_billing_form', array($this, 'ec_formatted_billing_address'), 9); 
  65. add_action('woocommerce_review_order_after_submit', array($this, 'ec_cancel_link')); 
  66. add_filter('woocommerce_terms_is_checked_default', array($this, 'ec_terms_express_checkout')); 
  67. add_action('woocommerce_cart_emptied', array($this, 'ec_clear_session_data')); 
  68. add_filter('woocommerce_thankyou_order_received_text', array($this, 'ec_order_received_text'), 10, 2); 
  69. add_action('wp_enqueue_scripts', array($this, 'ec_enqueue_scripts_product_page')); 
  70. add_action('woocommerce_before_cart_table', array($this, 'top_cart_button')); 
  71. if($this->show_on_cart == 'yes') { 
  72. add_action( 'woocommerce_after_mini_cart', array($this, 'mini_cart_button')); 
  73. add_action( 'woocommerce_before_cart', array( $this, 'woocommerce_before_cart'), 12 ); 
  74. add_filter('woocommerce_is_sold_individually', array($this, 'angelleye_woocommerce_is_sold_individually'), 10, 2); 
  75. add_filter('woocommerce_ship_to_different_address_checked', array($this, 'angelleye_ship_to_different_address_checked'), 10, 1); 
  76. add_filter('woocommerce_order_button_html', array($this, 'angelleye_woocommerce_order_button_html'), 10, 1); 
  77. if (AngellEYE_Utility::is_express_checkout_credentials_is_set()) { 
  78. if ($this->button_position == 'bottom' || $this->button_position == 'both') { 
  79. add_action('woocommerce_proceed_to_checkout', array($this, 'woocommerce_paypal_express_checkout_button_angelleye'), 22); 
  80. if ($this->enabled == 'yes' && ($this->show_on_checkout == 'top' || $this->show_on_checkout == 'both')) { 
  81. add_action('woocommerce_before_checkout_form', array($this, 'checkout_message'), 5); 
  82. if (!class_exists('WC_Gateway_PayPal_Express_Function_AngellEYE')) { 
  83. require_once( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php' ); 
  84. $this->function_helper = new WC_Gateway_PayPal_Express_Function_AngellEYE(); 
  85. $this->is_order_completed = true; 
  86. } catch (Exception $ex) { 
  87.  
  88.  
  89. public function buy_now_button() { 
  90. try { 
  91. global $product; 
  92. $is_ec_button_enable_product_level = get_post_meta($product->get_id(), '_enable_ec_button', true); 
  93. if( $this->enabled == 'yes' && $this->show_on_product_page == 'yes' && $is_ec_button_enable_product_level == 'yes') { 
  94. $ec_html_button = ''; 
  95. $_product = wc_get_product($product->get_id()); 
  96. if ( $_product->is_type( 'simple' ) && (version_compare( WC_VERSION, '3.0', '<' ) == false)) { 
  97. ?> 
  98. <input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" /> 
  99. <?php 
  100. $ec_html_button .= '<div class="angelleye_button_single">'; 
  101. $button_dynamic_class = 'single_variation_wrap_angelleye_' . $product->get_id(); 
  102. $hide = ''; 
  103. if ($_product->is_type('variation') || $_product->is_type('external') || $_product->get_price() == 0 || $_product->get_price() == '') { 
  104. $hide = 'display:none;'; 
  105. $add_to_cart_action = esc_url(add_query_arg('express_checkout', '1')); 
  106. switch ($this->checkout_with_pp_button_type) { 
  107. case 'textbutton': 
  108. $ec_html_button .= '<input data-action="' . esc_url($add_to_cart_action) . '" type="button" style="'.$hide.'" class="single_add_to_cart_button button alt paypal_checkout_button single_variation_wrap_angelleye paypal_checkout_button button alt ec_product_page_button_type_textbutton "' . $button_dynamic_class . '" name="express_checkout" value="' . $this->pp_button_type_text_button . '"/>'; 
  109. break; 
  110. case "paypalimage": 
  111. $button_img = WC_Gateway_PayPal_Express_AngellEYE::angelleye_get_paypalimage(); 
  112. $ec_html_button .= '<input data-action="' . esc_url($add_to_cart_action) . '" type="image" src="'.$button_img.'" style="'.$hide.'" class="single_add_to_cart_button button alt paypal_checkout_button single_variation_wrap_angelleye ec_product_page_button_type_paypalimage ' . $button_dynamic_class . '" name="express_checkout" value="' . __('Pay with PayPal', 'paypal-for-woocommerce') . '"/>'; 
  113. break; 
  114. case "customimage": 
  115. $ec_html_button .= '<input data-action="' . esc_url($add_to_cart_action) . '" type="image" src="'.$this->pp_button_type_my_custom.'" style="'.$hide.'" class="single_add_to_cart_button button alt paypal_checkout_button single_variation_wrap_angelleye ec_product_page_button_type_customimage ' . $button_dynamic_class . '" name="express_checkout" value="' . __('Pay with PayPal', 'paypal-for-woocommerce') . '"/>'; 
  116. break; 
  117. $ec_html_button .= '</div>'; 
  118. if ($this->enable_tokenized_payments == 'yes') { 
  119. $ec_html_button .= $this->function_helper->angelleye_ec_save_payment_method_checkbox(); 
  120. echo apply_filters('angelleye_ec_product_page_buy_now_button', $ec_html_button); 
  121. } catch (Exception $ex) { 
  122.  
  123.  
  124. public function angelleye_paypal_express_checkout_redirect_to_paypal() { 
  125. try { 
  126. WC()->session->set( 'post_data', $_POST); 
  127. if (isset($_POST['payment_method']) && 'paypal_express' === $_POST['payment_method'] && $this->function_helper->ec_notice_count('error') == 0) { 
  128. $this->function_helper->ec_redirect_after_checkout(); 
  129. } catch (Exception $ex) { 
  130.  
  131.  
  132. public function add_to_cart_redirect($url = null) { 
  133. try { 
  134. if (isset($_REQUEST['express_checkout']) || isset($_REQUEST['express_checkout_x'])) { 
  135. wc_clear_notices(); 
  136. if( isset($_POST['wc-paypal_express-new-payment-method']) && $_POST['wc-paypal_express-new-payment-method'] = 'on' ) { 
  137. WC()->session->set( 'ec_save_to_account', 'on'); 
  138. $url = esc_url_raw(add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))); 
  139. return $url; 
  140. } catch (Exception $ex) { 
  141.  
  142.  
  143. public function ec_get_session_data($key = '') { 
  144. try { 
  145. $session_data = WC()->session->get( 'paypal_express_checkout' ); 
  146. if (isset($session_data[$key])) { 
  147. $session_data = $session_data[$key]; 
  148. return $session_data; 
  149. } catch (Exception $ex) { 
  150.  
  151.  
  152. public function ec_is_available() { 
  153. try { 
  154. return $this->function_helper->express_checkout_is_available(); 
  155. } catch (Exception $ex) { 
  156.  
  157.  
  158. public function ec_set_checkout_post_data() { 
  159. try { 
  160. if (!$this->function_helper->ec_is_express_checkout() || !$this->ec_get_session_data('shipping_details')) { 
  161. return; 
  162. foreach ($this->ec_get_session_data('shipping_details') as $field => $value) { 
  163. if ($value) { 
  164. $_POST['billing_' . $field] = $value; 
  165. $post_data = WC()->session->get( 'post_data' ); 
  166. $_POST['order_comments'] = isset($post_data['order_comments']) ? $post_data['order_comments'] : ''; 
  167. if( !empty($post_data) ) { 
  168. foreach ($post_data as $key => $value) { 
  169. $_POST[$key] = $value; 
  170. $this->chosen = true; 
  171. } catch (Exception $ex) { 
  172.  
  173.  
  174. public function ec_display_checkout_fields($checkout_fields) { 
  175. try { 
  176. if ($this->function_helper->ec_is_express_checkout() && $this->ec_get_session_data('shipping_details')) { 
  177. foreach ($this->ec_get_session_data('shipping_details') as $field => $value) { 
  178. if (isset($checkout_fields['billing']) && isset($checkout_fields['billing']['billing_' . $field])) { 
  179. $required = isset($checkout_fields['billing']['billing_' . $field]['required']) && $checkout_fields['billing']['billing_' . $field]['required']; 
  180. if (!$required || $required && $value) { 
  181. $checkout_fields['billing']['billing_' . $field]['class'][] = 'express-provided'; 
  182. $checkout_fields['billing']['billing_' . $field]['class'][] = 'hidden'; 
  183. // if (isset($checkout_fields['shipping']) && isset($checkout_fields['shipping']['billing_' . $field])) { 
  184. // $required = isset($checkout_fields['billing']['billing_' . $field]['required']) && $checkout_fields['billing']['billing_' . $field]['required']; 
  185. // if (!$required || $required && $value) { 
  186. // $checkout_fields['billing']['billing_' . $field]['class'][] = 'express-provided'; 
  187. // $checkout_fields['billing']['billing_' . $field]['class'][] = 'hidden'; 
  188. // } 
  189. // } 
  190. return $checkout_fields; 
  191. } catch (Exception $ex) { 
  192.  
  193.  
  194. public function ec_formatted_address($type) { 
  195. try { 
  196. if (!$this->function_helper->ec_is_express_checkout()) { 
  197. return; 
  198. if (!$this->is_order_completed) { 
  199. return; 
  200. ?> 
  201. <div class="express-provided-address"> 
  202. <!-- <a href="#" class="ex-show-address-fields" data-type="<?php echo esc_attr($type); ?>"><?php esc_html_e('Edit', 'paypal-for-woocommerce'); ?></a>--> 
  203. <address> 
  204. <?php 
  205. $address = array( 
  206. 'first_name' => WC()->checkout->get_value($type . '_first_name'),  
  207. 'last_name' => WC()->checkout->get_value($type . '_last_name'),  
  208. 'company' => WC()->checkout->get_value($type . '_company'),  
  209. 'address_1' => WC()->checkout->get_value($type . '_address_1'),  
  210. 'address_2' => WC()->checkout->get_value($type . '_address_2'),  
  211. 'city' => WC()->checkout->get_value($type . '_city'),  
  212. 'state' => WC()->checkout->get_value($type . '_state'),  
  213. 'postcode' => WC()->checkout->get_value($type . '_postcode'),  
  214. 'country' => WC()->checkout->get_value($type . '_country'),  
  215. ); 
  216. echo WC()->countries->get_formatted_address($address); 
  217. ?> 
  218. </address> 
  219. </div> 
  220. <?php 
  221. } catch (Exception $ex) { 
  222.  
  223.  
  224. public function ec_disable_gateways($gateways) { 
  225. try { 
  226. if ($this->function_helper->ec_is_express_checkout()) { 
  227. foreach ($gateways as $id => $gateway) { 
  228. if ($id !== 'paypal_express') { 
  229. unset($gateways[$id]); 
  230. return $gateways; 
  231. } catch (Exception $ex) { 
  232.  
  233.  
  234. public function ec_add_body_class($classes) { 
  235. try { 
  236. if (sizeof(WC()->session) == 0) { 
  237. return $classes; 
  238. $paypal_express_terms = WC()->session->get( 'paypal_express_terms' ); 
  239. if ($this->ec_is_checkout() && $this->function_helper->ec_is_express_checkout()) { 
  240. $classes[] = 'express-checkout'; 
  241. if ($this->show_on_checkout && isset($paypal_express_terms)) { 
  242. $classes[] = 'express-hide-terms'; 
  243. return $classes; 
  244. } catch (Exception $ex) { 
  245.  
  246.  
  247. public function ec_formatted_billing_address() { 
  248. $this->ec_formatted_address('billing'); 
  249.  
  250. public function ec_cancel_link() { 
  251. if (!$this->ec_is_available() || !$this->function_helper->ec_is_express_checkout()) { 
  252. return; 
  253. printf( 
  254. '<a href="%1$s" class="ex-paypal-express-cancel">%2$s</a>', esc_url(add_query_arg(array('wc_paypal_express_clear_session' => true), WC()->cart->get_cart_url())), esc_html__('Cancel', 'paypal-for-woocommerce') 
  255. ); 
  256.  
  257. public function ec_terms_express_checkout($checked_default) { 
  258. if (sizeof(WC()->session) == 0) { 
  259. return $checked_default; 
  260. if (!$this->ec_is_available() || !$this->function_helper->ec_is_express_checkout()) { 
  261. return $checked_default; 
  262. $paypal_express_terms = WC()->session->get( 'paypal_express_terms' ); 
  263. if ($this->show_on_checkout && isset($paypal_express_terms)) { 
  264. $checked_default = true; 
  265. return $checked_default; 
  266.  
  267. public function ec_clear_session_data() { 
  268. unset(WC()->session->paypal_express_checkout); 
  269. unset(WC()->session->paypal_express_terms); 
  270. unset(WC()->session->ec_save_to_account); 
  271. unset(WC()->session->held_order_received_text); 
  272. unset(WC()->session->post_data); 
  273. unset(WC()->session->shiptoname); 
  274. unset(WC()->session->payeremail); 
  275.  
  276. public function ec_is_checkout() { 
  277. return is_page(wc_get_page_id('checkout')) || apply_filters('woocommerce_is_checkout', false); 
  278.  
  279. public function ec_order_received_text($text, $order) { 
  280. $held_order_received_text = WC()->session->get( 'held_order_received_text' ); 
  281. if ($order && $order->has_status('on-hold') && isset($held_order_received_text)) { 
  282. $text = $held_order_received_text; 
  283. unset(WC()->session->held_order_received_text); 
  284. return $text; 
  285.  
  286. public function ec_enqueue_scripts_product_page() { 
  287. try { 
  288. wp_enqueue_style('angelleye-express-checkout-css', PAYPAL_FOR_WOOCOMMERCE_ASSET_URL . '/assets/css/angelleye-express-checkout.css', array(), $this->version, 'all'); 
  289. if (is_checkout()) { 
  290. wp_enqueue_script('angelleye-express-checkout-js', PAYPAL_FOR_WOOCOMMERCE_ASSET_URL . '/assets/js/angelleye-express-checkout.js', array(), $this->version, 'all'); 
  291. wp_enqueue_script('angelleye-express-checkout-custom', PAYPAL_FOR_WOOCOMMERCE_ASSET_URL . '/assets/js/angelleye-express-checkout-custom.js', array(), $this->version, 'all'); 
  292. wp_localize_script('angelleye-express-checkout-js', 'is_page_name', 'checkout_page'); 
  293. wp_localize_script('angelleye-express-checkout-custom', 'is_page_name', 'checkout_page'); 
  294. if (is_product()) { 
  295. wp_enqueue_script('angelleye-express-checkout-custom', PAYPAL_FOR_WOOCOMMERCE_ASSET_URL . '/assets/js/angelleye-express-checkout-custom.js', array(), $this->version, 'all'); 
  296. wp_localize_script('angelleye-express-checkout-custom', 'is_page_name', 'single_product_page'); 
  297. if (is_cart()) { 
  298. wp_enqueue_script('angelleye-express-checkout-custom', PAYPAL_FOR_WOOCOMMERCE_ASSET_URL . '/assets/js/angelleye-express-checkout-custom.js', array(), $this->version, 'all'); 
  299. wp_localize_script('angelleye-express-checkout-custom', 'is_page_name', 'cart_page'); 
  300. return true; 
  301. } catch (Exception $ex) { 
  302.  
  303.  
  304. public function top_cart_button() { 
  305. if (AngellEYE_Utility::is_express_checkout_credentials_is_set()) { 
  306. $top_cart_button_html = ''; 
  307. if ($this->button_position == 'top' || $this->button_position == 'both') { 
  308. do_action('angelleye_ec_before_top_cart_button', $this); 
  309. $top_cart_button_html .= '<div class="wc-proceed-to-checkout angelleye_cart_button">'; 
  310. $top_cart_button_html .= $this->woocommerce_paypal_express_checkout_button_angelleye($return = true); 
  311. $top_cart_button_html .= '</div>'; 
  312. echo apply_filters('angelleye_ec_top_cart_button', $top_cart_button_html); 
  313. do_action('angelleye_ec_after_top_cart_button', $this);  
  314.  
  315. public function mini_cart_button() { 
  316. if (AngellEYE_Utility::is_express_checkout_credentials_is_set()) { 
  317. $mini_cart_button_html = ''; 
  318. $mini_cart_button_html .= $this->woocommerce_paypal_express_checkout_button_angelleye($return = true); 
  319. $mini_cart_button_html .= "<div class='clear'></div></div>"; 
  320. echo apply_filters('angelleye_ec_mini_cart_button_html', $mini_cart_button_html); 
  321.  
  322. public function woocommerce_paypal_express_checkout_button_angelleye($return = false) { 
  323. if (!defined('WOOCOMMERCE_CHECKOUT')) { 
  324. define('WOOCOMMERCE_CHECKOUT', true); 
  325. if (!defined('WOOCOMMERCE_CART')) { 
  326. define('WOOCOMMERCE_CART', true); 
  327. WC()->cart->calculate_totals(); 
  328. if (!AngellEYE_Utility::is_valid_for_use_paypal_express()) { 
  329. return false; 
  330. if ($this->enabled == 'yes' && $this->show_on_cart == 'yes' && 0 < WC()->cart->total) { 
  331. $cart_button_html = ''; 
  332. if($return == false) { 
  333. do_action('angelleye_ec_before_buttom_cart_button', $this); 
  334. switch ($this->checkout_with_pp_button_type) { 
  335. case 'textbutton': 
  336. $cart_button_html .= '<a class="paypal_checkout_button button alt ec_checkout_page_button_type_textbutton" href="' . esc_url(add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))) . '">' . $this->pp_button_type_text_button . '</a>'; 
  337. break; 
  338. case 'paypalimage': 
  339. $cart_button_html .= '<a class="paypal_checkout_button" href="' . esc_url(add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))) . '">'; 
  340. $cart_button_html .= '<img src=' . WC_Gateway_PayPal_Express_AngellEYE::angelleye_get_paypalimage() . ' class="ec_checkout_page_button_type_paypalimage" align="top" alt="' . __('Pay with PayPal', 'paypal-for-woocommerce') . '" />'; 
  341. $cart_button_html .= "</a>"; 
  342. break; 
  343. case 'customimage': 
  344. $cart_button_html .= '<a class="paypal_checkout_button" href="' . esc_url(add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))) . '">'; 
  345. $cart_button_html .= '<img src="' . $this->pp_button_type_my_custom . '" class="ec_checkout_page_button_type_customimage" align="top" alt="' . __('Pay with PayPal', 'paypal-for-woocommerce') . '" />'; 
  346. $cart_button_html .= "</a>"; 
  347. break; 
  348. if ($this->show_paypal_credit == 'yes') { 
  349. $paypal_credit_button_markup = '<a class="paypal_checkout_button" href="' . esc_url(add_query_arg('use_paypal_credit', 'true', add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/'))))) . '" >'; 
  350. $paypal_credit_button_markup .= '<img src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-small.png" width="148" height="26" class="ppcreditlogo ec_checkout_page_button_type_pc" align="top" alt="' . __('Check out with PayPal Credit', 'paypal-for-woocommerce') . '" />'; 
  351. $paypal_credit_button_markup .= '</a>'; 
  352. $cart_button_html .= $paypal_credit_button_markup; 
  353. if ($this->enable_tokenized_payments == 'yes') { 
  354. $cart_button_html .= $this->function_helper->angelleye_ec_save_payment_method_checkbox(); 
  355. if($return == true) { 
  356. return $cart_button_html; 
  357. } else { 
  358. echo $cart_button_html; 
  359. do_action('angelleye_ec_after_buttom_cart_button', $this); 
  360.  
  361. public function checkout_message() { 
  362. if (!defined('WOOCOMMERCE_CHECKOUT')) { 
  363. define('WOOCOMMERCE_CHECKOUT', true); 
  364. if (!defined('WOOCOMMERCE_CART')) { 
  365. define('WOOCOMMERCE_CART', true); 
  366. WC()->cart->calculate_totals();  
  367. if (AngellEYE_Utility::is_express_checkout_credentials_is_set() == false) { 
  368. return false; 
  369. if (!AngellEYE_Utility::is_valid_for_use_paypal_express()) { 
  370. return false; 
  371. if (WC()->cart->total > 0) { 
  372. $ec_top_checkout_button = ''; 
  373. wp_enqueue_script('angelleye_button'); 
  374. echo '<div id="checkout_paypal_message" class="woocommerce-info info">'; 
  375.  
  376. do_action('angelleye_ec_checkout_page_before_checkout_button', $this); 
  377. $ec_top_checkout_button .= '<div id="paypal_box_button">'; 
  378. switch ($this->checkout_with_pp_button_type) { 
  379. case "textbutton": 
  380. $ec_top_checkout_button .= '<div class="paypal_ec_textbutton">'; 
  381. $ec_top_checkout_button .= '<a class="paypal_checkout_button paypal_checkout_button_text button alt" href="' . esc_url(add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))) . '">' . $this->pp_button_type_text_button . '</a>'; 
  382. $ec_top_checkout_button .= '</div>'; 
  383. break; 
  384. case "paypalimage": 
  385. $ec_top_checkout_button .= '<div id="paypal_ec_button">'; 
  386. $ec_top_checkout_button .= '<a class="paypal_checkout_button" href="' . esc_url(add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))) . '">'; 
  387. $ec_top_checkout_button .= "<img src='" . WC_Gateway_PayPal_Express_AngellEYE::angelleye_get_paypalimage() . "' class='ec_checkout_page_button_type_paypalimage' border='0' alt='" . __('Pay with PayPal', 'paypal-for-woocommerce') . "'/>"; 
  388. $ec_top_checkout_button .= "</a>"; 
  389. $ec_top_checkout_button .= '</div>'; 
  390. break; 
  391. case "customimage": 
  392. $button_img = $this->pp_button_type_my_custom; 
  393. $ec_top_checkout_button .= '<div id="paypal_ec_button">'; 
  394. $ec_top_checkout_button .= '<a class="paypal_checkout_button" href="' . esc_url(add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))) . '">'; 
  395. $ec_top_checkout_button .= "<img src='{$button_img}' class='ec_checkout_page_button_type_paypalimage' width='150' border='0' alt='" . __('Pay with PayPal', 'paypal-for-woocommerce') . "'/>"; 
  396. $ec_top_checkout_button .= "</a>"; 
  397. $ec_top_checkout_button .= '</div>'; 
  398. break; 
  399. if ($this->show_paypal_credit == 'yes') { 
  400. $paypal_credit_button_markup = '<div id="paypal_ec_paypal_credit_button">'; 
  401. $paypal_credit_button_markup .= '<a class="paypal_checkout_button" href="' . esc_url(add_query_arg('use_paypal_credit', 'true', add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/'))))) . '" >'; 
  402. $paypal_credit_button_markup .= "<img src='https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-small.png' class='ec_checkout_page_button_type_paypalimage' alt='Check out with PayPal Credit'/>"; 
  403. $paypal_credit_button_markup .= '</a>'; 
  404. $paypal_credit_button_markup .= '</div>'; 
  405. $ec_top_checkout_button .= $paypal_credit_button_markup; 
  406. if($this->enable_tokenized_payments == 'yes') { 
  407. $ec_top_checkout_button .= $this->function_helper->angelleye_ec_save_payment_method_checkbox(); 
  408. $ec_top_checkout_button .= '<div class="woocommerce_paypal_ec_checkout_message">'; 
  409. $ec_top_checkout_button .= '<p class="checkoutStatus">' . $this->angelleye_skip_text . '</p>'; 
  410. $ec_top_checkout_button .= '</div>'; 
  411. echo apply_filters('angelleye_ec_checkout_page_buy_now_nutton', $ec_top_checkout_button); 
  412. do_action('angelleye_ec_checkout_page_after_checkout_button', $this); 
  413. echo '<div class="clear"></div></div>'; 
  414. echo '</div>'; 
  415. echo '<div style="clear:both; margin-bottom:10px;"></div>'; 
  416.  
  417. public function angelleye_woocommerce_is_sold_individually($return, $data) { 
  418. if (isset($_REQUEST['express_checkout']) || isset($_REQUEST['express_checkout_x'])) { 
  419. if($this->prevent_to_add_additional_item) { 
  420. return true; 
  421. return $return; 
  422.  
  423. public function angelleye_ship_to_different_address_checked($bool) { 
  424. if (sizeof(WC()->session) == 0) { 
  425. return $bool; 
  426. $post_data = WC()->session->get( 'post_data' ); 
  427. if(!empty($post_data['ship_to_different_address']) && $post_data['ship_to_different_address'] == '1') { 
  428. return 1; 
  429. return $bool; 
  430.  
  431. public function woocommerce_before_cart() { 
  432. if (!defined('WOOCOMMERCE_CHECKOUT')) { 
  433. define('WOOCOMMERCE_CHECKOUT', true); 
  434. if (!defined('WOOCOMMERCE_CART')) { 
  435. define('WOOCOMMERCE_CART', true); 
  436. WC()->cart->calculate_totals(); 
  437. $payment_gateways_count = 0; 
  438. echo "<style>table.cart td.actions .input-text, table.cart td.actions .button, table.cart td.actions .checkout-button {margin-bottom: 0.53em !important}</style>"; 
  439. if ($this->enabled == 'yes' && 0 < WC()->cart->total) { 
  440. $payment_gateways = WC()->payment_gateways->get_available_payment_gateways(); 
  441. unset($payment_gateways['paypal_pro']); 
  442. unset($payment_gateways['paypal_pro_payflow']); 
  443. $payment_gateway_count = count($payment_gateways); 
  444. if( $this->show_on_checkout != 'regular' && $this->show_on_checkout != 'both') { 
  445. $payment_gateway_count = $payment_gateway_count + 1; 
  446. if ($this->enabled == 'yes' && $payment_gateway_count == 1) { 
  447. if ($this->paypal_pro_enabled == 'yes' || $this->paypal_flow_enabled == 'yes') { 
  448. $checkout_button_display_text = $this->show_on_cart == 'yes' ? __('Pay with Credit Card', 'paypal-for-woocommerce') : __('Proceed to Checkout', 'paypal-for-woocommerce'); 
  449. echo '<script type="text/javascript"> 
  450. jQuery(document).ready(function() { 
  451. if (jQuery(".checkout-button").is("input")) { 
  452. jQuery(".checkout-button").val("' . $checkout_button_display_text . '"); 
  453. } else { 
  454. jQuery(".checkout-button").html("<span>' . $checkout_button_display_text . '</span>"); 
  455. }); 
  456. </script>'; 
  457. } elseif ($this->show_on_cart == 'yes') { 
  458. echo '<style> input.checkout-button,  
  459. a.checkout-button { 
  460. display: none !important; 
  461. }</style>'; 
  462.  
  463. public function angelleye_woocommerce_order_button_html($order_button_hrml) { 
  464. if($this->function_helper->ec_is_express_checkout()) { 
  465. $order_button_text = __('Cancel order', 'paypal-for-woocommerce'); 
  466. $cancel_order_url = add_query_arg('pp_action', 'cancel_order', WC()->api_request_url('WC_Gateway_PayPal_Express_AngellEYE')); 
  467. $order_button_hrml .= apply_filters( 'angelleye_review_order_cance_button_html', '<a class="button alt angelleye_cancel" name="woocommerce_checkout_place_order" href="' . esc_attr( $cancel_order_url ) . '" >' .$order_button_text. '</a>' ); 
  468. return $order_button_hrml;