PluginProbe
PayPlug for WooCommerce (Official) / 2.0.1
PayPlug for WooCommerce (Official) v2.0.1
3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 101 releases
payplug / src / Admin / Vue.php

Vue.php in PayPlug for WooCommerce (Official) 2.0.1, at src/Admin/Vue.php

453 lines 15.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Payplug\PayplugWoocommerce\Admin;
4
5
6 use Payplug\PayplugWoocommerce\Admin\Vue\Component;
7 use Payplug\PayplugWoocommerce\Admin\Vue\PaymentMethods;
8 use Payplug\PayplugWoocommerce\Controller\ApplePay;
9 use Payplug\PayplugWoocommerce\Gateway\PayplugGateway;
10 use Payplug\PayplugWoocommerce\Gateway\PayplugGatewayRequirements;
11 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
12
13 /**
14 * PayPlug admin Vue.js dashboard handler.
15 *
16 * @package Payplug\PayplugWoocommerce\Admin
17 */
18 class Vue {
19
20 /**
21 * @return array
22 */
23 public function init() {
24
25 if ( PayplugWoocommerceHelper::user_logged_in() ) {
26 $header = $this->payplug_section_header();
27 $logged = $this->payplug_section_logged();
28 $payplug_wooc_settings = get_option( 'woocommerce_payplug_settings', [] );
29 unset($payplug_wooc_settings["payplug_live_key"]);
30
31 return [
32 "payplug_wooc_settings" => $payplug_wooc_settings,
33 "header" => $header,
34 "login" => $this->payplug_section_login(),
35 "logged" => $logged,
36 "payment_methods" => $this->payplug_section_payment_methods($payplug_wooc_settings),
37 "payment_paylater" => $this->payplug_section_paylater($payplug_wooc_settings),
38 "status" => $this->payplug_section_status($payplug_wooc_settings)
39 ];
40 }
41
42 return [
43 "header" => $this->payplug_section_header(),
44 "login" => $this->payplug_section_login(),
45 "subscribe" => $this->payplug_section_subscribe(),
46 "payment_methods" => $this->payplug_section_payment_methods(),
47 "payment_paylater" => $this->payplug_section_paylater(),
48 "status" => $this->payplug_section_status()
49 ];
50 }
51
52 /**
53 * @return array
54 */
55 public function payplug_section_logged() {
56
57 $inactive = false;
58 if( empty(PayplugWoocommerceHelper::get_live_key()) ){
59 $inactive = true;
60 }
61
62 return [
63 "title" => __( 'payplug_section_logged_title', 'payplug' ),
64 "descriptions" => [
65 "live" => [
66 "description" => __( 'payplug_section_logged_description', 'payplug' ),
67 "logout" => __( 'payplug_section_logged_logout', 'payplug' ),
68 "mode" => __( 'payplug_section_logged_mode', 'payplug' ),
69 "mode_description" => __( 'payplug_section_logged_live_description', 'payplug' ),
70 "link_learn_more" => [
71 "text" => __( 'payplug_learn_more', 'payplug' ),
72 "url" => __( 'payplug_mode_learn_more_url', 'payplug' ),
73 "target" => "_blank"
74 ],
75 "link_access_portal" => [
76 "text" => __( 'payplug_section_logged_link_access_portal', 'payplug' ),
77 "url" => "https://www.payplug.com/portal",
78 "target" => "_blank"
79 ],
80 ],
81 "sandbox" => [
82 "description" => __( 'payplug_section_logged_description', 'payplug' ),
83 "logout" => __( 'payplug_section_logged_logout', 'payplug' ),
84 "mode" => __( 'payplug_section_logged_mode', 'payplug' ),
85 "mode_description" => __( 'payplug_section_logged_test_description', 'payplug' ),
86 "link_learn_more" => [
87 "text" => __( 'payplug_learn_more', 'payplug' ),
88 "url" => __( 'payplug_mode_learn_more_url', 'payplug' ),
89 "target" => "_blank"
90 ],
91 "link_access_portal" => [
92 "text" => __( 'payplug_section_logged_link_access_portal', 'payplug' ),
93 "url" => "https://www.payplug.com/portal",
94 "target" => "_blank"
95 ],
96 ]
97 ],
98 "options" => [
99 [
100 "name" => "payplug_sandbox",
101 "label" => "Live",
102 "value" => 0, //live
103 "checked" => PayplugWoocommerceHelper::check_mode()
104 ],
105 [
106 "name" => "payplug_sandbox",
107 "label" => "Test",
108 "value" => 1, //test
109 "checked" => !PayplugWoocommerceHelper::check_mode()
110 ],
111 ],
112 "inactive_modal" => [
113 "inactive" => $inactive,
114 "title" => __( 'payplug_live_mode', 'payplug' ),
115 "description" => __( 'payplug_section_logged_modal_description', 'payplug' ),
116 "password_label" => __( 'payplug_section_login_password_label', 'payplug' ),
117 "cancel" => __( 'payplug_cancel', 'payplug' ),
118 "ok" => __( 'payplug_ok', 'payplug' ),
119 ],
120 "inactive_account" => [
121 "warning" => [
122 "title" => __( 'payplug_inactive_account_warning_title', 'payplug' ),
123 "description" => __( 'payplug_inactive_account_warning_description1', 'payplug' ) .
124 __( 'payplug_inactive_account_warning_description2', 'payplug' ) .
125 __( 'payplug_inactive_account_warning_description3', 'payplug' ),
126 ],
127 "error" => [
128 "title" => __( 'payplug_inactive_account_error_title', 'payplug' ),
129 "description" => __( 'payplug_inactive_account_error_description', 'payplug' ),
130 ]
131 ],
132 ];
133 }
134
135 /**
136 * @return array[]
137 */
138 public function payplug_section_login() {
139
140 $login = [
141 "name" => "generalLogin",
142 "title" => __( 'payplug_section_logged_title', 'payplug' ),
143 "descriptions" => [
144 "live" => [
145 "description" => __( 'payplug_section_login_description', 'payplug' ),
146 "not_registered" => __( 'payplug_section_login_not_registered', 'payplug' ),
147 "connect" => __( 'payplug_section_login_connect', 'payplug' ),
148 "email_label" => __( 'payplug_section_login_email_label', 'payplug' ),
149 "email_placeholder" => __( 'payplug_section_login_email_label', 'payplug' ),
150 "password_label" => __( 'payplug_section_login_password_label', 'payplug' ),
151 "password_placeholder" => __( 'payplug_section_login_password_label', 'payplug' ),
152 "link_forgot_password" => [
153 "text" => __( 'payplug_section_login_forgot_password', 'payplug' ),
154 "url" => "https://www.payplug.com/portal/forgot_password",
155 "target" => "_blank"
156 ],
157 ],
158 "sandbox" => [
159 "description" => __( 'payplug_section_login_description', 'payplug' ),
160 "not_registered" => __( 'payplug_section_login_not_registered', 'payplug' ),
161 "connect" => __( 'payplug_section_login_connect', 'payplug' ),
162 "email_label" => __( 'payplug_section_login_email_label', 'payplug' ),
163 "email_placeholder" => __( 'payplug_section_login_email_label', 'payplug' ),
164 "password_label" => __( 'payplug_section_login_password_label', 'payplug' ),
165 "password_placeholder" => __( 'payplug_section_login_password_label', 'payplug' ),
166 "link_forgot_password" => [
167 "text" => __( 'payplug_section_login_forgot_password', 'payplug' ),
168 "url" => "https://www.payplug.com/portal/forgot_password",
169 "target" => "_blank"
170 ],
171 ]
172 ]
173 ];
174
175 return $login;
176 }
177
178 /**
179 * @return array
180 */
181 public function payplug_section_subscribe() {
182 return [
183 "name" => "generalSubscribe",
184 "title" => __( 'payplug_section_logged_title', 'payplug' ),
185 "descriptions" => [
186 "live" => [
187 "description" => __( 'payplug_section_subscribe_description', 'payplug' ),
188 "link_create_account" => [
189 "text" => __( 'payplug_section_subscribe_link_create_account', 'payplug' ),
190 "url" => "https://portal.payplug.com/signup",
191 "target" => "_blank"
192 ],
193 "content_description" => __( 'payplug_section_subscribe_content_description', 'payplug' ),
194 "already_have_account" => __( 'payplug_section_subscribe_already_have_account', 'payplug' ),
195 ],
196 "sandbox" => [
197 "description" => __( 'payplug_section_subscribe_description', 'payplug' ),
198 "link_create_account" => [
199 "text" => __( 'payplug_section_subscribe_link_create_account', 'payplug' ),
200 "url" => "https://portal.payplug.com/signup",
201 "target" => "_blank"
202 ],
203 "content_description" => __( 'payplug_section_subscribe_content_description', 'payplug' ),
204 "already_have_account" => __( 'payplug_section_subscribe_already_have_account', 'payplug' ),
205 ]
206 ]
207 ];
208 }
209
210 /**
211 * @return array
212 */
213 public function payplug_section_header() {
214 $enable = ( !empty( get_option( 'woocommerce_payplug_settings', [] )['enabled'] ) && get_option( 'woocommerce_payplug_settings', [] )['enabled'] === "yes") ? true : false;
215 $enable = $enable && $this->payplug_requirements();
216 $disabled = !$this->payplug_requirements();
217
218 return [
219 "title" => __( 'payplug_section_header_title', 'payplug' ),
220 "descriptions" => [
221 "live" => [
222 "description" => __( 'payplug_section_header_live_description', 'payplug' ),
223 "plugin_version" => PAYPLUG_GATEWAY_VERSION
224 ],
225 "sandbox" => [
226 "description" => __( 'payplug_section_header_test_description', 'payplug' ),
227 "plugin_version" => PAYPLUG_GATEWAY_VERSION
228 ],
229 ],
230 "options" => [
231 "type" => "select",
232 "name" => "payplug_enable",
233 "disabled" => $disabled,
234 "options" => [
235 [
236 "value" => 1,
237 "label" => __( 'payplug_section_header_enable_label', 'payplug' ),
238 "checked" => $enable === true ? true : false
239 ],
240 [
241 "value" => 0,
242 "label" => __( 'payplug_section_header_disable_label', 'payplug' ),
243 "checked" => $enable === false ? true : false
244 ]
245 ]
246 ]
247 ];
248
249 }
250
251 /**
252 * @return array
253 */
254 public function payplug_section_payment_methods($options = array()) {
255
256 $section = [
257 "name" => "paymentMethodsBlock",
258 "title" => __( 'payplug_section_payment_methods_title', 'payplug' ),
259 "descriptions" => [
260 "live" => [
261 "description" => __( 'payplug_section_payment_methods_description', 'payplug' ),
262 ],
263 "sandbox" => [
264 "description" => __( 'payplug_section_payment_methods_description', 'payplug' ),
265 ]
266 ],
267 "options" => [
268 (new PaymentMethods())->payment_method_standard(),
269 PaymentMethods::payment_method_amex(!empty($options) && $options['american_express'] === 'yes'),
270 PaymentMethods::payment_method_applepay(!empty($options) && $options['apple_pay'] === 'yes'),
271 PaymentMethods::payment_method_bancontact(!empty($options) &&$options['bancontact'] === 'yes')
272 ]
273 ];
274
275 return $section;
276 }
277
278 /**
279 * @param $active
280 *
281 * @return array
282 */
283 public function payplug_section_paylater($options = array() ) {
284
285 $max = !empty($options['oney_thresholds_max']) ? $options['oney_thresholds_max'] : 3000;
286 $min = !empty($options['oney_thresholds_min']) ? $options['oney_thresholds_min'] : 100;
287 $product_page = !empty($options['oney_product_animation']) && $options['oney_product_animation'] === 'yes' ? true : false;
288
289 $section = [
290 "name" => "paymentMethodsBlock",
291 "title" => __( 'payplug_section_paylater_title', 'payplug' ),
292 "descriptions" => [
293 "live" => [
294 "description" => __( 'payplug_section_paylater_description', 'payplug' ),
295 ],
296 "sandbox" => [
297 "description" => __( 'payplug_section_paylater_description', 'payplug' ),
298 ]
299 ],
300 "options" => [
301 "name" => "oney",
302 "title" => __( 'payplug_section_oney_title', 'payplug' ),
303 "image" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/lg-oney.png' ),
304 "checked" => !empty($options) && $options['oney'] === 'yes',
305 "descriptions" => [
306 "live" => [
307 "description" => __( 'payplug_section_paylater_description_oney', 'payplug' ),
308 "link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), "https://support.payplug.com/hc/fr/articles/4408142346002", "_blank"),
309 ],
310 "sandbox" => [
311 "description" => __( 'payplug_section_paylater_description_oney', 'payplug' ),
312 "link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), "https://support.payplug.com/hc/fr/articles/4408142346002", "_blank"),
313 ],
314 "advanced" => [
315 "description" => __( 'payplug_advanced_settings', 'payplug' ),""
316 ]
317 ],
318 "options" => [
319 [
320 "name" => "payplug_oney_type",
321 "className" => "_paylaterLabel",
322 "label" => __( 'payplug_label_with_fees', 'payplug' ),
323 "subText" => __( 'payplug_text_with_fees', 'payplug' ),
324 "value" => "with_fees",
325 "checked" => !empty($options) && $options['oney_type'] === 'with_fees',
326 ],
327 [
328 "name" => "payplug_oney_type",
329 "className" => "_paylaterLabel",
330 "label" => __( 'payplug_label_without_fees', 'payplug' ),
331 "subText" => __( 'payplug_text_without_fees', 'payplug' ),
332 "value" => "without_fees",
333 "checked" => !empty($options) && $options['oney_type'] === 'without_fees',
334 ]
335 ],
336 "advanced_options" => [
337 $this->thresholds_option($max, $min),
338 $this->show_oney_popup_product($product_page)
339 ]
340 ]
341 ];
342
343 return $section;
344 }
345
346 /**
347 * @return array
348 */
349 public function thresholds_option($max, $min) {
350
351 $thresholds = [
352 "name" => "thresholds",
353 "image_url" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/thresholds.jpg' ),
354 "title" => __( 'payplug_thresholds_oney_title', 'payplug' ),
355 "descriptions" => [
356 "description" => __( 'payplug_thresholds_oney_description', 'payplug' ),
357 "min_amount" => [
358 "name" => "oney_min_amounts",
359 "value" => $min,
360 "placeholder" => $min,
361 ],
362 "inter" => __( 'and', 'payplug' ),
363 "max_amount" => [
364 "name" => "oney_max_amounts",
365 "value" => $max,
366 "placeholder" => $max,
367 ],
368 "error" => [
369 "text" => __( 'payplug_thresholds_error_msg', 'payplug' )
370 ]
371 ],
372 "switch" => false
373 ];
374
375 return $thresholds;
376 }
377
378 /**
379 * @param $active
380 *
381 * @return array
382 */
383 public function show_oney_popup_product($active = false) {
384 return [
385 "name" => "oney_product_animation",
386 "image_url" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/product.jpg' ),
387 "title" => __( 'display_the_oney_installments_pop_up_on_the_product_page', 'payplug' ),
388 "descriptions" => [[
389 "description" => __( 'payplug_oney_product_page_description', 'payplug' ),
390 "link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), "https://support.payplug.com/hc/fr/articles/4408142346002", "_blank")
391 ]],
392 "switch" => true,
393 "checked" => $active
394 ];
395 }
396
397
398 /**
399 * @return array
400 */
401 public function payplug_section_status( $options = [] ) {
402 $payplug_requirements = new PayplugGatewayRequirements(new PayplugGateway());
403 $checked = !empty($options['debug']) && $options['debug'] === 'yes' ? true : false;
404
405 $status = [
406 "error" => !$this->payplug_requirements(),
407 "title" => __("payplug_section_status_title", "payplug"),
408 "descriptions" => [
409 "live" => [
410 "description" => __("payplug_section_status_description", "payplug"),
411 "errorMessage" => __("payplug_section_status_errorMessage", "payplug"),
412 "check" => __("payplug_section_status_check", "payplug"),
413 ],
414 "sandbox" => [
415 "description" => __("payplug_section_status_description", "payplug"),
416 "errorMessage" => __("payplug_section_status_errorMessage", "payplug"),
417 "check" => __("payplug_section_status_check", "payplug"),
418 ]
419 ],
420 "requirements" => [
421 $payplug_requirements->curl_requirement(),
422 $payplug_requirements->php_requirement(),
423 $payplug_requirements->openssl_requirement(),
424 $payplug_requirements->currency_requirement(), //MISSING THIS MESSAGES
425 $payplug_requirements->account_requirement(),
426 ],
427 "debug" => [
428 "live" => [
429 "title" => __("payplug_section_status_debug_label", "payplug"),
430 "description" => __("payplug_section_status_debug_description", "payplug"),
431 ],
432 "sandbox" => [
433 "title" => __("payplug_section_status_debug_label", "payplug"),
434 "description" => __("payplug_section_status_debug_description", "payplug"),
435 ]
436 ],
437 "enable_debug_check" => $checked
438 ];
439
440 return $status;
441 }
442
443 /**
444 * check if there's any requirement missing
445 * @return bool
446 */
447 private function payplug_requirements() {
448 $payplug_requirements = new PayplugGatewayRequirements(new PayplugGateway());
449 return $payplug_requirements->satisfy_requirements();
450 }
451
452 }
453