1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Give - Stripe Core Admin Settings |
4
|
|
|
* |
5
|
|
|
* @since 2.5.0 |
6
|
|
|
* |
7
|
|
|
* @package Give |
8
|
|
|
* @subpackage Stripe Core |
9
|
|
|
* @copyright Copyright (c) 2019, GiveWP |
10
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
// Exit, if accessed directly. |
14
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
15
|
|
|
exit; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
if ( ! class_exists( 'Give_Stripe_Admin_Settings' ) ) { |
19
|
|
|
/** |
20
|
|
|
* Class Give_Stripe_Admin_Settings |
21
|
|
|
* |
22
|
|
|
* @since 2.5.0 |
23
|
|
|
*/ |
24
|
|
|
class Give_Stripe_Admin_Settings { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Single Instance. |
28
|
|
|
* |
29
|
|
|
* @since 2.5.0 |
30
|
|
|
* @access private |
31
|
|
|
* |
32
|
|
|
* @var Give_Stripe_Admin_Settings $instance |
33
|
|
|
*/ |
34
|
|
|
private static $instance; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Section ID. |
38
|
|
|
* |
39
|
|
|
* @since 2.5.0 |
40
|
|
|
* @access private |
41
|
|
|
* |
42
|
|
|
* @var string $section_id |
43
|
|
|
*/ |
44
|
|
|
private $section_id; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Section Label. |
48
|
|
|
* |
49
|
|
|
* @since 2.5.0 |
50
|
|
|
* @access private |
51
|
|
|
* |
52
|
|
|
* @var string $section_label |
53
|
|
|
*/ |
54
|
|
|
private $section_label; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Give_Stripe_Admin_Settings() constructor. |
58
|
|
|
* |
59
|
|
|
* @since 2.5.0 |
60
|
|
|
* @access public |
61
|
|
|
* |
62
|
|
|
* @return void |
|
|
|
|
63
|
|
|
*/ |
64
|
|
|
public function __construct() { |
65
|
|
|
|
66
|
|
|
$this->section_id = 'stripe'; |
67
|
|
|
$this->section_label = __( 'Stripe', 'give' ); |
68
|
|
|
|
69
|
|
|
// Bailout, if not accessed via admin. |
70
|
|
|
if ( ! is_admin() ) { |
71
|
|
|
return; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
add_filter( 'give_get_sections_gateways', array( $this, 'register_sections' ) ); |
75
|
|
|
add_filter( 'give_get_settings_gateways', array( $this, 'register_settings' ) ); |
76
|
|
|
add_filter( 'give_get_sections_advanced', array( $this, 'register_advanced_sections' ) ); |
77
|
|
|
add_filter( 'give_get_settings_advanced', array( $this, 'register_advanced_settings' ), 10, 1 ); |
78
|
|
|
add_action( 'give_admin_field_stripe_connect', array( $this, 'stripe_connect_field' ), 10, 2 ); |
79
|
|
|
add_action( 'give_admin_field_stripe_webhooks', array( $this, 'stripe_webhook_field' ), 10, 2 ); |
80
|
|
|
add_action( 'give_admin_field_stripe_styles_field', array( $this, 'stripe_styles_field' ), 10, 2 ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Register sections. |
85
|
|
|
* |
86
|
|
|
* @since 2.5.0 |
87
|
|
|
* @access public |
88
|
|
|
* |
89
|
|
|
* @param array $sections List of sections. |
90
|
|
|
* |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function register_sections( $sections ) { |
94
|
|
|
$sections['stripe-settings'] = __( 'Stripe Settings', 'give' ); |
95
|
|
|
|
96
|
|
|
return $sections; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Add "Stripe" advanced settings. |
101
|
|
|
* |
102
|
|
|
* @since 2.5.0 |
103
|
|
|
* @access public |
104
|
|
|
* |
105
|
|
|
* @param array $section List of sections. |
106
|
|
|
* |
107
|
|
|
* @return mixed |
108
|
|
|
*/ |
109
|
|
|
public function register_advanced_sections( $section ) { |
110
|
|
|
$section['stripe'] = __( 'Stripe', 'give' ); |
111
|
|
|
|
112
|
|
|
return $section; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Register Stripe Main Settings. |
117
|
|
|
* |
118
|
|
|
* @param array $settings List of setting fields. |
119
|
|
|
* |
120
|
|
|
* @since 2.5.0 |
121
|
|
|
* @access public |
122
|
|
|
* |
123
|
|
|
* @return array |
124
|
|
|
*/ |
125
|
|
|
public function register_settings( $settings ) { |
126
|
|
|
|
127
|
|
|
switch ( give_get_current_setting_section() ) { |
128
|
|
|
|
129
|
|
|
case 'stripe-settings': |
130
|
|
|
// Stripe Admin Settings - Header |
131
|
|
|
$settings = array( |
132
|
|
|
array( |
133
|
|
|
'id' => 'give_title_stripe', |
134
|
|
|
'type' => 'title', |
135
|
|
|
), |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
if ( apply_filters( 'give_stripe_show_connect_button', true ) ) { |
139
|
|
|
// Stripe Admin Settings - Configuration Fields. |
140
|
|
|
$settings[] = array( |
141
|
|
|
'name' => __( 'Stripe Connect', 'give' ), |
142
|
|
|
'desc' => '', |
143
|
|
|
'wrapper_class' => 'give-stripe-connect-tr', |
144
|
|
|
'id' => 'stripe_connect', |
145
|
|
|
'type' => 'stripe_connect', |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* This filter hook is used to add configuration fields like api key, access token, oAuth button, etc. |
151
|
|
|
* |
152
|
|
|
* @since 2.5.0 |
153
|
|
|
* |
154
|
|
|
* @return array |
155
|
|
|
*/ |
156
|
|
|
$settings = apply_filters( 'give_stripe_add_configuration_fields', $settings ); |
157
|
|
|
|
158
|
|
|
$settings[] = array( |
159
|
|
|
'name' => __( 'Stripe Webhooks', 'give' ), |
160
|
|
|
'desc' => '', |
161
|
|
|
'wrapper_class' => 'give-stripe-webhooks-tr', |
162
|
|
|
'id' => 'stripe_webhooks', |
163
|
|
|
'type' => 'stripe_webhooks', |
164
|
|
|
); |
165
|
|
|
|
166
|
|
|
$settings[] = array( |
167
|
|
|
'name' => __( 'Statement Descriptor', 'give' ), |
168
|
|
|
'desc' => __( 'This is the text that appears on your donor\'s bank statements. Statement descriptors are limited to 22 characters, cannot use the special characters <code><</code>, <code>></code>, <code>\'</code>, or <code>"</code>, and must not consist solely of numbers. This is typically the name of your website or organization.', 'give' ), |
169
|
|
|
'id' => 'stripe_statement_descriptor', |
170
|
|
|
'type' => 'text', |
171
|
|
|
'attributes' => array( |
172
|
|
|
'maxlength' => '22', |
173
|
|
|
'placeholder' => get_bloginfo( 'name' ), |
174
|
|
|
), |
175
|
|
|
'default' => get_bloginfo( 'name' ), |
176
|
|
|
); |
177
|
|
|
|
178
|
|
|
$settings[] = array( |
179
|
|
|
'name' => __( 'Collect Billing Details', 'give' ), |
180
|
|
|
'desc' => __( 'This option will enable the billing details section for Stripe which requires the donor\'s address to complete the donation. These fields are not required by Stripe to process the transaction, but you may have the need to collect the data.', 'give' ), |
181
|
|
|
'id' => 'stripe_collect_billing', |
182
|
|
|
'type' => 'checkbox', |
183
|
|
|
); |
184
|
|
|
|
185
|
|
|
$settings[] = array( |
186
|
|
|
'name' => __( 'Credit Card Fields Format', 'give' ), |
187
|
|
|
'desc' => __( 'This option will enable you to show single or multiple credit card fields on your donation form for Stripe Payment Gateway.', 'give' ), |
188
|
|
|
'id' => 'stripe_cc_fields_format', |
189
|
|
|
'wrapper_class' => 'stripe-cc-field-format-settings ' . $this->stripe_modal_checkout_status( 'disabled' ), |
190
|
|
|
'type' => 'radio_inline', |
191
|
|
|
'default' => 'multi', |
192
|
|
|
'options' => array( |
193
|
|
|
'single' => __( 'Single Field', 'give' ), |
194
|
|
|
'multi' => __( 'Multi Field', 'give' ), |
195
|
|
|
), |
196
|
|
|
); |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* This filter hook is used to add fields before Stripe Checkout fields. |
200
|
|
|
* |
201
|
|
|
* @since 2.5.0 |
202
|
|
|
* |
203
|
|
|
* @return array |
204
|
|
|
*/ |
205
|
|
|
$settings = apply_filters( 'give_stripe_add_before_checkout_fields', $settings ); |
206
|
|
|
|
207
|
|
|
$settings[] = array( |
208
|
|
|
'name' => __( 'Enable Stripe Checkout', 'give' ), |
209
|
|
|
'desc' => sprintf( __( 'This option will enable <a href="%s" target="_blank">Stripe\'s modal checkout</a> where the donor will complete the donation rather than the default credit card fields on page.', 'give' ), 'http://docs.givewp.com/stripe-checkout' ), |
210
|
|
|
'id' => 'stripe_checkout_enabled', |
211
|
|
|
'type' => 'checkbox', |
212
|
|
|
); |
213
|
|
|
|
214
|
|
|
$settings[] = array( |
215
|
|
|
'name' => __( 'Checkout Heading', 'give' ), |
216
|
|
|
'desc' => __( 'This is the main heading within the modal checkout. Typically, this is the name of your organization, cause, or website.', 'give' ), |
217
|
|
|
'id' => 'stripe_checkout_name', |
218
|
|
|
'wrapper_class' => 'stripe-checkout-field ' . $this->stripe_modal_checkout_status(), |
219
|
|
|
'default' => get_bloginfo( 'name' ), |
220
|
|
|
'type' => 'text', |
221
|
|
|
); |
222
|
|
|
|
223
|
|
|
$settings[] = array( |
224
|
|
|
'name' => __( 'Stripe Checkout Image', 'give' ), |
225
|
|
|
'desc' => __( 'This image appears in when the Stripe checkout modal window opens and provides better brand recognition that leads to increased conversion rates. The recommended minimum size is a square image at 128x128px. The supported image types are: .gif, .jpeg, and .png.', 'give' ), |
226
|
|
|
'id' => 'stripe_checkout_image', |
227
|
|
|
'wrapper_class' => 'stripe-checkout-field ' . $this->stripe_modal_checkout_status(), |
228
|
|
|
'type' => 'file', |
229
|
|
|
// Optional. |
230
|
|
|
'options' => array( |
231
|
|
|
'url' => false, // Hide the text input for the url. |
232
|
|
|
), |
233
|
|
|
'text' => array( |
234
|
|
|
'add_upload_file_text' => __( 'Add or Upload Image', 'give' ), |
235
|
|
|
), |
236
|
|
|
); |
237
|
|
|
|
238
|
|
|
$settings[] = array( |
239
|
|
|
'name' => __( 'Processing Text', 'give' ), |
240
|
|
|
'desc' => __( 'This text appears briefly after the donor has made a successful donation while Give is confirming the payment with the Stripe API.', 'give' ), |
241
|
|
|
'id' => 'stripe_checkout_processing_text', |
242
|
|
|
'wrapper_class' => 'stripe-checkout-field ' . $this->stripe_modal_checkout_status(), |
243
|
|
|
'default' => __( 'Donation Processing...', 'give' ), |
244
|
|
|
'type' => 'text', |
245
|
|
|
); |
246
|
|
|
|
247
|
|
|
$settings[] = array( |
248
|
|
|
'name' => __( 'Verify Zip Code', 'give' ), |
249
|
|
|
'desc' => __( 'Specify whether Checkout should validate the billing ZIP code of the donor for added fraud protection.', 'give' ), |
250
|
|
|
'id' => 'stripe_checkout_zip_verify', |
251
|
|
|
'wrapper_class' => 'stripe-checkout-field ' . $this->stripe_modal_checkout_status(), |
252
|
|
|
'default' => 'on', |
253
|
|
|
'type' => 'checkbox', |
254
|
|
|
); |
255
|
|
|
|
256
|
|
|
$settings[] = array( |
257
|
|
|
'name' => __( 'Remember Me', 'give' ), |
258
|
|
|
'desc' => __( 'Specify whether to include the option to "Remember Me" for future donations.', 'give' ), |
259
|
|
|
'id' => 'stripe_checkout_remember_me', |
260
|
|
|
'wrapper_class' => 'stripe-checkout-field ' . $this->stripe_modal_checkout_status(), |
261
|
|
|
'default' => 'on', |
262
|
|
|
'type' => 'checkbox', |
263
|
|
|
); |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* This filter hook is used to add fields after Stripe Checkout fields. |
267
|
|
|
* |
268
|
|
|
* @since 2.5.0 |
269
|
|
|
* |
270
|
|
|
* @return array |
271
|
|
|
*/ |
272
|
|
|
$settings = apply_filters( 'give_stripe_add_after_checkout_fields', $settings ); |
273
|
|
|
|
274
|
|
|
$settings[] = array( |
275
|
|
|
'name' => __( 'Stripe Gateway Documentation', 'give' ), |
276
|
|
|
'id' => 'display_settings_docs_link', |
277
|
|
|
'url' => esc_url( 'http://docs.givewp.com/addon-stripe' ), |
278
|
|
|
'title' => __( 'Stripe Gateway Documentation', 'give' ), |
279
|
|
|
'type' => 'give_docs_link', |
280
|
|
|
); |
281
|
|
|
|
282
|
|
|
// Stripe Admin Settings - Footer. |
283
|
|
|
$settings[] = array( |
284
|
|
|
'id' => 'give_title_stripe', |
285
|
|
|
'type' => 'sectionend', |
286
|
|
|
); |
287
|
|
|
break; |
288
|
|
|
} // End switch(). |
289
|
|
|
|
290
|
|
|
return $settings; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Add advanced Stripe settings. |
295
|
|
|
* |
296
|
|
|
* New tab under Settings > Advanced that allows users to use their own API key. |
297
|
|
|
* |
298
|
|
|
* @since 2.5.0 |
299
|
|
|
* @access public |
300
|
|
|
* |
301
|
|
|
* @param array $settings List of settings. |
302
|
|
|
* |
303
|
|
|
* @return array |
304
|
|
|
*/ |
305
|
|
|
public function register_advanced_settings( $settings ) { |
306
|
|
|
|
307
|
|
|
$current_section = give_get_current_setting_section(); |
308
|
|
|
|
309
|
|
|
// Bailout, if stripe is not the current section. |
310
|
|
|
if ( 'stripe' !== $current_section ) { |
311
|
|
|
return $settings; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
$stripe_fonts = give_get_option( 'stripe_fonts', 'google_fonts' ); |
315
|
|
|
|
316
|
|
|
switch ( $current_section ) { |
317
|
|
|
|
318
|
|
|
case 'stripe': |
319
|
|
|
$settings = array( |
320
|
|
|
array( |
321
|
|
|
'id' => 'give_title_stripe_advanced', |
322
|
|
|
'type' => 'title', |
323
|
|
|
), |
324
|
|
|
); |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* This filter hook is used to add setting fields before stripe advanced settings. |
328
|
|
|
* |
329
|
|
|
* @since 2.5.0 |
330
|
|
|
* |
331
|
|
|
* @return array |
332
|
|
|
*/ |
333
|
|
|
$settings = apply_filters( 'give_stripe_before_advanced_setting_fields', $settings ); |
334
|
|
|
|
335
|
|
|
$settings[] = array( |
336
|
|
|
'name' => __( 'Stripe JS Incompatibility', 'give' ), |
337
|
|
|
'desc' => __( 'If your site has problems with processing cards using Stripe JS, check this option to use a fallback method of processing.', 'give' ), |
338
|
|
|
'id' => 'stripe_js_fallback', |
339
|
|
|
'type' => 'checkbox', |
340
|
|
|
); |
341
|
|
|
|
342
|
|
|
$settings[] = array( |
343
|
|
|
'name' => __( 'Stripe Styles', 'give' ), |
344
|
|
|
'desc' => __( 'Edit the properties above to match the look and feel of your WordPress theme. These styles will be applied to Stripe Credit Card fields including Card Number, CVC and Expiration. Any valid CSS property can be defined, however, it must be formatted as JSON, not CSS. For more information on Styling Stripe CC fields please see this <a href="https://stripe.com/docs/stripe-js/reference#element-options" target="_blank">article</a>.', 'give' ), |
345
|
|
|
'id' => 'stripe_styles', |
346
|
|
|
'type' => 'stripe_styles_field', |
347
|
|
|
'css' => 'width: 100%', |
348
|
|
|
); |
349
|
|
|
|
350
|
|
|
$settings[] = array( |
351
|
|
|
'name' => __( 'Stripe Fonts', 'give' ), |
352
|
|
|
'desc' => __( 'Select the type of font you want to load in Stripe Credit Card fields including Card Number, CVC and Expiration. For more information on Styling Stripe CC fields please see this <a href="https://stripe.com/docs/stripe-js/reference#stripe-elements" target="_blank">article</a>.', 'give' ), |
353
|
|
|
'id' => 'stripe_fonts', |
354
|
|
|
'type' => 'radio_inline', |
355
|
|
|
'default' => 'google_fonts', |
356
|
|
|
'options' => array( |
357
|
|
|
'google_fonts' => __( 'Google Fonts', 'give' ), |
358
|
|
|
'custom_fonts' => __( 'Custom Fonts', 'give' ), |
359
|
|
|
), |
360
|
|
|
); |
361
|
|
|
|
362
|
|
|
$settings[] = array( |
363
|
|
|
'name' => __( 'Google Fonts URL', 'give' ), |
364
|
|
|
'desc' => __( 'Please enter the Google Fonts URL which is applied to your theme to have the Stripe Credit Card fields reflect the same fonts.', 'give' ), |
365
|
|
|
'id' => 'stripe_google_fonts_url', |
366
|
|
|
'type' => 'text', |
367
|
|
|
'wrapper_class' => 'give-stripe-google-fonts-wrap ' . ( 'google_fonts' !== $stripe_fonts ? 'give-hidden' : '' ), |
368
|
|
|
); |
369
|
|
|
|
370
|
|
|
$settings[] = array( |
371
|
|
|
'name' => __( 'Custom Fonts', 'give' ), |
372
|
|
|
'desc' => __( 'Edit the font properties above to match the fonts of your WordPress theme. These font properties will be applied to Stripe Credit Card fields including Card Number, CVC and Expiration. However, it must be formatted as JSON, not CSS.', 'give' ), |
373
|
|
|
'wrapper_class' => 'give-stripe-custom-fonts-wrap ' . ( 'custom_fonts' !== $stripe_fonts ? 'give-hidden' : '' ), |
374
|
|
|
'id' => 'stripe_custom_fonts', |
375
|
|
|
'type' => 'textarea', |
376
|
|
|
'default' => '{}', |
377
|
|
|
); |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* This filter hook is used to add setting fields after stripe advanced settings. |
381
|
|
|
* |
382
|
|
|
* @since 2.5.0 |
383
|
|
|
* |
384
|
|
|
* @return array |
385
|
|
|
*/ |
386
|
|
|
$settings = apply_filters( 'give_stripe_after_advanced_setting_fields', $settings ); |
387
|
|
|
|
388
|
|
|
$settings[] = array( |
389
|
|
|
'id' => 'give_title_stripe_advanced', |
390
|
|
|
'type' => 'sectionend', |
391
|
|
|
); |
392
|
|
|
break; |
393
|
|
|
} // End switch(). |
394
|
|
|
|
395
|
|
|
// Output. |
396
|
|
|
return $settings; |
397
|
|
|
|
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* This function return hidden for fields which should get hidden on toggle of modal checkout checkbox. |
402
|
|
|
* |
403
|
|
|
* @param string $status Status - Enabled or Disabled. |
404
|
|
|
* |
405
|
|
|
* @since 2.5.0 |
406
|
|
|
* @access public |
407
|
|
|
* |
408
|
|
|
* @return string |
409
|
|
|
*/ |
410
|
|
|
public function stripe_modal_checkout_status( $status = 'enabled' ) { |
411
|
|
|
|
412
|
|
|
$stripe_checkout = give_stripe_is_checkout_enabled(); |
413
|
|
|
|
414
|
|
|
if ( |
415
|
|
|
( $stripe_checkout && 'disabled' === $status ) || |
416
|
|
|
( ! $stripe_checkout && 'enabled' === $status ) |
417
|
|
|
) { |
418
|
|
|
return 'give-hidden'; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
return ''; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Connect button to connect with Stripe account. |
426
|
|
|
* |
427
|
|
|
* @param string $value Actual value. |
428
|
|
|
* @param string $option_value Option value. |
429
|
|
|
* |
430
|
|
|
* @since 2.5.0 |
431
|
|
|
* @access public |
432
|
|
|
*/ |
433
|
|
|
public function stripe_connect_field( $value, $option_value ) { |
|
|
|
|
434
|
|
|
?> |
435
|
|
|
<tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . esc_attr( $value['wrapper_class'] ) . '"' : ''; ?>> |
436
|
|
|
<th scope="row" class="titledesc"> |
437
|
|
|
<label for="give-stripe-connect"> <?php esc_attr_e( 'Stripe Connection', 'give' ); ?></label> |
438
|
|
|
</th> |
439
|
|
|
<td class="give-forminp give-forminp-api_key"> |
440
|
|
|
<?php |
441
|
|
|
if ( give_stripe_is_connected() ) : |
442
|
|
|
$stripe_user_id = give_get_option( 'give_stripe_user_id' ); |
443
|
|
|
?> |
444
|
|
|
<span id="give-stripe-connect" class="stripe-btn-disabled"><span>Connected</span></span> |
445
|
|
|
<p class="give-field-description"> |
446
|
|
|
<span class="dashicons dashicons-yes" style="color:#25802d;"></span> |
447
|
|
|
<?php |
448
|
|
|
esc_attr_e( 'Stripe is connected.', 'give' ); |
449
|
|
|
$disconnect_confirmation_message = sprintf( |
|
|
|
|
450
|
|
|
/* translators: %s Stripe User ID */ |
451
|
|
|
__( 'Are you sure you want to disconnect Give from Stripe? If disconnected, this website and any others sharing the same Stripe account (%s) that are connected to Give will need to reconnect in order to process payments.', 'give' ), |
452
|
|
|
$stripe_user_id |
453
|
|
|
); |
454
|
|
|
?> |
455
|
|
|
<a href="<?php give_stripe_disconnect_url(); ?>" class="give-stripe-disconnect"> |
456
|
|
|
<?php esc_attr_e( '[Disconnect]', 'give' ); ?> |
457
|
|
|
</a> |
458
|
|
|
</p> |
459
|
|
|
<?php else : ?> |
460
|
|
|
<?php echo give_stripe_connect_button(); ?> |
461
|
|
|
<p class="give-field-description"> |
462
|
|
|
<span class="dashicons dashicons-no" |
463
|
|
|
style="color:red;"></span><?php esc_html_e( 'Stripe is NOT connected.', 'give' ); ?> |
464
|
|
|
</p> |
465
|
|
|
<?php if ( isset( $_GET['error_code'] ) && isset( $_GET['error_message'] ) ) : ?> |
466
|
|
|
<p class="stripe-connect-error"> |
467
|
|
|
<strong><?php echo give_clean( $_GET['error_code'] ); ?>:</strong> <?php echo give_clean( $_GET['error_message'] ); ?> |
468
|
|
|
</p> |
469
|
|
|
<?php endif; ?> |
470
|
|
|
<?php endif; ?> |
471
|
|
|
<?php |
472
|
|
|
if ( ! defined( 'GIVE_STRIPE_VERSION' ) ) { |
473
|
|
|
?> |
474
|
|
|
<p class="give-field-description"> |
475
|
|
|
<?php |
476
|
|
|
echo sprintf( |
477
|
|
|
__( 'The free Stripe payment gateway includes an additional 2%% fee for processing one-time donations. This fee is removed by using the premium <a href="%1$s" target="_blank">Stripe add-on</a> and never applies to subscription donations made through the <a href="%2$s" target="_blank">Recurring Donations add-on</a>. <a href="%3$s" target="_blank">Learn More ></a>', 'give' ), |
478
|
|
|
esc_url( 'https://givewp.com/addons/stripe-gateway/' ), |
479
|
|
|
esc_url( 'https://givewp.com/addons/recurring-donations/' ), |
480
|
|
|
esc_url( 'http://docs.givewp.com/addon-stripe' ) |
481
|
|
|
); |
482
|
|
|
?> |
483
|
|
|
</p> |
484
|
|
|
<?php |
485
|
|
|
} |
486
|
|
|
?> |
487
|
|
|
</td> |
488
|
|
|
</tr> |
489
|
|
|
<?php |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* Stripe Webhook field. |
494
|
|
|
* |
495
|
|
|
* @since 2.5.0 |
496
|
|
|
* |
497
|
|
|
* @param $value |
498
|
|
|
* @param $option_value |
499
|
|
|
*/ |
500
|
|
|
public function stripe_webhook_field( $value, $option_value ) { |
|
|
|
|
501
|
|
|
?> |
502
|
|
|
<tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>> |
503
|
|
|
<th scope="row" class="titledesc"> |
504
|
|
|
<label for=""><?php _e( 'Stripe Webhooks', 'give' ); ?></label> |
505
|
|
|
</th> |
506
|
|
|
|
507
|
|
|
<td class="give-forminp give-forminp-api_key"> |
508
|
|
|
<div class="give-stripe-webhook-sync-wrap"> |
509
|
|
|
<p class="give-stripe-webhook-explanation" style="margin-bottom: 15px;"> |
510
|
|
|
<?php |
511
|
|
|
esc_html_e( 'In order for Stripe to function properly, you must configure your Stripe webhooks.', 'give' ); |
512
|
|
|
echo sprintf( |
513
|
|
|
/* translators: 1. Webhook settings page. */ |
514
|
|
|
__( ' You can visit your <a href="%1$s" target="_blank">Stripe Account Dashboard</a> to add a new webhook. ', 'give' ), |
515
|
|
|
esc_url_raw( 'https://dashboard.stripe.com/account/webhooks' ) |
516
|
|
|
); |
517
|
|
|
esc_html_e( 'Please add a new webhook endpoint for the following URL:', 'give' ); |
518
|
|
|
?> |
519
|
|
|
</p> |
520
|
|
|
<p style="margin-bottom: 15px;"> |
521
|
|
|
<strong><?php echo esc_html__( 'Webhook URL:', 'give' ); ?></strong> |
522
|
|
|
<input style="width: 400px;" type="text" readonly="true" value="<?php echo site_url() . '/?give-listener=stripe'; ?>"/> |
523
|
|
|
</p> |
524
|
|
|
<?php |
525
|
|
|
$webhook_received_on = give_get_option( 'give_stripe_last_webhook_received_timestamp' ); |
526
|
|
|
if ( ! empty( $webhook_received_on ) ) { |
527
|
|
|
$date_time_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); |
528
|
|
|
?> |
529
|
|
|
<p> |
530
|
|
|
<strong><?php esc_html_e( 'Last webhook received on' ); ?></strong> <?php echo date_i18n( esc_html( $date_time_format ), $webhook_received_on ); ?> |
531
|
|
|
</p> |
532
|
|
|
<?php |
533
|
|
|
} |
534
|
|
|
?> |
535
|
|
|
<p> |
536
|
|
|
<?php |
537
|
|
|
echo sprintf( |
538
|
|
|
/* translators: 1. Documentation on webhook setup. */ |
539
|
|
|
__( 'See our <a href="%1$s" target="_blank">documentation</a> for more information.', 'give' ), |
540
|
|
|
esc_url_raw( 'https://givewp.com/documentation/add-ons/recurring-donations/supported-payment-gateways/stripe/ ' ) |
541
|
|
|
); |
542
|
|
|
?> |
543
|
|
|
</p> |
544
|
|
|
</div> |
545
|
|
|
|
546
|
|
|
<p class="give-field-description"> |
547
|
|
|
<?php esc_html_e( 'Stripe webhooks are important to setup so Give can communicate properly with the payment gateway. It is not required to have the sandbox webhooks setup unless you are testing. Note: webhooks cannot be setup on localhost or websites in maintenance mode.', 'give' ); ?> |
548
|
|
|
</p> |
549
|
|
|
</td> |
550
|
|
|
</tr> |
551
|
|
|
<?php |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* Advanced Stripe Styles field to manage theme stylings for Stripe CC fields. |
556
|
|
|
* |
557
|
|
|
* @param array $field_options List of field options. |
558
|
|
|
* @param string $option_value Option value. |
559
|
|
|
* |
560
|
|
|
* @since 2.5.0 |
561
|
|
|
* @access public |
562
|
|
|
* |
563
|
|
|
*/ |
564
|
|
|
public function stripe_styles_field( $field_options, $option_value ) { |
565
|
|
|
|
566
|
|
|
$default_attributes = array( |
567
|
|
|
'rows' => 10, |
568
|
|
|
'cols' => 60, |
569
|
|
|
); |
570
|
|
|
$textarea_attributes = isset( $value['attributes'] ) ? $field_options['attributes'] : array(); |
571
|
|
|
|
572
|
|
|
// Make sure empty textarea have default valid json data so that the textarea doesn't show error. |
573
|
|
|
$base_styles_value = ! empty( $option_value['base'] ) ? trim( $option_value['base'] ) : give_stripe_get_default_base_styles(); |
574
|
|
|
$empty_styles_value = ! empty( $option_value['empty'] ) ? trim( $option_value['empty'] ) : '{}'; |
575
|
|
|
$invalid_styles_value = ! empty( $option_value['invalid'] ) ? trim( $option_value['invalid'] ) : '{}'; |
576
|
|
|
$complete_styles_value = ! empty( $option_value['complete'] ) ? trim( $option_value['complete'] ) : '{}'; |
577
|
|
|
|
578
|
|
|
?> |
579
|
|
|
<tr valign="top" <?php echo ! empty( $field_options['wrapper_class'] ) ? 'class="' . esc_attr( $field_options['wrapper_class'] ) . '"' : ''; ?>> |
580
|
|
|
<th scope="row" class="titledesc"> |
581
|
|
|
<label for="<?php echo esc_html( $field_options['type'] ); ?>"> |
582
|
|
|
<?php echo esc_attr( $field_options['title'] ); ?> |
583
|
|
|
</label> |
584
|
|
|
</th> |
585
|
|
|
<td class="give-forminp give-forminp-<?php echo esc_html( $field_options['type'] ); ?>"> |
586
|
|
|
<div> |
587
|
|
|
<p> |
588
|
|
|
<strong><?php esc_attr_e( 'Base Styles', 'give' ); ?></strong> |
589
|
|
|
</p> |
590
|
|
|
<p> |
591
|
|
|
<textarea |
592
|
|
|
name="stripe_styles[base]" |
593
|
|
|
id="<?php echo esc_attr( $field_options['id'] ) . '_base'; ?>" |
594
|
|
|
style="<?php echo esc_attr( $field_options['css'] ); ?>" |
595
|
|
|
class="<?php echo esc_attr( $field_options['class'] ); ?>" |
596
|
|
|
<?php echo give_get_attribute_str( $textarea_attributes, $default_attributes ); ?> |
597
|
|
|
><?php echo esc_textarea( $base_styles_value ); ?></textarea> |
598
|
|
|
</p> |
599
|
|
|
</div> |
600
|
|
|
<div> |
601
|
|
|
<p> |
602
|
|
|
<strong><?php esc_attr_e( 'Empty Styles', 'give' ); ?></strong> |
603
|
|
|
</p> |
604
|
|
|
<p> |
605
|
|
|
<textarea |
606
|
|
|
name="stripe_styles[empty]" |
607
|
|
|
id="<?php echo esc_attr( $field_options['id'] ) . '_empty'; ?>" |
608
|
|
|
style="<?php echo esc_attr( $field_options['css'] ); ?>" |
609
|
|
|
class="<?php echo esc_attr( $field_options['class'] ); ?>" |
610
|
|
|
<?php echo give_get_attribute_str( $textarea_attributes, $default_attributes ); ?> |
611
|
|
|
> |
612
|
|
|
<?php echo esc_textarea( $empty_styles_value ); ?> |
613
|
|
|
</textarea> |
614
|
|
|
</p> |
615
|
|
|
</div> |
616
|
|
|
<div> |
617
|
|
|
<p> |
618
|
|
|
<strong><?php esc_attr_e( 'Invalid Styles', 'give' ); ?></strong> |
619
|
|
|
</p> |
620
|
|
|
<p> |
621
|
|
|
<textarea |
622
|
|
|
name="stripe_styles[invalid]" |
623
|
|
|
id="<?php echo esc_attr( $field_options['id'] ) . '_invalid'; ?>" |
624
|
|
|
style="<?php echo esc_attr( $field_options['css'] ); ?>" |
625
|
|
|
class="<?php echo esc_attr( $field_options['class'] ); ?>" |
626
|
|
|
<?php echo give_get_attribute_str( $textarea_attributes, $default_attributes ); ?> |
627
|
|
|
> |
628
|
|
|
<?php echo esc_textarea( $invalid_styles_value ); ?> |
629
|
|
|
</textarea> |
630
|
|
|
</p> |
631
|
|
|
</div> |
632
|
|
|
<div> |
633
|
|
|
<p> |
634
|
|
|
<strong><?php esc_attr_e( 'Complete Styles', 'give' ); ?></strong> |
635
|
|
|
</p> |
636
|
|
|
<p> |
637
|
|
|
<textarea |
638
|
|
|
name="stripe_styles[complete]" |
639
|
|
|
id="<?php echo esc_attr( $field_options['id'] ) . '_complete'; ?>" |
640
|
|
|
style="<?php echo esc_attr( $field_options['css'] ); ?>" |
641
|
|
|
class="<?php echo esc_attr( $field_options['class'] ); ?>" |
642
|
|
|
<?php echo give_get_attribute_str( $textarea_attributes, $default_attributes ); ?> |
643
|
|
|
> |
644
|
|
|
<?php echo esc_textarea( $complete_styles_value ); ?> |
645
|
|
|
</textarea> |
646
|
|
|
</p> |
647
|
|
|
</div> |
648
|
|
|
<p class="give-field-description"> |
649
|
|
|
<?php echo $field_options['desc']; ?> |
650
|
|
|
</p> |
651
|
|
|
</td> |
652
|
|
|
</tr> |
653
|
|
|
<?php |
654
|
|
|
} |
655
|
|
|
} |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
new Give_Stripe_Admin_Settings(); |
659
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.