From 158b1452d248cd802a1e95a8118c28589e84d284 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Thu, 11 Jan 2024 06:42:00 +0100 Subject: [PATCH] Add birthdate check on the pay for order page for in3 payment method --- src/Gateway/GatewayModule.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index 9d997e07..f564543e 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -6,6 +6,7 @@ namespace Mollie\WooCommerce\Gateway; +use Automattic\WooCommerce\Admin\Overrides\Order; use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; use Mollie\WooCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule; use Mollie\WooCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait; @@ -58,6 +59,8 @@ class GatewayModule implements ServiceModule, ExecutableModule */ protected $pluginId; + const FIELD_IN3_BIRTHDATE = 'billing_birthdate'; + public function services(): array { return [ @@ -255,6 +258,11 @@ static function () { 11, 2 ); + add_action( + 'woocommerce_before_pay_action', + [$this, 'in3FieldsMandatoryPayForOrder'], + 11 + ); } // Set order to paid and processed when eventually completed without Mollie add_action('woocommerce_payment_complete', [$this, 'setOrderPaidByOtherGateway'], 10, 1); @@ -622,12 +630,32 @@ public function in3FieldsMandatory($fields, $errors) { $gatewayName = "mollie_wc_gateway_in3"; $phoneField = 'billing_phone'; - $birthdateField = 'billing_birthdate'; + $birthdateField = self::FIELD_IN3_BIRTHDATE; $paymentMethodName = 'in3'; $fields = $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $phoneField, $errors, $paymentMethodName); return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $birthdateField, $errors, $paymentMethodName); } + /** + * @param Order $order + */ + public function in3FieldsMandatoryPayForOrder(Order $order) + { + $birthdateValue = filter_input(INPUT_POST, self::FIELD_IN3_BIRTHDATE, FILTER_SANITIZE_SPECIAL_CHARS) ?? false; + if (!$birthdateValue) { + wc_add_notice( + sprintf( + __( + 'Error processing %1$s payment, the birthdate field is required.', + 'mollie-payments-for-woocommerce' + ), + $order->get_payment_method_title() + ), + 'error' + ); + } + } + /** * @param string $id * @param IconFactory $iconFactory