PluginProbe
PayPlug for WooCommerce (Official) / 3.1.0
PayPlug for WooCommerce (Official) v3.1.0
3.1.0 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 All 102 releases
payplug / src / Admin / Validator.php

Validator.php in PayPlug for WooCommerce (Official) 3.1.0, at src/Admin/Validator.php

216 lines 5.2 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 class Validator
6 {
7 public static function enabled($value)
8 {
9 if ($value == 1) {
10 return true;
11 }
12
13 if ($value == 0) {
14 return false;
15 }
16
17 http_response_code(400);
18 wp_send_json_error(['error' => 'enabled is missing']);
19 }
20
21 public static function mode($value)
22 {
23 if ($value == 1) {
24 return false;
25 }
26
27 if ($value == 0) {
28 return true;
29 }
30
31 http_response_code(400);
32 wp_send_json_error(['error' => 'mode is missing']);
33 }
34
35 public static function payment_method($value)
36 {
37 if (!empty($value) && in_array($value, ['redirect', 'popup', 'integrated'])) {
38 return true;
39 }
40
41 http_response_code(400);
42 wp_send_json_error(['error' => 'payment_method is missing']);
43 }
44
45 public static function debug($value)
46 {
47 if ($value == 1) {
48 return true;
49 }
50
51 if ($value == 0) {
52 return false;
53 }
54
55 http_response_code(400);
56 wp_send_json_error(['error' => 'mode is missing']);
57
58 return false;
59 }
60
61 public static function save_card($value)
62 {
63 if ($value == 1) {
64 return true;
65 }
66
67 if ($value == 0) {
68 return false;
69 }
70
71 http_response_code(400);
72 wp_send_json_error(['error' => 'oneclick is missing']);
73 }
74
75 public static function genericPaymentGateway($value, $payment, $test_mode)
76 {
77 if ($test_mode) {
78 return false;
79 }
80
81 if ($value == 1 || $value) {
82 return true;
83 }
84
85 return false;
86 }
87
88 /**
89 * prevent saving when neither cart and checkout is enabled
90 *
91 * @param $cart
92 * @param $product
93 * @param $checkout
94 *
95 * @return true
96 */
97 public static function applePayPaymentGatewayOptions($apple_pay, $cart, $product, $checkout, $carriers)
98 {
99 if ($apple_pay === false) {
100 return true;
101 }
102
103 if ($cart === false && $product === false && $checkout === false) {
104 http_response_code(200);
105
106 $arr = [
107 'msg' => __('applepay_cart_checkout_option_validation', 'payplug'),
108 'class' => 'error',
109 'title' => __('applepay_cart_checkout_option_validation_title', 'payplug'),
110 'close' => __('payplug_ok', 'payplug'),
111 ];
112
113 wp_send_json_error($arr);
114 }
115
116 if (($cart === true || $product === true) && empty($carriers)) {
117 http_response_code(200);
118
119 $arr = [
120 'msg' => __('applepay_cart_carrier_enabled', 'payplug'),
121 'class' => 'error',
122 'title' => __('applepay_cart_checkout_option_validation_title', 'payplug'),
123 'close' => __('payplug_ok', 'payplug'),
124 ];
125
126 wp_send_json_error($arr);
127 }
128
129 return true;
130 }
131
132 public static function oney($value)
133 {
134 if ($value == 1) {
135 return true;
136 }
137
138 return false;
139
140 http_response_code(400);
141 wp_send_json_error(['error' => 'oney is missing']);
142 }
143
144 public static function oney_type($value)
145 {
146 if (isset($value) && !empty($value)) {
147 if (in_array($value, ['with_fees', 'without_fees'])) {
148 return true;
149 }
150 }
151
152 return false;
153 }
154
155 public static function oney_thresholds($min, $max)
156 {
157 $rmin = 100;
158 $rmax = 3000;
159 if ($min > 99 && $min < $max) {
160 $rmin = $min;
161 }
162
163 if ($max <= 3000 && $max > $min) {
164 $rmax = $max;
165 }
166
167 return ['min' => $rmin, 'max' => $rmax];
168 }
169
170 /**
171 * Reject Scalapay min/max amounts (cents) that are inconsistent, or that widen beyond
172 * what the PayPlug account currently authorizes (also in cents). The merchant can only
173 * narrow the account's range, never widen it.
174 *
175 * @param $min
176 * @param $max
177 * @param $account_min
178 * @param $account_max
179 *
180 * @return array{min: int, max: int}
181 */
182 public static function scalapay_thresholds($min, $max, $account_min, $account_max)
183 {
184 if ($min > $max) {
185 http_response_code(200);
186 wp_send_json_error([
187 'msg' => __('payplug_thresholds_scalapay_error_mintext_msg', 'payplug'),
188 'class' => 'error',
189 'title' => __('payplug_thresholds_scalapay_error_title', 'payplug'),
190 'close' => __('payplug_ok', 'payplug'),
191 ]);
192 }
193
194 if ($min < $account_min || $max > $account_max) {
195 http_response_code(200);
196 wp_send_json_error([
197 'msg' => __('payplug_thresholds_scalapay_error_msg', 'payplug'),
198 'class' => 'error',
199 'title' => __('payplug_thresholds_scalapay_error_title', 'payplug'),
200 'close' => __('payplug_ok', 'payplug'),
201 ]);
202 }
203
204 return ['min' => $min, 'max' => $max];
205 }
206
207 public static function oney_product_animation($status)
208 {
209 if ($status) {
210 return true;
211 } else {
212 return false;
213 }
214 }
215 }
216