| 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 |
public static function oney_product_animation($status) |
| 171 |
{ |
| 172 |
if ($status) { |
| 173 |
return true; |
| 174 |
} else { |
| 175 |
return false; |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
|