|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class WC_Pagantis_Notices |
|
5
|
|
|
{ |
|
6
|
|
|
|
|
7
|
|
|
//TODO https://wordpress.stackexchange.com/questions/242705/how-to-stop-showing-admin-notice-after-close-button-has-been-clicked |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* WC_Pagantis_Gateway for WooCommerce settings. |
|
11
|
|
|
* |
|
12
|
|
|
* @var $settings |
|
|
|
|
|
|
13
|
|
|
*/ |
|
14
|
|
|
public $settings = array(); |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Customizable configuration options |
|
19
|
|
|
* |
|
20
|
|
|
* @var array $extraConfig |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
private $extraConfig; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Array of allowed currencies with Pagantis |
|
29
|
|
|
* |
|
30
|
|
|
* @var array $allowed_currencies |
|
31
|
|
|
*/ |
|
32
|
|
|
private $allowed_currencies; |
|
33
|
|
|
/** |
|
34
|
|
|
* WC_Pagantis_Notices constructor. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct() |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
require_once dirname(__FILE__) . '/../includes/class-wc-pagantis-config.php'; |
|
40
|
|
|
require_once dirname(__FILE__) . '/../includes/functions.php'; |
|
41
|
|
|
$this->settings = get_option('woocommerce_pagantis_settings'); |
|
|
|
|
|
|
42
|
|
|
$this->extraConfig = WC_Pagantis_Config::getExtraConfig(); |
|
43
|
|
|
$this->allowed_currencies = array('EUR'); |
|
44
|
|
|
add_action('admin_notices', array($this, 'check_plugin_settings')); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Check dependencies. |
|
49
|
|
|
* |
|
50
|
|
|
* @hook admin_notices |
|
51
|
|
|
* @throws Exception |
|
52
|
|
|
*/ |
|
53
|
|
|
public function check_plugin_settings() |
|
54
|
|
|
{ |
|
55
|
|
|
if (!pg_wc_is_screen_correct()) { |
|
56
|
|
|
return; |
|
57
|
|
|
} |
|
58
|
|
|
if ($this->settings['enabled'] !== 'yes') { |
|
59
|
|
|
WC_Admin_Notices::add_custom_notice( |
|
|
|
|
|
|
60
|
|
|
PAGANTIS_PLUGIN_ID, |
|
61
|
|
|
sprintf( |
|
62
|
|
|
// translators: 1: URL to WP plugin page. |
|
63
|
|
|
__('Activate Pagantis to start offering comfortable payments in installments to your clients. <a class="button button-primary" href="%1$s">Activate Pagantis now!</a>', 'pagantis'), |
|
|
|
|
|
|
64
|
|
|
pg_wc_get_pagantis_admin_url() |
|
65
|
|
|
) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ($this->settings['pagantis_public_key'] === '' xor $this->settings['pagantis_private_key'] === '' |
|
70
|
|
|
|| $this->settings['enabled'] === 'yes' |
|
71
|
|
|
) { |
|
72
|
|
|
WC_Admin_Notices::add_custom_notice( |
|
73
|
|
|
PAGANTIS_PLUGIN_ID.'keys_setup', |
|
74
|
|
|
sprintf( |
|
75
|
|
|
// translators: 1: URL to WP plugin page. |
|
76
|
|
|
__('Set your Pagantis merchant keys to start offering comfortable payments in installments <a class="button button-primary" href="%1$s">Go to keys setup</a></p>', 'pagantis'), |
|
77
|
|
|
pg_wc_get_pagantis_admin_url() |
|
78
|
|
|
) |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
if ($this->settings['pagantis_public_key'] === '' xor $this->settings['pagantis_private_key'] === '') { |
|
84
|
|
|
WC_Admin_Notices::add_custom_notice( |
|
85
|
|
|
PAGANTIS_PLUGIN_ID, |
|
86
|
|
|
sprintf( |
|
87
|
|
|
// translators: 1: URL to WP plugin page. |
|
88
|
|
|
__('Check your Pagantis merchant keys to start offering Pagantis as a payment method . <a class="button button-primary" href="%1$s">Go to keys setup</a>', 'pagantis'), |
|
89
|
|
|
pg_wc_get_pagantis_admin_url() |
|
90
|
|
|
) |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if ($this->settings['pagantis_public_key'] === '' || $this->settings['pagantis_private_key'] === '') { |
|
95
|
|
|
WC_Admin_Notices::add_custom_notice( |
|
96
|
|
|
PAGANTIS_PLUGIN_ID.'keys_error', |
|
97
|
|
|
sprintf( |
|
98
|
|
|
// translators: 1: URL to WP plugin page. |
|
99
|
|
|
__('Set your Pagantis merchant Api keys to start offering comfortable payments in installments. <a class="button button-primary" href="%1$s">Go to keys setup.</a>', 'pagantis'), |
|
100
|
|
|
pg_wc_get_pagantis_admin_url() |
|
101
|
|
|
) |
|
102
|
|
|
); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
if ($this->settings['pagantis_public_key'] !== '' xor $this->settings['pagantis_private_key'] !== '') { |
|
106
|
|
|
WC_Admin_Notices::remove_notice(PAGANTIS_PLUGIN_ID.'keys_setup'); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
if ($this->settings['pagantis_public_key'] !== '' || $this->settings['pagantis_private_key'] !== '') { |
|
110
|
|
|
WC_Admin_Notices::remove_notice(PAGANTIS_PLUGIN_ID.'keys_error'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
if (! in_array(get_woocommerce_currency(), $this->allowed_currencies, true)) { |
|
|
|
|
|
|
114
|
|
|
WC_Admin_Settings::add_error(__('Error: Pagantis only can be used in Euros.', 'pagantis')); |
|
|
|
|
|
|
115
|
|
|
$this->settings['enabled'] = 'no'; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
if ($this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'] < '2' |
|
119
|
|
|
|| $this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'] > '12' |
|
120
|
|
|
) { |
|
121
|
|
|
$this->settings['enabled'] = 'no'; |
|
122
|
|
|
|
|
123
|
|
|
WC_Admin_Settings::add_error(__( |
|
124
|
|
|
'Error: Pagantis can be used up to 12 installments please contact your account manager', |
|
125
|
|
|
'pagantis' |
|
126
|
|
|
)); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
if ($this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] < '2' |
|
130
|
|
|
|| $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] > '12' |
|
131
|
|
|
) { |
|
132
|
|
|
WC_Admin_Settings::add_error(__( |
|
133
|
|
|
'Error: Pagantis can be used from 2 installments please contact your account manager', |
|
134
|
|
|
'pagantis' |
|
135
|
|
|
)); |
|
136
|
|
|
} |
|
137
|
|
|
if ($this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] < 0) { |
|
138
|
|
|
WC_Admin_Settings::add_error(__('Error: Pagantis can not be used for free products', 'pagantis')); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|