|
1 | 1 | <?php
|
2 |
| -/** |
3 |
| - * Plugin Name: WooCommerce Moip |
4 |
| - * Plugin URI: https://github.com/claudiosmweb/woocommerce-moip |
5 |
| - * Description: Gateway de pagamento Moip para WooCommerce. |
6 |
| - * Author: claudiosanches |
7 |
| - * Author URI: http://claudiosmweb.com/ |
8 |
| - * Version: 2.2.8 |
9 |
| - * License: GPLv2 or later |
10 |
| - * Text Domain: woocommerce-moip |
11 |
| - * Domain Path: /languages/ |
12 |
| - */ |
13 |
| - |
14 | 2 | if ( ! defined( 'ABSPATH' ) ) {
|
15 |
| - exit; // Exit if accessed directly. |
| 3 | + exit; // Exit if accessed directly |
16 | 4 | }
|
17 | 5 |
|
18 |
| -if ( ! class_exists( 'WC_Moip' ) ) : |
19 |
| - |
20 |
| -/** |
21 |
| - * WooCommerce Moip main class. |
22 |
| - */ |
23 |
| -class WC_Moip { |
24 |
| - |
25 |
| - /** |
26 |
| - * Plugin version. |
27 |
| - * |
28 |
| - * @var string |
29 |
| - */ |
30 |
| - const VERSION = '2.2.8'; |
31 |
| - |
32 |
| - /** |
33 |
| - * Integration id. |
34 |
| - * |
35 |
| - * @var string |
36 |
| - */ |
37 |
| - protected static $gateway_id = 'moip'; |
38 |
| - |
39 |
| - /** |
40 |
| - * Instance of this class. |
41 |
| - * |
42 |
| - * @var object |
43 |
| - */ |
44 |
| - protected static $instance = null; |
45 |
| - |
46 |
| - /** |
47 |
| - * Initialize the plugin actions. |
48 |
| - */ |
49 |
| - public function __construct() { |
50 |
| - // Load plugin text domain |
51 |
| - add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
52 |
| - |
53 |
| - // Checks with WooCommerce is installed. |
54 |
| - if ( class_exists( 'WC_Payment_Gateway' ) ) { |
55 |
| - // Include the WC_Moip_Gateway class. |
56 |
| - include_once 'includes/class-wc-moip-messages.php'; |
57 |
| - include_once 'includes/class-wc-moip-gateway.php'; |
58 |
| - |
59 |
| - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) ); |
60 |
| - add_action( 'wp_ajax_woocommerce_moip_transparent_checkout', array( $this, 'transparent_checkout_ajax' ) ); |
61 |
| - add_action( 'wp_ajax_nopriv_woocommerce_moip_transparent_checkout', array( $this, 'transparent_checkout_ajax' ) ); |
62 |
| - } else { |
63 |
| - add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) ); |
64 |
| - } |
65 |
| - } |
66 |
| - |
67 |
| - /** |
68 |
| - * Return an instance of this class. |
69 |
| - * |
70 |
| - * @return object A single instance of this class. |
71 |
| - */ |
72 |
| - public static function get_instance() { |
73 |
| - // If the single instance hasn't been set, set it now. |
74 |
| - if ( null == self::$instance ) { |
75 |
| - self::$instance = new self; |
76 |
| - } |
77 |
| - |
78 |
| - return self::$instance; |
79 |
| - } |
80 |
| - |
81 |
| - /** |
82 |
| - * Return the gateway id/slug. |
83 |
| - * |
84 |
| - * @return string Gateway id/slug variable. |
85 |
| - */ |
86 |
| - public static function get_gateway_id() { |
87 |
| - return self::$gateway_id; |
88 |
| - } |
89 |
| - |
90 |
| - /** |
91 |
| - * Load the plugin text domain for translation. |
92 |
| - * |
93 |
| - * @return void |
94 |
| - */ |
95 |
| - public function load_plugin_textdomain() { |
96 |
| - $locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-moip' ); |
97 |
| - |
98 |
| - load_textdomain( 'woocommerce-moip', trailingslashit( WP_LANG_DIR ) . 'woocommerce-moip/woocommerce-moip-' . $locale . '.mo' ); |
99 |
| - load_plugin_textdomain( 'woocommerce-moip', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
100 |
| - } |
101 |
| - |
102 |
| - /** |
103 |
| - * Add the gateway to WooCommerce. |
104 |
| - * |
105 |
| - * @param array $methods WooCommerce payment methods. |
106 |
| - * |
107 |
| - * @return array Payment methods with Moip. |
108 |
| - */ |
109 |
| - public function add_gateway( $methods ) { |
110 |
| - $methods[] = 'WC_Moip_Gateway'; |
111 |
| - |
112 |
| - return $methods; |
113 |
| - } |
114 |
| - |
115 |
| - /** |
116 |
| - * Saved by ajax the order information. |
117 |
| - * |
118 |
| - * @return void |
119 |
| - */ |
120 |
| - public function transparent_checkout_ajax() { |
121 |
| - $settings = get_option( 'woocommerce_moip_settings' ); |
122 |
| - |
123 |
| - if ( 'tc' != $settings['api'] ) { |
124 |
| - die(); |
125 |
| - } |
126 |
| - |
127 |
| - check_ajax_referer( 'woocommerce_moip_transparent_checkout', 'security' ); |
128 |
| - |
129 |
| - $method = $_POST['method']; |
130 |
| - $order_id = (int) $_POST['order_id']; |
131 |
| - $order = new WC_Order( $order_id ); |
132 |
| - if ( function_exists( 'WC' ) ) { |
133 |
| - $mailer = WC()->mailer(); |
134 |
| - } else { |
135 |
| - global $woocommerce; |
136 |
| - $mailer = $woocommerce->mailer(); |
137 |
| - } |
138 |
| - |
139 |
| - if ( 'CartaoCredito' == $method ) { |
140 |
| - // Add payment information. |
141 |
| - $status = esc_attr( WC_Moip_Messages::translate_status( $_POST['status'] ) ); |
142 |
| - update_post_meta( $order_id, 'woocommerce_moip_method', esc_attr( $_POST['method'] ) ); |
143 |
| - update_post_meta( $order_id, 'woocommerce_moip_code', esc_attr( $_POST['code'] ) ); |
144 |
| - update_post_meta( $order_id, 'woocommerce_moip_status', $status ); |
145 |
| - |
146 |
| - // Send email with payment information. |
147 |
| - $message_body = '<p>'; |
148 |
| - $message_body .= WC_Moip_Messages::credit_cart_message( $status, $_POST['code'] ); |
149 |
| - $message_body .= '</p>'; |
150 |
| - |
151 |
| - $message = $mailer->wrap_message( |
152 |
| - sprintf( __( 'Order %s received', 'woocommerce-moip' ), $order->get_order_number() ), |
153 |
| - apply_filters( 'woocommerce_moip_thankyou_creditcard_email_message', $message_body, $order_id ) |
154 |
| - ); |
155 |
| - |
156 |
| - $mailer->send( $order->billing_email, sprintf( __( 'Order %s received', 'woocommerce-moip' ), $order->get_order_number() ), $message ); |
157 |
| - } else if ( 'DebitoBancario' == $method ) { |
158 |
| - // Add payment information. |
159 |
| - update_post_meta( $order_id, 'woocommerce_moip_method', esc_attr( $_POST['method'] ) ); |
160 |
| - update_post_meta( $order_id, 'woocommerce_moip_url', esc_url( $_POST['url'] ) ); |
161 |
| - |
162 |
| - // Send email with payment information. |
163 |
| - $url = sprintf( '<p><a class="button" href="%1$s" target="_blank">%1$s</a></p>', esc_url( $_POST['url'] ) ); |
164 |
| - $message_body = '<p>'; |
165 |
| - $message_body .= WC_Moip_Messages::debit_email_message(); |
166 |
| - $message_body .= '</p>'; |
167 |
| - |
168 |
| - $message = $mailer->wrap_message( |
169 |
| - sprintf( __( 'Order %s received', 'woocommerce-moip' ), $order->get_order_number() ), |
170 |
| - apply_filters( 'woocommerce_moip_thankyou_debit_email_message', $message_body, $order_id ) . $url |
171 |
| - ); |
172 |
| - |
173 |
| - $mailer->send( $order->billing_email, sprintf( __( 'Order %s received', 'woocommerce-moip' ), $order->get_order_number() ), $message ); |
174 |
| - } else { |
175 |
| - // Add payment information. |
176 |
| - update_post_meta( $order_id, 'woocommerce_moip_method', esc_attr( $_POST['method'] ) ); |
177 |
| - update_post_meta( $order_id, 'woocommerce_moip_url', esc_url( $_POST['url'] ) ); |
178 |
| - |
179 |
| - // Send email with payment information. |
180 |
| - $url = sprintf( '<p><a class="button" href="%1$s" target="_blank">%1$s</a></p>', esc_url( $_POST['url'] ) ); |
181 |
| - $message_body = '<p>'; |
182 |
| - $message_body .= WC_Moip_Messages::billet_email_message(); |
183 |
| - $message_body .= '</p>'; |
184 |
| - |
185 |
| - $message = $mailer->wrap_message( |
186 |
| - sprintf( __( 'Order %s received', 'woocommerce-moip' ), $order->get_order_number() ), |
187 |
| - apply_filters( 'woocommerce_moip_thankyou_billet_email_message', $message_body, $order_id ) . $url |
188 |
| - ); |
189 |
| - |
190 |
| - $mailer->send( $order->billing_email, sprintf( __( 'Order %s received', 'woocommerce-moip' ), $order->get_order_number() ), $message ); |
191 |
| - } |
192 |
| - |
193 |
| - die(); |
194 |
| - } |
195 |
| - |
196 |
| - /** |
197 |
| - * WooCommerce fallback notice. |
198 |
| - * |
199 |
| - * @return string |
200 |
| - */ |
201 |
| - public function woocommerce_missing_notice() { |
202 |
| - echo '<div class="error"><p>' . sprintf( __( 'WooCommerce Moip Gateway depends on the last version of %s to work!', 'woocommerce-moip' ), '<a href="http://wordpress.org/extend/plugins/woocommerce/">WooCommerce</a>' ) . '</p></div>'; |
203 |
| - } |
204 |
| -} |
205 |
| - |
206 |
| -add_action( 'plugins_loaded', array( 'WC_Moip', 'get_instance' ), 0 ); |
207 |
| - |
208 |
| -endif; |
209 |
| - |
210 |
| -/** |
211 |
| - * Adds support to legacy IPN. |
212 |
| - * |
213 |
| - * @return void |
214 |
| - */ |
215 |
| -function wcmoip_legacy_ipn() { |
216 |
| - if ( isset( $_POST['cod_moip'] ) && ! isset( $_GET['wc-api'] ) ) { |
217 |
| - global $woocommerce; |
218 |
| - |
219 |
| - $woocommerce->payment_gateways(); |
| 6 | +// Update the main file. |
| 7 | +$active_plugins = get_option( 'active_plugins', array() ); |
220 | 8 |
|
221 |
| - do_action( 'woocommerce_api_wc_moip_gateway' ); |
| 9 | +foreach ( $active_plugins as $key => $active_plugin ) { |
| 10 | + if ( strstr( $active_plugin, '/wc-moip.php' ) ) { |
| 11 | + $active_plugins[ $key ] = str_replace( '/wc-moip.php', '/woocommerce-moip.php', $active_plugin ); |
222 | 12 | }
|
223 | 13 | }
|
224 | 14 |
|
225 |
| -add_action( 'init', 'wcmoip_legacy_ipn' ); |
| 15 | +update_option( 'active_plugins', $active_plugins ); |
0 commit comments