WC_Boleto

WooCommerce Boleto main class.

Defined (1)

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

/woocommerce-boleto.php  
  1. class WC_Boleto { 
  2.  
  3. /** 
  4. * Plugin version. 
  5. * @var string 
  6. */ 
  7. const VERSION = '1.5.3'; 
  8.  
  9. /** 
  10. * Instance of this class. 
  11. * @var object 
  12. */ 
  13. protected static $instance = null; 
  14.  
  15. /** 
  16. * Initialize the plugin actions. 
  17. */ 
  18. private function __construct() { 
  19. // Load plugin text domain 
  20. add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); 
  21.  
  22. // Checks with WooCommerce is installed. 
  23. if ( class_exists( 'WC_Payment_Gateway' ) ) { 
  24. // Public includes. 
  25. $this->includes(); 
  26.  
  27. // Admin includes. 
  28. if ( is_admin() ) { 
  29. $this->admin_includes(); 
  30.  
  31. add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) ); 
  32. add_action( 'init', array( __CLASS__, 'add_boleto_endpoint' ) ); 
  33. add_filter( 'template_include', array( $this, 'boleto_template' ), 9999 ); 
  34. add_action( 'woocommerce_view_order', array( $this, 'pending_payment_message' ) ); 
  35. add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); 
  36. } else { 
  37. add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) ); 
  38.  
  39. /** 
  40. * Return an instance of this class. 
  41. * @return object A single instance of this class. 
  42. */ 
  43. public static function get_instance() { 
  44. // If the single instance hasn't been set, set it now. 
  45. if ( null == self::$instance ) { 
  46. self::$instance = new self; 
  47.  
  48. return self::$instance; 
  49.  
  50. /** 
  51. * Get plugin path. 
  52. * @return string 
  53. */ 
  54. public static function get_plugin_path() { 
  55. return plugin_dir_path( __FILE__ ); 
  56.  
  57. /** 
  58. * Load the plugin text domain for translation. 
  59. */ 
  60. public function load_plugin_textdomain() { 
  61. $locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-boleto' ); 
  62.  
  63. load_textdomain( 'woocommerce-boleto', trailingslashit( WP_LANG_DIR ) . 'woocommerce-boleto/woocommerce-boleto-' . $locale . '.mo' ); 
  64. load_plugin_textdomain( 'woocommerce-boleto', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
  65.  
  66. /** 
  67. * Includes. 
  68. */ 
  69. private function includes() { 
  70. include_once 'includes/wc-boleto-functions.php'; 
  71. include_once 'includes/class-wc-boleto-gateway.php'; 
  72.  
  73. /** 
  74. * Includes. 
  75. */ 
  76. private function admin_includes() { 
  77. require_once 'includes/class-wc-boleto-admin.php'; 
  78.  
  79. /** 
  80. * Add the gateway to WooCommerce. 
  81. * @param array $methods WooCommerce payment methods. 
  82. * @return array Payment methods with Boleto. 
  83. */ 
  84. public function add_gateway( $methods ) { 
  85. $methods[] = 'WC_Boleto_Gateway'; 
  86.  
  87. return $methods; 
  88.  
  89. /** 
  90. * Created the boleto endpoint. 
  91. */ 
  92. public static function add_boleto_endpoint() { 
  93. add_rewrite_endpoint( 'boleto', EP_PERMALINK | EP_ROOT ); 
  94.  
  95. /** 
  96. * Plugin activate method. 
  97. */ 
  98. public static function activate() { 
  99. self::add_boleto_endpoint(); 
  100.  
  101. flush_rewrite_rules(); 
  102.  
  103. /** 
  104. * Plugin deactivate method. 
  105. */ 
  106. public static function deactivate() { 
  107. flush_rewrite_rules(); 
  108.  
  109. /** 
  110. * Add custom template page. 
  111. * @param string $template 
  112. * @return string 
  113. */ 
  114. public function boleto_template( $template ) { 
  115. global $wp_query; 
  116.  
  117. if ( isset( $wp_query->query_vars['boleto'] ) ) { 
  118. return self::get_plugin_path() . 'includes/views/html-boleto.php'; 
  119.  
  120. return $template; 
  121.  
  122. /** 
  123. * Gets the boleto URL. 
  124. * @param string $code Boleto code. 
  125. * @return string Boleto URL. 
  126. */ 
  127. public static function get_boleto_url( $code ) { 
  128. $home = home_url( '/' ); 
  129.  
  130. if ( get_option( 'permalink_structure' ) ) { 
  131. $url = trailingslashit( $home ) . 'boleto/' . $code; 
  132. } else { 
  133. $url = add_query_arg( array( 'boleto' => $code ), $home ); 
  134.  
  135. return apply_filters( 'woocommerce_boleto_url', $url, $code, $home ); 
  136.  
  137. /** 
  138. * Display pending payment message in order details. 
  139. * @param int $order_id Order id. 
  140. * @return string Message HTML. 
  141. */ 
  142. public function pending_payment_message( $order_id ) { 
  143. $order = new WC_Order( $order_id ); 
  144.  
  145. if ( 'on-hold' === $order->status && 'boleto' == $order->payment_method ) { 
  146. $html = '<div class="woocommerce-info">'; 
  147. $html .= sprintf( '<a class="button" href="%s" target="_blank" style="display: block !important; visibility: visible !important;">%s</a>', esc_url( wc_boleto_get_boleto_url( $order->order_key ) ), __( 'Pay the Ticket →', 'woocommerce-boleto' ) ); 
  148.  
  149. $message = sprintf( __( '%sAttention!%s Not registered the payment the docket for this product yet.', 'woocommerce-boleto' ), '<strong>', '</strong>' ) . '<br />'; 
  150. $message .= __( 'Please click the following button and pay the Ticket in your Internet Banking.', 'woocommerce-boleto' ) . '<br />'; 
  151. $message .= __( 'If you prefer, print and pay at any bank branch or lottery retailer.', 'woocommerce-boleto' ) . '<br />'; 
  152. $message .= __( 'Ignore this message if the payment has already been made**.', 'woocommerce-boleto' ) . '<br />'; 
  153.  
  154. $html .= apply_filters( 'wcboleto_pending_payment_message', $message, $order ); 
  155.  
  156. $html .= '</div>'; 
  157.  
  158. echo $html; 
  159.  
  160. /** 
  161. * Action links. 
  162. * @param array $links 
  163. * @return array 
  164. */ 
  165. public function plugin_action_links( $links ) { 
  166. $plugin_links = array(); 
  167.  
  168. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) { 
  169. $settings_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_boleto_gateway' ); 
  170. } else { 
  171. $settings_url = admin_url( 'admin.php?page=woocommerce_settings&tab=payment_gateways§ion=WC_Boleto_Gateway' ); 
  172.  
  173. $plugin_links[] = '<a href="' . esc_url( $settings_url ) . '">' . __( 'Settings', 'woocommerce-boleto' ) . '</a>'; 
  174.  
  175. return array_merge( $plugin_links, $links ); 
  176.  
  177. /** 
  178. * WooCommerce fallback notice. 
  179. * @return string 
  180. */ 
  181. public function woocommerce_missing_notice() { 
  182. include_once 'includes/views/html-notice-woocommerce-missing.php';