forked from claudiosanches/woocommerce-pagarme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce-pagarme.php
185 lines (158 loc) · 5.15 KB
/
woocommerce-pagarme.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
<?php
/**
* Plugin Name: Pagar.me for WooCommerce
* Plugin URI: http://github.com/claudiosmweb/woocommerce-pagarme
* Description: Gateway de pagamento Pagar.me para WooCommerce.
* Author: Pagar.me, Claudio Sanches
* Author URI: https://pagar.me/
* Version: 2.0.17
* License: GPLv2 or later
* Text Domain: woocommerce-pagarme
* Domain Path: /languages/
*
* @package WooCommerce_Pagarme
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_Pagarme' ) ) :
/**
* WooCommerce WC_Pagarme main class.
*/
class WC_Pagarme {
/**
* Plugin version.
*
* @var string
*/
const VERSION = '2.0.17';
/**
* Instance of this class.
*
* @var object
*/
protected static $instance = null;
/**
* Initialize the plugin public actions.
*/
private 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->upgrade();
$this->includes();
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, '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;
}
/**
* Includes.
*/
private function includes() {
include_once dirname( __FILE__ ) . '/includes/class-wc-pagarme-api.php';
include_once dirname( __FILE__ ) . '/includes/class-wc-pagarme-my-account.php';
include_once dirname( __FILE__ ) . '/includes/class-wc-pagarme-banking-ticket-gateway.php';
include_once dirname( __FILE__ ) . '/includes/class-wc-pagarme-credit-card-gateway.php';
}
/**
* Load the plugin text domain for translation.
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'woocommerce-pagarme', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Get templates path.
*
* @return string
*/
public static function get_templates_path() {
return plugin_dir_path( __FILE__ ) . 'templates/';
}
/**
* Add the gateway to WooCommerce.
*
* @param array $methods WooCommerce payment methods.
*
* @return array
*/
public function add_gateway( $methods ) {
$methods[] = 'WC_Pagarme_Banking_Ticket_Gateway';
$methods[] = 'WC_Pagarme_Credit_Card_Gateway';
return $methods;
}
/**
* Action links.
*
* @param array $links Plugin links.
*
* @return array
*/
public function plugin_action_links( $links ) {
$plugin_links = array();
$banking_ticket = 'wc_pagarme_banking_ticket_gateway';
$credit_card = 'wc_pagarme_credit_card_gateway';
$plugin_links[] = '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $banking_ticket ) ) . '">' . __( 'Bank Slip Settings', 'woocommerce-pagarme' ) . '</a>';
$plugin_links[] = '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $credit_card ) ) . '">' . __( 'Credit Card Settings', 'woocommerce-pagarme' ) . '</a>';
return array_merge( $plugin_links, $links );
}
/**
* WooCommerce fallback notice.
*/
public function woocommerce_missing_notice() {
include dirname( __FILE__ ) . '/includes/admin/views/html-notice-missing-woocommerce.php';
}
/**
* Upgrade.
*
* @since 2.0.0
*/
private function upgrade() {
if ( is_admin() ) {
if ( $old_options = get_option( 'woocommerce_pagarme_settings' ) ) {
// Banking ticket options.
$banking_ticket = array(
'enabled' => $old_options['enabled'],
'title' => 'Boleto bancário',
'description' => '',
'api_key' => $old_options['api_key'],
'encryption_key' => $old_options['encryption_key'],
'debug' => $old_options['debug'],
);
// Credit card options.
$credit_card = array(
'enabled' => $old_options['enabled'],
'title' => 'Cartão de crédito',
'description' => '',
'api_key' => $old_options['api_key'],
'encryption_key' => $old_options['encryption_key'],
'checkout' => 'no',
'max_installment' => $old_options['max_installment'],
'smallest_installment' => $old_options['smallest_installment'],
'interest_rate' => $old_options['interest_rate'],
'free_installments' => $old_options['free_installments'],
'debug' => $old_options['debug'],
);
update_option( 'woocommerce_pagarme-banking-ticket_settings', $banking_ticket );
update_option( 'woocommerce_pagarme-credit-card_settings', $credit_card );
delete_option( 'woocommerce_pagarme_settings' );
}
}
}
}
add_action( 'plugins_loaded', array( 'WC_Pagarme', 'get_instance' ) );
endif;