Skip to content

Commit

Permalink
Add birthdate check on the pay for order page for in3 payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
inpsyde-maticluznar committed Jan 11, 2024
1 parent fde6a3a commit 158b145
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +59,8 @@ class GatewayModule implements ServiceModule, ExecutableModule
*/
protected $pluginId;

const FIELD_IN3_BIRTHDATE = 'billing_birthdate';

public function services(): array
{
return [
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 158b145

Please sign in to comment.