| 1 |
<?php |
| 2 |
|
| 3 |
namespace Payplug\PayplugWoocommerce\Admin\Vue; |
| 4 |
|
| 5 |
use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper; |
| 6 |
|
| 7 |
class PaymentMethods { |
| 8 |
|
| 9 |
/** |
| 10 |
* @param $active |
| 11 |
* |
| 12 |
* @return array |
| 13 |
*/ |
| 14 |
public function payment_method_standard( ) { |
| 15 |
|
| 16 |
$option = (get_option( 'woocommerce_payplug_settings', [] )['payment_method'] != "") ? get_option( 'woocommerce_payplug_settings', [] )['payment_method'] : ""; |
| 17 |
|
| 18 |
$method = [ |
| 19 |
"redirect" => false, |
| 20 |
"popup" => false, |
| 21 |
"integrated" => false, |
| 22 |
]; |
| 23 |
|
| 24 |
switch($option){ |
| 25 |
case "popup" : $method["popup"] = true;break; |
| 26 |
case "integrated" : $method["integrated"] = true;break; |
| 27 |
default: $method["redirect"] = true;break; |
| 28 |
} |
| 29 |
|
| 30 |
return [ |
| 31 |
"type" => "payment_method", |
| 32 |
"name" => "standard", |
| 33 |
"title" => __( 'payplug_section_standard_payment_title', 'payplug' ), |
| 34 |
"image" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/standard.svg' ), |
| 35 |
"checked" => true, |
| 36 |
"hide" => true, |
| 37 |
"available_test_mode" => true, |
| 38 |
"descriptions" => [ |
| 39 |
"live" => [ |
| 40 |
"description" => __( 'payplug_section_standard_payment_description', 'payplug' ), |
| 41 |
"advanced_options" => __( 'payplug_section_standard_payment_advanced_options_label', 'payplug' ), |
| 42 |
], |
| 43 |
"sandbox" => [ |
| 44 |
"description" => __( 'payplug_section_standard_payment_description', 'payplug' ), |
| 45 |
"advanced_options" => __( 'payplug_section_standard_payment_advanced_options_label', 'payplug' ), |
| 46 |
] |
| 47 |
], |
| 48 |
"options" => [ |
| 49 |
$this->title_field(), |
| 50 |
$this->description_field(), |
| 51 |
$this->embeded_option($method), |
| 52 |
$this->standard_warning_message(), |
| 53 |
$this->one_click_option() |
| 54 |
], |
| 55 |
]; |
| 56 |
} |
| 57 |
|
| 58 |
private function description_field(){ |
| 59 |
$description = get_option( 'woocommerce_payplug_settings', [] )['description']; |
| 60 |
return array( |
| 61 |
"type" => "payment_option", |
| 62 |
"sub_type" => "input", |
| 63 |
"name" => "standard_payment_description", |
| 64 |
"title" => __("payplug_standard_payment_description_title", "payplug"), |
| 65 |
"value" => $description ?: null, |
| 66 |
"descriptions" => [ |
| 67 |
"live" => [ |
| 68 |
"description" => __("payplug_standard_payment_description_description", "payplug"), |
| 69 |
"placeholder" => __("payplug_standard_payment_description_placeholder", "payplug"), |
| 70 |
], |
| 71 |
"sandbox" => [ |
| 72 |
"description" => __("payplug_standard_payment_description_description", "payplug"), |
| 73 |
"placeholder" => __("payplug_standard_payment_description_placeholder", "payplug"), |
| 74 |
] |
| 75 |
] |
| 76 |
); |
| 77 |
} |
| 78 |
private function title_field(){ |
| 79 |
$title = get_option( 'woocommerce_payplug_settings', [] )['title']; |
| 80 |
return array( |
| 81 |
"type" => "payment_option", |
| 82 |
"sub_type" => "input", |
| 83 |
"name" => "standard_payment_title", |
| 84 |
"title" => __("payplug_standard_payment_title_title", "payplug"), |
| 85 |
"value" => !empty($title) ? $title : __("payplug_standard_payment_title_placeholder", "payplug"), |
| 86 |
"descriptions" => [ |
| 87 |
"live" => [ |
| 88 |
"description" => __("payplug_standard_payment_title_description", "payplug"), |
| 89 |
"placeholder" => __("payplug_standard_payment_title_placeholder", "payplug"), |
| 90 |
], |
| 91 |
"sandbox" => [ |
| 92 |
"description" => __("payplug_standard_payment_title_description", "payplug"), |
| 93 |
"placeholder" => __("payplug_standard_payment_title_placeholder", "payplug"), |
| 94 |
] |
| 95 |
], |
| 96 |
); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* @param $active |
| 101 |
* |
| 102 |
* @return array|bool[]|false[] |
| 103 |
*/ |
| 104 |
public function standard_warning_message( $active = null ) { |
| 105 |
$arr = [ |
| 106 |
"type" => "warning_message", |
| 107 |
"sub_type" => "warning", |
| 108 |
"name" => "warning_message", |
| 109 |
"payment_method" => "integrated", |
| 110 |
"description" => __( 'payplug_section_standard_ip_warning', 'payplug' ) |
| 111 |
]; |
| 112 |
|
| 113 |
return $arr; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* @param $active |
| 118 |
* |
| 119 |
* @return array|bool[]|false[] |
| 120 |
*/ |
| 121 |
public function one_click_option( $active = null ) { |
| 122 |
$option = [ |
| 123 |
"type" => "payment_option", |
| 124 |
"sub_type" => "switch", |
| 125 |
"name" => "one_click", |
| 126 |
"title" => __( 'payplug_section_one_click_option_title', 'payplug' ), |
| 127 |
"descriptions" => [ |
| 128 |
"live" => [ |
| 129 |
"description" => __( 'payplug_section_one_click_option_description', 'payplug' ), |
| 130 |
"link_know_more" => Component::link( |
| 131 |
__( 'payplug_know_more_label', 'payplug' ), |
| 132 |
"https://support.payplug.com/hc/en-gb/articles/4409698334098", |
| 133 |
"_blank" ), |
| 134 |
], |
| 135 |
"sandbox" => [ |
| 136 |
"description" => __( 'payplug_section_one_click_option_description', 'payplug' ), |
| 137 |
"link_know_more" => Component::link( |
| 138 |
__( 'payplug_know_more_label', 'payplug' ), |
| 139 |
"https://support.payplug.com/hc/en-gb/articles/4409698334098", |
| 140 |
"_blank" ), |
| 141 |
] |
| 142 |
] |
| 143 |
]; |
| 144 |
if (isset(get_option( 'woocommerce_payplug_settings', [] )['oneclick'])) { |
| 145 |
if (get_option( 'woocommerce_payplug_settings', [] )['oneclick'] != 'no') { |
| 146 |
$option = $option + ["checked" => true]; |
| 147 |
} elseif (get_option( 'woocommerce_payplug_settings', [] )['oneclick'] == 'no') { |
| 148 |
$option = $option + ["checked" => false]; |
| 149 |
} |
| 150 |
|
| 151 |
} |
| 152 |
return $option; |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* @return array |
| 157 |
*/ |
| 158 |
public function embeded_option($method) { |
| 159 |
|
| 160 |
$options = Array( |
| 161 |
array( |
| 162 |
"name" => "payplug_embedded", |
| 163 |
"label" => __( 'payplug_section_standard_payment_option_integrated_label', 'payplug' ), |
| 164 |
"value" => "integrated", |
| 165 |
"checked" => $method['integrated'] |
| 166 |
), |
| 167 |
array( |
| 168 |
"name" => "payplug_embedded", |
| 169 |
"label" => __( 'payplug_section_standard_payment_option_popup_label', 'payplug' ), |
| 170 |
"value" => "popup", |
| 171 |
"checked" => $method['popup'] |
| 172 |
), |
| 173 |
array( |
| 174 |
"name" => "payplug_embedded", |
| 175 |
"label" => __( 'payplug_section_standard_payment_option_redirected_label', 'payplug' ), |
| 176 |
"value" => "redirect", |
| 177 |
"checked" => $method['redirect'] |
| 178 |
) |
| 179 |
); |
| 180 |
|
| 181 |
return [ |
| 182 |
"type" => "payment_option", |
| 183 |
"sub_type" => "IOptions", |
| 184 |
"name" => "embeded", |
| 185 |
"title" => __( 'payplug_section_standard_payment_option_title', 'payplug' ), |
| 186 |
"descriptions" => [ |
| 187 |
"live" => [ |
| 188 |
"description_redirect" => __( 'payplug_section_standard_payment_redirected_description', 'payplug' ), |
| 189 |
"description_popup" => __( 'payplug_section_standard_payment_popup_description', 'payplug' ), |
| 190 |
"description_integrated" => __( 'payplug_section_standard_payment_integrated_description', 'payplug' ), |
| 191 |
"link_know_more" => Component::link( |
| 192 |
__( 'payplug_know_more_label', 'payplug' ), |
| 193 |
__( 'payplug_embeded_option_url', 'payplug' ), |
| 194 |
"_blank" ), |
| 195 |
], |
| 196 |
"sandbox" => [ |
| 197 |
"description_redirect" => __( 'payplug_section_standard_payment_redirected_description', 'payplug' ), |
| 198 |
"description_popup" => __( 'payplug_section_standard_payment_popup_description', 'payplug' ), |
| 199 |
"description_integrated" => __( 'payplug_section_standard_payment_integrated_description', 'payplug' ), |
| 200 |
"link_know_more" => Component::link( |
| 201 |
__( 'payplug_know_more_label', 'payplug' ), |
| 202 |
__( 'payplug_embeded_option_url', 'payplug' ), |
| 203 |
"_blank" ), |
| 204 |
] |
| 205 |
], |
| 206 |
"options" => $options |
| 207 |
]; |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* @param $active |
| 212 |
* |
| 213 |
* @return array |
| 214 |
*/ |
| 215 |
public static function payment_method_applepay( $active, $options, $carriers = [] ) { |
| 216 |
|
| 217 |
$checkout = $cart = false; |
| 218 |
|
| 219 |
if( !empty($options['applepay_checkout']) && ($options['applepay_checkout'] == "yes" ) ){ |
| 220 |
$checkout = true; |
| 221 |
} |
| 222 |
|
| 223 |
if( !empty($options['applepay_cart']) && ($options['applepay_cart'] == "yes" ) ){ |
| 224 |
$cart = true; |
| 225 |
} |
| 226 |
|
| 227 |
if( $active === true && !$checkout && !$cart ){ |
| 228 |
$checkout = true; |
| 229 |
} |
| 230 |
|
| 231 |
return [ |
| 232 |
"type" => "payment_method", |
| 233 |
"name" => "applepay", |
| 234 |
"title" => __( 'payplug_section_applepay_payment_title', 'payplug' ), |
| 235 |
"image" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/applepay.svg' ), |
| 236 |
"checked" => $active, |
| 237 |
"available_test_mode" => false, |
| 238 |
"descriptions" => [ |
| 239 |
"live" => [ |
| 240 |
"description" => __( 'payplug_section_applepay_payment_description', 'payplug' ), |
| 241 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_applepay_more_url', 'payplug' ), "_blank"), |
| 242 |
], |
| 243 |
"sandbox" => [ |
| 244 |
"description" => __( 'payplug_applepay_unavailable_testmode_description', 'payplug' ), |
| 245 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_applepay_more_url', 'payplug' ), "_blank"), |
| 246 |
] |
| 247 |
], |
| 248 |
"options" => |
| 249 |
[ |
| 250 |
[ |
| 251 |
"type" => "payment_option", |
| 252 |
"sub_type" => "IOptions", |
| 253 |
"name" => "applepay_display", |
| 254 |
"title" => __( 'applepay_display_choice_title', 'payplug' ), |
| 255 |
"options" => |
| 256 |
[ |
| 257 |
[ |
| 258 |
"name" => "applepay_checkout", |
| 259 |
"title" => __( 'applepay_display_checkout', 'payplug' ), |
| 260 |
"image_url" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/cart/applepay_checkout.svg' ), |
| 261 |
"label" => __( 'applepay_display_checkout', 'payplug' ), |
| 262 |
"value" => "checkout", |
| 263 |
"switch" => true, |
| 264 |
"checked" => $checkout || ($active && !$cart) |
| 265 |
], |
| 266 |
[ |
| 267 |
"name" => "applepay_cart", |
| 268 |
"title" => __( 'applepay_display_cart', 'payplug' ), |
| 269 |
"image_url" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/cart/applepay_cart.svg' ), |
| 270 |
"label" => __( 'applepay_display_cart', 'payplug' ), |
| 271 |
"value" => "cart", |
| 272 |
"switch" => true, |
| 273 |
"checked" => $cart |
| 274 |
] |
| 275 |
], |
| 276 |
"carriers" => |
| 277 |
[ |
| 278 |
"title" => __( 'applepay_active_carriers_title', 'payplug' ), |
| 279 |
"alert" => __( 'applepay_active_carriers_alert', 'payplug' ), |
| 280 |
"descriptions" => [ |
| 281 |
"live" => [ |
| 282 |
"description" => __( 'applepay_active_carriers_description', 'payplug' ), |
| 283 |
"description_bold" => __( 'applepay_active_carriers_description_bold', 'payplug' ), |
| 284 |
"description_warning" => __( 'applepay_active_carriers_description_warning', 'payplug' ), |
| 285 |
], |
| 286 |
"sandbox" => [] |
| 287 |
], |
| 288 |
"instructions" => __( 'applepay_active_carriers_instructions', 'payplug' ), |
| 289 |
"carriers_list" => PayplugWoocommerceHelper::available_shipping_methods($carriers), |
| 290 |
|
| 291 |
] |
| 292 |
] |
| 293 |
] |
| 294 |
]; |
| 295 |
} |
| 296 |
|
| 297 |
/** |
| 298 |
* @param $active |
| 299 |
* |
| 300 |
* @return array |
| 301 |
*/ |
| 302 |
public static function payment_method_bancontact( $active = false ) { |
| 303 |
return [ |
| 304 |
"type" => "payment_method", |
| 305 |
"name" => "bancontact", |
| 306 |
"title" => __( 'payplug_section_bancontact_payment_title', 'payplug' ), |
| 307 |
"image" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/bancontact.svg' ), |
| 308 |
"checked" => $active, |
| 309 |
"available_test_mode" => false, |
| 310 |
"descriptions" => [ |
| 311 |
"live" => [ |
| 312 |
"description" => __( 'payplug_section_bancontact_payment_description', 'payplug' ), |
| 313 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_bancontact_more_url', 'payplug' ), "_blank"), |
| 314 |
], |
| 315 |
"sandbox" => [ |
| 316 |
"description" => __( 'payplug_bancontact_unavailable_testmode_description', 'payplug' ), |
| 317 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_bancontact_more_url', 'payplug' ), "_blank"), |
| 318 |
] |
| 319 |
], |
| 320 |
]; |
| 321 |
} |
| 322 |
|
| 323 |
/** |
| 324 |
* @param $active |
| 325 |
* |
| 326 |
* @return array |
| 327 |
*/ |
| 328 |
public static function payment_method_amex( $active = false ) { |
| 329 |
return [ |
| 330 |
"type" => "payment_method", |
| 331 |
"name" => "american_express", |
| 332 |
"title" => __( 'payplug_section_american_express_payment_title', 'payplug' ), |
| 333 |
"image" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/Amex_logo_color.svg' ), |
| 334 |
"checked" => $active, |
| 335 |
"available_test_mode" => false, |
| 336 |
"descriptions" => [ |
| 337 |
"live" => [ |
| 338 |
"description" => __( 'payplug_section_american_express_payment_description', 'payplug' ), |
| 339 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_amex_more_url', 'payplug' ), "_blank"), |
| 340 |
], |
| 341 |
"sandbox" => [ |
| 342 |
"description" => __( 'payplug_amex_unavailable_testmode_description', 'payplug' ), |
| 343 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_amex_more_url', 'payplug' ), "_blank"), |
| 344 |
] |
| 345 |
], |
| 346 |
]; |
| 347 |
} |
| 348 |
|
| 349 |
/** |
| 350 |
* @param $active |
| 351 |
* @return array |
| 352 |
*/ |
| 353 |
public static function payment_method_satispay( $active = false ) { |
| 354 |
return [ |
| 355 |
"type" => "payment_method", |
| 356 |
"name" => "satispay", |
| 357 |
"title" => __( 'payplug_satispay_activate', 'payplug' ), |
| 358 |
"image" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/satispay.svg' ), |
| 359 |
"checked" => $active, |
| 360 |
"available_test_mode" => false, |
| 361 |
"descriptions" => [ |
| 362 |
"live" => [ |
| 363 |
"description" => __( 'payplug_section_satispay_payment_description', 'payplug' ), |
| 364 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_satispay_more_url', 'payplug' ), "_blank"), |
| 365 |
], |
| 366 |
"sandbox" => [ |
| 367 |
"description" => __( 'payplug_satispay_unavailable_testmode_description', 'payplug' ), |
| 368 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_satispay_more_url', 'payplug' ), "_blank"), |
| 369 |
] |
| 370 |
], |
| 371 |
"options" => [ |
| 372 |
self::get_allowed_countries("satispay") |
| 373 |
], |
| 374 |
]; |
| 375 |
} |
| 376 |
|
| 377 |
/** |
| 378 |
* @param $active |
| 379 |
* @return array |
| 380 |
*/ |
| 381 |
public static function payment_method_mybank( $active = false ) { |
| 382 |
return [ |
| 383 |
"type" => "payment_method", |
| 384 |
"name" => "mybank", |
| 385 |
"title" => __( 'payplug_mybank_activate', 'payplug' ), |
| 386 |
"image" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/mybank.svg' ), |
| 387 |
"checked" => $active, |
| 388 |
"available_test_mode" => false, |
| 389 |
"descriptions" => [ |
| 390 |
"live" => [ |
| 391 |
"description" => __( 'payplug_section_mybank_payment_description', 'payplug' ), |
| 392 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_mybank_more_url', 'payplug' ), "_blank"), |
| 393 |
], |
| 394 |
"sandbox" => [ |
| 395 |
"description" => __( 'payplug_mybank_unavailable_testmode_description', 'payplug' ), |
| 396 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_mybank_more_url', 'payplug' ), "_blank"), |
| 397 |
] |
| 398 |
], |
| 399 |
"options" => [ |
| 400 |
self::get_allowed_countries("mybank") |
| 401 |
], |
| 402 |
]; |
| 403 |
} |
| 404 |
|
| 405 |
/** |
| 406 |
* @param $active |
| 407 |
* @return array |
| 408 |
*/ |
| 409 |
public static function payment_method_sofort( $active = false ) { |
| 410 |
return [ |
| 411 |
"type" => "payment_method", |
| 412 |
"name" => "sofort", |
| 413 |
"title" => __( 'payplug_sofort_activate', 'payplug' ), |
| 414 |
"image" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/sofort.svg' ), |
| 415 |
"checked" => $active, |
| 416 |
"available_test_mode" => false, |
| 417 |
"descriptions" => [ |
| 418 |
"live" => [ |
| 419 |
"description" => __( 'payplug_section_sofort_payment_description', 'payplug' ), |
| 420 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_sofort_more_url', 'payplug' ), "_blank"), |
| 421 |
], |
| 422 |
"sandbox" => [ |
| 423 |
"description" => __( 'payplug_sofort_unavailable_testmode_description', 'payplug' ), |
| 424 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_sofort_more_url', 'payplug' ), "_blank"), |
| 425 |
] |
| 426 |
], |
| 427 |
"options" => [ |
| 428 |
self::get_allowed_countries("sofort") |
| 429 |
], |
| 430 |
]; |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
/** |
| 435 |
* @param $active |
| 436 |
* @return array |
| 437 |
*/ |
| 438 |
public static function payment_method_ideal( $active = false ) { |
| 439 |
return [ |
| 440 |
"type" => "payment_method", |
| 441 |
"name" => "ideal", |
| 442 |
"title" => __( 'payplug_ideal_activate', 'payplug' ), |
| 443 |
"image" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/ideal.svg' ), |
| 444 |
"checked" => $active, |
| 445 |
"available_test_mode" => false, |
| 446 |
"descriptions" => [ |
| 447 |
"live" => [ |
| 448 |
"description" => __( 'payplug_section_ideal_payment_description', 'payplug' ), |
| 449 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_ideal_more_url', 'payplug' ), "_blank"), |
| 450 |
], |
| 451 |
"sandbox" => [ |
| 452 |
"description" => __( 'payplug_ideal_unavailable_testmode_description', 'payplug' ), |
| 453 |
"link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), __( 'payplug_ideal_more_url', 'payplug' ), "_blank"), |
| 454 |
] |
| 455 |
], |
| 456 |
"options" => [ |
| 457 |
self::get_allowed_countries("ideal") |
| 458 |
], |
| 459 |
]; |
| 460 |
} |
| 461 |
|
| 462 |
/** |
| 463 |
* @param $id |
| 464 |
* @return false|string |
| 465 |
*/ |
| 466 |
private static function get_allowed_countries($id){ |
| 467 |
$account = PayplugWoocommerceHelper::get_account_data_from_options(); |
| 468 |
|
| 469 |
if(empty($account['payment_methods'][$id])){ |
| 470 |
return false; |
| 471 |
} |
| 472 |
|
| 473 |
$arr = [ |
| 474 |
"type" => "info_message", |
| 475 |
"sub_type" => "text", |
| 476 |
"name" => "allowed_countries", |
| 477 |
"payment_method" => $id, |
| 478 |
"description" => trim(sprintf(__("payplug_payment_gateways_country_permissions", "payplug"), ucfirst($id))) . implode(", ", $account['payment_methods'][$id]['allowed_countries']) . "." |
| 479 |
]; |
| 480 |
|
| 481 |
return $arr; |
| 482 |
|
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
} |
| 487 |
|