-
Notifications
You must be signed in to change notification settings - Fork 2
/
give-sofort.php
324 lines (274 loc) · 8.04 KB
/
give-sofort.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
<?php
/**
* Plugin Name: Give - Sofort Payment Gateway
* Plugin URI: https://givewp.com/addons/sofort/
* Description: Accept donations with the Sofort payment gateway.
* Version: 1.0
* Author: GiveWP
* Author URI: http://givewp.com
* Text Domain: give-sofort
* Domain Path: /languages
*
* Give Sofort 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 3 of the License, or
* any later version.
*
* Give Sofort 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 Give. If not, see <https://www.gnu.org/licenses/>.
*
* A Tribute to Open Source:
*
* "Open source software is software that can be freely used, changed, and shared (in modified or unmodified form) by anyone. Open
* source software is made by many people, and distributed under licenses that comply with the Open Source Definition."
*
* -- The Open Source Initiative
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'GIVE_SOFORT_VERSION' ) ) {
define( 'GIVE_SOFORT_VERSION', '1.0' );
}
if ( ! defined( 'GIVE_SOFORT_MIN_GIVE_VER' ) ) {
define( 'GIVE_SOFORT_MIN_GIVE_VER', '2.0' );
}
if ( ! defined( 'GIVE_SOFORT_FILE' ) ) {
define( 'GIVE_SOFORT_FILE', __FILE__ );
}
if ( ! defined( 'GIVE_SOFORT_BASENAME' ) ) {
define( 'GIVE_SOFORT_BASENAME', plugin_basename( GIVE_SOFORT_FILE ) );
}
if ( ! defined( 'GIVE_SOFORT_DIR' ) ) {
define( 'GIVE_SOFORT_DIR', plugin_dir_path( GIVE_SOFORT_FILE ) );
}
if ( ! defined( 'GIVE_SOFORT_URL' ) ) {
define( 'GIVE_SOFORT_URL', plugin_dir_url( GIVE_SOFORT_FILE ) );
}
if ( file_exists( GIVE_SOFORT_DIR . 'vendor/autoload.php' ) ) {
require GIVE_SOFORT_DIR . 'vendor/autoload.php';
}
/**
* Class Give_Sofort_Gateway
*/
class Give_Sofort_Gateway {
/**
* @var Give_Sofort_Gateway The one true Give_Sofort_Gateway
*/
private static $instance;
/**
* Notices (array)
*
* @since 1.0.1
*
* @var array
*/
public $notices = array();
/**
* Main Sofort Instance
*
* @since v1.0
* @static var array $instance
* @return Give_Sofort_Gateway()
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new Give_Sofort_Gateway();
self::$instance->setup();
}
return self::$instance;
}
/**
* Setup Give Sofort Gateway.
*
* @since 1.0.1
* @access private
*/
private function setup() {
// 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 );
}
/**
* Init the plugin after plugins_loaded so environment variables are set.
*
* @since 1.0.1
*/
public function init() {
$this->load_plugin_textdomain();
$this->licensing();
if ( ! $this->get_environment_warning() ) {
return;
}
// Actions
$this->activation_banner();
if ( is_admin() ) {
require_once GIVE_SOFORT_DIR . 'includes/admin/plugin-activation.php';
}
// Includes
include_once GIVE_SOFORT_DIR . 'includes/admin/class-admin-settings.php';
include_once GIVE_SOFORT_DIR . 'includes/class-sofort-payment.php';
}
/**
* Load textdomain for translations.
*
* @since 1.0.1
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'give-sofort', false, basename( dirname( __FILE__ ) ) . '/languages/' );
}
/**
* Check plugin environment.
*
* @since 1.0.1
* @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 - Sofort to activate.', 'give-sofort' ), 'https://givewp.com' ) );
$is_working = false;
}
return $is_working;
}
/**
* Check plugin for Give environment.
*
* @since 1.0.1
* @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_SOFORT_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="%s" target="_blank">Give</a> core version %s for the Give - Sofort add-on to activate.', 'give-sofort' ), 'https://givewp.com', GIVE_SOFORT_MIN_GIVE_VER ) );
$is_working = false;
}
return $is_working;
}
/**
* Allow this class and other classes to add notices.
*
* @since 1.0.1
*
* @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.1
*/
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.1
*
* @return bool
*/
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' => GIVE_SOFORT_FILE,
'name' => __( 'Sofort Gateway', 'give-sofort' ),
'version' => GIVE_SOFORT_VERSION,
'settings_url' => admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=sofort' ),
'documentation_url' => 'http://docs.givewp.com/addon-sofort',
'support_url' => 'https://givewp.com/support/',
'testing' => false, // Never leave true.
);
new Give_Addon_Activation_Banner( $args );
}
}
/**
* Implement Give Licensing for Give Sofort Add On.
*
* @since 1.0.1
* @access private
*/
private function licensing() {
if ( class_exists( 'Give_License' ) ) {
new Give_License( GIVE_SOFORT_FILE, 'Sofort', GIVE_SOFORT_VERSION, 'WordImpress' );
}
}
}
/**
* The main function responsible for returning the one true Give_Sofort_Gateway Instance
* to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $sofort = Give_Sofort_Gateway(); ?>
*
* @since v1.0
*
* @return mixed one true Give_Sofort_Gateway Instance
*/
function give_sofort() {
return Give_Sofort_Gateway::instance();
}
give_sofort();