コード例 #1
0
 /**
  * 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());
     }
 }
コード例 #2
0
 /**
  * Mark the given order as failed and set the order note
  *
  * @since 2.1
  * @param WC_Order $order the order
  * @param string $error_message a message to display inside the "Payment Failed" order note
  */
 private function mark_order_as_failed($order, $error_message)
 {
     $order_note = sprintf(__('Authorize.net AIM Payment Failed (%s)', WC_Authorize_Net_AIM::TEXT_DOMAIN), $error_message);
     // Mark order as failed if not already set, otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
     if ('failed' != $order->status) {
         $order->update_status('failed', $order_note);
     } else {
         $order->add_order_note($order_note);
     }
     SV_WC_Plugin_Compatibility::wc_add_notice(__('An error occurred, please try again or try an alternate form of payment.', WC_Authorize_Net_AIM::TEXT_DOMAIN), 'error');
 }
コード例 #3
0
 /**
  * Adds debug messages to the page as a WC message/error, and / or to the WC Error log
  *
  * @since 2.0
  * @param array $errors error messages to add
  */
 protected function add_debug_message($errors)
 {
     // do nothing when debug mode is off
     if ('off' == $this->debug_mode || empty($errors)) {
         return;
     }
     $message = implode(', ', is_array($errors) ? $errors : array($errors));
     // add debug message to checkout page
     if ('checkout' === $this->debug_mode || 'both' === $this->debug_mode) {
         SV_WC_Plugin_Compatibility::wc_add_notice($message, 'error');
     }
     // add debug message to WC error log
     if ('log' === $this->debug_mode || 'both' === $this->debug_mode) {
         $GLOBALS['wc_braintree']->log($message);
     }
 }
コード例 #4
0
 /**
  * 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;
     }
 }