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. private $subscription_support_enabled = false; 
  6. /** 
  7. * General class constructor where we'll setup our actions, hooks, and shortcodes. 
  8. */ 
  9.  
  10. public $customer_id = ''; 
  11. public function __construct() 
  12.  
  13. include_once plugin_dir_path(__FILE__) . 'angelleye-includes/angelleye-utility.php'; 
  14. $plugin_admin = new AngellEYE_Utility($this->plugin_slug, VERSION_PFW); 
  15. $woo_version = $this->wpbo_get_woo_version_number(); 
  16. add_filter( 'woocommerce_paypal_args', array($this, 'ae_paypal_standard_additional_parameters')); 
  17. if(version_compare($woo_version, '2.6', '>=')) { 
  18. add_action( 'plugins_loaded', array($this, 'init')); 
  19. register_activation_hook( __FILE__, array($this, 'activate_paypal_for_woocommerce' )); 
  20. register_deactivation_hook( __FILE__, array($this, 'deactivate_paypal_for_woocommerce' )); 
  21. add_action( 'wp_enqueue_scripts', array($this, 'frontend_scripts'), 100 ); 
  22. add_action( 'admin_notices', array($this, 'admin_notices') ); 
  23. add_action( 'admin_init', array($this, 'set_ignore_tag')); 
  24. add_filter( 'woocommerce_product_title' , array($this, 'woocommerce_product_title') ); 
  25. add_action( 'woocommerce_sections_checkout', array( $this, 'donate_message' ), 11 ); 
  26.  
  27. add_action( 'parse_request', array($this, 'wc_gateway_payment_token_api_parser') , 99); 
  28.  
  29. // http://stackoverflow.com/questions/22577727/problems-adding-action-links-to-wordpress-plugin 
  30. $basename = plugin_basename(__FILE__); 
  31. $prefix = is_network_admin() ? 'network_admin_' : ''; 
  32. add_filter("{$prefix}plugin_action_links_$basename", array($this, 'plugin_action_links'), 10, 4); 
  33.  
  34.  
  35.  
  36. add_action( 'admin_enqueue_scripts', array( $this , 'admin_scripts' ) ); 
  37. add_action( 'admin_print_styles', array( $this , 'admin_styles' ) ); 
  38.  
  39. add_action( 'admin_menu', array( $this, 'angelleye_admin_menu_own' ) ); 
  40. add_action( 'product_type_options', array( $this, 'angelleye_product_type_options_own' ), 10, 1); 
  41. add_action( 'woocommerce_process_product_meta', array( $this, 'angelleye_woocommerce_process_product_meta_own' ), 10, 1 ); 
  42. add_filter( 'woocommerce_add_to_cart_sold_individually_quantity', array( $this, 'angelleye_woocommerce_add_to_cart_sold_individually_quantity' ), 10, 5 ); 
  43. add_action('admin_enqueue_scripts', array( $this, 'angelleye_woocommerce_admin_enqueue_scripts' ) ); 
  44. add_action( 'wp_ajax_pfw_ed_shipping_bulk_tool', array( $this, 'angelleye_woocommerce_pfw_ed_shipping_bulk_tool' ) ); 
  45. add_filter('body_class', array($this, 'add_body_classes')); 
  46. add_action('http_api_curl', array($this, 'http_api_curl_ec_add_curl_parameter'), 10, 3); 
  47. add_filter( "pre_option_woocommerce_paypal_express_settings", array($this, 'angelleye_express_checkout_decrypt_gateway_api'), 10, 1); 
  48. add_filter( "pre_option_woocommerce_paypal_advanced_settings", array($this, 'angelleye_paypal_advanced_decrypt_gateway_api'), 10, 1); 
  49. add_filter( "pre_option_woocommerce_paypal_credit_card_rest_settings", array($this, 'angelleye_paypal_credit_card_rest_decrypt_gateway_api'), 10, 1); 
  50. add_filter( "pre_option_woocommerce_paypal_pro_settings", array($this, 'angelleye_paypal_pro_decrypt_gateway_api'), 10, 1); 
  51. add_filter( "pre_option_woocommerce_paypal_pro_payflow_settings", array($this, 'angelleye_paypal_pro_payflow_decrypt_gateway_api'), 10, 1); 
  52. add_filter( "pre_option_woocommerce_braintree_settings", array($this, 'angelleye_braintree_decrypt_gateway_api'), 10, 1); 
  53. add_filter( "pre_option_woocommerce_enable_guest_checkout", array($this, 'angelleye_express_checkout_woocommerce_enable_guest_checkout'), 10, 1); 
  54. add_filter('the_title', array($this, 'angelleye_paypal_for_woocommerce_page_title'), 99, 1); 
  55. $this->customer_id; 
  56.  
  57. /** 
  58. * Adds class name to HTML body to enable easy conditional CSS styling 
  59. * @access public 
  60. * @param array $classes 
  61. * @return array 
  62. */ 
  63. public function add_body_classes($classes) { 
  64. global $pp_settings; 
  65. if(@$pp_settings['enabled'] == 'yes') 
  66. $classes[] = 'has_paypal_express_checkout'; 
  67. return $classes; 
  68.  
  69. /** 
  70. * Get WooCommerce Version Number 
  71. * http://wpbackoffice.com/get-current-woocommerce-version-number/ 
  72. */ 
  73. function wpbo_get_woo_version_number() 
  74. // If get_plugins() isn't available, require it 
  75. if ( ! function_exists( 'get_plugins' ) ) 
  76. include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
  77.  
  78. // Create the plugins folder and file variables 
  79. $plugin_folder = get_plugins( '/' . 'woocommerce' ); 
  80. $plugin_file = 'woocommerce.php'; 
  81.  
  82. // If the plugin version number is set, return it 
  83. if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) 
  84. return $plugin_folder[$plugin_file]['Version']; 
  85. else 
  86. // Otherwise return null 
  87. return NULL; 
  88.  
  89.  
  90.  
  91. /** 
  92. * Return the plugin action links. This will only be called if the plugin 
  93. * is active. 
  94. * @since 1.0.6 
  95. * @param array $actions associative array of action names to anchor tags 
  96. * @return array associative array of plugin action links 
  97. */ 
  98. public function plugin_action_links($actions, $plugin_file, $plugin_data, $context) 
  99. $custom_actions = array( 
  100. //'configure' => sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=wc-settings&tab=checkout' ), __( 'Configure', 'paypal-for-woocommerce' ) ),  
  101. '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' ) ),  
  102. 'support' => sprintf( '<a href="%s" target="_blank">%s</a>', 'http://wordpress.org/support/plugin/paypal-for-woocommerce/', __( 'Support', 'paypal-for-woocommerce' ) ),  
  103. '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' ) ),  
  104. ); 
  105.  
  106. // add the links to the front of the actions list 
  107. return array_merge( $custom_actions, $actions ); 
  108.  
  109. function woocommerce_product_title($title) { 
  110. $title = str_replace(array("–", "–"), array("-"), $title); 
  111. return $title; 
  112.  
  113. function set_ignore_tag() { 
  114. global $current_user; 
  115. $plugin = plugin_basename( __FILE__ ); 
  116. $plugin_data = get_plugin_data( __FILE__, false ); 
  117.  
  118. if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && !is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) { 
  119. if(!in_array(@$_GET['action'], array('activate-plugin', 'upgrade-plugin', 'activate', 'do-plugin-upgrade')) && is_plugin_active($plugin) ) { 
  120. deactivate_plugins( $plugin ); 
  121. 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>." ); 
  122.  
  123. $user_id = $current_user->ID; 
  124.  
  125. /** If user clicks to ignore the notice, add that to their user meta */ 
  126. $notices = array('ignore_pp_ssl', 'ignore_pp_sandbox', 'ignore_pp_woo', 'ignore_pp_check', 'ignore_pp_donate', 'ignore_paypal_plus_move_notice'); 
  127.  
  128. foreach ($notices as $notice) { 
  129. if ( isset($_GET[$notice]) && '0' == $_GET[$notice] ) { 
  130. add_user_meta($user_id, $notice, 'true', true); 
  131. $set_ignore_tag_url = remove_query_arg( $notice ); 
  132. wp_redirect($set_ignore_tag_url); 
  133.  
  134. function admin_notices() { 
  135. global $current_user, $pp_settings ; 
  136. $user_id = $current_user->ID; 
  137.  
  138. $pp_pro = get_option('woocommerce_paypal_pro_settings'); 
  139. $pp_payflow = get_option('woocommerce_paypal_pro_payflow_settings'); 
  140. $pp_standard = get_option('woocommerce_paypal_settings'); 
  141.  
  142. do_action( 'angelleye_admin_notices', $pp_pro, $pp_payflow, $pp_standard ); 
  143.  
  144. if (@$pp_pro['enabled']=='yes' || @$pp_payflow['enabled']=='yes') { 
  145. // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected 
  146. if ( get_option('woocommerce_force_ssl_checkout')=='no' && ! class_exists( 'WordPressHTTPS' ) && !get_user_meta($user_id, 'ignore_pp_ssl') ) 
  147. 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>'; 
  148. if ((@$pp_pro['testmode']=='yes' || @$pp_payflow['testmode']=='yes' || @$pp_settings['testmode']=='yes') && !get_user_meta($user_id, 'ignore_pp_sandbox')) { 
  149. $testmodes = array(); 
  150. if (@$pp_pro['enabled']=='yes' && @$pp_pro['testmode']=='yes') $testmodes[] = 'PayPal Pro'; 
  151. if (@$pp_payflow['enabled']=='yes' && @$pp_payflow['testmode']=='yes') $testmodes[] = 'PayPal Pro PayFlow'; 
  152. if (@$pp_settings['enabled']=='yes' && @$pp_settings['testmode']=='yes') $testmodes[] = 'PayPal Express'; 
  153. $testmodes_str = implode(", ", $testmodes); 
  154. 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>'; 
  155. } elseif (@$pp_settings['enabled']=='yes') { 
  156. if (@$pp_settings['testmode']=='yes' && !get_user_meta($user_id, 'ignore_pp_sandbox')) { 
  157. 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>'; 
  158. if(@$pp_settings['enabled']=='yes' && @$pp_standard['enabled']=='yes' && !get_user_meta($user_id, 'ignore_pp_check')) { 
  159. 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>'; 
  160.  
  161. 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' )) { 
  162. 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>'; 
  163.  
  164. $screen = get_current_screen(); 
  165.  
  166. if( $screen->id == "settings_page_paypal-for-woocommerce" ) { 
  167. $processed = (isset($_GET['processed']) ) ? $_GET['processed'] : FALSE; 
  168. if($processed) { 
  169. echo '<div class="updated">'; 
  170. echo '<p>'. sprintf( __('Action completed; %s records processed. ', 'paypal-for-woocommerce'), ($processed == 'zero') ? 0 : $processed); 
  171. echo '</div>'; 
  172.  
  173. $this->angelleye_paypal_plus_notice($user_id); 
  174.  
  175. //init function 
  176. public function init() { 
  177. if (!class_exists("WC_Payment_Gateway")) return; 
  178. load_plugin_textdomain( 'paypal-for-woocommerce', FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' ); 
  179. include_once plugin_dir_path(__FILE__) . 'angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php'; 
  180. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-pro-payflow-angelleye.php' ); 
  181. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-advanced-angelleye.php'); 
  182. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-express-angelleye.php'); 
  183. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-pro-angelleye.php'); 
  184. if (version_compare(phpversion(), '5.4.0', '>=')) { 
  185. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-braintree-angelleye.php'); 
  186. if (version_compare(phpversion(), '5.3.0', '>=')) { 
  187. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-credit-cards-rest-angelleye.php'); 
  188. new Angelleye_PayPal_Express_Checkout_Helper(VERSION_PFW); 
  189. /** 
  190. * Check current WooCommerce version to ensure compatibility. 
  191. */ 
  192.  
  193. $woo_version = $this->wpbo_get_woo_version_number(); 
  194. if(version_compare($woo_version, '2.6', '<')) { 
  195. add_action( 'admin_notices', array($this, 'woo_compatibility_notice') ); 
  196. } else { 
  197. add_filter( 'woocommerce_payment_gateways', array($this, 'angelleye_add_paypal_pro_gateway'), 1000 ); 
  198.  
  199.  
  200. /** 
  201. * Admin Script 
  202. */ 
  203. public function admin_scripts() 
  204. $dir = plugin_dir_path( __FILE__ ); 
  205. wp_enqueue_media(); 
  206. wp_enqueue_script( 'jquery'); 
  207. // Localize the script with new data 
  208. wp_register_script( 'angelleye_admin', plugins_url( '/assets/js/angelleye-admin.js' , __FILE__ ), array( 'jquery' )); 
  209. $translation_array = array( 
  210. 'is_ssl' => AngellEYE_Gateway_Paypal::is_ssl()? "yes":"no",  
  211. 'choose_image' => __('Choose Image', 'paypal-for-woocommerce'),  
  212. 'shop_based_us' => (substr(get_option("woocommerce_default_country"), 0, 2) == 'US')? "yes":"no" 
  213.  
  214. ); 
  215. wp_localize_script( 'angelleye_admin', 'angelleye_admin', $translation_array ); 
  216. wp_enqueue_script( 'angelleye_admin'); 
  217.  
  218. /** 
  219. * Admin Style 
  220. */ 
  221. function admin_styles() 
  222. wp_enqueue_style('thickbox'); 
  223.  
  224.  
  225. /** 
  226. * frontend_scripts function. 
  227. * @access public 
  228. * @return void 
  229. */ 
  230. function frontend_scripts() { 
  231. global $pp_settings; 
  232. global $post; 
  233. $_enable_ec_button = 'no'; 
  234. if( !empty($post) ) { 
  235. $_enable_ec_button = get_post_meta($post->ID, '_enable_ec_button', true); 
  236. wp_register_script( 'angelleye_frontend', plugins_url( '/assets/js/angelleye-frontend.js' , __FILE__ ), array( 'jquery' ), WC_VERSION, true ); 
  237. $translation_array = array( 
  238. 'is_product' => is_product()? "yes" : "no",  
  239. 'is_cart' => is_cart()? "yes":"no",  
  240. 'is_checkout' => is_checkout()? "yes":"no",  
  241. 'three_digits' => __('3 digits usually found on the signature strip.', 'paypal-for-woocommerce'),  
  242. 'four_digits' => __('4 digits usually found on the front of the card.', 'paypal-for-woocommerce') 
  243. ); 
  244. wp_localize_script( 'angelleye_frontend', 'angelleye_frontend', $translation_array ); 
  245. wp_enqueue_script('angelleye_frontend'); 
  246.  
  247. if ( ! is_admin() && is_cart()) { 
  248. wp_enqueue_style( 'ppe_cart', plugins_url( 'assets/css/cart.css' , __FILE__ ) ); 
  249.  
  250. if ( ! is_admin() && is_checkout() ) { 
  251. wp_enqueue_style( 'ppe_checkout', plugins_url( 'assets/css/checkout.css' , __FILE__ ) ); 
  252. if ( ! is_admin() && is_single() && @$pp_settings['enabled']=='yes' && @$pp_settings['show_on_product_page']=='yes' && $_enable_ec_button == 'yes') { 
  253. wp_enqueue_style( 'ppe_single', plugins_url( 'assets/css/single.css' , __FILE__ ) ); 
  254. wp_enqueue_script('angelleye_button'); 
  255.  
  256.  
  257. /** 
  258. * Run when plugin is activated 
  259. */ 
  260. function activate_paypal_for_woocommerce() 
  261. // If WooCommerce is not enabled, deactivate plugin. 
  262. if(!in_array( 'woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))) && !is_plugin_active_for_network( 'woocommerce/woocommerce.php' )) 
  263. deactivate_plugins(plugin_basename(__FILE__)); 
  264. else 
  265. global $woocommerce; 
  266.  
  267. // Log activation in Angell EYE database via web service. 
  268. // @todo Need to turn this into an option people can enable by request. 
  269. //$log_url = $_SERVER['HTTP_HOST']; 
  270. //$log_plugin_id = 1; 
  271. //$log_activation_status = 1; 
  272. //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); 
  273.  
  274. /** 
  275. * Run when plugin is deactivated. 
  276. */ 
  277. function deactivate_paypal_for_woocommerce() 
  278. // Log activation in Angell EYE database via web service. 
  279. // @todo Need to turn this into an option people can enable. 
  280. //$log_url = $_SERVER['HTTP_HOST']; 
  281. //$log_plugin_id = 1; 
  282. //$log_activation_status = 0; 
  283. //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); 
  284.  
  285. /** 
  286. * Adds PayPal gateway options for Payments Pro and Express Checkout into the WooCommerce checkout settings. 
  287. */ 
  288. function angelleye_add_paypal_pro_gateway( $methods ) { 
  289. if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { 
  290. $this->subscription_support_enabled = true; 
  291. foreach ($methods as $key=>$method) { 
  292. if (in_array($method, array('WC_Gateway_PayPal_Pro', 'WC_Gateway_PayPal_Pro_Payflow', 'WC_Gateway_PayPal_Express'))) { 
  293. unset($methods[$key]); 
  294. break; 
  295. if( $this->subscription_support_enabled ) { 
  296. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/subscriptions/wc-gateway-paypal-pro-payflow-subscriptions-angelleye.php' ); 
  297. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/subscriptions/wc-gateway-paypal-advanced-subscriptions-angelleye.php'); 
  298. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/subscriptions/wc-gateway-paypal-express-subscriptions-angelleye.php'); 
  299. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/subscriptions/wc-gateway-paypal-pro-subscriptions-angelleye.php'); 
  300.  
  301. $methods[] = 'WC_Gateway_PayPal_Pro_PayFlow_Subscriptions_AngellEYE'; 
  302. $methods[] = 'WC_Gateway_PayPal_Advanced_Subscriptions_AngellEYE'; 
  303. $methods[] = 'WC_Gateway_PayPal_Pro_Subscriptions_AngellEYE'; 
  304. $methods[] = 'WC_Gateway_PayPal_Express_Subscriptions_AngellEYE'; 
  305. if (version_compare(phpversion(), '5.4.0', '>=')) { 
  306. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/subscriptions/wc-gateway-braintree-subscriptions-angelleye.php'); 
  307. $methods[] = 'WC_Gateway_Braintree_Subscriptions_AngellEYE'; 
  308. if (version_compare(phpversion(), '5.3.0', '>=')) { 
  309. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/subscriptions/wc-gateway-paypal-credit-cards-rest-subscriptions-angelleye.php'); 
  310. $methods[] = 'WC_Gateway_PayPal_Credit_Card_Rest_Subscriptions_AngellEYE'; 
  311. } else { 
  312. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-pro-payflow-angelleye.php' ); 
  313. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-advanced-angelleye.php'); 
  314. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-express-angelleye.php'); 
  315. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-pro-angelleye.php'); 
  316. $methods[] = 'WC_Gateway_PayPal_Pro_Payflow_AngellEYE'; 
  317. $methods[] = 'WC_Gateway_PayPal_Advanced_AngellEYE'; 
  318. $methods[] = 'WC_Gateway_PayPal_Pro_AngellEYE'; 
  319. $methods[] = 'WC_Gateway_PayPal_Express_AngellEYE'; 
  320. if (version_compare(phpversion(), '5.4.0', '>=')) { 
  321. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-braintree-angelleye.php'); 
  322. $methods[] = 'WC_Gateway_Braintree_AngellEYE'; 
  323.  
  324. if (version_compare(phpversion(), '5.3.0', '>=')) { 
  325. include_once ( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-paypal-credit-cards-rest-angelleye.php'); 
  326. $methods[] = 'WC_Gateway_PayPal_Credit_Card_Rest_AngellEYE'; 
  327. return $methods; 
  328.  
  329. /** 
  330. * Add additional parameters to the PayPal Standard checkout built into WooCommerce. 
  331. */ 
  332. public function ae_paypal_standard_additional_parameters($paypal_args) 
  333. $paypal_args['bn'] = 'AngellEYE_SP_WooCommerce'; 
  334. return $paypal_args; 
  335.  
  336. /** 
  337.  
  338. * Donate function 
  339. */ 
  340. function donate_message() { 
  341. 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') ) { 
  342. ?> 
  343. <div class="updated welcome-panel notice" id="paypal-for-woocommerce-donation"> 
  344. <div style="float:left; margin: 19px 16px 19px 0;" id="plugin-icon-paypal-for-woocommerce" ></div> 
  345. <h3>PayPal for WooCommerce</h3> 
  346. <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> 
  347. <p>Developers, join us on <a href="https://github.com/angelleye/paypal-woocommerce" target="_blank">GitHub</a>. Pull Requests are welcomed!</p> 
  348. <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> 
  349. <a class="welcome-panel-close" href="<?php echo esc_url( add_query_arg( array( 'ignore_pp_donate' => '0' ) ) ); ?>"><?php _e( 'Dismiss' ); ?></a> 
  350. <div style="clear:both"></div> 
  351. </div> 
  352. <?php 
  353.  
  354.  
  355.  
  356.  
  357. public static function calculate($order, $send_items = false) { 
  358. $PaymentOrderItems = array(); 
  359. $ctr = $giftwrapamount = $total_items = $total_discount = $total_tax = $shipping = 0; 
  360. $ITEMAMT = 0; 
  361. if ($order) { 
  362. $order_total = $order->get_total(); 
  363. $items = $order->get_items(); 
  364. /** 
  365. * Set shipping and tax values. 
  366. */ 
  367. if (get_option('woocommerce_prices_include_tax') == 'yes') { 
  368. $shipping = version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_total_shipping() : $order->get_shipping_total() + $order->get_shipping_tax(); 
  369. $tax = 0; 
  370. } else { 
  371. $shipping = version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_total_shipping() : $order->get_shipping_total(); 
  372. $tax = $order->get_total_tax(); 
  373. if('yes' === get_option( 'woocommerce_calc_taxes' ) && 'yes' === get_option( 'woocommerce_prices_include_tax' )) { 
  374. $tax = $order->get_total_tax(); 
  375. else { 
  376. //if empty order we get data from cart 
  377. $order_total = WC()->cart->total; 
  378. $items = WC()->cart->get_cart(); 
  379. /** 
  380. * Get shipping and tax. 
  381. */ 
  382. if(get_option('woocommerce_prices_include_tax' ) == 'yes') 
  383. $shipping = WC()->cart->shipping_total + WC()->cart->shipping_tax_total; 
  384. $tax = 0; 
  385. else 
  386. $shipping = WC()->cart->shipping_total; 
  387. $tax = WC()->cart->get_taxes_total(); 
  388. if('yes' === get_option( 'woocommerce_calc_taxes' ) && 'yes' === get_option( 'woocommerce_prices_include_tax' )) { 
  389. $tax = WC()->cart->get_taxes_total(); 
  390. if ($send_items) { 
  391. foreach ($items as $item) { 
  392. /** 
  393. * Get product data from WooCommerce 
  394. */ 
  395. if ($order) { 
  396. $_product = $order->get_product_from_item($item); 
  397. $qty = absint($item['qty']); 
  398. $item_meta = new WC_Order_Item_Meta($item, $_product); 
  399. $meta = $item_meta->display(true, true); 
  400. } else { 
  401. $_product = $item['data']; 
  402. $qty = absint($item['quantity']); 
  403. $meta = WC()->cart->get_item_data($item, true); 
  404. $sku = $_product->get_sku(); 
  405. $item['name'] = html_entity_decode($_product->get_title(), ENT_NOQUOTES, 'UTF-8'); 
  406. if ($_product->is_type('variation')) { 
  407. if (empty($sku)) { 
  408. $sku = $_product->parent->get_sku(); 
  409. if (!empty($meta)) { 
  410. $item['name'] .= " - " . str_replace(", \n", " - ", $meta); 
  411. $Item = array( 
  412. 'name' => $item['name'], // Item name. 127 char max. 
  413. 'desc' => '', // Item description. 127 char max. 
  414. 'amt' => self::number_format(self::round( $item['line_subtotal'] / $qty)), // Cost of item. 
  415. 'number' => $sku, // Item number. 127 char max. 
  416. 'qty' => $qty, // Item qty on order. Any positive integer. 
  417. ); 
  418. array_push($PaymentOrderItems, $Item); 
  419. $ITEMAMT += self::round( $item['line_subtotal'] / $qty ) * $qty; 
  420. /** 
  421. * Add custom Woo cart fees as line items 
  422. */ 
  423. foreach (WC()->cart->get_fees() as $fee) { 
  424. $Item = array( 
  425. 'name' => $fee->name, // Item name. 127 char max. 
  426. 'desc' => '', // Item description. 127 char max. 
  427. 'amt' => self::number_format($fee->amount, 2, '.', ''), // Cost of item. 
  428. 'number' => $fee->id, // Item number. 127 char max. 
  429. 'qty' => 1, // Item qty on order. Any positive integer. 
  430. ); 
  431. /** 
  432. * The gift wrap amount actually has its own parameter in 
  433. * DECP, so we don't want to include it as one of the line 
  434. * items. 
  435. */ 
  436. if ($Item['number'] != 'gift-wrap') { 
  437. array_push($PaymentOrderItems, $Item); 
  438. $ITEMAMT += self::round($fee->amount); 
  439. } else { 
  440. $giftwrapamount = self::round($fee->amount); 
  441. $ctr++; 
  442. //caculate discount 
  443. if ($order) { 
  444. if (!AngellEYE_Gateway_Paypal::is_wc_version_greater_2_3()) { 
  445. if ($order->get_cart_discount() > 0) { 
  446. foreach (WC()->cart->get_coupons('cart') as $code => $coupon) { 
  447. $Item = array( 
  448. 'name' => 'Cart Discount',  
  449. 'number' => $code,  
  450. 'qty' => '1',  
  451. 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]) 
  452. ); 
  453. array_push($PaymentOrderItems, $Item); 
  454. $total_discount -= $order->get_cart_discount(); 
  455. if ($order->get_order_discount() > 0) { 
  456. foreach (WC()->cart->get_coupons('order') as $code => $coupon) { 
  457. $Item = array( 
  458. 'name' => 'Order Discount',  
  459. 'number' => $code,  
  460. 'qty' => '1',  
  461. 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]) 
  462. ); 
  463. array_push($PaymentOrderItems, $Item); 
  464. $total_discount -= $order->get_order_discount(); 
  465. } else { 
  466. if ($order->get_total_discount() > 0) { 
  467. $Item = array( 
  468. 'name' => 'Total Discount',  
  469. 'qty' => 1,  
  470. 'amt' => - self::number_format($order->get_total_discount()),  
  471. 'number' => implode(", ", $order->get_used_coupons()) 
  472. ); 
  473. array_push($PaymentOrderItems, $Item); 
  474. $total_discount -= $order->get_total_discount(); 
  475. } else { 
  476. if ( !empty( WC()->cart->applied_coupons ) ) { 
  477. foreach (WC()->cart->get_coupons('cart') as $code => $coupon) { 
  478. $Item = array( 
  479. 'name' => 'Cart Discount',  
  480. 'qty' => '1',  
  481. 'number'=> $code,  
  482. 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]) 
  483. ); 
  484. array_push($PaymentOrderItems, $Item); 
  485. $total_discount -= self::number_format(WC()->cart->coupon_discount_amounts[$code]); 
  486. if (!AngellEYE_Gateway_Paypal::is_wc_version_greater_2_3()) { 
  487. if ( !empty( WC()->cart->applied_coupons ) ) { 
  488. foreach (WC()->cart->get_coupons('order') as $code => $coupon) { 
  489. $Item = array( 
  490. 'name' => 'Order Discount',  
  491. 'qty' => '1',  
  492. 'number'=> $code,  
  493. 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]) 
  494. ); 
  495. array_push($PaymentOrderItems, $Item); 
  496. $total_discount -= self::number_format(WC()->cart->coupon_discount_amounts[$code]); 
  497. if( $tax > 0) { 
  498. $tax = self::number_format($tax); 
  499. if( $shipping > 0) { 
  500. $shipping = self::number_format($shipping); 
  501. if( $total_discount ) { 
  502. $total_discount = self::round($total_discount); 
  503. if (empty($ITEMAMT)) { 
  504. $cart_fees = WC()->cart->get_fees(); 
  505. if( isset($cart_fees[0]->id) && $cart_fees[0]->id == 'gift-wrap' ) { 
  506. $giftwrapamount = isset($cart_fees[0]->amount) ? $cart_fees[0]->amount : 0; 
  507. } else { 
  508. $giftwrapamount = 0; 
  509. $Payment['itemamt'] = $order_total - $tax - $shipping - $giftwrapamount; 
  510. } else { 
  511. $Payment['itemamt'] = self::number_format($ITEMAMT + $total_discount); 
  512. /** 
  513. * Set tax 
  514. */ 
  515. if ($tax > 0) { 
  516. $Payment['taxamt'] = self::number_format($tax); // Required if you specify itemized L_TAXAMT fields. Sum of all tax items in this order. 
  517. } else { 
  518. $Payment['taxamt'] = 0; 
  519. /** 
  520. * Set shipping 
  521. */ 
  522. if ($shipping > 0) { 
  523. $Payment['shippingamt'] = self::number_format($shipping); // Total shipping costs for this order. If you specify SHIPPINGAMT you mut also specify a value for ITEMAMT. 
  524. } else { 
  525. $Payment['shippingamt'] = 0; 
  526. $Payment['order_items'] = $PaymentOrderItems; 
  527. // Rounding amendment 
  528. if (trim(self::number_format($order_total)) !== trim(self::number_format($Payment['itemamt'] + $giftwrapamount + $tax + $shipping))) { 
  529. $diffrence_amount = AngellEYE_Gateway_Paypal::get_diffrent($order_total, $Payment['itemamt'] + $tax + $shipping); 
  530. if($shipping > 0) { 
  531. $Payment['shippingamt'] = abs(self::number_format($shipping + $diffrence_amount)); 
  532. } elseif ($tax > 0) { 
  533. $Payment['taxamt'] = abs(self::number_format($tax + $diffrence_amount)); 
  534. } else { 
  535. //make change to itemamt 
  536. $Payment['itemamt'] = abs(self::number_format($Payment['itemamt'] + $diffrence_amount)); 
  537. //also make change to the first item 
  538. if ($send_items) { 
  539. $Payment['order_items'][0]['amt'] = abs(self::number_format($Payment['order_items'][0]['amt'] + $diffrence_amount / $Payment['order_items'][0]['qty'])); 
  540. return $Payment; 
  541.  
  542. public static function get_diffrent($amout_1, $amount_2) { 
  543. $diff_amount = $amout_1 - $amount_2; 
  544. return $diff_amount; 
  545. public static function cut_off($number) { 
  546. $parts = explode(".", $number); 
  547. $newnumber = $parts[0] . "." . $parts[1][0] . $parts[1][1]; 
  548. return $newnumber; 
  549.  
  550. public static function is_wc_version_greater_2_3() { 
  551. return AngellEYE_Gateway_Paypal::get_wc_version() && version_compare(AngellEYE_Gateway_Paypal::get_wc_version(), '2.3', '>='); 
  552.  
  553. public static function get_wc_version() { 
  554. return defined('WC_VERSION') && WC_VERSION ? WC_VERSION : null; 
  555.  
  556. /** 
  557. * Check if site is SSL ready 
  558. */ 
  559. static public function is_ssl() 
  560. if (is_ssl() || get_option('woocommerce_force_ssl_checkout') == 'yes' || class_exists('WordPressHTTPS')) 
  561. return true; 
  562. return false; 
  563.  
  564. public function angelleye_admin_menu_own() { 
  565. $this->plugin_screen_hook_suffix = add_submenu_page( 
  566. 'options-general.php',  
  567. __( 'PayPal for WooCommerce - Settings', 'paypal-for-woocommerce' ),  
  568. __( 'PayPal for WooCommerce', 'paypal-for-woocommerce' ),  
  569. 'manage_options',  
  570. 'paypal-for-woocommerce',  
  571. array( $this, 'display_plugin_admin_page'));  
  572.  
  573. public function display_plugin_admin_page() { 
  574. // WooCommerce product categories 
  575. $taxonomy = 'product_cat'; 
  576. $orderby = 'name'; 
  577. $show_count = 0; // 1 for yes, 0 for no 
  578. $pad_counts = 0; // 1 for yes, 0 for no 
  579. $hierarchical = 1; // 1 for yes, 0 for no 
  580. $title = ''; 
  581. $empty = 0; 
  582.  
  583. $args = array( 
  584. 'taxonomy' => $taxonomy,  
  585. 'orderby' => $orderby,  
  586. 'show_count' => $show_count,  
  587. 'pad_counts' => $pad_counts,  
  588. 'hierarchical' => $hierarchical,  
  589. 'title_li' => $title,  
  590. 'hide_empty' => $empty 
  591. ); 
  592.  
  593. $product_cats = get_categories( $args ); 
  594. include_once( 'template/admin.php' ); 
  595.  
  596. static public function curPageURL() { 
  597. $pageURL = 'http'; 
  598. if (@$_SERVER["HTTPS"] == "on") {$pageURL .= "s";} 
  599. $pageURL .= "://"; 
  600. if ($_SERVER["SERVER_PORT"] != "80") { 
  601. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; 
  602. } else { 
  603. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; 
  604. return $pageURL; 
  605.  
  606. function angelleye_product_type_options_own($product_type) { 
  607. if( isset($product_type) && !empty($product_type) ) { 
  608. $product_type['no_shipping_required'] = array( 
  609. 'id' => '_no_shipping_required',  
  610. 'wrapper_class' => '',  
  611. 'label' => __( 'No Shipping Required', 'paypal-for-woocommerce' ),  
  612. 'description' => __( 'Disables shipping requirements in the PayPal checkout flow.', 'paypal-for-woocommerce' ),  
  613. 'default' => 'no' 
  614. ); 
  615. $product_type['paypal_billing_agreement'] = array( 
  616. 'id' => '_paypal_billing_agreement',  
  617. 'wrapper_class' => '',  
  618. 'label' => __( 'Enable PayPal Billing Agreement', 'paypal-for-woocommerce' ),  
  619. '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' ),  
  620. 'default' => 'no' 
  621. ); 
  622. $product_type['enable_sandbox_mode'] = array( 
  623. 'id' => '_enable_sandbox_mode',  
  624. 'wrapper_class' => '',  
  625. 'label' => __( 'Enable Sandbox Mode', 'paypal-for-woocommerce' ),  
  626. 'description' => __( 'If this product is included in the cart the order will be processed in the PayPal sandbox for testing purposes.', 'paypal-for-woocommerce' ),  
  627. 'default' => 'no' 
  628. ); 
  629. $product_type['enable_ec_button'] = array( 
  630. 'id' => '_enable_ec_button',  
  631. 'wrapper_class' => '',  
  632. 'label' => __( 'Enable Express Checkout Button', 'paypal-for-woocommerce' ),  
  633. 'description' => __( 'Adds the PayPal Express Checkout button to the product page allowing buyers to checkout directly from the product page.', 'paypal-for-woocommerce' ),  
  634. 'default' => 'no' 
  635. ); 
  636. return $product_type; 
  637. } else { 
  638. return $product_type; 
  639.  
  640. function angelleye_woocommerce_process_product_meta_own( $post_id ) { 
  641. $no_shipping_required = isset( $_POST['_no_shipping_required'] ) ? 'yes' : 'no'; 
  642. update_post_meta( $post_id, '_no_shipping_required', $no_shipping_required ); 
  643. $_paypal_billing_agreement = isset( $_POST['_paypal_billing_agreement'] ) ? 'yes' : 'no'; 
  644. update_post_meta( $post_id, '_paypal_billing_agreement', $_paypal_billing_agreement ); 
  645. $_enable_sandbox_mode = isset( $_POST['_enable_sandbox_mode'] ) ? 'yes' : 'no'; 
  646. update_post_meta( $post_id, '_enable_sandbox_mode', $_enable_sandbox_mode ); 
  647. $_enable_ec_button = isset( $_POST['_enable_ec_button'] ) ? 'yes' : 'no'; 
  648. update_post_meta( $post_id, '_enable_ec_button', $_enable_ec_button ); 
  649.  
  650. public static function angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = null, $gateway = null, $error_email_notify = true) { 
  651. if( isset( $PayPalResult['CURL_ERROR'] ) ) { 
  652. try { 
  653. if($error_email_notify == true) { 
  654. $admin_email = get_option("admin_email"); 
  655. $message = __( $methos_name . " call failed." , "paypal-for-woocommerce" )."\n\n"; 
  656. $message .= __( 'Error Code: 0' , 'paypal-for-woocommerce' ) . "\n"; 
  657. $message .= __( 'Detailed Error Message: ' , 'paypal-for-woocommerce') . $PayPalResult['CURL_ERROR']; 
  658. wp_mail($admin_email, $gateway . " Error Notification", $message); 
  659. $display_error = 'There was a problem connecting to the payment gateway.'; 
  660. wc_add_notice($display_error, 'error'); 
  661. if (!is_ajax()) { 
  662. wp_redirect(get_permalink(wc_get_page_id('cart'))); 
  663. exit; 
  664. } else { 
  665. wp_send_json_error( array( 'error' => $display_error ) ); 
  666.  
  667. } catch ( Exception $e ) { 
  668. if ( ! empty( $e ) ) { 
  669. throw new Exception( __( $e->getMessage(), 'paypal-for-woocommerce' ) ); 
  670.  
  671.  
  672.  
  673.  
  674. /** 
  675. * Express Checkout - Adjust button on product details page. #208  
  676. * @param type $qtyone 
  677. * @param type $quantity 
  678. * @param type $product_id 
  679. * @param type $variation_id 
  680. * @param type $cart_item_data 
  681. * @return type 
  682. * @since 1.1.8 
  683. */ 
  684. public function angelleye_woocommerce_add_to_cart_sold_individually_quantity($qtyone, $quantity, $product_id, $variation_id, $cart_item_data) { 
  685. if( (isset($_REQUEST['express_checkout']) && $_REQUEST['express_checkout'] == 1) && (isset($_REQUEST['add-to-cart']) && !empty($_REQUEST['add-to-cart'])) ) { 
  686. if (sizeof(WC()->cart->get_cart()) != 0) { 
  687. foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { 
  688. $cart_product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); 
  689. if( $product_id == $cart_product_id || $variation_id == $cart_product_id) { 
  690. wp_redirect(add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/')))); 
  691. exit(); 
  692. } else { 
  693. return $qtyone;  
  694. } else { 
  695. return $qtyone; 
  696.  
  697. public function angelleye_woocommerce_admin_enqueue_scripts() { 
  698. wp_enqueue_style( 'ppe_cart', plugins_url( 'assets/css/admin.css' , __FILE__ ) ); 
  699.  
  700. public function angelleye_woocommerce_pfw_ed_shipping_bulk_tool() { 
  701.  
  702. if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) { 
  703.  
  704. global $wpdb; 
  705.  
  706. $processed_product_id = array(); 
  707. $errors = FALSE; 
  708. $products = FALSE; 
  709. $product_ids = FALSE; 
  710. $update_count = 0; 
  711. $where_args = array( 
  712. 'post_type' => array('product', 'product_variation'),  
  713. 'posts_per_page' => -1,  
  714. 'post_status' => 'publish',  
  715. 'fields' => 'id=>parent',  
  716. ); 
  717. $where_args['meta_query'] = array(); 
  718. $pfw_bulk_action_type = ( isset($_POST["actionType"]) ) ? $_POST['actionType'] : FALSE; 
  719. $pfw_bulk_action_target_type = ( isset($_POST["actionTargetType"]) ) ? $_POST['actionTargetType'] : FALSE; 
  720. $pfw_bulk_action_target_where_type = ( isset($_POST["actionTargetWhereType"]) ) ? $_POST['actionTargetWhereType'] : FALSE; 
  721. $pfw_bulk_action_target_where_category = ( isset($_POST["actionTargetWhereCategory"]) ) ? $_POST['actionTargetWhereCategory'] : FALSE; 
  722. $pfw_bulk_action_target_where_product_type = ( isset($_POST["actionTargetWhereProductType"]) ) ? $_POST['actionTargetWhereProductType'] : FALSE; 
  723. $pfw_bulk_action_target_where_price_value = ( isset($_POST["actionTargetWherePriceValue"]) ) ? $_POST['actionTargetWherePriceValue'] : FALSE; 
  724. $pfw_bulk_action_target_where_stock_value = ( isset($_POST["actionTargetWhereStockValue"]) ) ? $_POST['actionTargetWhereStockValue'] : FALSE; 
  725.  
  726. if (!$pfw_bulk_action_type || !$pfw_bulk_action_target_type) { 
  727. $errors = TRUE; 
  728.  
  729. $is_enable_value = explode("_", $pfw_bulk_action_type); 
  730. $is_enable = (isset($is_enable_value[0]) && $is_enable_value[0] == 'enable') ? 'yes' : 'no'; 
  731.  
  732. if( $pfw_bulk_action_type == 'enable_no_shipping' || $pfw_bulk_action_type == 'disable_no_shipping' ) { 
  733. $action_key = "_no_shipping_required"; 
  734.  
  735. } elseif ($pfw_bulk_action_type == 'enable_paypal_billing_agreement' || $pfw_bulk_action_type == 'disable_paypal_billing_agreement') { 
  736. $action_key = "_paypal_billing_agreement"; 
  737. } elseif ($pfw_bulk_action_type == 'enable_express_checkout_button' || $pfw_bulk_action_type == 'disable_express_checkout_button') { 
  738. $action_key = "_enable_ec_button"; 
  739.  
  740. // All Products 
  741. if ($pfw_bulk_action_target_type == 'all') { 
  742.  
  743. $products = new WP_Query($where_args); 
  744.  
  745. } elseif ($pfw_bulk_action_target_type == 'featured') { 
  746. // Featured products 
  747. array_push($where_args['meta_query'], array( 
  748. 'key' => '_featured',  
  749. 'value' => 'yes' 
  750. ); 
  751. $products = new WP_Query($where_args); 
  752. } elseif($pfw_bulk_action_target_type == 'all_downloadable') { 
  753. // downloadable products. 
  754. array_push($where_args['meta_query'], array( 
  755. 'key' => '_downloadable',  
  756. 'value' => 'yes' 
  757. )); 
  758.  
  759. $products = new WP_Query($where_args); 
  760.  
  761. } elseif($pfw_bulk_action_target_type == 'all_virtual') { 
  762. // virtual products. 
  763. array_push($where_args['meta_query'], array( 
  764. 'key' => '_virtual',  
  765. 'value' => 'yes' 
  766. )); 
  767.  
  768. $products = new WP_Query($where_args); 
  769.  
  770. } elseif ($pfw_bulk_action_target_type == 'where' && $pfw_bulk_action_target_where_type) { 
  771.  
  772. // Where - By Category 
  773. if ($pfw_bulk_action_target_where_type == 'category' && $pfw_bulk_action_target_where_category) { 
  774. $where_args['product_cat'] = $pfw_bulk_action_target_where_category; 
  775. $products = new WP_Query($where_args); 
  776. } elseif ($pfw_bulk_action_target_where_type == 'product_type' && $pfw_bulk_action_target_where_product_type) { 
  777. // Where - By Product type 
  778. $where_args['product_type'] = $pfw_bulk_action_target_where_product_type; 
  779. $products = new WP_Query($where_args); 
  780. } elseif ($pfw_bulk_action_target_where_type == 'price_greater') { 
  781. array_push($where_args['meta_query'], array( 
  782. 'key' => '_price',  
  783. 'value' => str_replace(", ", "", number_format($pfw_bulk_action_target_where_price_value, 2)),  
  784. 'compare' => '>',  
  785. 'type' => 'DECIMAL(10, 2)' 
  786. ); 
  787. $products = new WP_Query($where_args); 
  788. } elseif ($pfw_bulk_action_target_where_type == 'price_less') { 
  789. // Where - By Price - less than 
  790. array_push($where_args['meta_query'], array( 
  791. 'key' => '_price',  
  792. 'value' => str_replace(", ", "", number_format($pfw_bulk_action_target_where_price_value, 2)),  
  793. 'compare' => '<',  
  794. 'type' => 'DECIMAL(10, 2)' 
  795. ); 
  796. $products = new WP_Query($where_args); 
  797. } elseif ($pfw_bulk_action_target_where_type == 'stock_greater') { 
  798. // Where - By Stock - greater than 
  799. array_push($where_args['meta_query'], array( 
  800. 'key' => '_manage_stock',  
  801. 'value' => 'yes' 
  802. ); 
  803. array_push($where_args['meta_query'], array( 
  804. 'key' => '_stock',  
  805. 'value' => str_replace(", ", "", number_format($pfw_bulk_action_target_where_stock_value, 0)),  
  806. 'compare' => '>',  
  807. 'type' => 'NUMERIC' 
  808. ); 
  809. $products = new WP_Query($where_args); 
  810. } elseif ($pfw_bulk_action_target_where_type == 'stock_less') { 
  811. // Where - By Stock - less than 
  812. array_push($where_args['meta_query'], array( 
  813. 'key' => '_manage_stock',  
  814. 'value' => 'yes' 
  815. ); 
  816. array_push($where_args['meta_query'], array( 
  817. 'key' => '_stock',  
  818. 'value' => str_replace(", ", "", number_format($pfw_bulk_action_target_where_stock_value, 0)),  
  819. 'compare' => '<',  
  820. 'type' => 'NUMERIC' 
  821. ); 
  822. $products = new WP_Query($where_args); 
  823. } elseif ($pfw_bulk_action_target_where_type == 'instock') { 
  824. // Where - Stock status 'instock' 
  825. array_push($where_args['meta_query'], array( 
  826. 'key' => '_stock_status',  
  827. 'value' => 'instock' 
  828. ); 
  829. $products = new WP_Query($where_args); 
  830. } elseif ($pfw_bulk_action_target_where_type == 'outofstock') { 
  831. // Where - Stock status 'outofstock' 
  832. array_push($where_args['meta_query'], array( 
  833. 'key' => '_stock_status',  
  834. 'value' => 'outofstock' 
  835. ); 
  836. $products = new WP_Query($where_args); 
  837. } elseif ($pfw_bulk_action_target_where_type == 'sold_individually') { 
  838. // Where - Sold Individually 
  839. array_push($where_args['meta_query'], array( 
  840. 'key' => '_sold_individually',  
  841. 'value' => 'yes' 
  842. ); 
  843. $products = new WP_Query($where_args); 
  844. } else { 
  845. $errors = TRUE; 
  846.  
  847. // Update posts 
  848. if (!$errors && $products) { 
  849. if (count($products->posts) < 1) { 
  850. $errors = TRUE; 
  851. $update_count = 'zero'; 
  852. $redirect_url = admin_url('options-general.php?page=' . $this->plugin_slug . '&tab=tools&processed=' . $update_count); 
  853. echo $redirect_url; 
  854. } else { 
  855. foreach ($products->posts as $target) { 
  856. $target_product_id = ( $target->post_parent != '0' ) ? $target->post_parent : $target->ID; 
  857. if (get_post_type($target_product_id) == 'product' && !in_array($target_product_id, $processed_product_id)) { 
  858. if (!update_post_meta($target_product_id, $action_key, $is_enable)) { 
  859.  
  860. } else { 
  861. $processed_product_id[$target_product_id] = $target_product_id; 
  862. $update_count = count($processed_product_id); 
  863.  
  864. // return 
  865. if (!$errors) { 
  866. if ($update_count == 0) { 
  867. $update_count = 'zero'; 
  868. $redirect_url = admin_url('options-general.php?page=paypal-for-woocommerce&tab=tabs&processed=' . $update_count); 
  869. echo $redirect_url; 
  870. } else { 
  871. //echo 'failed'; 
  872. die(); // this is required to return a proper result 
  873.  
  874. /** 
  875. * @since 1.1.8.1 
  876. * Non-decimal currency bug..?? #384  
  877. * Check if currency has decimals 
  878. * @param type $currency 
  879. * @return boolean 
  880. */ 
  881. public static function currency_has_decimals( $currency ) { 
  882. if ( in_array( $currency, array( 'HUF', 'JPY', 'TWD' ) ) ) { 
  883. return false; 
  884.  
  885. return true; 
  886.  
  887. /** 
  888. * @since 1.1.8.1 
  889. * Non-decimal currency bug..?? #384  
  890. * Round prices 
  891. * @param type $price 
  892. * @return type 
  893. */ 
  894. public static function round( $price ) { 
  895. $precision = 2; 
  896.  
  897. if ( !self::currency_has_decimals( get_woocommerce_currency() ) ) { 
  898. $precision = 0; 
  899.  
  900. return round( $price, $precision ); 
  901.  
  902. /** 
  903. * @since 1.1.8.1 
  904. * Non-decimal currency bug..?? #384  
  905. * Round prices 
  906. * @param type $price 
  907. * @return type 
  908. */ 
  909. public static function number_format( $price ) { 
  910. $decimals = 2; 
  911.  
  912. if ( !self::currency_has_decimals( get_woocommerce_currency() ) ) { 
  913. $decimals = 0; 
  914.  
  915. return number_format( $price, $decimals, '.', '' ); 
  916.  
  917. public function angelleye_paypal_express_checkout_process_checkout_fields() { 
  918. $this->set_session('checkout_form_post_data', serialize($_POST)); 
  919.  
  920. private function set_session($key, $value) { 
  921. WC()->session->set( $key, $value ); 
  922. public function http_api_curl_ec_add_curl_parameter($handle, $r, $url ) { 
  923. $Force_tls_one_point_two = get_option('Force_tls_one_point_two', 'no'); 
  924. if ( (strstr( $url, 'https://' ) && strstr( $url, '.paypal.com' )) && isset($Force_tls_one_point_two) && $Force_tls_one_point_two == 'yes' ) { 
  925. curl_setopt($handle, CURLOPT_VERBOSE, 1); 
  926. curl_setopt($handle, CURLOPT_SSLVERSION, 6); 
  927.  
  928. public function angelleye_paypal_plus_notice($user_id) { 
  929. $paypal_plus = get_option('woocommerce_paypal_plus_settings'); 
  930. $ignore_paypal_plus_move_notice = get_option('ignore_paypal_plus_move_notice'); 
  931. $ignore_paypal_plus_move_notice = get_user_meta($user_id, 'ignore_paypal_plus_move_notice'); 
  932. if($ignore_paypal_plus_move_notice == 'true') { 
  933. return false; 
  934. if ( !empty($paypal_plus['enabled']) && $paypal_plus['enabled'] == 'yes' && version_compare(VERSION_PFW, '1.2.4', '<=') && $this->is_paypal_plus_plugin_active() == false && $ignore_paypal_plus_move_notice == false) { 
  935. 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>")); 
  936. ?></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  
  937.  
  938. public function is_paypal_plus_plugin_active() { 
  939. 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' )) { 
  940. return false; 
  941. } else { 
  942. return true; 
  943.  
  944. public function wc_gateway_payment_token_api_parser() { 
  945. if( !empty($_GET['do_action']) && $_GET['do_action'] = 'update_payment_method') { 
  946. if( !empty($_GET['method_name']) && $_GET['method_name'] == 'paypal_express') { 
  947. switch ($_GET['action_name']) { 
  948. case 'SetExpressCheckout': 
  949. $woocommerce_token_api = new WC_Gateway_PayPal_Express_AngellEYE(); 
  950. $woocommerce_token_api->paypal_express_checkout_token_request_handler(); 
  951. break; 
  952. default: 
  953. break; 
  954.  
  955. public function woo_compatibility_notice() { 
  956. echo '<div class="error"><p>' . __('PayPal for WooCommerce requires WooCommerce version 2.6 or higher. Please backup your site files and database, update WooCommerce, and try again.', 'paypal-for-woocommerce') . '</p></div>'; 
  957.  
  958. public function angelleye_express_checkout_decrypt_gateway_api($bool) { 
  959. global $wpdb; 
  960. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'woocommerce_paypal_express_settings' ) ); 
  961. $gateway_settings = isset($row->option_value) ? maybe_unserialize($row->option_value) : array(); 
  962. if( !empty($row->option_value) && !empty($gateway_settings['is_encrypt'])) { 
  963. $gateway_settings_key_array = array('sandbox_api_username', 'sandbox_api_password', 'sandbox_api_signature', 'api_username', 'api_password', 'api_signature'); 
  964. foreach ($gateway_settings_key_array as $gateway_setting_key => $gateway_settings_value) { 
  965. if( !empty( $gateway_settings[$gateway_settings_value]) ) { 
  966. $gateway_settings[$gateway_settings_value] = AngellEYE_Utility::crypting($gateway_settings[$gateway_settings_value], $action = 'd'); 
  967. return $gateway_settings; 
  968. } else { 
  969. return $bool; 
  970. public function angelleye_paypal_advanced_decrypt_gateway_api($bool) { 
  971. global $wpdb; 
  972. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'woocommerce_paypal_advanced_settings' ) ); 
  973. $gateway_settings = isset($row->option_value) ? maybe_unserialize($row->option_value) : array(); 
  974. if( !empty($row->option_value) && !empty($gateway_settings['is_encrypt'])) { 
  975. $gateway_settings_key_array = array('loginid', 'resellerid', 'user', 'password'); 
  976. foreach ($gateway_settings_key_array as $gateway_settings_key => $gateway_settings_value) { 
  977. if( !empty( $gateway_settings[$gateway_settings_value]) ) { 
  978. $gateway_settings[$gateway_settings_value] = AngellEYE_Utility::crypting($gateway_settings[$gateway_settings_value], $action = 'd'); 
  979. return $gateway_settings; 
  980. } else { 
  981. return $bool; 
  982. public function angelleye_paypal_credit_card_rest_decrypt_gateway_api($bool) { 
  983. global $wpdb; 
  984. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'woocommerce_paypal_credit_card_rest_settings' ) ); 
  985. $gateway_settings = isset($row->option_value) ? maybe_unserialize($row->option_value) : array(); 
  986. if( !empty($row->option_value) && !empty($gateway_settings['is_encrypt'])) { 
  987. $gateway_settings_key_array = array('rest_client_id_sandbox', 'rest_secret_id_sandbox', 'rest_client_id', 'rest_secret_id'); 
  988. foreach ($gateway_settings_key_array as $gateway_settings_key => $gateway_settings_value) { 
  989. if( !empty( $gateway_settings[$gateway_settings_value]) ) { 
  990. $gateway_settings[$gateway_settings_value] = AngellEYE_Utility::crypting($gateway_settings[$gateway_settings_value], $action = 'd'); 
  991. return $gateway_settings; 
  992. } else { 
  993. return $bool; 
  994. public function angelleye_paypal_pro_decrypt_gateway_api($bool) { 
  995. global $wpdb; 
  996. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'woocommerce_paypal_pro_settings' ) ); 
  997. $gateway_settings = isset($row->option_value) ? maybe_unserialize($row->option_value) : array(); 
  998. if( !empty($row->option_value) && !empty($gateway_settings['is_encrypt'])) { 
  999. $gateway_settings_key_array = array('sandbox_api_username', 'sandbox_api_password', 'sandbox_api_signature', 'api_username', 'api_password', 'api_signature'); 
  1000. foreach ($gateway_settings_key_array as $gateway_settings_key => $gateway_settings_value) { 
  1001. if( !empty( $gateway_settings[$gateway_settings_value]) ) { 
  1002. $gateway_settings[$gateway_settings_value] = AngellEYE_Utility::crypting($gateway_settings[$gateway_settings_value], $action = 'd'); 
  1003. return $gateway_settings; 
  1004. } else { 
  1005. return $bool; 
  1006. public function angelleye_paypal_pro_payflow_decrypt_gateway_api($bool) { 
  1007. global $wpdb; 
  1008. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'woocommerce_paypal_pro_payflow_settings' ) ); 
  1009. $gateway_settings = isset($row->option_value) ? maybe_unserialize($row->option_value) : array(); 
  1010. if( !empty($row->option_value) && !empty($gateway_settings['is_encrypt'])) { 
  1011. $gateway_settings_key_array = array('sandbox_paypal_vendor', 'sandbox_paypal_password', 'sandbox_paypal_user', 'sandbox_paypal_partner', 'paypal_vendor', 'paypal_password', 'paypal_user', 'paypal_partner'); 
  1012. foreach ($gateway_settings_key_array as $gateway_settings_key => $gateway_settings_value) { 
  1013. if( !empty( $gateway_settings[$gateway_settings_value]) ) { 
  1014. $gateway_settings[$gateway_settings_value] = AngellEYE_Utility::crypting($gateway_settings[$gateway_settings_value], $action = 'd'); 
  1015. return $gateway_settings; 
  1016. } else { 
  1017. return $bool; 
  1018.  
  1019. public function angelleye_express_checkout_woocommerce_enable_guest_checkout($bool) { 
  1020. global $wpdb; 
  1021. if (sizeof(WC()->session) == 0) { 
  1022. return false; 
  1023. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'woocommerce_enable_guest_checkout' ) ); 
  1024. $paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' ); 
  1025. $ec_save_to_account = WC()->session->get( 'ec_save_to_account' ); 
  1026. if( !empty($row->option_value) && $row->option_value == 'yes' && isset($paypal_express_checkout) && !empty($paypal_express_checkout) && isset($ec_save_to_account) && $ec_save_to_account == 'on') { 
  1027. return 'no'; 
  1028. } else { 
  1029. return $bool; 
  1030. public function angelleye_braintree_decrypt_gateway_api($bool) { 
  1031. global $wpdb; 
  1032. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'woocommerce_braintree_settings' ) ); 
  1033. $gateway_settings = isset($row->option_value) ? maybe_unserialize($row->option_value) : array(); 
  1034. if( !empty($row->option_value) && !empty($gateway_settings['is_encrypt'])) { 
  1035. $gateway_settings_key_array = array('sandbox_public_key', 'sandbox_private_key', 'sandbox_merchant_id', 'sandbox_merchant_account_id', 'public_key', 'private_key', 'merchant_id', 'merchant_account_id'); 
  1036. foreach ($gateway_settings_key_array as $gateway_settings_key => $gateway_settings_value) { 
  1037. if( !empty( $gateway_settings[$gateway_settings_value]) ) { 
  1038. $gateway_settings[$gateway_settings_value] = AngellEYE_Utility::crypting($gateway_settings[$gateway_settings_value], $action = 'd'); 
  1039. return $gateway_settings; 
  1040. } else { 
  1041. return $bool; 
  1042.  
  1043. public function angelleye_paypal_for_woocommerce_page_title($page_title) { 
  1044. if (sizeof(WC()->session) == 0) { 
  1045. return $page_title; 
  1046. $paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' ); 
  1047. if ('Checkout' == $page_title && !empty($paypal_express_checkout)) { 
  1048. remove_filter('the_title', array($this, 'angelleye_paypal_for_woocommerce_page_title')); 
  1049. return 'Review Order'; 
  1050. } else { 
  1051. return $page_title;