PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.15
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.15
6.2.15 6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 All 197 releases
← All changes | app/Modules/Payments/PaymentHandler.php +24 -5 6.2.14 → 6.2.15 View file →
@@ -323,9 +323,12 @@
323 323 [$this, 'validatePaymentInputs'],
324 324 10,
325 325 3
326 326 );
327 -
327 +
328 + add_filter('fluentform/validate_input_item_custom_payment_component', [$this, 'validatePaymentNumber'], 10, 3);
329 + add_filter('fluentform/validate_input_item_item_quantity_component', [$this, 'validatePaymentNumber'], 10, 3);
330 +
328 331 add_filter(
329 332 'fluentform/validate_input_item_payment_method',
330 333 [$this, 'validatePaymentMethod'],
331 334 10,
@@ -490,10 +493,11 @@
490 493 return;
491 494 }
492 495
493 496 $paymentAction = new PaymentAction($form, $insertData, $data);
494 -
497 +
495 498 if (!$paymentAction->getSubscriptionItems() && !$paymentAction->getCalculatedAmount()) {
499 + $paymentAction->flagZeroTotalOrder();
496 500 return;
497 501 }
498 502
499 503 /*
@@ -725,9 +729,10 @@
725 729 }
726 730
727 731 public function validatePaymentInputs($error, $field, $formData)
728 732 {
729 - if (ArrayHelper::get($formData, $field['name'])) {
733 + // A submitted "0" is still a value and must match an offered option.
734 + if (!in_array(ArrayHelper::get($formData, $field['name']), [null, '', []], true)) {
730 735 $fieldType = ArrayHelper::get($field, 'raw.attributes.type');
731 736
732 737 if (in_array($fieldType, ['radio', 'select', 'checkbox'])) {
733 738 $pricingOptions = array_column(
@@ -739,9 +744,9 @@
739 744
740 745 if (in_array($fieldType, ['radio', 'select'])) {
741 746 $acceptedPaymentPlan = in_array($formData[$field['name']], $pricingOptions);
742 747 } else {
743 - $acceptedPaymentPlan = array_diff($formData[$field['name']], $pricingOptions);
748 + $acceptedPaymentPlan = array_diff((array) $formData[$field['name']], $pricingOptions);
744 749
745 750 $acceptedPaymentPlan = empty($acceptedPaymentPlan);
746 751 }
747 752
@@ -752,9 +757,23 @@
752 757 }
753 758
754 759 return $error;
755 760 }
756 -
761 +
762 + // The order builder silently drops an amount or quantity it cannot price, zeroing the order.
763 + public function validatePaymentNumber($error, $field, $formData)
764 + {
765 + $value = ArrayHelper::get($formData, $field['name']);
766 + if ($error || in_array($value, [null, ''], true) || (is_numeric($value) && $value > 0)) {
767 + return $error;
768 + }
769 +
770 + $isOptionalZero = is_numeric($value) && 0 == $value
771 + && !ArrayHelper::get($field, 'raw.settings.validation_rules.required.value');
772 +
773 + return $isOptionalZero ? $error : __('This payment item is invalid', 'fluentform');
774 + }
775 +
757 776 public function validatePaymentMethod($error, $field, $formData, $fields, $form)
758 777 {
759 778 if ($selectedMethod = ArrayHelper::get($formData, $field['name'])) {
760 779 $activeMethods = array_keys(PaymentHelper::getFormPaymentMethods($form->id));