forked from claudiosanches/wc-itau-shopline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wc-itau-shopline.php
172 lines (147 loc) · 4.61 KB
/
wc-itau-shopline.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
<?php
/**
* Plugin Name: Itau Shopline for WooCommerce
* Plugin URI: https://github.com/claudiosanches/wc-itau-shopline
* Description: Itau Shopline payment gateway for WooCommerce.
* Author: Claudio Sanches
* Author URI: https://claudiosmweb.com
* Version: 1.1.1
* License: GPLv2 or later
* Text Domain: wc-itau-shopline
* Domain Path: /languages
*
* Itau Shopline for WooCommerce is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* Itau Shopline for WooCommerce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Itau Shopline for WooCommerce. If not, see
* <https://www.gnu.org/licenses/gpl-2.0.txt>.
*
* @package WC_Itau_Shopline
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_Itau_Shopline' ) ) :
// Load plugin classes.
include_once dirname( __FILE__ ) . '/includes/wc-class-itau-shopline-cripto.php';
include_once dirname( __FILE__ ) . '/includes/wc-class-itau-shopline-api.php';
include_once dirname( __FILE__ ) . '/includes/wc-class-itau-shopline-sounder.php';
/**
* Itau Shopline for WooCommerce main class.
*/
class WC_Itau_Shopline {
/**
* Plugin version.
*
* @var string
*/
const VERSION = '1.1.1';
/**
* 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 is installed.
if ( class_exists( 'WC_Payment_Gateway' ) && defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.2', '>=' ) ) {
$this->includes();
// Hook to add Itau Shopline 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;
}
/**
* Load the plugin text domain for translation.
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'wc-itau-shopline', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Includes.
*/
private function includes() {
include_once dirname( __FILE__ ) . '/includes/wc-class-itau-shopline-gateway.php';
}
/**
* Get templates path.
*
* @return string
*/
public static function get_templates_path() {
return plugin_dir_path( __FILE__ ) . 'templates/';
}
/**
* Get payment url.
*
* @param string $order_key
*
* @return string
*/
public static function get_payment_url( $order_key ) {
$url = WC()->api_request_url( 'WC_Itau_Shopline_Gateway' );
return add_query_arg( array( 'key' => $order_key ), $url );
}
/**
* Add the gateway to WooCommerce.
*
* @param array $methods WooCommerce payment methods.
*
* @return array Payment methods with Itau Shopline.
*/
public function add_gateway( $methods ) {
$methods[] = 'WC_Itau_Shopline_Gateway';
return $methods;
}
/**
* Dependencies notices.
*/
public function dependencies_notices() {
include_once dirname( __FILE__ ) . '/includes/views/html-notice-woocommerce-missing.php';
}
/**
* Action links.
*
* @param array $links
*
* @return array
*/
public function plugin_action_links( $links ) {
$plugin_links = array();
$plugin_links[] = '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_itau_shopline_gateway' ) ) . '">' . __( 'Settings', 'wc-itau-shopline' ) . '</a>';
return array_merge( $plugin_links, $links );
}
}
// Sounder schedule.
register_activation_hook( __FILE__, array( 'WC_Itau_Shopline_Sounder', 'schedule_event' ) );
// Remove sounder schedule.
register_deactivation_hook( __FILE__, array( 'WC_Itau_Shopline_Sounder', 'clear_scheduled_event' ) );
add_action( 'plugins_loaded', array( 'WC_Itau_Shopline', 'get_instance' ) );
endif;