/** * Adds debug messages to the page as a WC message/error, and/or to the WC Error log * * @since 1.0 * @param string $message message to add * @param string $type how to add the message, options are: * 'message' (styled as WC message), 'error' (styled as WC Error) * @param bool $set_message sets any WC messages/errors provided so they appear on the next page load, useful for displaying messages on the thank you page */ protected function add_debug_message($message, $type = 'message', $set_message = false) { // do nothing when debug mode is off or no message if ('off' == $this->debug_off() || !$message) { return; } // add debug message to woocommerce->errors/messages if checkout or both is enabled if ($this->debug_checkout() && !is_admin()) { if ('message' === $type) { SV_WC_Plugin_Compatibility::wc_add_notice(str_replace("\n", "<br/>", htmlspecialchars($message)), 'notice'); } else { // defaults to error message SV_WC_Plugin_Compatibility::wc_add_notice(str_replace("\n", "<br/>", htmlspecialchars($message)), 'error'); } } // set messages for next page load if ($set_message && (!is_admin() || defined('DOING_AJAX'))) { SV_WC_Plugin_Compatibility::set_messages(); } // add log message to WC logger if log/both is enabled if ($this->debug_log()) { $this->get_plugin()->log($message, $this->get_id()); } }
/** * Handle any actions from the 'My Payment Methods' section on the * 'My Account' page * * @since 1.0 */ public function handle_my_payment_methods_actions() { if (!$this->supports_tokenization()) { throw new SV_WC_Payment_Gateway_Feature_Unsupported_Exception('Payment tokenization not supported by gateway'); } // pre-conditions if (!$this->is_available() || !$this->tokenization_enabled()) { return; } $token = isset($_GET['wc-' . $this->get_id_dasherized() . '-token']) ? trim($_GET['wc-' . $this->get_id_dasherized() . '-token']) : ''; $action = isset($_GET['wc-' . $this->get_id_dasherized() . '-action']) ? $_GET['wc-' . $this->get_id_dasherized() . '-action'] : ''; // process payment method actions if ($token && $action && !empty($_GET['_wpnonce']) && is_user_logged_in()) { // security check if (false === wp_verify_nonce($_GET['_wpnonce'], 'wc-' . $this->get_id_dasherized() . '-token-action')) { SV_WC_Plugin_Compatibility::wc_add_notice(_x('There was an error with your request, please try again.', 'Supports direct payment method tokenization', $this->text_domain), 'error'); SV_WC_Plugin_Compatibility::set_messages(); wp_redirect(get_permalink(woocommerce_get_page_id('myaccount'))); exit; } // current logged in user $user_id = get_current_user_id(); // handle deletion if ('delete' === $action) { if (!$this->remove_payment_token($user_id, $token)) { SV_WC_Plugin_Compatibility::wc_add_notice(_x('Error removing payment method', 'Supports direct payment method tokenization', $this->text_domain), 'error'); SV_WC_Plugin_Compatibility::set_messages(); } else { SV_WC_Plugin_Compatibility::wc_add_notice(_x('Payment method deleted.', 'Supports direct payment method tokenization', $this->text_domain)); } } // handle default change if ('make-default' === $action) { $this->set_default_payment_token($user_id, $token); } // remove the query params wp_redirect(get_permalink(woocommerce_get_page_id('myaccount'))); exit; } }