-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwoocommerce-moip.php
More file actions
147 lines (123 loc) · 3.33 KB
/
Copy pathwoocommerce-moip.php
File metadata and controls
147 lines (123 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* Plugin Name: Claudio Sanches - Moip for WooCommerce
* Plugin URI: https://github.com/claudiosanches/woocommerce-moip
* Description: Gateway de pagamento Moip para WooCommerce.
* Author: Claudio Sanches
* Author URI: http://claudiosanches.com/
* Version: 2.3.1
* License: GPLv2 or later
* Text Domain: woocommerce-moip
* Domain Path: /languages/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Moip' ) ) :
/**
* Plugin's main class.
*/
class WC_Moip {
/**
* Plugin version.
*
* @var string
*/
const VERSION = '2.3.1';
/**
* Integration id.
*
* @var string
*/
protected static $gateway_id = 'moip';
/**
* Instance of this class.
*
* @var object
*/
protected static $instance = null;
/**
* Initialize the plugin actions.
*/
public function __construct() {
// Load plugin text domain
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
// Checks with WooCommerce is installed.
if ( class_exists( 'WC_Payment_Gateway' ) ) {
$this->includes();
add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) );
} else {
add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
}
}
/**
* Return an instance of this class.
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Return the gateway id/slug.
*
* @return string Gateway id/slug variable.
*/
public static function get_gateway_id() {
return self::$gateway_id;
}
/**
* Load the plugin text domain for translation.
*/
public function load_plugin_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-moip' );
load_textdomain( 'woocommerce-moip', trailingslashit( WP_LANG_DIR ) . 'woocommerce-moip/woocommerce-moip-' . $locale . '.mo' );
load_plugin_textdomain( 'woocommerce-moip', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Add the gateway to WooCommerce.
*
* @param array $methods WooCommerce payment methods.
*
* @return array Payment methods with Moip.
*/
public function add_gateway( $methods ) {
$methods[] = 'WC_Moip_Gateway';
return $methods;
}
/**
* Includes.
*/
private function includes() {
include_once 'includes/class-wc-moip-messages.php';
include_once 'includes/class-wc-moip-ajax.php';
include_once 'includes/class-wc-moip-gateway.php';
}
/**
* WooCommerce fallback notice.
*
* @return string
*/
public function woocommerce_missing_notice() {
echo '<div class="error"><p>' . sprintf( __( 'Claudio Sanches - Moip for WooCommerce depends on the last version of %s to work!', 'woocommerce-moip' ), '<a href="http://wordpress.org/extend/plugins/woocommerce/">WooCommerce</a>' ) . '</p></div>';
}
}
add_action( 'plugins_loaded', array( 'WC_Moip', 'get_instance' ), 0 );
endif;
/**
* Adds support to legacy IPN.
*
* @return void
*/
function wcmoip_legacy_ipn() {
if ( isset( $_POST['cod_moip'] ) && ! isset( $_GET['wc-api'] ) ) {
global $woocommerce;
$woocommerce->payment_gateways();
do_action( 'woocommerce_api_wc_moip_gateway' );
}
}
add_action( 'init', 'wcmoip_legacy_ipn' );