AngellEYE_Gateway_Paypal

The PayPal for WooCommerce AngellEYE Gateway Paypal class.

Defined (1)

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

/paypal-for-woocommerce.php  
  1. class AngellEYE_Gateway_Paypal 
  2.  
  3. protected $plugin_screen_hook_suffix = null; 
  4. protected $plugin_slug = 'paypal-for-woocommerce'; 
  5.  
  6. /** 
  7. * General class constructor where we'll setup our actions, hooks, and shortcodes. 
  8. */ 
  9.  
  10. const VERSION_PFW = '1.2.4'; 
  11.  
  12. public function __construct() 
  13.  
  14. /** 
  15. * Check current WooCommerce version to ensure compatibility. 
  16. */ 
  17.  
  18. $woo_version = $this->wpbo_get_woo_version_number(); 
  19. if(version_compare($woo_version, '2.1', '<')) 
  20. exit( __('PayPal for WooCommerce requires WooCommerce version 2.1 or higher. Please backup your site files and database, update WooCommerce, and try again.', 'paypal-for-woocommerce')); 
  21.  
  22. require_once plugin_dir_path(__FILE__) . 'angelleye-includes/angelleye-utility.php'; 
  23. $plugin_admin = new AngellEYE_Utility($this->plugin_slug, self::VERSION_PFW); 
  24. add_filter( 'woocommerce_paypal_args', array($this, 'ae_paypal_standard_additional_parameters')); 
  25. add_action( 'plugins_loaded', array($this, 'init')); 
  26. register_activation_hook( __FILE__, array($this, 'activate_paypal_for_woocommerce' )); 
  27. register_deactivation_hook( __FILE__, array($this, 'deactivate_paypal_for_woocommerce' )); 
  28. add_action( 'wp_enqueue_scripts', array($this, 'frontend_scripts'), 100 ); 
  29. add_action( 'admin_notices', array($this, 'admin_notices') ); 
  30. add_action( 'admin_init', array($this, 'set_ignore_tag')); 
  31. add_filter( 'woocommerce_product_title' , array($this, 'woocommerce_product_title') ); 
  32. add_action( 'woocommerce_sections_checkout', array( $this, 'donate_message' ), 11 ); 
  33. add_action( 'parse_request', array($this, 'woocommerce_paypal_express_review_order_page_angelleye') , 11); 
  34.  
  35. // http://stackoverflow.com/questions/22577727/problems-adding-action-links-to-wordpress-plugin 
  36. $basename = plugin_basename(__FILE__); 
  37. $prefix = is_network_admin() ? 'network_admin_' : ''; 
  38. add_filter("{$prefix}plugin_action_links_$basename", array($this, 'plugin_action_links'), 10, 4); 
  39. add_action( 'woocommerce_after_add_to_cart_button', array($this, 'buy_now_button')); 
  40. add_action( 'woocommerce_after_mini_cart', array($this, 'mini_cart_button'));  
  41. add_action( 'woocommerce_add_to_cart_redirect', array($this, 'add_to_cart_redirect')); 
  42. add_action( 'admin_enqueue_scripts', array( $this , 'admin_scripts' ) ); 
  43. add_action( 'admin_print_styles', array( $this , 'admin_styles' ) ); 
  44. add_action( 'woocommerce_cart_calculate_fees', array($this, 'woocommerce_custom_surcharge') ); 
  45. add_action( 'admin_init', array( $this, 'angelleye_check_version' ), 5 ); 
  46. add_filter( 'woocommerce_add_to_cart_redirect', array($this, 'angelleye_woocommerce_add_to_cart_redirect'), 1000, 1); 
  47. add_action( 'admin_menu', array( $this, 'angelleye_admin_menu_own' ) ); 
  48. add_action( 'product_type_options', array( $this, 'angelleye_product_type_options_own' ), 10, 1); 
  49. add_action( 'woocommerce_process_product_meta', array( $this, 'angelleye_woocommerce_process_product_meta_own' ), 10, 1 ); 
  50. add_filter( 'woocommerce_add_to_cart_sold_individually_quantity', array( $this, 'angelleye_woocommerce_add_to_cart_sold_individually_quantity' ), 10, 5 ); 
  51. add_action('admin_enqueue_scripts', array( $this, 'angelleye_woocommerce_admin_enqueue_scripts' ) ); 
  52. add_action( 'wp_ajax_pfw_ed_shipping_bulk_tool', array( $this, 'angelleye_woocommerce_pfw_ed_shipping_bulk_tool' ) ); 
  53. add_action( 'woocommerce_checkout_process', array( $this, 'angelleye_paypal_express_checkout_process_checkout_fields' ) ); 
  54. add_filter('body_class', array($this, 'add_body_classes')); 
  55. add_action('http_api_curl', array($this, 'http_api_curl_ex_add_curl_parameter'), 10, 3); 
  56.  
  57.  
  58. /** 
  59. * Adds class name to HTML body to enable easy conditional CSS styling 
  60. * @access public 
  61. * @param array $classes 
  62. * @return array 
  63. */ 
  64. public function add_body_classes($classes) { 
  65. global $pp_settings; 
  66. if(@$pp_settings['enabled'] == 'yes') 
  67. $classes[] = 'has_paypal_express_checkout'; 
  68. return $classes; 
  69.  
  70. /** 
  71. * Get WooCommerce Version Number 
  72. * http://wpbackoffice.com/get-current-woocommerce-version-number/ 
  73. */ 
  74. function wpbo_get_woo_version_number() 
  75. // If get_plugins() isn't available, require it 
  76. if ( ! function_exists( 'get_plugins' ) ) 
  77. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
  78.  
  79. // Create the plugins folder and file variables 
  80. $plugin_folder = get_plugins( '/' . 'woocommerce' ); 
  81. $plugin_file = 'woocommerce.php'; 
  82.  
  83. // If the plugin version number is set, return it 
  84. if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) 
  85. return $plugin_folder[$plugin_file]['Version']; 
  86. else 
  87. // Otherwise return null 
  88. return NULL; 
  89.  
  90. /** 
  91. * Add gift amount to cart 
  92. * @param $cart 
  93. */ 
  94. function woocommerce_custom_surcharge($cart) { 
  95. if (isset($_REQUEST['pp_action']) && ($_REQUEST['pp_action']=='revieworder' || $_REQUEST['pp_action']=='payaction') && WC()->session->giftwrapamount) { 
  96. $cart->add_fee( __('Gift Wrap', 'paypal-for-woocommerce'), WC()->session->giftwrapamount ); 
  97.  
  98. /** 
  99. * Return the plugin action links. This will only be called if the plugin 
  100. * is active. 
  101. * @since 1.0.6 
  102. * @param array $actions associative array of action names to anchor tags 
  103. * @return array associative array of plugin action links 
  104. */ 
  105. public function plugin_action_links($actions, $plugin_file, $plugin_data, $context) 
  106. $custom_actions = array( 
  107. //'configure' => sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=wc-settings&tab=checkout' ), __( 'Configure', 'paypal-for-woocommerce' ) ),  
  108. 'docs' => sprintf( '<a href="%s" target="_blank">%s</a>', 'http://www.angelleye.com/category/docs/paypal-for-woocommerce/?utm_source=paypal_for_woocommerce&utm_medium=docs_link&utm_campaign=paypal_for_woocommerce', __( 'Docs', 'paypal-for-woocommerce' ) ),  
  109. 'support' => sprintf( '<a href="%s" target="_blank">%s</a>', 'http://wordpress.org/support/plugin/paypal-for-woocommerce/', __( 'Support', 'paypal-for-woocommerce' ) ),  
  110. 'review' => sprintf( '<a href="%s" target="_blank">%s</a>', 'http://wordpress.org/support/view/plugin-reviews/paypal-for-woocommerce', __( 'Write a Review', 'paypal-for-woocommerce' ) ),  
  111. ); 
  112.  
  113. // add the links to the front of the actions list 
  114. return array_merge( $custom_actions, $actions ); 
  115.  
  116. function woocommerce_product_title($title) { 
  117. $title = str_replace(array("–", "–"), array("-"), $title); 
  118. return $title; 
  119.  
  120. function set_ignore_tag() { 
  121. global $current_user; 
  122. $plugin = plugin_basename( __FILE__ ); 
  123. $plugin_data = get_plugin_data( __FILE__, false ); 
  124.  
  125. if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && !is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) { 
  126. if(!in_array(@$_GET['action'], array('activate-plugin', 'upgrade-plugin', 'activate', 'do-plugin-upgrade')) && is_plugin_active($plugin) ) { 
  127. deactivate_plugins( $plugin ); 
  128. wp_die( "<strong>".$plugin_data['Name']."</strong> requires <strong>WooCommerce</strong> plugin to work normally. Please activate it or install it from <a href=\"http://wordpress.org/plugins/woocommerce/\" target=\"_blank\">here</a>.<br /><br />Back to the WordPress <a href='".get_admin_url(null, 'plugins.php')."'>Plugins page</a>." ); 
  129.  
  130. $user_id = $current_user->ID; 
  131.  
  132. /** If user clicks to ignore the notice, add that to their user meta */ 
  133. $notices = array('ignore_pp_ssl', 'ignore_pp_sandbox', 'ignore_pp_woo', 'ignore_pp_check', 'ignore_pp_donate', 'ignore_paypal_plus_move_notice'); 
  134.  
  135. foreach ($notices as $notice) { 
  136. if ( isset($_GET[$notice]) && '0' == $_GET[$notice] ) { 
  137. add_user_meta($user_id, $notice, 'true', true); 
  138. $set_ignore_tag_url = remove_query_arg( $notice ); 
  139. wp_redirect($set_ignore_tag_url); 
  140.  
  141. function admin_notices() { 
  142. global $current_user, $pp_settings ; 
  143. $user_id = $current_user->ID; 
  144.  
  145. $pp_pro = get_option('woocommerce_paypal_pro_settings'); 
  146. $pp_payflow = get_option('woocommerce_paypal_pro_payflow_settings'); 
  147. $pp_standard = get_option('woocommerce_paypal_settings'); 
  148.  
  149. do_action( 'angelleye_admin_notices', $pp_pro, $pp_payflow, $pp_standard ); 
  150.  
  151. if (@$pp_pro['enabled']=='yes' || @$pp_payflow['enabled']=='yes') { 
  152. // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected 
  153. if ( get_option('woocommerce_force_ssl_checkout')=='no' && ! class_exists( 'WordPressHTTPS' ) && !get_user_meta($user_id, 'ignore_pp_ssl') ) 
  154. echo '<div class="error"><p>' . sprintf(__('WooCommerce PayPal Payments Pro requires that the %sForce secure checkout%s option is enabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - PayPal Pro will only work in test mode. | <a href=%s>%s</a>', 'paypal-for-woocommerce'), '<a href="'.admin_url('admin.php?page=woocommerce').'">', "</a>", '"'.esc_url(add_query_arg("ignore_pp_ssl", 0)).'"', __("Hide this notice", 'paypal-for-woocommerce')) . '</p></div>'; 
  155. if ((@$pp_pro['testmode']=='yes' || @$pp_payflow['testmode']=='yes' || @$pp_settings['testmode']=='yes') && !get_user_meta($user_id, 'ignore_pp_sandbox')) { 
  156. $testmodes = array(); 
  157. if (@$pp_pro['enabled']=='yes' && @$pp_pro['testmode']=='yes') $testmodes[] = 'PayPal Pro'; 
  158. if (@$pp_payflow['enabled']=='yes' && @$pp_payflow['testmode']=='yes') $testmodes[] = 'PayPal Pro PayFlow'; 
  159. if (@$pp_settings['enabled']=='yes' && @$pp_settings['testmode']=='yes') $testmodes[] = 'PayPal Express'; 
  160. $testmodes_str = implode(", ", $testmodes); 
  161. echo '<div class="error"><p>' . sprintf(__('WooCommerce PayPal Payments ( %s ) is currently running in Sandbox mode and will NOT process any actual payments. | <a href=%s>%s</a>', 'paypal-for-woocommerce'), $testmodes_str, '"'.esc_url(add_query_arg("ignore_pp_sandbox", 0)).'"', __("Hide this notice", 'paypal-for-woocommerce')) . '</p></div>'; 
  162. } elseif (@$pp_settings['enabled']=='yes') { 
  163. if (@$pp_settings['testmode']=='yes' && !get_user_meta($user_id, 'ignore_pp_sandbox')) { 
  164. echo '<div class="error"><p>' . sprintf(__('WooCommerce PayPal Express is currently running in Sandbox mode and will NOT process any actual payments. | <a href=%s>%s</a>', 'paypal-for-woocommerce'), '"'.esc_url(add_query_arg("ignore_pp_sandbox", 0)).'"', __("Hide this notice", 'paypal-for-woocommerce')) . '</p></div>'; 
  165. if(@$pp_settings['enabled']=='yes' && @$pp_standard['enabled']=='yes' && !get_user_meta($user_id, 'ignore_pp_check')) { 
  166. echo '<div class="error"><p>' . sprintf(__('You currently have both PayPal (standard) and Express Checkout enabled. It is recommended that you disable the standard PayPal from <a href="'.get_admin_url().'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_paypal">the settings page</a> when using Express Checkout. | <a href=%s>%s</a>', 'paypal-for-woocommerce'), '"'.esc_url(add_query_arg("ignore_pp_check", 0)).'"', __("Hide this notice", 'paypal-for-woocommerce')) . '</p></div>'; 
  167.  
  168. if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && !get_user_meta($user_id, 'ignore_pp_woo') && !is_plugin_active_for_network( 'woocommerce/woocommerce.php' )) { 
  169. echo '<div class="error"><p>' . sprintf( __("WooCommerce PayPal Payments requires WooCommerce plugin to work normally. Please activate it or install it from <a href='http://wordpress.org/plugins/woocommerce/' target='_blank'>here</a>. | <a href=%s>%s</a>", 'paypal-for-woocommerce'), '"'.esc_url(add_query_arg("ignore_pp_woo", 0)).'"', __("Hide this notice", 'paypal-for-woocommerce') ) . '</p></div>'; 
  170.  
  171. $screen = get_current_screen(); 
  172.  
  173. if( $screen->id == "settings_page_paypal-for-woocommerce" ) { 
  174. $processed = (isset($_GET['processed']) ) ? $_GET['processed'] : FALSE; 
  175. if($processed) { 
  176. echo '<div class="updated">'; 
  177. echo '<p>'. sprintf( __('Action completed; %s records processed. ', 'paypal-for-woocommerce'), ($processed == 'zero') ? 0 : $processed); 
  178. echo '</div>'; 
  179.  
  180. $this->angelleye_paypal_plus_notice($user_id); 
  181.  
  182. //init function 
  183. function init() { 
  184. global $pp_settings; 
  185. if (!class_exists("WC_Payment_Gateway")) return; 
  186. load_plugin_textdomain( 'paypal-for-woocommerce', FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' ); 
  187. add_filter( 'woocommerce_payment_gateways', array($this, 'angelleye_add_paypal_pro_gateway'), 1000 ); 
  188. //remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_paypal_express_checkout_button', 12 ); 
  189.  
  190.  
  191. if(AngellEYE_Utility::is_express_checkout_credentials_is_set()) { 
  192. if( isset($pp_settings['button_position']) && ($pp_settings['button_position'] == 'bottom' || $pp_settings['button_position'] == 'both')) { 
  193. add_action( 'woocommerce_proceed_to_checkout', array( 'WC_Gateway_PayPal_Express_AngellEYE', 'woocommerce_paypal_express_checkout_button_angelleye'), 22 ); 
  194.  
  195. add_action( 'woocommerce_before_cart', array( 'WC_Gateway_PayPal_Express_AngellEYE', 'woocommerce_before_cart'), 12 ); 
  196. remove_action( 'init', 'woocommerce_paypal_express_review_order_page') ; 
  197. remove_shortcode( 'woocommerce_review_order'); 
  198. add_shortcode( 'woocommerce_review_order', array($this, 'get_woocommerce_review_order_angelleye' )); 
  199.  
  200. require_once('classes/wc-gateway-paypal-pro-payflow-angelleye.php'); 
  201. require_once('classes/wc-gateway-paypal-pro-angelleye.php'); 
  202. require_once('classes/wc-gateway-braintree-angelleye.php'); 
  203. require_once('classes/wc-gateway-paypal-express-angelleye.php'); 
  204. require_once('classes/wc-gateway-paypal-advanced-angelleye.php'); 
  205.  
  206.  
  207. if (version_compare(phpversion(), '5.3.0', '>=')) { 
  208. require_once('classes/wc-gateway-paypal-credit-cards-rest-angelleye.php'); 
  209.  
  210. /** 
  211. * Admin Script 
  212. */ 
  213. function admin_scripts() 
  214. $dir = plugin_dir_path( __FILE__ ); 
  215. wp_enqueue_media(); 
  216. wp_enqueue_script( 'jquery'); 
  217. // Localize the script with new data 
  218. wp_register_script( 'angelleye_admin', plugins_url( '/assets/js/angelleye-admin.js' , __FILE__ ), array( 'jquery' )); 
  219. $translation_array = array( 
  220. 'is_ssl' => AngellEYE_Gateway_Paypal::is_ssl()? "yes":"no",  
  221. 'choose_image' => __('Choose Image', 'paypal-for-woocommerce'),  
  222. 'shop_based_us' => (substr(get_option("woocommerce_default_country"), 0, 2) == 'US')? "yes":"no" 
  223.  
  224. ); 
  225. wp_localize_script( 'angelleye_admin', 'angelleye_admin', $translation_array ); 
  226. wp_enqueue_script( 'angelleye_admin'); 
  227.  
  228. /** 
  229. * Admin Style 
  230. */ 
  231. function admin_styles() 
  232. wp_enqueue_style('thickbox'); 
  233.  
  234.  
  235. /** 
  236. * frontend_scripts function. 
  237. * @access public 
  238. * @return void 
  239. */ 
  240. function frontend_scripts() { 
  241. global $pp_settings; 
  242. wp_register_script( 'angelleye_frontend', plugins_url( '/assets/js/angelleye-frontend.js' , __FILE__ ), array( 'jquery' ), WC_VERSION, true ); 
  243. $translation_array = array( 
  244. 'is_product' => is_product()? "yes" : "no",  
  245. 'is_cart' => is_cart()? "yes":"no",  
  246. 'is_checkout' => is_checkout()? "yes":"no",  
  247. 'three_digits' => __('3 digits usually found on the signature strip.', 'paypal-for-woocommerce'),  
  248. 'four_digits' => __('4 digits usually found on the front of the card.', 'paypal-for-woocommerce') 
  249. ); 
  250. wp_localize_script( 'angelleye_frontend', 'angelleye_frontend', $translation_array ); 
  251. wp_enqueue_script('angelleye_frontend'); 
  252.  
  253. if ( ! is_admin() && is_cart()) { 
  254. wp_enqueue_style( 'ppe_cart', plugins_url( 'assets/css/cart.css' , __FILE__ ) ); 
  255.  
  256. if ( ! is_admin() && is_checkout() ) { 
  257. wp_enqueue_style( 'ppe_checkout', plugins_url( 'assets/css/checkout.css' , __FILE__ ) ); 
  258. if ( ! is_admin() && is_single() && @$pp_settings['enabled']=='yes' && @$pp_settings['show_on_product_page']=='yes') { 
  259. wp_enqueue_style( 'ppe_single', plugins_url( 'assets/css/single.css' , __FILE__ ) ); 
  260. wp_enqueue_script('angelleye_button'); 
  261.  
  262. if (is_page( wc_get_page_id( 'review_order' ) )) { 
  263. $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/'; 
  264. $frontend_script_path = $assets_path . 'js/frontend/'; 
  265. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  266. wp_enqueue_script( 'wc-checkout', plugins_url( '/assets/js/checkout.js' , __FILE__ ), array( 'jquery' ), WC_VERSION, true ); 
  267.  
  268. wp_localize_script( 'wc-checkout', 'wc_checkout_params', apply_filters( 'wc_checkout_params', array( 
  269. 'ajax_url' => WC()->ajax_url(),  
  270. 'update_order_review_nonce' => wp_create_nonce( "update-order-review" ),  
  271. 'apply_coupon_nonce' => wp_create_nonce( "apply-coupon" ),  
  272. 'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),  
  273. 'checkout_url' => esc_url(add_query_arg( 'action', 'woocommerce_checkout', WC()->ajax_url() )),  
  274. 'is_checkout' => 1 
  275. ) ) ); 
  276.  
  277.  
  278. /** 
  279. * Run when plugin is activated 
  280. */ 
  281. function activate_paypal_for_woocommerce() 
  282. // If WooCommerce is not enabled, deactivate plugin. 
  283. if(!in_array( 'woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))) && !is_plugin_active_for_network( 'woocommerce/woocommerce.php' )) 
  284. deactivate_plugins(plugin_basename(__FILE__)); 
  285. else 
  286. global $woocommerce; 
  287.  
  288. // Create review page for Express Checkout 
  289. wc_create_page(esc_sql(_x('review-order', 'page_slug', 'paypal-for-woocommerce')), 'woocommerce_review_order_page_id', __('Checkout → Review Order', 'paypal-for-woocommerce'), '[woocommerce_review_order]', wc_get_page_id('checkout')); 
  290.  
  291. // Log activation in Angell EYE database via web service. 
  292. // @todo Need to turn this into an option people can enable by request. 
  293. //$log_url = $_SERVER['HTTP_HOST']; 
  294. //$log_plugin_id = 1; 
  295. //$log_activation_status = 1; 
  296. //wp_remote_request('http://www.angelleye.com/web-services/wordpress/update-plugin-status.php?url='.$log_url.'&plugin_id='.$log_plugin_id.'&activation_status='.$log_activation_status); 
  297.  
  298. /** 
  299. * Run when plugin is deactivated. 
  300. */ 
  301. function deactivate_paypal_for_woocommerce() 
  302. // Log activation in Angell EYE database via web service. 
  303. // @todo Need to turn this into an option people can enable. 
  304. //$log_url = $_SERVER['HTTP_HOST']; 
  305. //$log_plugin_id = 1; 
  306. //$log_activation_status = 0; 
  307. //wp_remote_request('http://www.angelleye.com/web-services/wordpress/update-plugin-status.php?url='.$log_url.'&plugin_id='.$log_plugin_id.'&activation_status='.$log_activation_status); 
  308.  
  309. /** 
  310. * Adds PayPal gateway options for Payments Pro and Express Checkout into the WooCommerce checkout settings. 
  311. */ 
  312. function angelleye_add_paypal_pro_gateway( $methods ) { 
  313. foreach ($methods as $key=>$method) { 
  314. if (in_array($method, array('WC_Gateway_PayPal_Pro', 'WC_Gateway_PayPal_Pro_Payflow', 'WC_Gateway_PayPal_Express'))) { 
  315. unset($methods[$key]); 
  316. break; 
  317. $methods[] = 'WC_Gateway_PayPal_Pro_AngellEYE'; 
  318. $methods[] = 'WC_Gateway_PayPal_Pro_Payflow_AngellEYE'; 
  319. $methods[] = 'WC_Gateway_PayPal_Express_AngellEYE'; 
  320. $methods[] = 'WC_Gateway_Braintree_AngellEYE'; 
  321. $methods[] = 'WC_Gateway_PayPal_Advanced_AngellEYE'; 
  322. if (version_compare(phpversion(), '5.3.0', '>=')) { 
  323. $methods[] = 'WC_Gateway_PayPal_Credit_Card_Rest_AngellEYE'; 
  324.  
  325.  
  326. return $methods; 
  327.  
  328. /** 
  329. * Add additional parameters to the PayPal Standard checkout built into WooCommerce. 
  330. */ 
  331. public function ae_paypal_standard_additional_parameters($paypal_args) 
  332. $paypal_args['bn'] = 'AngellEYE_SP_WooCommerce'; 
  333. return $paypal_args; 
  334.  
  335. /** 
  336. * Add the gateway to woocommerce 
  337. */ 
  338. function get_woocommerce_review_order_angelleye( $atts ) { 
  339. global $woocommerce; 
  340. return WC_Shortcodes::shortcode_wrapper(array($this, 'woocommerce_review_order_angelleye'), $atts); 
  341. /** 
  342. * Outputs the pay page - payment gateways can hook in here to show payment forms etc 
  343. **/ 
  344. function woocommerce_review_order_angelleye() { 
  345.  
  346. echo " 
  347. <script> 
  348. jQuery(document).ready(function($) { 
  349. // Inputs/selects which update totals instantly 
  350. $('form.checkout').unbind( 'submit' ); 
  351. }); 
  352. </script> 
  353. "; 
  354. //echo '<form class="checkout" method="POST" action="' . add_query_arg( 'pp_action', 'payaction', add_query_arg( 'wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url( '/' ) ) ) . '">'; 
  355. $template = plugin_dir_path( __FILE__ ) . 'template/'; 
  356.  
  357. //Allow override in theme: <theme_name>/woocommerce/paypal-paypal-review-order.php 
  358. wc_get_template('paypal-review-order.php', array(), '', $template); 
  359.  
  360. do_action( 'woocommerce_ppe_checkout_order_review' ); 
  361. //echo '<p><a class="button cancel" href="' . $woocommerce->cart->get_cart_url() . '">'.__('Cancel order', 'paypal-for-woocommerce').'</a> '; 
  362. //echo '<input type="submit" class="button" value="' . __( 'Place Order', 'paypal-for-woocommerce') . '" /></p>'; 
  363. //echo '</form>'; 
  364.  
  365. /** 
  366. * Review page for PayPal Express Checkout 
  367. */ 
  368. function woocommerce_paypal_express_review_order_page_angelleye() { 
  369. if ( ! empty( $_GET['pp_action'] ) && ($_GET['pp_action'] == 'revieworder' || $_GET['pp_action'] == 'payaction') ) { 
  370. $woocommerce_ppe = new WC_Gateway_PayPal_Express_AngellEYE(); 
  371. $woocommerce_ppe->paypal_express_checkout(); 
  372.  
  373. /** 
  374. * Display Paypal Express Checkout on product page 
  375. */ 
  376. function buy_now_button() { 
  377. global $pp_settings, $post, $product; 
  378. if(!AngellEYE_Utility::is_valid_for_use()) { 
  379. return false; 
  380. if(!AngellEYE_Utility::is_express_checkout_credentials_is_set()) { 
  381. return false; 
  382. if (@$pp_settings['enabled']=='yes' && @$pp_settings['show_on_product_page']=='yes') 
  383. ?> 
  384. <div class="angelleye_button_single"> 
  385. <?php 
  386. $_product = wc_get_product($post->ID); 
  387. $button_dynamic_class = 'single_variation_wrap_angelleye_' . $product->id; 
  388. $hide = ''; 
  389. if($_product->product_type == 'variation' || 
  390. $_product->is_type('external') || 
  391. $_product->get_price() == 0 || 
  392. $_product->get_price() == '') 
  393. $hide = 'display:none;'; 
  394. $add_to_cart_action = esc_url(add_query_arg( 'express_checkout', '1')); 
  395. if (empty($pp_settings['checkout_with_pp_button_type'])) $pp_settings['checkout_with_pp_button_type']='paypalimage'; 
  396. switch($pp_settings['checkout_with_pp_button_type']) 
  397. case "textbutton": 
  398. if(!empty($pp_settings['pp_button_type_text_button'])) { 
  399. $button_text = $pp_settings['pp_button_type_text_button']; 
  400. } else { 
  401. $button_text = __( 'Proceed to Checkout', 'paypal-for-woocommerce' ); 
  402. echo '<input data-action="'.$add_to_cart_action.'" type="button" style="float: left; clear: both; margin: 3px 0 0 0; border: none;', $hide, '" class="single_add_to_cart_button single_variation_wrap_angelleye paypal_checkout_button button alt '.$button_dynamic_class.'" name="express_checkout" value="' .$button_text .'"/>'; 
  403. break; 
  404. case "paypalimage": 
  405. $button_img = "https://www.paypal.com/".WC_Gateway_PayPal_Express_AngellEYE::get_button_locale_code()."/i/btn/btn_xpressCheckout.gif"; 
  406. echo '<input data-action="'.$add_to_cart_action.'" type="image" src="', $button_img, '" style="width: 145px; height: 42px; float: left; clear: both; margin: 3px 0 0 0; border: none; padding: 0;', $hide, '" class="single_add_to_cart_button single_variation_wrap_angelleye '.$button_dynamic_class.'" name="express_checkout" value="' . __('Pay with PayPal', 'paypal-for-woocommerce') .'"/>'; 
  407. break; 
  408. case "customimage": 
  409. $add_to_cart_action = esc_url(add_query_arg( 'express_checkout', '1')); 
  410. $button_img = $pp_settings['pp_button_type_my_custom']; 
  411. echo '<input data-action="'.$add_to_cart_action.'" type="image" src="', $button_img, '" style="float: left; clear: both; margin: 3px 0 0 0; border: none; padding: 0;', $hide, '" class="single_add_to_cart_button single_variation_wrap_angelleye '.$button_dynamic_class.'" name="express_checkout" value="' . __('Pay with PayPal', 'paypal-for-woocommerce') .'"/>'; 
  412. break; 
  413. ?> 
  414. </div> 
  415. <?php 
  416.  
  417. /** 
  418. * Redirect to PayPal from the product page EC button 
  419. * @param $url 
  420. * @return string 
  421. */ 
  422. function add_to_cart_redirect($url) { 
  423. if (isset($_REQUEST['express_checkout'])||isset($_REQUEST['express_checkout_x'])) { 
  424. wc_clear_notices(); 
  425. $url = esc_url_raw(add_query_arg( 'pp_action', 'expresscheckout', add_query_arg( 'wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url( '/' ) ) )) ; 
  426. return $url; 
  427.  
  428. /** 
  429. * Donate function 
  430. */ 
  431. function donate_message() { 
  432. if (@$_GET['page']=='wc-settings' && @$_GET['tab']=='checkout' && in_array( @$_GET['section'], array('wc_gateway_paypal_express_angelleye', 'wc_gateway_paypal_pro_angelleye', 'wc_gateway_paypal_pro_payflow_angelleye')) && !get_user_meta(get_current_user_id(), 'ignore_pp_donate') ) { 
  433. ?> 
  434. <div class="updated welcome-panel notice" id="paypal-for-woocommerce-donation"> 
  435. <div style="float:left; margin: 19px 16px 19px 0;" id="plugin-icon-paypal-for-woocommerce" ></div> 
  436. <h3>PayPal for WooCommerce</h3> 
  437. <p class="donation_text">We are learning why it is difficult to provide, support, and maintain free software. Every little bit helps and is greatly appreciated.</p> 
  438. <p>Developers, join us on <a href="https://github.com/angelleye/paypal-woocommerce" target="_blank">GitHub</a>. Pull Requests are welcomed!</p> 
  439. <a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SG9SQU2GBXJNA"><img style="float:left;margin-right:10px;" src="https://www.angelleye.com/images/paypal-for-woocommerce/donate-button.png" border="0" alt="PayPal - The safer, easier way to pay online!"></a> 
  440. <a class="welcome-panel-close" href="<?php echo esc_url( add_query_arg( array( 'ignore_pp_donate' => '0' ) ) ); ?>"><?php _e( 'Dismiss' ); ?></a> 
  441. <div style="clear:both"></div> 
  442. </div> 
  443. <?php 
  444. function mini_cart_button() { 
  445. global $pp_settings, $pp_pro, $pp_payflow; 
  446. if(!AngellEYE_Utility::is_valid_for_use()) { 
  447. return false; 
  448. if(!AngellEYE_Utility::is_express_checkout_credentials_is_set()) { 
  449. return false; 
  450. if( @$pp_settings['enabled']=='yes' && (empty($pp_settings['show_on_cart']) || $pp_settings['show_on_cart']=='yes') && WC()->cart->cart_contents_count > 0) { 
  451. echo '<div class="paypal_box_button">'; 
  452. if (empty($pp_settings['checkout_with_pp_button_type'])) $pp_settings['checkout_with_pp_button_type'] = 'paypalimage'; 
  453.  
  454. $_angelleyeOverlay = '<div class="blockUI blockOverlay angelleyeOverlay" style="display:none;z-index: 1000; border: none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; opacity: 0.6; cursor: default; position: absolute; background: url('. WC()->plugin_url() .'/assets/images/select2-spinner.gif) 50% 50% / 16px 16px no-repeat rgb(255, 255, 255);"></div>'; 
  455.  
  456. switch ($pp_settings['checkout_with_pp_button_type']) { 
  457. case "textbutton": 
  458. if (!empty($pp_settings['pp_button_type_text_button'])) { 
  459. $button_text = $pp_settings['pp_button_type_text_button']; 
  460. } else { 
  461. $button_text = __('Proceed to Checkout', 'paypal-for-woocommerce'); 
  462. echo '<div class="paypal_ec_textbutton">'; 
  463. echo '<a class="paypal_checkout_button button alt" href="' . esc_url(add_query_arg('pp_action', 'expresscheckout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))) . '">' . $button_text . '</a>'; 
  464. echo $_angelleyeOverlay; 
  465. echo '</div>'; 
  466. break; 
  467. case "paypalimage": 
  468. echo '<div id="paypal_ec_button">'; 
  469. echo '<a class="paypal_checkout_button" href="' . esc_url(add_query_arg('pp_action', 'expresscheckout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))) . '">'; 
  470. echo "<img src='https://www.paypal.com/" . WC_Gateway_PayPal_Express_AngellEYE::get_button_locale_code() . "/i/btn/btn_xpressCheckout.gif' border='0' alt='" . __('Pay with PayPal', 'paypal-for-woocommerce') . "'/>"; 
  471. echo "</a>"; 
  472. echo $_angelleyeOverlay; 
  473. echo '</div>'; 
  474. break; 
  475. case "customimage": 
  476. $button_img = $pp_settings['pp_button_type_my_custom']; 
  477. echo '<div id="paypal_ec_button">'; 
  478. echo '<a class="paypal_checkout_button" href="' . esc_url(add_query_arg('pp_action', 'expresscheckout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))) . '">'; 
  479. echo "<img src='{$button_img}' width='150' border='0' alt='" . __('Pay with PayPal', 'paypal-for-woocommerce') . "'/>"; 
  480. echo "</a>"; 
  481. echo $_angelleyeOverlay; 
  482. echo '</div>'; 
  483. break; 
  484.  
  485. /** 
  486. * Displays the PayPal Credit checkout button if enabled in EC settings. 
  487. */ 
  488. if (isset($pp_settings['show_paypal_credit']) && $pp_settings['show_paypal_credit'] == 'yes') { 
  489. // PayPal Credit button 
  490. $paypal_credit_button_markup = '<div id="paypal_ec_paypal_credit_button">'; 
  491. $paypal_credit_button_markup .= '<a class="paypal_checkout_button" href="' . esc_url(add_query_arg('use_paypal_credit', 'true', add_query_arg('pp_action', 'expresscheckout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/'))))) . '" >'; 
  492. $paypal_credit_button_markup .= "<img src='https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-small.png' alt='Check out with PayPal Credit'/>"; 
  493. $paypal_credit_button_markup .= '</a>'; 
  494. $paypal_credit_button_markup .= $_angelleyeOverlay; 
  495. $paypal_credit_button_markup .= '</div>'; 
  496.  
  497. echo $paypal_credit_button_markup; 
  498. ?> 
  499. <!--<div class="blockUI blockOverlay angelleyeOverlay" style="display:none;z-index: 1000; border: none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; opacity: 0.6; cursor: default; position: absolute; background: url(<?php /**echo WC()->plugin_url(); */?>/assets/images/select2-spinner.gif) 50% 50% / 16px 16px no-repeat rgb(255, 255, 255);"></div>--> 
  500. <script type="text/javascript"> 
  501. jQuery(document).ready(function($) { 
  502. $(".paypal_checkout_button").click(function() { 
  503. $(this).parent().find(".angelleyeOverlay").show(); 
  504. return true; 
  505. }); 
  506. }); 
  507. </script> 
  508. <?php 
  509. echo "<div class='clear'></div></div>"; 
  510. function add_div_before_add_to_cart_button() { 
  511. ?> 
  512. <div class="angelleye_buton_box_relative" style="position: relative;"> 
  513. <?php 
  514. function add_div_after_add_to_cart_button() { 
  515. ?> 
  516. <div class="blockUI blockOverlay angelleyeOverlay" style="display:none;z-index: 1000; border: none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; opacity: 0.6; cursor: default; position: absolute; background: url(<?php echo WC()->plugin_url(); ?>/assets/images/select2-spinner.gif) 50% 50% / 16px 16px no-repeat rgb(255, 255, 255);"></div> 
  517. </div> 
  518. <?php 
  519.  
  520. public function angelleye_check_version() { 
  521.  
  522. $paypal_for_woocommerce_version = get_option('paypal_for_woocommerce_version'); 
  523. if( empty($paypal_for_woocommerce_version) ) { 
  524.  
  525. // PayFlow 
  526. $woocommerce_paypal_pro_payflow_settings = get_option('woocommerce_paypal_pro_payflow_settings'); 
  527. if( isset($woocommerce_paypal_pro_payflow_settings) && !empty($woocommerce_paypal_pro_payflow_settings)) { 
  528.  
  529. if( !isset($woocommerce_paypal_pro_payflow_settings['payment_action']) && empty($woocommerce_paypal_pro_payflow_settings['payment_action'])) { 
  530. $woocommerce_paypal_pro_payflow_settings['payment_action'] = 'Sale'; 
  531.  
  532. if( !isset($woocommerce_paypal_pro_payflow_settings['send_items']) && empty($woocommerce_paypal_pro_payflow_settings['send_items']) ) { 
  533. $woocommerce_paypal_pro_payflow_settings['send_items'] = 'yes'; 
  534.  
  535. update_option('woocommerce_paypal_pro_payflow_settings', $woocommerce_paypal_pro_payflow_settings); 
  536.  
  537. // DoDirectPayment 
  538. $woocommerce_paypal_pro_settings = get_option('woocommerce_paypal_pro_settings'); 
  539. if( isset($woocommerce_paypal_pro_settings) && !empty($woocommerce_paypal_pro_settings)) { 
  540.  
  541. if( !isset($woocommerce_paypal_pro_settings['payment_action']) && empty($woocommerce_paypal_pro_settings['payment_action']) ) { 
  542. $woocommerce_paypal_pro_settings['payment_action'] = 'Sale'; 
  543.  
  544. if( !isset($woocommerce_paypal_pro_settings['send_items']) && empty($woocommerce_paypal_pro_settings['send_items']) ) { 
  545. $woocommerce_paypal_pro_settings['send_items'] = 'yes'; 
  546.  
  547. update_option('woocommerce_paypal_pro_settings', $woocommerce_paypal_pro_settings); 
  548.  
  549. // PayPal Express Checkout 
  550. $woocommerce_paypal_express_settings = get_option('woocommerce_paypal_express_settings'); 
  551. if( isset($woocommerce_paypal_express_settings) && !empty($woocommerce_paypal_express_settings)) { 
  552.  
  553. if( !isset($woocommerce_paypal_express_settings['payment_action']) && empty($woocommerce_paypal_express_settings['payment_action'])) { 
  554. $woocommerce_paypal_express_settings['payment_action'] = 'Sale'; 
  555.  
  556. if( !isset($woocommerce_paypal_express_settings['cancel_page']) && empty($woocommerce_paypal_express_settings['cancel_page'])) { 
  557. $woocommerce_paypal_express_settings['cancel_page'] = get_option('woocommerce_cart_page_id'); 
  558.  
  559. if( !isset($woocommerce_paypal_express_settings['send_items']) && empty($woocommerce_paypal_express_settings['send_items'])) { 
  560. $woocommerce_paypal_express_settings['send_items'] = 'yes'; 
  561.  
  562. if( !isset($woocommerce_paypal_express_settings['billing_address']) && empty($woocommerce_paypal_express_settings['billing_address'])) { 
  563. $woocommerce_paypal_express_settings['billing_address'] = 'no'; 
  564.  
  565. if( !isset($woocommerce_paypal_express_settings['button_position']) && empty($woocommerce_paypal_express_settings['button_position'])) { 
  566. $woocommerce_paypal_express_settings['button_position'] = 'bottom'; 
  567.  
  568. update_option('woocommerce_paypal_express_settings', $woocommerce_paypal_express_settings); 
  569. update_option('paypal_for_woocommerce_version', self::VERSION_PFW); 
  570.  
  571.  
  572. public static function calculate($order, $send_items = false) { 
  573.  
  574. $PaymentOrderItems = array(); 
  575. $ctr = $giftwrapamount = $total_items = $total_discount = $total_tax = $shipping = 0; 
  576. $ITEMAMT = 0; 
  577. if ($order) { 
  578. $order_total = $order->get_total(); 
  579. $items = $order->get_items(); 
  580. /** 
  581. * Set shipping and tax values. 
  582. */ 
  583. if (get_option('woocommerce_prices_include_tax') == 'yes') { 
  584. $shipping = $order->get_total_shipping() + $order->get_shipping_tax(); 
  585. $tax = 0; 
  586. } else { 
  587. $shipping = $order->get_total_shipping(); 
  588. $tax = $order->get_total_tax(); 
  589.  
  590. if('yes' === get_option( 'woocommerce_calc_taxes' ) && 'yes' === get_option( 'woocommerce_prices_include_tax' )) { 
  591. $tax = $order->get_total_tax(); 
  592. else { 
  593. //if empty order we get data from cart 
  594. $order_total = WC()->cart->total; 
  595. $items = WC()->cart->get_cart(); 
  596. /** 
  597. * Get shipping and tax. 
  598. */ 
  599. if(get_option('woocommerce_prices_include_tax' ) == 'yes') 
  600. $shipping = WC()->cart->shipping_total + WC()->cart->shipping_tax_total; 
  601. $tax = 0; 
  602. else 
  603. $shipping = WC()->cart->shipping_total; 
  604. $tax = WC()->cart->get_taxes_total(); 
  605.  
  606. if('yes' === get_option( 'woocommerce_calc_taxes' ) && 'yes' === get_option( 'woocommerce_prices_include_tax' )) { 
  607. $tax = WC()->cart->get_taxes_total(); 
  608.  
  609. if ($send_items) { 
  610. foreach ($items as $item) { 
  611. /** 
  612. * Get product data from WooCommerce 
  613. */ 
  614. if ($order) { 
  615. $_product = $order->get_product_from_item($item); 
  616. $qty = absint($item['qty']); 
  617. $item_meta = new WC_Order_Item_Meta($item, $_product); 
  618. $meta = $item_meta->display(true, true); 
  619. } else { 
  620. $_product = $item['data']; 
  621. $qty = absint($item['quantity']); 
  622. $meta = WC()->cart->get_item_data($item, true); 
  623.  
  624. $sku = $_product->get_sku(); 
  625. $item['name'] = html_entity_decode($_product->get_title(), ENT_NOQUOTES, 'UTF-8'); 
  626. if ($_product->product_type == 'variation') { 
  627. if (empty($sku)) { 
  628. $sku = $_product->parent->get_sku(); 
  629.  
  630. if (!empty($meta)) { 
  631. $item['name'] .= " - " . str_replace(", \n", " - ", $meta); 
  632.  
  633. $Item = array( 
  634. 'name' => $item['name'], // Item name. 127 char max. 
  635. 'desc' => '', // Item description. 127 char max. 
  636. 'amt' => self::number_format(self::round( $item['line_subtotal'] / $qty)), // Cost of item. 
  637. 'number' => $sku, // Item number. 127 char max. 
  638. 'qty' => $qty, // Item qty on order. Any positive integer. 
  639. ); 
  640. array_push($PaymentOrderItems, $Item); 
  641. $ITEMAMT += self::round( $item['line_subtotal'] / $qty ) * $qty; 
  642.  
  643. /** 
  644. * Add custom Woo cart fees as line items 
  645. */ 
  646. foreach (WC()->cart->get_fees() as $fee) { 
  647. $Item = array( 
  648. 'name' => $fee->name, // Item name. 127 char max. 
  649. 'desc' => '', // Item description. 127 char max. 
  650. 'amt' => self::number_format($fee->amount, 2, '.', ''), // Cost of item. 
  651. 'number' => $fee->id, // Item number. 127 char max. 
  652. 'qty' => 1, // Item qty on order. Any positive integer. 
  653. ); 
  654.  
  655. /** 
  656. * The gift wrap amount actually has its own parameter in 
  657. * DECP, so we don't want to include it as one of the line 
  658. * items. 
  659. */ 
  660. if ($Item['number'] != 'gift-wrap') { 
  661. array_push($PaymentOrderItems, $Item); 
  662. $ITEMAMT += self::round($fee->amount); 
  663. } else { 
  664. $giftwrapamount = self::round($fee->amount); 
  665.  
  666. $ctr++; 
  667.  
  668. //caculate discount 
  669. if ($order) { 
  670. if (!AngellEYE_Gateway_Paypal::is_wc_version_greater_2_3()) { 
  671. if ($order->get_cart_discount() > 0) { 
  672. foreach (WC()->cart->get_coupons('cart') as $code => $coupon) { 
  673. $Item = array( 
  674. 'name' => 'Cart Discount',  
  675. 'number' => $code,  
  676. 'qty' => '1',  
  677. 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]) 
  678. ); 
  679. array_push($PaymentOrderItems, $Item); 
  680. $total_discount -= $order->get_cart_discount(); 
  681.  
  682. if ($order->get_order_discount() > 0) { 
  683. foreach (WC()->cart->get_coupons('order') as $code => $coupon) { 
  684. $Item = array( 
  685. 'name' => 'Order Discount',  
  686. 'number' => $code,  
  687. 'qty' => '1',  
  688. 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]) 
  689. ); 
  690. array_push($PaymentOrderItems, $Item); 
  691. $total_discount -= $order->get_order_discount(); 
  692. } else { 
  693. if ($order->get_total_discount() > 0) { 
  694. $Item = array( 
  695. 'name' => 'Total Discount',  
  696. 'qty' => 1,  
  697. 'amt' => - self::number_format($order->get_total_discount()),  
  698. 'number' => implode(", ", $order->get_used_coupons()) 
  699. ); 
  700. array_push($PaymentOrderItems, $Item); 
  701. $total_discount -= $order->get_total_discount(); 
  702. } else { 
  703. if ( !empty( WC()->cart->applied_coupons ) ) { 
  704. foreach (WC()->cart->get_coupons('cart') as $code => $coupon) { 
  705. $Item = array( 
  706. 'name' => 'Cart Discount',  
  707. 'qty' => '1',  
  708. 'number'=> $code,  
  709. 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]) 
  710. ); 
  711. array_push($PaymentOrderItems, $Item); 
  712. $total_discount -= self::number_format(WC()->cart->coupon_discount_amounts[$code]); 
  713.  
  714.  
  715. if (!AngellEYE_Gateway_Paypal::is_wc_version_greater_2_3()) { 
  716. if ( !empty( WC()->cart->applied_coupons ) ) { 
  717. foreach (WC()->cart->get_coupons('order') as $code => $coupon) { 
  718. $Item = array( 
  719. 'name' => 'Order Discount',  
  720. 'qty' => '1',  
  721. 'number'=> $code,  
  722. 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]) 
  723. ); 
  724. array_push($PaymentOrderItems, $Item); 
  725. $total_discount -= self::number_format(WC()->cart->coupon_discount_amounts[$code]); 
  726.  
  727.  
  728.  
  729.  
  730. if( $tax > 0) { 
  731. $tax = self::number_format($tax); 
  732.  
  733. if( $shipping > 0) { 
  734. $shipping = self::number_format($shipping); 
  735.  
  736. if( $total_discount ) { 
  737. $total_discount = self::round($total_discount); 
  738.  
  739. if (empty($ITEMAMT)) { 
  740. $cart_fees = WC()->cart->get_fees(); 
  741. if( isset($cart_fees[0]->id) && $cart_fees[0]->id == 'gift-wrap' ) { 
  742. $giftwrapamount = isset($cart_fees[0]->amount) ? $cart_fees[0]->amount : 0; 
  743. } else { 
  744. $giftwrapamount = 0; 
  745. $Payment['itemamt'] = $order_total - $tax - $shipping - $giftwrapamount; 
  746. } else { 
  747. $Payment['itemamt'] = self::number_format($ITEMAMT + $total_discount); 
  748.  
  749.  
  750. /** 
  751. * Set tax 
  752. */ 
  753. if ($tax > 0) { 
  754. $Payment['taxamt'] = self::number_format($tax); // Required if you specify itemized L_TAXAMT fields. Sum of all tax items in this order. 
  755. } else { 
  756. $Payment['taxamt'] = 0; 
  757.  
  758. /** 
  759. * Set shipping 
  760. */ 
  761. if ($shipping > 0) { 
  762. $Payment['shippingamt'] = self::number_format($shipping); // Total shipping costs for this order. If you specify SHIPPINGAMT you mut also specify a value for ITEMAMT. 
  763. } else { 
  764. $Payment['shippingamt'] = 0; 
  765.  
  766. $Payment['order_items'] = $PaymentOrderItems; 
  767.  
  768. // Rounding amendment 
  769. if (trim(self::number_format($order_total)) !== trim(self::number_format($Payment['itemamt'] + $giftwrapamount + $tax + $shipping))) { 
  770. $diffrence_amount = AngellEYE_Gateway_Paypal::get_diffrent($order_total, $Payment['itemamt'] + $tax + $shipping); 
  771. if($shipping > 0) { 
  772. $Payment['shippingamt'] = abs(self::number_format($shipping + $diffrence_amount)); 
  773. } elseif ($tax > 0) { 
  774. $Payment['taxamt'] = abs(self::number_format($tax + $diffrence_amount)); 
  775. } else { 
  776. //make change to itemamt 
  777. $Payment['itemamt'] = abs(self::number_format($Payment['itemamt'] + $diffrence_amount)); 
  778. //also make change to the first item 
  779. if ($send_items) { 
  780. $Payment['order_items'][0]['amt'] = abs(self::number_format($Payment['order_items'][0]['amt'] + $diffrence_amount / $Payment['order_items'][0]['qty'])); 
  781.  
  782.  
  783. return $Payment; 
  784.  
  785. public static function get_diffrent($amout_1, $amount_2) { 
  786. $diff_amount = $amout_1 - $amount_2; 
  787. return $diff_amount; 
  788. public static function cut_off($number) { 
  789. $parts = explode(".", $number); 
  790. $newnumber = $parts[0] . "." . $parts[1][0] . $parts[1][1]; 
  791. return $newnumber; 
  792.  
  793. public static function is_wc_version_greater_2_3() { 
  794. return AngellEYE_Gateway_Paypal::get_wc_version() && version_compare(AngellEYE_Gateway_Paypal::get_wc_version(), '2.3', '>='); 
  795.  
  796. public static function get_wc_version() { 
  797. return defined('WC_VERSION') && WC_VERSION ? WC_VERSION : null; 
  798.  
  799. /** 
  800. * Check if site is SSL ready 
  801. */ 
  802. static public function is_ssl() 
  803. if (is_ssl() || get_option('woocommerce_force_ssl_checkout') == 'yes' || class_exists('WordPressHTTPS')) 
  804. return true; 
  805. return false; 
  806.  
  807. public function angelleye_admin_menu_own() { 
  808. $this->plugin_screen_hook_suffix = add_submenu_page( 
  809. 'options-general.php',  
  810. __( 'PayPal for WooCommerce - Settings', 'paypal-for-woocommerce' ),  
  811. __( 'PayPal for WooCommerce', 'paypal-for-woocommerce' ),  
  812. 'manage_options',  
  813. 'paypal-for-woocommerce',  
  814. array( $this, 'display_plugin_admin_page'));  
  815.  
  816. public function display_plugin_admin_page() { 
  817. // WooCommerce product categories 
  818. $taxonomy = 'product_cat'; 
  819. $orderby = 'name'; 
  820. $show_count = 0; // 1 for yes, 0 for no 
  821. $pad_counts = 0; // 1 for yes, 0 for no 
  822. $hierarchical = 1; // 1 for yes, 0 for no 
  823. $title = ''; 
  824. $empty = 0; 
  825.  
  826. $args = array( 
  827. 'taxonomy' => $taxonomy,  
  828. 'orderby' => $orderby,  
  829. 'show_count' => $show_count,  
  830. 'pad_counts' => $pad_counts,  
  831. 'hierarchical' => $hierarchical,  
  832. 'title_li' => $title,  
  833. 'hide_empty' => $empty 
  834. ); 
  835.  
  836. $product_cats = get_categories( $args ); 
  837. include_once( 'template/admin.php' ); 
  838.  
  839. static public function curPageURL() { 
  840. $pageURL = 'http'; 
  841. if (@$_SERVER["HTTPS"] == "on") {$pageURL .= "s";} 
  842. $pageURL .= "://"; 
  843. if ($_SERVER["SERVER_PORT"] != "80") { 
  844. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; 
  845. } else { 
  846. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; 
  847. return $pageURL; 
  848.  
  849. public function angelleye_woocommerce_add_to_cart_redirect($url) { 
  850. if (isset($_REQUEST['express_checkout']) && $_REQUEST['express_checkout'] == '1') { 
  851. return add_query_arg('pp_action', 'expresscheckout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/'))); 
  852. } else { 
  853. return $url; 
  854.  
  855. /** 
  856. * Billing Agreement Adjustments #382  
  857. */ 
  858. public static function angelleye_paypal_for_woocommerce_paypal_billing_agreement($PayPalRequestData) { 
  859. if (sizeof(WC()->cart->get_cart()) != 0) { 
  860. foreach (WC()->cart->get_cart() as $key => $value) { 
  861. $_product = $value['data']; 
  862. if (isset($_product->id) && !empty($_product->id) ) { 
  863. $_paypal_billing_agreement = get_post_meta($_product->id, '_paypal_billing_agreement', true); 
  864. if( $_paypal_billing_agreement == 'yes' ) { 
  865. $BillingAgreements = array(); 
  866. $Item = array( 
  867. 'l_billingtype' => '', // Required. Type of billing agreement. For recurring payments it must be RecurringPayments. You can specify up to ten billing agreements. For reference transactions, this field must be either: MerchantInitiatedBilling, or MerchantInitiatedBillingSingleSource 
  868. 'l_billingtype' => 'MerchantInitiatedBilling', // Required. Type of billing agreement. For recurring payments it must be RecurringPayments. You can specify up to ten billing agreements. For reference transactions, this field must be either: MerchantInitiatedBilling, or MerchantInitiatedBillingSingleSource 
  869. 'l_billingagreementdescription' => '', // Required for recurring payments. Description of goods or services associated with the billing agreement. 
  870. 'l_paymenttype' => '', // Specifies the type of PayPal payment you require for the billing agreement. Any or IntantOnly 
  871. 'l_paymenttype' => 'Any', // Specifies the type of PayPal payment you require for the billing agreement. Any or IntantOnly 
  872. 'l_billingagreementcustom' => '' // Custom annotation field for your own use. 256 char max. 
  873. ); 
  874. array_push($BillingAgreements, $Item); 
  875. $PayPalRequestData['BillingAgreements'] = $BillingAgreements; 
  876. }  
  877. }  
  878. return $PayPalRequestData; 
  879.  
  880.  
  881. /** 
  882. * Express Checkout - Digital / Virtual Goods - NOSHIPPING #174  
  883. */ 
  884. public static function angelleye_paypal_for_woocommerce_needs_shipping($SECFields) { 
  885. if (sizeof(WC()->cart->get_cart()) != 0) { 
  886. foreach (WC()->cart->get_cart() as $key => $value) { 
  887. $_product = $value['data']; 
  888. if (isset($_product->id) && !empty($_product->id) ) { 
  889. $_no_shipping_required = get_post_meta($_product->id, '_no_shipping_required', true); 
  890. if( $_no_shipping_required == 'yes' ) { 
  891. $SECFields['noshipping'] = 1; 
  892. } else { 
  893. $SECFields['noshipping'] = 0; 
  894. return $SECFields; 
  895. } else { 
  896. $SECFields['noshipping'] = 0; 
  897. return $SECFields; 
  898.  
  899.  
  900. function angelleye_product_type_options_own($product_type) { 
  901. if( isset($product_type) && !empty($product_type) ) { 
  902. $product_type['no_shipping_required'] = array( 
  903. 'id' => '_no_shipping_required',  
  904. 'wrapper_class' => '',  
  905. 'label' => __( 'No Shipping Required', 'paypal-for-woocommerce' ),  
  906. 'description' => __( 'Disables shipping requirements in the PayPal checkout flow.', 'paypal-for-woocommerce' ),  
  907. 'default' => 'no' 
  908. ); 
  909. $product_type['paypal_billing_agreement'] = array( 
  910. 'id' => '_paypal_billing_agreement',  
  911. 'wrapper_class' => '',  
  912. 'label' => __( 'Enable PayPal Billing Agreement', 'paypal-for-woocommerce' ),  
  913. 'description' => __( 'Adds a billing agreement to the product. The user must agree to the billing agreement on the PayPal checkout pages, and then you can process future payments for the buyer using reference transactions..', 'paypal-for-woocommerce' ),  
  914. 'default' => 'no' 
  915. ); 
  916. return $product_type; 
  917. } else { 
  918. return $product_type; 
  919.  
  920. function angelleye_woocommerce_process_product_meta_own( $post_id ) { 
  921. $no_shipping_required = isset( $_POST['_no_shipping_required'] ) ? 'yes' : 'no'; 
  922. update_post_meta( $post_id, '_no_shipping_required', $no_shipping_required ); 
  923. $_paypal_billing_agreement = isset( $_POST['_paypal_billing_agreement'] ) ? 'yes' : 'no'; 
  924. update_post_meta( $post_id, '_paypal_billing_agreement', $_paypal_billing_agreement ); 
  925.  
  926. public static function angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = null, $gateway = null, $error_email_notify = true) { 
  927. if( isset( $PayPalResult['CURL_ERROR'] ) ) { 
  928. try { 
  929. if($error_email_notify == true) { 
  930. $admin_email = get_option("admin_email"); 
  931. $message = __( $methos_name . " call failed." , "paypal-for-woocommerce" )."\n\n"; 
  932. $message .= __( 'Error Code: 0' , 'paypal-for-woocommerce' ) . "\n"; 
  933. $message .= __( 'Detailed Error Message: ' , 'paypal-for-woocommerce') . $PayPalResult['CURL_ERROR']; 
  934. wp_mail($admin_email, $gateway . " Error Notification", $message); 
  935. $display_error = 'There was a problem connecting to the payment gateway.'; 
  936. wc_add_notice($display_error, 'error'); 
  937. if (!is_ajax()) { 
  938. wp_redirect(get_permalink(wc_get_page_id('cart'))); 
  939. exit; 
  940. } else { 
  941. wp_send_json_error( array( 'error' => $display_error ) ); 
  942.  
  943. } catch ( Exception $e ) { 
  944. if ( ! empty( $e ) ) { 
  945. throw new Exception( __( $e->getMessage(), 'paypal-for-woocommerce' ) ); 
  946.  
  947. /** 
  948. * Check payment gateway settings to cancel order based on transaction's seller protection response 
  949. * @param WC_Payment_Gateway $Payment_Gateway 
  950. * @param array $PayPalResult 
  951. * @return bool 
  952. */ 
  953. public static function angelleye_woocommerce_sellerprotection_should_cancel_order(&$Payment_Gateway, &$PayPalResult) { 
  954. // Following check should not be needed, but in case something goes wrong, we know what happened. 
  955. if(in_array('WC_Payment_Gateway', class_parents($Payment_Gateway)) === false) { 
  956. error_log('FATAL ERROR! Payment gateway provided to angelleye_woocommerce_sellerprotection_should_cancel_order() is not of WC_Payment_Gateway.'); 
  957. return false; 
  958. // TODO: Add $order_cancellations setting to all applicable Angell EYE payment gateways 
  959. // If there is no setting available, this will become a NULL, which will default in the following case switch. 
  960. // NOTE: All gateways that use this function need to correctly add a note to the order which will explain WHY 
  961. // it wias cancelled (i.e. seller protection protection requirements failed) 
  962. $order_cancellation_setting = @$Payment_Gateway->order_cancellations; 
  963. // TODO: (?) Add some function that will take the returned (and verified) PayPal transaction details and return the applicable 
  964. // seller protection value based on the payment gateway/API call. **The following line is only for PayPal Express!** 
  965. $txn_protection_eligibility_response = isset($PayPalResult['PAYMENTINFO_0_PROTECTIONELIGIBILITY'])?$PayPalResult['PAYMENTINFO_0_PROTECTIONELIGIBILITY']:'ERROR!'; 
  966. // TODO: (?) Same goes for the transaction ID. **The following line is only for PayPal Express!** 
  967. $txn_id = isset($PayPalResult['PAYMENTINFO_0_TRANSACTIONID'])?$PayPalResult['PAYMENTINFO_0_TRANSACTIONID']:'ERROR!'; 
  968. switch($order_cancellation_setting) { 
  969. // If transaction does not have ANY seller protection 
  970. case 'no_seller_protection': 
  971. if($txn_protection_eligibility_response != 'Eligible' && $txn_protection_eligibility_response != 'PartiallyEligible') { 
  972. $Payment_Gateway->add_log('Transaction '.$txn_id.' is BAD. Setting: no_seller_protection, Response: '.$txn_protection_eligibility_response); 
  973. return true; 
  974. $Payment_Gateway->add_log('Transaction '.$txn_id.' is OK. Setting: no_seller_protection, Response: '.$txn_protection_eligibility_response); 
  975. return false; 
  976. // If transaction is not protected for unauthorized payments 
  977. case 'no_unauthorized_payment_protection': 
  978. if($txn_protection_eligibility_response != 'Eligible') { 
  979. $Payment_Gateway->add_log('Transaction '.$txn_id.' is BAD. Setting: no_unauthorized_payment_protection, Response: '.$txn_protection_eligibility_response); 
  980. return true; 
  981. $Payment_Gateway->add_log('Transaction '.$txn_id.' is OK. Setting: no_unauthorized_payment_protection, Response: '.$txn_protection_eligibility_response); 
  982. return false; 
  983. // If we have disabled this check/feature 
  984. case 'disabled': 
  985. $Payment_Gateway->add_log('Transaction '.$txn_id.' is OK. Setting: disabled, Response: '.$txn_protection_eligibility_response); 
  986. return false; 
  987. // Catch all other invalid values 
  988. default: 
  989. $Payment_Gateway->add_log('ERROR! order_cancellations setting for '.$Payment_Gateway->method_title.' is not valid!'); 
  990. return true; 
  991.  
  992. /** 
  993. * Express Checkout - Adjust button on product details page. #208  
  994. * @param type $qtyone 
  995. * @param type $quantity 
  996. * @param type $product_id 
  997. * @param type $variation_id 
  998. * @param type $cart_item_data 
  999. * @return type 
  1000. * @since 1.1.8 
  1001. */ 
  1002. public function angelleye_woocommerce_add_to_cart_sold_individually_quantity($qtyone, $quantity, $product_id, $variation_id, $cart_item_data) { 
  1003. if( (isset($_REQUEST['express_checkout']) && $_REQUEST['express_checkout'] == 1) && (isset($_REQUEST['add-to-cart']) && !empty($_REQUEST['add-to-cart'])) ) { 
  1004. if (sizeof(WC()->cart->get_cart()) != 0) { 
  1005. foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { 
  1006. $_product = $values['data']; 
  1007. if( $product_id == $_product->id || $variation_id == $_product->id) { 
  1008. wp_redirect(add_query_arg('pp_action', 'expresscheckout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))); 
  1009. exit(); 
  1010. } else { 
  1011. return $qtyone;  
  1012. } else { 
  1013. return $qtyone; 
  1014.  
  1015. public function angelleye_woocommerce_admin_enqueue_scripts() { 
  1016. wp_enqueue_style( 'ppe_cart', plugins_url( 'assets/css/admin.css' , __FILE__ ) ); 
  1017.  
  1018. public function angelleye_woocommerce_pfw_ed_shipping_bulk_tool() { 
  1019.  
  1020. if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) { 
  1021.  
  1022. global $wpdb; 
  1023.  
  1024. $processed_product_id = array(); 
  1025. $errors = FALSE; 
  1026. $products = FALSE; 
  1027. $product_ids = FALSE; 
  1028. $update_count = 0; 
  1029. $where_args = array( 
  1030. 'post_type' => array('product', 'product_variation'),  
  1031. 'posts_per_page' => -1,  
  1032. 'post_status' => 'publish',  
  1033. 'fields' => 'id=>parent',  
  1034. ); 
  1035. $where_args['meta_query'] = array(); 
  1036. $pfw_bulk_action_type = ( isset($_POST["actionType"]) ) ? $_POST['actionType'] : FALSE; 
  1037. $pfw_bulk_action_target_type = ( isset($_POST["actionTargetType"]) ) ? $_POST['actionTargetType'] : FALSE; 
  1038. $pfw_bulk_action_target_where_type = ( isset($_POST["actionTargetWhereType"]) ) ? $_POST['actionTargetWhereType'] : FALSE; 
  1039. $pfw_bulk_action_target_where_category = ( isset($_POST["actionTargetWhereCategory"]) ) ? $_POST['actionTargetWhereCategory'] : FALSE; 
  1040. $pfw_bulk_action_target_where_product_type = ( isset($_POST["actionTargetWhereProductType"]) ) ? $_POST['actionTargetWhereProductType'] : FALSE; 
  1041. $pfw_bulk_action_target_where_price_value = ( isset($_POST["actionTargetWherePriceValue"]) ) ? $_POST['actionTargetWherePriceValue'] : FALSE; 
  1042. $pfw_bulk_action_target_where_stock_value = ( isset($_POST["actionTargetWhereStockValue"]) ) ? $_POST['actionTargetWhereStockValue'] : FALSE; 
  1043.  
  1044. if (!$pfw_bulk_action_type || !$pfw_bulk_action_target_type) { 
  1045. $errors = TRUE; 
  1046.  
  1047. $is_enable_value = explode("_", $pfw_bulk_action_type); 
  1048. $is_enable = (isset($is_enable_value[0]) && $is_enable_value[0] == 'enable') ? 'yes' : 'no'; 
  1049.  
  1050. if( $pfw_bulk_action_type == 'enable_no_shipping' || $pfw_bulk_action_type == 'disable_no_shipping' ) { 
  1051. $action_key = "_no_shipping_required"; 
  1052.  
  1053. } elseif ($pfw_bulk_action_type == 'enable_paypal_billing_agreement' || $pfw_bulk_action_type == 'disable_paypal_billing_agreement') { 
  1054. $action_key = "_paypal_billing_agreement"; 
  1055.  
  1056. // All Products 
  1057. if ($pfw_bulk_action_target_type == 'all') { 
  1058.  
  1059. $products = new WP_Query($where_args); 
  1060.  
  1061. } elseif ($pfw_bulk_action_target_type == 'featured') { 
  1062. // Featured products 
  1063. array_push($where_args['meta_query'], array( 
  1064. 'key' => '_featured',  
  1065. 'value' => 'yes' 
  1066. ); 
  1067. $products = new WP_Query($where_args); 
  1068. } elseif($pfw_bulk_action_target_type == 'all_downloadable') { 
  1069. // downloadable products. 
  1070. array_push($where_args['meta_query'], array( 
  1071. 'key' => '_downloadable',  
  1072. 'value' => 'yes' 
  1073. )); 
  1074.  
  1075. $products = new WP_Query($where_args); 
  1076.  
  1077. } elseif($pfw_bulk_action_target_type == 'all_virtual') { 
  1078. // virtual products. 
  1079. array_push($where_args['meta_query'], array( 
  1080. 'key' => '_virtual',  
  1081. 'value' => 'yes' 
  1082. )); 
  1083.  
  1084. $products = new WP_Query($where_args); 
  1085.  
  1086. } elseif ($pfw_bulk_action_target_type == 'where' && $pfw_bulk_action_target_where_type) { 
  1087.  
  1088. // Where - By Category 
  1089. if ($pfw_bulk_action_target_where_type == 'category' && $pfw_bulk_action_target_where_category) { 
  1090. $where_args['product_cat'] = $pfw_bulk_action_target_where_category; 
  1091. $products = new WP_Query($where_args); 
  1092. } elseif ($pfw_bulk_action_target_where_type == 'product_type' && $pfw_bulk_action_target_where_product_type) { 
  1093. // Where - By Product type 
  1094. $where_args['product_type'] = $pfw_bulk_action_target_where_product_type; 
  1095. $products = new WP_Query($where_args); 
  1096. } elseif ($pfw_bulk_action_target_where_type == 'price_greater') { 
  1097. array_push($where_args['meta_query'], array( 
  1098. 'key' => '_price',  
  1099. 'value' => str_replace(", ", "", number_format($pfw_bulk_action_target_where_price_value, 2)),  
  1100. 'compare' => '>',  
  1101. 'type' => 'DECIMAL(10, 2)' 
  1102. ); 
  1103. $products = new WP_Query($where_args); 
  1104. } elseif ($pfw_bulk_action_target_where_type == 'price_less') { 
  1105. // Where - By Price - less than 
  1106. array_push($where_args['meta_query'], array( 
  1107. 'key' => '_price',  
  1108. 'value' => str_replace(", ", "", number_format($pfw_bulk_action_target_where_price_value, 2)),  
  1109. 'compare' => '<',  
  1110. 'type' => 'DECIMAL(10, 2)' 
  1111. ); 
  1112. $products = new WP_Query($where_args); 
  1113. } elseif ($pfw_bulk_action_target_where_type == 'stock_greater') { 
  1114. // Where - By Stock - greater than 
  1115. array_push($where_args['meta_query'], array( 
  1116. 'key' => '_manage_stock',  
  1117. 'value' => 'yes' 
  1118. ); 
  1119. array_push($where_args['meta_query'], array( 
  1120. 'key' => '_stock',  
  1121. 'value' => str_replace(", ", "", number_format($pfw_bulk_action_target_where_stock_value, 0)),  
  1122. 'compare' => '>',  
  1123. 'type' => 'NUMERIC' 
  1124. ); 
  1125. $products = new WP_Query($where_args); 
  1126. } elseif ($pfw_bulk_action_target_where_type == 'stock_less') { 
  1127. // Where - By Stock - less than 
  1128. array_push($where_args['meta_query'], array( 
  1129. 'key' => '_manage_stock',  
  1130. 'value' => 'yes' 
  1131. ); 
  1132. array_push($where_args['meta_query'], array( 
  1133. 'key' => '_stock',  
  1134. 'value' => str_replace(", ", "", number_format($pfw_bulk_action_target_where_stock_value, 0)),  
  1135. 'compare' => '<',  
  1136. 'type' => 'NUMERIC' 
  1137. ); 
  1138. $products = new WP_Query($where_args); 
  1139. } elseif ($pfw_bulk_action_target_where_type == 'instock') { 
  1140. // Where - Stock status 'instock' 
  1141. array_push($where_args['meta_query'], array( 
  1142. 'key' => '_stock_status',  
  1143. 'value' => 'instock' 
  1144. ); 
  1145. $products = new WP_Query($where_args); 
  1146. } elseif ($pfw_bulk_action_target_where_type == 'outofstock') { 
  1147. // Where - Stock status 'outofstock' 
  1148. array_push($where_args['meta_query'], array( 
  1149. 'key' => '_stock_status',  
  1150. 'value' => 'outofstock' 
  1151. ); 
  1152. $products = new WP_Query($where_args); 
  1153. } elseif ($pfw_bulk_action_target_where_type == 'sold_individually') { 
  1154. // Where - Sold Individually 
  1155. array_push($where_args['meta_query'], array( 
  1156. 'key' => '_sold_individually',  
  1157. 'value' => 'yes' 
  1158. ); 
  1159. $products = new WP_Query($where_args); 
  1160. } else { 
  1161. $errors = TRUE; 
  1162.  
  1163. // Update posts 
  1164. if (!$errors && $products) { 
  1165. if (count($products->posts) < 1) { 
  1166. $errors = TRUE; 
  1167. $update_count = 'zero'; 
  1168. $redirect_url = admin_url('options-general.php?page=' . $this->plugin_slug . '&tab=tools&processed=' . $update_count); 
  1169. echo $redirect_url; 
  1170. } else { 
  1171. foreach ($products->posts as $target) { 
  1172. $target_product_id = ( $target->post_parent != '0' ) ? $target->post_parent : $target->ID; 
  1173. if (get_post_type($target_product_id) == 'product' && !in_array($target_product_id, $processed_product_id)) { 
  1174. if (!update_post_meta($target_product_id, $action_key, $is_enable)) { 
  1175.  
  1176. } else { 
  1177. $processed_product_id[$target_product_id] = $target_product_id; 
  1178. $update_count = count($processed_product_id); 
  1179.  
  1180. // return 
  1181. if (!$errors) { 
  1182. if ($update_count == 0) { 
  1183. $update_count = 'zero'; 
  1184. $redirect_url = admin_url('options-general.php?page=paypal-for-woocommerce&tab=tabs&processed=' . $update_count); 
  1185. echo $redirect_url; 
  1186. } else { 
  1187. //echo 'failed'; 
  1188. die(); // this is required to return a proper result 
  1189.  
  1190. /** 
  1191. * @since 1.1.8.1 
  1192. * Non-decimal currency bug..?? #384  
  1193. * Check if currency has decimals 
  1194. * @param type $currency 
  1195. * @return boolean 
  1196. */ 
  1197. public static function currency_has_decimals( $currency ) { 
  1198. if ( in_array( $currency, array( 'HUF', 'JPY', 'TWD' ) ) ) { 
  1199. return false; 
  1200.  
  1201. return true; 
  1202.  
  1203. /** 
  1204. * @since 1.1.8.1 
  1205. * Non-decimal currency bug..?? #384  
  1206. * Round prices 
  1207. * @param type $price 
  1208. * @return type 
  1209. */ 
  1210. public static function round( $price ) { 
  1211. $precision = 2; 
  1212.  
  1213. if ( !self::currency_has_decimals( get_woocommerce_currency() ) ) { 
  1214. $precision = 0; 
  1215.  
  1216. return round( $price, $precision ); 
  1217.  
  1218. /** 
  1219. * @since 1.1.8.1 
  1220. * Non-decimal currency bug..?? #384  
  1221. * Round prices 
  1222. * @param type $price 
  1223. * @return type 
  1224. */ 
  1225. public static function number_format( $price ) { 
  1226. $decimals = 2; 
  1227.  
  1228. if ( !self::currency_has_decimals( get_woocommerce_currency() ) ) { 
  1229. $decimals = 0; 
  1230.  
  1231. return number_format( $price, $decimals, '.', '' ); 
  1232.  
  1233. public function angelleye_paypal_express_checkout_process_checkout_fields() { 
  1234. $this->set_session('checkout_form_post_data', serialize($_POST)); 
  1235.  
  1236. private function set_session($key, $value) { 
  1237. WC()->session->$key = $value; 
  1238. public function http_api_curl_ex_add_curl_parameter($handle, $r, $url ) { 
  1239. $Force_tls_one_point_two = get_option('Force_tls_one_point_two', 'no'); 
  1240. if ( (strstr( $url, 'https://' ) && strstr( $url, '.paypal.com' )) && isset($Force_tls_one_point_two) && $Force_tls_one_point_two == 'yes' ) { 
  1241. curl_setopt($handle, CURLOPT_VERBOSE, 1); 
  1242. curl_setopt($handle, CURLOPT_SSLVERSION, 6); 
  1243.  
  1244. public function angelleye_paypal_plus_notice($user_id) { 
  1245. $paypal_plus = get_option('woocommerce_paypal_plus_settings'); 
  1246. $ignore_paypal_plus_move_notice = get_option('ignore_paypal_plus_move_notice'); 
  1247. $ignore_paypal_plus_move_notice = get_user_meta($user_id, 'ignore_paypal_plus_move_notice'); 
  1248. if($ignore_paypal_plus_move_notice == 'true') { 
  1249. return false; 
  1250. if ( !empty($paypal_plus['enabled']) && $paypal_plus['enabled'] == 'yes' && version_compare(self::VERSION_PFW, '1.2.4', '<=') && $this->is_paypal_plus_plugin_active() == false && $ignore_paypal_plus_move_notice == false) { 
  1251. echo '<div class="notice welcome-panel error"><p style="margin: 10px;">' . sprintf( __("In order to better support the different countries and international features that PayPal Plus provides we have created a new, separate plugin. <a href='https://www.angelleye.com/product/woocommerce-paypal-plus-plugin' target='_blank'>Get the New PayPal Plus Plugin!</a>")); 
  1252. ?></p><a class="welcome-panel-close" href="<?php echo esc_url( add_query_arg( array( 'ignore_paypal_plus_move_notice' => '0' ) ) ); ?>"><?php _e( 'Dismiss' ); ?></a></div><?php  
  1253.  
  1254. public function is_paypal_plus_plugin_active() { 
  1255. if ( !in_array( 'woo-paypal-plus/woo-paypal-plus.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && !is_plugin_active_for_network( 'woo-paypal-plus/woo-paypal-plus.php' )) { 
  1256. return false; 
  1257. } else { 
  1258. return true;