コード例 #1
0
 /**
  * Entry method for the Add Payment Method feature flow. Note this is *not*
  * stubbed in the WC_Payment_Gateway abstract class, but is called if the
  * gateway declares support for it.
  *
  * @since 4.0.0
  */
 public function add_payment_method()
 {
     assert($this->supports_add_payment_method());
     $order = $this->get_order_for_add_payment_method();
     try {
         $result = $this->do_add_payment_method_transaction($order);
     } catch (SV_WC_Plugin_Exception $e) {
         $result = array('message' => sprintf(esc_html__('Oops, adding your new payment method failed: %s', 'woocommerce-plugin-framework'), $e->getMessage()), 'success' => false);
     }
     SV_WC_Helper::wc_add_notice($result['message'], $result['success'] ? 'success' : 'error');
     // if successful, redirect to the newly added method
     if ($result['success']) {
         // if this is WooCommerce 2.5.5 or older, redirect to the My Account page
         if (SV_WC_Plugin_Compatibility::is_wc_version_lt_2_6()) {
             $redirect_url = wc_get_page_permalink('myaccount');
             // otherwise, redirect to the Payment Methods page (WC 2.6+)
         } else {
             $redirect_url = wc_get_account_endpoint_url('payment-methods');
         }
         // otherwise, back to the Add Payment Method page
     } else {
         $redirect_url = wc_get_endpoint_url('add-payment-method');
     }
     wp_safe_redirect($redirect_url);
     exit;
 }
 /**
  * Get the "Manage Payment Methods" button HTML
  *
  * @since 4.0.0
  * @return string manage payment methods button html
  */
 protected function get_manage_payment_methods_button_html()
 {
     if (SV_WC_Plugin_Compatibility::is_wc_version_lt_2_6()) {
         $url = wc_get_page_permalink('myaccount') . '#wc-' . $this->get_gateway()->get_plugin()->get_id_dasherized() . '-my-payment-methods';
     } else {
         $url = wc_get_endpoint_url('payment-methods', '', wc_get_page_permalink('myaccount'));
     }
     /**
      * Payment Form Manage Payment Methods Button Text Filter.
      *
      * Allow actors to modify the "manage payment methods" button text rendered
      * on the checkout page.
      *
      * @since 4.0.0
      * @param string $button_text button text
      */
     $html = sprintf('<a class="button" style="float:right;" href="%s">%s</a>', esc_url($url), wp_kses_post(apply_filters('wc_' . $this->get_gateway()->get_id() . '_manage_payment_methods_text', esc_html__('Manage Payment Methods', 'woocommerce-plugin-framework'))));
     /**
      * Payment Gateway Payment Form Manage Payment Methods Button HTML.
      *
      * Filters the HTML rendered for the "Manage Payment Methods" button.
      *
      * @since 4.0.0
      * @param string $html
      * @param \SV_WC_Payment_Gateway_Payment_Form $this payment form instance
      */
     return apply_filters('wc_' . $this->get_gateway()->get_id() . '_payment_form_manage_payment_methods_button_html', $html, $this);
 }
コード例 #3
0
 /**
  * Get a gateway's settings screen section ID.
  *
  * @since 4.4.0
  * @param string $gateway_id the gateway ID
  * @return string
  */
 public function get_payment_gateway_configuration_section($gateway_id)
 {
     // WC 2.6+ uses the gateway ID instead of class name
     if (SV_WC_Plugin_Compatibility::is_wc_version_lt_2_6()) {
         $section = $this->get_gateway_class_name($gateway_id);
     } else {
         $section = $gateway_id;
     }
     return strtolower($section);
 }
 /**
  * Redirect back to the Payment Methods (WC 2.6+) or My Account page
  *
  * @since 4.0.0
  */
 protected function redirect_to_my_account()
 {
     if (SV_WC_Plugin_Compatibility::is_wc_version_lt_2_6()) {
         $url = wc_get_page_permalink('myaccount');
     } else {
         $url = wc_get_account_endpoint_url('payment-methods');
     }
     wp_redirect($url);
     exit;
 }