-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgive-paymoney.php
333 lines (281 loc) · 8.42 KB
/
give-paymoney.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
/**
* Plugin Name: Give - PayUmoney
* Plugin URI: https://github.com/impress-org/give-payumoney
* Description: Process online donations via the PayUmoney payment gateway.
* Author: GiveWP
* Author URI: https://givewp.com
* Version: 1.0.8
* Requires at least: 5.0
* Requires PHP: 7.0
* Text Domain: give-payumoney
* Domain Path: /languages
* GitHub Plugin URI: https://github.com/impress-org/give-payumoney
*/
if ( ! class_exists( 'Give_Payumoney_Gateway' ) ) {
/**
* Class Give_Payumoney_Gateway
*
* @since 1.0
*/
final class Give_Payumoney_Gateway {
/**
* @since 1.0
* @access static
* @var Give_Payumoney_Gateway $instance
*/
static private $instance;
/**
* Notices (array)
*
* @since 1.0
*
* @var array
*/
public $notices = array();
/**
* Get instance
*
* @since 1.0
* @access static
* @return Give_Payumoney_Gateway|static
*/
static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
self::$instance->setup();
}
return self::$instance;
}
/**
* Setup Give PayUmoney.
*
* @since 1.0.0
* @access private
*/
private function setup() {
// Setup constants.
$this->setup_constants();
// Give init hook.
add_action( 'give_init', array( $this, 'init' ), 10 );
add_action( 'admin_init', array( $this, 'check_environment' ), 999 );
add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
}
/**
* Setup constants.
*
* @since 1.0
* @access public
* @return Give_Payumoney_Gateway
*/
public function setup_constants() {
// Global Params.
define( 'GIVE_PAYU_VERSION', '1.0.8' );
define( 'GIVE_PAYU_MIN_GIVE_VER', '2.7.0' );
define( 'GIVE_PAYU_BASENAME', plugin_basename( __FILE__ ) );
define( 'GIVE_PAYU_URL', plugins_url( '/', __FILE__ ) );
define( 'GIVE_PAYU_DIR', plugin_dir_path( __FILE__ ) );
return self::$instance;
}
/**
* Load files.
*
* @since 1.0
* @access public
* @return Give_Payumoney_Gateway
*/
public function init() {
if ( ! $this->get_environment_warning() ) {
return;
}
$this->load_textdomain();
$this->licensing();
$this->activation_banner();
require_once GIVE_PAYU_DIR . 'includes/admin/plugin-activation.php';
// Load helper functions.
require_once GIVE_PAYU_DIR . 'includes/functions.php';
// Load plugin settings.
require_once GIVE_PAYU_DIR . 'includes/admin/admin-settings.php';
// Process payments.
require_once GIVE_PAYU_DIR . 'includes/payment-processing.php';
require_once GIVE_PAYU_DIR . 'includes/lib/class-give-payumoney-api.php';
require_once GIVE_PAYU_DIR . 'includes/filters.php';
require_once GIVE_PAYU_DIR . 'includes/actions.php';
if ( is_admin() ) {
// Add actions.
require_once GIVE_PAYU_DIR . 'includes/admin/actions.php';
}
return self::$instance;
}
/**
* Load the text domain.
*
* @access private
* @since 1.0
*
* @return void
*/
public function load_textdomain() {
// Set filter for plugin's languages directory.
$give_payumoney_lang_dir = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
$give_payumoney_lang_dir = apply_filters( 'give_payumoney_languages_directory', $give_payumoney_lang_dir );
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), 'give-payumoney' );
$mofile = sprintf( '%1$s-%2$s.mo', 'give-payumoney', $locale );
// Setup paths to current locale file
$mofile_local = $give_payumoney_lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/give-payumoney/' . $mofile;
if ( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/give-payumoney folder
load_textdomain( 'give-payumoney', $mofile_global );
} elseif ( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/give-payumoney/languages/ folder
load_textdomain( 'give-payumoney', $mofile_local );
} else {
// Load the default language files
load_plugin_textdomain( 'give-payumoney', false, $give_payumoney_lang_dir );
}
}
/**
* Implement Give Licensing for Give PayUmoney Add On.
*
* @since 1.0.2
* @access private
*/
private function licensing() {
if ( class_exists( 'Give_License' ) ) {
new Give_License( __FILE__, 'PayUmoney Gateway', GIVE_PAYU_VERSION, 'WordImpress' );
}
}
/**
* Check plugin environment.
*
* @since 1.0.0
* @access public
*
* @return bool
*/
public function check_environment() {
// Flag to check whether plugin file is loaded or not.
$is_working = true;
// Load plugin helper functions.
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
/*
Check to see if Give is activated, if it isn't deactivate and show a banner. */
// Check for if give plugin activate or not.
$is_give_active = defined( 'GIVE_PLUGIN_BASENAME' ) ? is_plugin_active( GIVE_PLUGIN_BASENAME ) : false;
if ( empty( $is_give_active ) ) {
// Show admin notice.
$this->add_admin_notice( 'prompt_give_activate', 'error', sprintf( __( '<strong>Activation Error:</strong> You must have the <a href="%s" target="_blank">Give</a> plugin installed and activated for Give - PayUmoney to activate.', 'give-payumoney' ), 'https://givewp.com' ) );
$is_working = false;
}
return $is_working;
}
/**
* Check plugin for Give environment.
*
* @since 1.1.2
* @access public
*
* @return bool
*/
public function get_environment_warning() {
// Flag to check whether plugin file is loaded or not.
$is_working = true;
// Verify dependency cases.
if (
defined( 'GIVE_VERSION' )
&& version_compare( GIVE_VERSION, GIVE_PAYU_MIN_GIVE_VER, '<' )
) {
/*
Min. Give. plugin version. */
// Show admin notice.
$this->add_admin_notice( 'prompt_give_incompatible', 'error', sprintf( __( '<strong>Activation Error:</strong> You must have the <a href="%1$s" target="_blank">Give</a> core version %2$s for the Give - PayUmoney add-on to activate.', 'give-payumoney' ), 'https://givewp.com', GIVE_PAYU_MIN_GIVE_VER ) );
$is_working = false;
}
return $is_working;
}
/**
* Allow this class and other classes to add notices.
*
* @since 1.0
*
* @param $slug
* @param $class
* @param $message
*/
public function add_admin_notice( $slug, $class, $message ) {
$this->notices[ $slug ] = array(
'class' => $class,
'message' => $message,
);
}
/**
* Display admin notices.
*
* @since 1.0
*/
public function admin_notices() {
$allowed_tags = array(
'a' => array(
'href' => array(),
'title' => array(),
'class' => array(),
'id' => array(),
),
'br' => array(),
'em' => array(),
'span' => array(
'class' => array(),
),
'strong' => array(),
);
foreach ( (array) $this->notices as $notice_key => $notice ) {
echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
echo wp_kses( $notice['message'], $allowed_tags );
echo '</p></div>';
}
}
/**
* Show activation banner for this add-on.
*
* @since 1.0
*/
public function activation_banner() {
// Check for activation banner inclusion.
if (
! class_exists( 'Give_Addon_Activation_Banner' )
&& file_exists( GIVE_PLUGIN_DIR . 'includes/admin/class-addon-activation-banner.php' )
) {
include GIVE_PLUGIN_DIR . 'includes/admin/class-addon-activation-banner.php';
}
// Initialize activation welcome banner.
if ( class_exists( 'Give_Addon_Activation_Banner' ) ) {
// Only runs on admin.
$args = array(
'file' => __FILE__,
'name' => esc_html__( 'PayUmoney Gateway', 'give-payumoney' ),
'version' => GIVE_PAYU_VERSION,
'settings_url' => admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=payumoney' ),
'documentation_url' => 'http://docs.givewp.com/addon-payumoney',
'support_url' => 'https://givewp.com/support/',
'testing' => false, // Never leave true.
);
new Give_Addon_Activation_Banner( $args );
}
}
}
function Give_Payumoney_Gateway() {
return Give_Payumoney_Gateway::get_instance();
}
/**
* Returns class object instance.
*
* @since 1.3
*
* @return Give_Payumoney_Gateway bool|object
*/
Give_Payumoney_Gateway();
}