-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathiugu-woocommerce.php
executable file
·199 lines (171 loc) · 5.79 KB
/
iugu-woocommerce.php
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/**
* Plugin Name: WooCommerce iugu
* Plugin URI: https://github.com/iugu/iugu-woocommerce
* Description: iugu payment gateway for WooCommerce.
* Author: iugu
* Author URI: https://iugu.com/
* Version: 2.0.2
* License: GPLv2 or later
* Text Domain: iugu-woocommerce
* Domain Path: languages/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_Iugu' ) ) :
/**
* WooCommerce Iugu main class.
*/
class WC_Iugu {
/**
* Plugin version.
*
* @var string
*/
const CLIENT_NAME = 'plugin-iugu-woocommerce';
const CLIENT_VERSION = '2.1.2';
/**
* 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 and WooCommerce Extra Checkout Fields for Brazil is installed.
if ( class_exists( 'WC_Payment_Gateway' ) && class_exists( 'Extra_Checkout_Fields_For_Brazil' ) ) {
$this->includes();
// Hook to add Iugu Gateway to WooCommerce.
add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
} else {
add_action( 'admin_notices', array( $this, 'dependencies_notices' ) );
}
}
/**
* 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;
}
/**
* Get templates path.
*
* @return string
*/
public static function get_templates_path() {
return plugin_dir_path( __FILE__ ) . 'templates/';
}
/**
* Load the plugin text domain for translation.
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'iugu-woocommerce', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Includes.
*/
private function includes() {
include_once 'includes/class-wc-iugu-api.php';
include_once 'includes/class-wc-iugu-bank-slip-gateway.php';
include_once 'includes/class-wc-iugu-credit-card-gateway.php';
include_once 'includes/class-wc-iugu-my-account.php';
if ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) {
// Subscriptions < 2.0.
if ( ! function_exists( 'wcs_create_renewal_order' ) ) {
include_once 'includes/class-wc-iugu-bank-slip-addons-gateway-deprecated.php';
include_once 'includes/class-wc-iugu-credit-card-addons-gateway-deprecated.php';
} else {
include_once 'includes/class-wc-iugu-bank-slip-addons-gateway.php';
include_once 'includes/class-wc-iugu-credit-card-addons-gateway.php';
}
}
}
/**
* Add the gateway to WooCommerce.
*
* @param array $methods WooCommerce payment methods.
*
* @return array Payment methods with Iugu.
*/
public function add_gateway( $methods ) {
if ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) {
if ( ! function_exists( 'wcs_create_renewal_order' ) ) {
$methods[] = 'WC_Iugu_Credit_Card_Addons_Gateway_Deprecated';
$methods[] = 'WC_Iugu_Bank_Slip_Addons_Gateway_Deprecated';
} else {
$methods[] = 'WC_Iugu_Credit_Card_Addons_Gateway';
$methods[] = 'WC_Iugu_Bank_Slip_Addons_Gateway';
}
} else {
$methods[] = 'WC_Iugu_Credit_Card_Gateway';
$methods[] = 'WC_Iugu_Bank_Slip_Gateway';
}
return $methods;
}
/**
* Dependencies notices.
*/
public function dependencies_notices() {
if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
include_once 'includes/views/html-notice-woocommerce-missing.php';
}
if ( ! class_exists( 'Extra_Checkout_Fields_For_Brazil' ) ) {
include_once 'includes/views/html-notice-ecfb-missing.php';
}
}
/**
* Get log.
*
* @return string
*/
public static function get_log_view( $gateway_id ) {
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.2', '>=' ) ) {
return '<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' . esc_attr( $gateway_id ) . '-' . sanitize_file_name( wp_hash( $gateway_id ) ) . '.log' ) ) . '">' . __( 'System status > logs', 'iugu-woocommerce' ) . '</a>';
}
return '<code>woocommerce/logs/' . esc_attr( $gateway_id ) . '-' . sanitize_file_name( wp_hash( $gateway_id ) ) . '.txt</code>';
}
/**
* Action links.
*
* @param array $links
*
* @return array
*/
public function plugin_action_links( $links ) {
$plugin_links = array();
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
$settings_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' );
} else {
$settings_url = admin_url( 'admin.php?page=woocommerce_settings&tab=payment_gateways§ion=' );
}
if ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) {
if ( ! function_exists( 'wcs_create_renewal_order' ) ) {
$credit_card = 'wc_iugu_credit_card_addons_gateway_deprecated';
$bank_slip = 'wc_iugu_bank_slip_addons_gateway_deprecated';
} else {
$credit_card = 'wc_iugu_credit_card_addons_gateway';
$bank_slip = 'wc_iugu_bank_slip_addons_gateway';
}
} else {
$credit_card = 'wc_iugu_credit_card_Gateway';
$bank_slip = 'wc_iugu_bank_slip_gateway';
}
$plugin_links[] = '<a href="' . esc_url( $settings_url . $credit_card ) . '">' . __( 'Credit card settings', 'iugu-woocommerce' ) . '</a>';
$plugin_links[] = '<a href="' . esc_url( $settings_url . $bank_slip ) . '">' . __( 'Bank slip settings', 'iugu-woocommerce' ) . '</a>';
return array_merge( $plugin_links, $links );
}
}
add_action( 'plugins_loaded', array( 'WC_Iugu', 'get_instance' ) );
endif;