| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Payplug\PayplugWoocommerce\Admin\Vue; |
| 4 | 4 | |
| 5 | +use Payplug\PayplugWoocommerce\Gateway\PPRO\Scalapay; | |
| 5 | 6 | use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper; |
| 6 | 7 | use Payplug\PayplugWoocommerce\Traits\ServiceGetter; |
| 7 | 8 | |
| 8 | 9 | class PaymentMethods |
| @@ -515,12 +516,15 @@ | ||
| 515 | 516 | } |
| 516 | 517 | |
| 517 | 518 | /** |
| 518 | 519 | * @param $active |
| 520 | + * @param $config payment_methods.configuration.scalapay options (active/custom_amounts/default_amounts) | |
| 521 | + * @param $api_amounts payment_methods.permissions.scalapay.amounts - the account's live PayPlug-authorized | |
| 522 | + * bounds, JSON-encoded {"min":{"EUR":n},"max":{"EUR":n}} (see AccountGateway::map()) | |
| 519 | 523 | * |
| 520 | 524 | * @return array |
| 521 | 525 | */ |
| 522 | - public static function payment_method_scalapay($active = false) | |
| 526 | + public static function payment_method_scalapay($active = false, $config = [], $api_amounts = '{}') | |
| 523 | 527 | { |
| 524 | 528 | return [ |
| 525 | 529 | 'type' => 'payment_method', |
| 526 | 530 | 'name' => 'scalapay', |
| @@ -540,8 +544,60 @@ | ||
| 540 | 544 | ], |
| 541 | 545 | 'options' => [ |
| 542 | 546 | self::get_allowed_countries('scalapay'), |
| 543 | 547 | ], |
| 548 | + 'advanced_options' => [ | |
| 549 | + self::scalapay_thresholds_option($config, $api_amounts), | |
| 550 | + ], | |
| 551 | + ]; | |
| 552 | + } | |
| 553 | + | |
| 554 | + /** | |
| 555 | + * @return array | |
| 556 | + */ | |
| 557 | + private static function scalapay_thresholds_option($config, $api_amounts) | |
| 558 | + { | |
| 559 | + // Shared with Scalapay::check_gateway()'s checkout-time enforcement, so the BO | |
| 560 | + // display and the actual gating logic can't silently drift apart. | |
| 561 | + [$min, $max] = Scalapay::effective_bounds($config, $api_amounts); | |
| 562 | + | |
| 563 | + // The widget's client-side validation ceiling is always the account's raw | |
| 564 | + // authorized range (matching the save-time validator), not the merchant's own | |
| 565 | + // possibly-narrower custom choice. | |
| 566 | + [$authorized_min, $authorized_max] = Scalapay::authorized_bounds($config, $api_amounts); | |
| 567 | + | |
| 568 | + // Convert cents to euros for display | |
| 569 | + $min = $min / 100; | |
| 570 | + $max = $max / 100; | |
| 571 | + $authorized_min = $authorized_min / 100; | |
| 572 | + $authorized_max = $authorized_max / 100; | |
| 573 | + | |
| 574 | + return [ | |
| 575 | + 'name' => 'thresholds', | |
| 576 | + 'image_url' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/thresholds.svg'), | |
| 577 | + 'title' => __('payplug_thresholds_scalapay_title', 'payplug'), | |
| 578 | + 'descriptions' => [ | |
| 579 | + 'description' => __('payplug_thresholds_scalapay_description', 'payplug'), | |
| 580 | + 'min_amount' => [ | |
| 581 | + 'name' => 'scalapay_min_amounts', | |
| 582 | + 'value' => $min, | |
| 583 | + 'placeholder' => $min, | |
| 584 | + 'default' => $authorized_min, | |
| 585 | + ], | |
| 586 | + 'inter' => __('and', 'payplug'), | |
| 587 | + 'max_amount' => [ | |
| 588 | + 'name' => 'scalapay_max_amounts', | |
| 589 | + 'value' => $max, | |
| 590 | + 'placeholder' => $max, | |
| 591 | + 'default' => $authorized_max, | |
| 592 | + ], | |
| 593 | + 'error' => [ | |
| 594 | + 'text' => __('payplug_thresholds_scalapay_error_msg', 'payplug'), | |
| 595 | + 'maxtext' => __('payplug_thresholds_scalapay_error_maxtext_msg', 'payplug'), | |
| 596 | + 'mintext' => __('payplug_thresholds_scalapay_error_mintext_msg', 'payplug'), | |
| 597 | + ], | |
| 598 | + ], | |
| 599 | + 'switch' => false, | |
| 544 | 600 | ]; |
| 545 | 601 | } |
| 546 | 602 | |
| 547 | 603 | /** |