| @@ -654,8 +654,30 @@ | ||
| 654 | 654 | 'max' => (int) $data['oney_max_amounts'] * 100, |
| 655 | 655 | ]); |
| 656 | 656 | $options['payment_methods']['configuration']['oney']['with_fees'] = 'with_fees' == (string) $data['payplug_oney']; |
| 657 | 657 | |
| 658 | + // scalapay payment - the thresholds widget isn't necessarily rendered (a stale admin | |
| 659 | + // JS bundle right after a deploy, for instance). Its absence must not reach | |
| 660 | + // Validator::scalapay_thresholds(), which would read the missing values as 0, fail | |
| 661 | + // the "below the account minimum" check and abort the whole request via | |
| 662 | + // wp_send_json_error() - discarding every other setting in this save, since | |
| 663 | + // update_options() only runs at the end of this method. | |
| 664 | + if (array_key_exists('scalapay_min_amounts', $data) && array_key_exists('scalapay_max_amounts', $data)) { | |
| 665 | + [$scalapay_authorized_min, $scalapay_authorized_max] = Scalapay::authorized_bounds( | |
| 666 | + $options['payment_methods']['configuration']['scalapay'] ?? [], | |
| 667 | + $options['payment_methods']['permissions']['scalapay']['amounts'] ?? '{}' | |
| 668 | + ); | |
| 669 | + // round() before the cast: the submitted values are euros, so a bare (int) cast | |
| 670 | + // would bind tighter than the * 100 and truncate the cents (49.99 -> 4900). | |
| 671 | + $scalapay_thresholds = Validator::scalapay_thresholds( | |
| 672 | + (int) round((float) $data['scalapay_min_amounts'] * 100), | |
| 673 | + (int) round((float) $data['scalapay_max_amounts'] * 100), | |
| 674 | + $scalapay_authorized_min, | |
| 675 | + $scalapay_authorized_max | |
| 676 | + ); | |
| 677 | + $options['payment_methods']['configuration']['scalapay']['custom_amounts'] = json_encode($scalapay_thresholds); | |
| 678 | + } | |
| 679 | + | |
| 658 | 680 | // Force-disable methods unavailable in test mode: submitted 'active' flags are |
| 659 | 681 | // trusted as-is, so one enabled while in live mode stays active after just |
| 660 | 682 | // switching to test unless we re-check it here. |
| 661 | 683 | if (!$options['mode']) { |