From 84dbc00c5f1f83fe1dba06e7004e99c4bf6f1be1 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 23 Dec 2024 08:56:24 +0100 Subject: [PATCH 1/5] Use different field name for company billie --- src/Gateway/GatewayModule.php | 7 ++++++- src/Payment/MollieObject.php | 2 +- .../PaymentFieldsStrategies/BillieFieldsStrategy.php | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index b8987f10..dadfc01b 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -269,6 +269,11 @@ static function () { 11, 2 ); + add_action( + 'woocommerce_checkout_posted_data', + [$this, 'switchFields'], + 11 + ); } $isIn3Enabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_in3_settings', 'enabled'); if ($isIn3Enabled) { @@ -657,7 +662,7 @@ protected function instantiatePaymentMethods($container): array public function BillieFieldsMandatory($fields, $errors) { $gatewayName = "mollie_wc_gateway_billie"; - $field = 'billing_company'; + $field = 'billing_company_billie'; $companyLabel = __('Company', 'mollie-payments-for-woocommerce'); return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $field, $companyLabel, $errors); } diff --git a/src/Payment/MollieObject.php b/src/Payment/MollieObject.php index d2f44480..e4ea3529 100644 --- a/src/Payment/MollieObject.php +++ b/src/Payment/MollieObject.php @@ -1109,7 +1109,7 @@ private function checkBillieCompanyField($order) $isBillieMethodId = $gateway->id === 'mollie_wc_gateway_billie'; if ($isBillieMethodId) { //phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - $fieldPosted = wc_clean(wp_unslash($_POST["billing_company"] ?? '')); + $fieldPosted = wc_clean(wp_unslash($_POST["billing_company_billie"] ?? '')); if ($fieldPosted === '' || !is_string($fieldPosted)) { return null; } diff --git a/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php index 3b8ac4bf..06a4e7a9 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php @@ -6,7 +6,7 @@ class BillieFieldsStrategy implements PaymentFieldsStrategyI { - const FIELD_COMPANY = "billing_company"; + const FIELD_COMPANY = "billing_company_billie"; public function execute($gateway, $dataHelper) { From 07f9443f882261ef58f7534e76221a8f5843a17b Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Tue, 24 Dec 2024 09:37:53 +0100 Subject: [PATCH 2/5] Move fields to payment method --- src/Gateway/GatewayModule.php | 61 ------------------------------- src/PaymentMethods/Billie.php | 68 ++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 62 deletions(-) diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index dadfc01b..777e0d84 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -261,20 +261,6 @@ static function () { } } ); - $isBillieEnabled = $container->get('gateway.isBillieEnabled'); - if ($isBillieEnabled) { - add_filter( - 'woocommerce_after_checkout_validation', - [$this, 'BillieFieldsMandatory'], - 11, - 2 - ); - add_action( - 'woocommerce_checkout_posted_data', - [$this, 'switchFields'], - 11 - ); - } $isIn3Enabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_in3_settings', 'enabled'); if ($isIn3Enabled) { add_filter( @@ -659,14 +645,6 @@ protected function instantiatePaymentMethods($container): array return $paymentMethods; } - public function BillieFieldsMandatory($fields, $errors) - { - $gatewayName = "mollie_wc_gateway_billie"; - $field = 'billing_company_billie'; - $companyLabel = __('Company', 'mollie-payments-for-woocommerce'); - return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $field, $companyLabel, $errors); - } - public function in3FieldsMandatory($fields, $errors) { $gatewayName = "mollie_wc_gateway_in3"; @@ -725,39 +703,6 @@ public function buildPaymentMethod( return $paymentMethod; } - - /** - * Some payment methods require mandatory fields, this function will add them to the checkout fields array - * @param $fields - * @param string $gatewayName - * @param string $field - * @param $errors - * @return mixed - */ - public function addPaymentMethodMandatoryFields($fields, string $gatewayName, string $field, string $fieldLabel, $errors) - { - if ($fields['payment_method'] !== $gatewayName) { - return $fields; - } - if (!isset($fields[$field])) { - $fieldPosted = filter_input(INPUT_POST, $field, FILTER_SANITIZE_SPECIAL_CHARS) ?? false; - if ($fieldPosted) { - $fields[$field] = $fieldPosted; - } else { - $errors->add( - 'validation', - sprintf( - /* translators: Placeholder 1: field name. */ - __('%s is a required field.', 'woocommerce'), - "$fieldLabel" - ) - ); - } - } - - return $fields; - } - public function addPaymentMethodMandatoryFieldsPhoneVerification( $fields, string $gatewayName, @@ -794,12 +739,6 @@ public function switchFields($data) $data['billing_phone'] = !empty($fieldPosted) ? $fieldPosted : $data['billing_phone']; } } - if (isset($data['payment_method']) && $data['payment_method'] === 'mollie_wc_gateway_billie') { - $fieldPosted = filter_input(INPUT_POST, 'billing_company_billie', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; - if ($fieldPosted) { - $data['billing_company'] = !empty($fieldPosted) ? $fieldPosted : $data['billing_company']; - } - } return $data; } diff --git a/src/PaymentMethods/Billie.php b/src/PaymentMethods/Billie.php index 0269b9da..c8d8f9d1 100644 --- a/src/PaymentMethods/Billie.php +++ b/src/PaymentMethods/Billie.php @@ -22,7 +22,7 @@ protected function getConfig(): array 'products', 'refunds', ], - 'filtersOnBuild' => false, + 'filtersOnBuild' => true, 'confirmationDelayed' => false, 'SEPA' => false, 'orderMandatory' => true, @@ -35,6 +35,21 @@ protected function getConfig(): array ]; } + public function filtersOnBuild() + { + add_filter( + 'woocommerce_after_checkout_validation', + [$this, 'BillieFieldsMandatory'], + 11, + 2 + ); + add_action( + 'woocommerce_checkout_posted_data', + [$this, 'switchFields'], + 11 + ); + } + public function getFormFields($generalFormFields): array { unset($generalFormFields[1]); @@ -42,4 +57,55 @@ public function getFormFields($generalFormFields): array return $generalFormFields; } + + public function BillieFieldsMandatory($fields, $errors) + { + $gatewayName = "mollie_wc_gateway_billie"; + $field = 'billing_company_billie'; + $companyLabel = __('Company', 'mollie-payments-for-woocommerce'); + return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $field, $companyLabel, $errors); + } + + public function switchFields($data) + { + if (isset($data['payment_method']) && $data['payment_method'] === 'mollie_wc_gateway_billie') { + $fieldPosted = filter_input(INPUT_POST, 'billing_company_billie', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; + if ($fieldPosted) { + $data['billing_company'] = !empty($fieldPosted) ? $fieldPosted : $data['billing_company']; + } + } + return $data; + } + + /** + * Some payment methods require mandatory fields, this function will add them to the checkout fields array + * @param $fields + * @param string $gatewayName + * @param string $field + * @param $errors + * @return mixed + */ + public function addPaymentMethodMandatoryFields($fields, string $gatewayName, string $field, string $fieldLabel, $errors) + { + if ($fields['payment_method'] !== $gatewayName) { + return $fields; + } + if (!isset($fields[$field])) { + $fieldPosted = filter_input(INPUT_POST, $field, FILTER_SANITIZE_SPECIAL_CHARS) ?? false; + if ($fieldPosted) { + $fields[$field] = $fieldPosted; + } else { + $errors->add( + 'validation', + sprintf( + /* translators: Placeholder 1: field name. */ + __('%s is a required field.', 'woocommerce'), + "$fieldLabel" + ) + ); + } + } + + return $fields; + } } From 78a8d776223323f424e8537bf825a0540717e8d0 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 9 Jan 2025 11:44:12 +0100 Subject: [PATCH 3/5] Fix Billie company with dedicated id --- resources/js/blocks/molliePaymentMethod.js | 22 +++-- resources/js/mollieBlockIndex.js | 21 +---- src/Assets/MollieCheckoutBlocksSupport.php | 2 + src/Payment/MollieObject.php | 12 +-- src/PaymentMethods/Billie.php | 81 ++++++++++++++----- .../BillieFieldsStrategy.php | 17 +++- 6 files changed, 97 insertions(+), 58 deletions(-) diff --git a/resources/js/blocks/molliePaymentMethod.js b/resources/js/blocks/molliePaymentMethod.js index f890ce92..48a16638 100644 --- a/resources/js/blocks/molliePaymentMethod.js +++ b/resources/js/blocks/molliePaymentMethod.js @@ -4,7 +4,7 @@ let activePaymentMethodLocal let cachedAvailableGateways let creditCardSelected = new Event("mollie_creditcard_component_selected", {bubbles: true}); const MollieComponent = (props) => { - let {onSubmit, activePaymentMethod, billing, item, useEffect, ajaxUrl, jQuery, emitResponse, eventRegistration, requiredFields, shippingData, isCompanyFieldVisible, isPhoneFieldVisible} = props + let {onSubmit, activePaymentMethod, billing, item, useEffect, ajaxUrl, jQuery, emitResponse, eventRegistration, requiredFields, shippingData, isPhoneFieldVisible} = props const { responseTypes } = emitResponse; const {onPaymentSetup, onCheckoutValidation} = eventRegistration; const [ selectedIssuer, selectIssuer ] = wp.element.useState(''); @@ -114,7 +114,7 @@ const MollieComponent = (props) => { payment_method_title: item.title, [issuerKey]: selectedIssuer, billing_phone: inputPhone, - billing_company: inputCompany, + billing_company_billie: inputCompany, billing_birthdate: inputBirthdate, cardToken: tokenVal, } @@ -133,7 +133,7 @@ const MollieComponent = (props) => { useEffect(() => { let companyLabel = jQuery('div.wc-block-components-text-input.wc-block-components-address-form__company > label') - if (companyLabel.length === 0) { + if (companyLabel.length === 0 || item.hideCompanyField === true) { return } @@ -219,14 +219,20 @@ const MollieComponent = (props) => { } if (item.name === "mollie_wc_gateway_billie") { - if (isCompanyFieldVisible) { - return; + const billingCompanyField = document.querySelector('#billing-company'); + const shippingCompanyField = document.querySelector('#shipping-company'); + const isBillingCompanyRequired = billingCompanyField?.hasAttribute('required'); + const isShippingCompanyRequired = shippingCompanyField?.hasAttribute('required'); + + if ((billingCompanyField && isBillingCompanyRequired) || (shippingCompanyField && isShippingCompanyRequired) || item.hideCompanyField === true) { + return; } + const companyField = item.companyPlaceholder ? item.companyPlaceholder : "Company name"; return ( <>

{item.content}

- {fieldMarkup("billing-company","text", companyField, updateCompany, inputCompany)} + {fieldMarkup("billing_company_billie","text", companyField, updateCompany, inputCompany)} ); } @@ -271,7 +277,7 @@ const MollieComponent = (props) => { return

{item.content}

} -const molliePaymentMethod = (useEffect, ajaxUrl, filters, gatewayData, availableGateways, item, jQuery, requiredFields, isCompanyFieldVisible, isPhoneFieldVisible) =>{ +const molliePaymentMethod = (useEffect, ajaxUrl, filters, gatewayData, availableGateways, item, jQuery, requiredFields, isPhoneFieldVisible) =>{ let billingCountry = filters.billingCountry let cartTotal = filters.cartTotal cachedAvailableGateways = availableGateways @@ -282,7 +288,7 @@ const molliePaymentMethod = (useEffect, ajaxUrl, filters, gatewayData, available return { name: item.name, label:
, - content: , + content: , edit:
{item.edit}
, paymentMethodId: item.paymentMethodId, canMakePayment: ({cartTotals, billingData}) => { diff --git a/resources/js/mollieBlockIndex.js b/resources/js/mollieBlockIndex.js index f6b8fd47..afa0ddef 100644 --- a/resources/js/mollieBlockIndex.js +++ b/resources/js/mollieBlockIndex.js @@ -10,26 +10,10 @@ import ApplePayButtonEditorComponent from './blocks/ApplePayButtonEditorComponen window.onload = (event) => { const { registerPaymentMethod } = wc.wcBlocksRegistry; - const { checkoutData, defaultFields } = wc.wcSettings.allSettings; - let billing_address, shipping_address; - - if (checkoutData) { - ({ billing_address, shipping_address } = checkoutData); - } else { - billing_address = {}; - shipping_address = {}; - } + const { defaultFields } = wc.wcSettings.allSettings; const { ajaxUrl, filters, gatewayData, availableGateways } = mollieBlockData.gatewayData; const {useEffect} = wp.element; const isAppleSession = typeof window.ApplePaySession === "function" - const isBlockEditor = !!wp?.blockEditor; - - function getCompanyField() { - let shippingCompany = shipping_address.company ?? false; - let billingCompany = billing_address.company ?? false; - return shippingCompany ? shippingCompany : billingCompany; - } - function getPhoneField() { const phoneFieldDataset = document.querySelector('[data-show-phone-field]'); @@ -39,7 +23,6 @@ import ApplePayButtonEditorComponent from './blocks/ApplePayButtonEditorComponen return phoneFieldDataset.dataset.showPhoneField !== "false" } - const isCompanyFieldVisible = getCompanyField(); const companyNameString = defaultFields.company.label const isPhoneFieldVisible = getPhoneField(); const phoneString = defaultFields.phone.label @@ -48,7 +31,7 @@ import ApplePayButtonEditorComponent from './blocks/ApplePayButtonEditorComponen 'phoneString': phoneString, } gatewayData.forEach(item => { - let register = () => registerPaymentMethod(molliePaymentMethod(useEffect, ajaxUrl, filters, gatewayData, availableGateways, item, jQuery, requiredFields, isCompanyFieldVisible, isPhoneFieldVisible)); + let register = () => registerPaymentMethod(molliePaymentMethod(useEffect, ajaxUrl, filters, gatewayData, availableGateways, item, jQuery, requiredFields, isPhoneFieldVisible)); if (item.name === 'mollie_wc_gateway_applepay') { const {isExpressEnabled} = item; if ((isAppleSession && window.ApplePaySession.canMakePayments())) { diff --git a/src/Assets/MollieCheckoutBlocksSupport.php b/src/Assets/MollieCheckoutBlocksSupport.php index 16d2d748..509d3a6e 100644 --- a/src/Assets/MollieCheckoutBlocksSupport.php +++ b/src/Assets/MollieCheckoutBlocksSupport.php @@ -140,6 +140,7 @@ public static function gatewayDataForWCBlocks(Data $dataService, array $gatewayI 'AT' => '+43xxxxxxxxx', ]; $country = WC()->customer ? WC()->customer->get_billing_country() : ''; + $hideCompanyFieldFilter = apply_filters('mollie_wc_hide_company_field', false); $phonePlaceholder = in_array($country, array_keys($countryCodes)) ? $countryCodes[$country] : $countryCodes['NL']; $gatewayData[] = [ 'name' => $gatewayKey, @@ -165,6 +166,7 @@ public static function gatewayDataForWCBlocks(Data $dataService, array $gatewayI 'phonePlaceholder' => $phonePlaceholder, 'birthdatePlaceholder' => $method->getProperty('birthdatePlaceholder'), 'isExpressEnabled' => $gatewayId === 'applepay' && $method->getProperty('mollie_apple_pay_button_enabled_express_checkout') === 'yes', + 'hideCompanyField' => $hideCompanyFieldFilter, ]; } $dataToScript['gatewayData'] = $gatewayData; diff --git a/src/Payment/MollieObject.php b/src/Payment/MollieObject.php index 20efddbe..135e144c 100644 --- a/src/Payment/MollieObject.php +++ b/src/Payment/MollieObject.php @@ -1108,15 +1108,9 @@ private function checkBillieCompanyField($order) } $isBillieMethodId = $gateway->id === 'mollie_wc_gateway_billie'; if ($isBillieMethodId) { - //phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - $fieldPosted = wc_clean(wp_unslash($_POST["billing_company_billie"] ?? '')); - if ($fieldPosted === '' || !is_string($fieldPosted)) { - return null; - } - return $this->maximalFieldLengths( - $fieldPosted, - self::MAXIMAL_LENGTH_ADDRESS - ); + $company = wc_clean(wp_unslash($_POST["billing_company_billie"] ?? '')) ?: $order->get_billing_company( + ) ?: $order->get_shipping_company(); + return $company ? $this->maximalFieldLengths($company, self::MAXIMAL_LENGTH_ADDRESS) : null; } return null; } diff --git a/src/PaymentMethods/Billie.php b/src/PaymentMethods/Billie.php index c8d8f9d1..a75a6404 100644 --- a/src/PaymentMethods/Billie.php +++ b/src/PaymentMethods/Billie.php @@ -4,8 +4,18 @@ namespace Mollie\WooCommerce\PaymentMethods; +/** + * Class Billie + * + * Handles the Billie payment method for WooCommerce. + */ class Billie extends AbstractPaymentMethod implements PaymentMethodI { + /** + * Get the configuration for the Billie payment method. + * + * @return array + */ protected function getConfig(): array { return [ @@ -35,6 +45,10 @@ protected function getConfig(): array ]; } + /** + * Add filters and actions for the Billie payment method. + * This will be added during constructor + */ public function filtersOnBuild() { add_filter( @@ -50,7 +64,13 @@ public function filtersOnBuild() ); } - public function getFormFields($generalFormFields): array + /** + * Modify the general form fields for the Billie payment method. + * + * @param array $generalFormFields + * @return array + */ + public function getFormFields(array $generalFormFields): array { unset($generalFormFields[1]); unset($generalFormFields['allowed_countries']); @@ -58,7 +78,13 @@ public function getFormFields($generalFormFields): array return $generalFormFields; } - public function BillieFieldsMandatory($fields, $errors) + /** + * Validate mandatory fields for the Billie payment method. + * + * @param array $fields + * @param array $errors + */ + public function BillieFieldsMandatory(array $fields, array $errors) { $gatewayName = "mollie_wc_gateway_billie"; $field = 'billing_company_billie'; @@ -66,12 +92,18 @@ public function BillieFieldsMandatory($fields, $errors) return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $field, $companyLabel, $errors); } - public function switchFields($data) + /** + * Switch fields for the Billie payment method. + * + * @param array $data + * @return array + */ + public function switchFields(array $data): array { if (isset($data['payment_method']) && $data['payment_method'] === 'mollie_wc_gateway_billie') { $fieldPosted = filter_input(INPUT_POST, 'billing_company_billie', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; - if ($fieldPosted) { - $data['billing_company'] = !empty($fieldPosted) ? $fieldPosted : $data['billing_company']; + if (!empty($fieldPosted) && is_string($fieldPosted)) { + $data['billing_company'] = $fieldPosted; } } return $data; @@ -79,31 +111,38 @@ public function switchFields($data) /** * Some payment methods require mandatory fields, this function will add them to the checkout fields array - * @param $fields + * @param array $fields * @param string $gatewayName * @param string $field - * @param $errors + * @param array $errors * @return mixed */ - public function addPaymentMethodMandatoryFields($fields, string $gatewayName, string $field, string $fieldLabel, $errors) + public function addPaymentMethodMandatoryFields(array $fields, string $gatewayName, string $field, string $fieldLabel, array $errors) { if ($fields['payment_method'] !== $gatewayName) { return $fields; } - if (!isset($fields[$field])) { - $fieldPosted = filter_input(INPUT_POST, $field, FILTER_SANITIZE_SPECIAL_CHARS) ?? false; - if ($fieldPosted) { - $fields[$field] = $fieldPosted; - } else { - $errors->add( - 'validation', - sprintf( - /* translators: Placeholder 1: field name. */ - __('%s is a required field.', 'woocommerce'), - "$fieldLabel" - ) - ); + $fieldPosted = filter_input(INPUT_POST, $field, FILTER_SANITIZE_SPECIAL_CHARS) ?? false; + + if (!empty($fieldPosted) && is_string($fieldPosted)) { + if (isset($fields['billing_company']) && $fields['billing_company'] === $fieldPosted) { + return $fields; } + if (isset($fields['shipping_company']) && $fields['shipping_company'] === $fieldPosted) { + return $fields; + } + $fields['billing_company'] = $fieldPosted; + } + + if (empty($fields['billing_company']) && empty($fields['shipping_company'])) { + $errors->add( + 'validation', + sprintf( + /* translators: Placeholder 1: field name. */ + __('%s is a required field.', 'woocommerce'), + "$fieldLabel" + ) + ); } return $fields; diff --git a/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php index 06a4e7a9..7c2bd037 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php @@ -17,7 +17,10 @@ public function execute($gateway, $dataHelper) $showCompanyField = empty($order->get_billing_company()); } - if (is_checkout() && !is_checkout_pay_page()) { + $companyFieldIsRequiredByWoo = $this->isCompanyFieldIsRequiredByWoo(); + $hideCompanyFieldFilter = apply_filters('mollie_wc_hide_company_field', false); + + if (is_checkout() && !is_checkout_pay_page() && !$companyFieldIsRequiredByWoo && !$hideCompanyFieldFilter) { $showCompanyField = true; } @@ -53,4 +56,16 @@ public function getFieldMarkup($gateway, $dataHelper) { return ""; } + + /** + * + * @return bool + */ + public function isCompanyFieldIsRequiredByWoo(): bool + { + $checkoutFields = WC()->checkout()->get_checkout_fields(); + $billingCompanyFieldIsRequiredByWoo = isset($checkoutFields['billing']['billing_company']['required']) && ($checkoutFields['billing']['billing_company']['required'] === true); + $shippingCompanyFieldIsRequiredByWoo = isset($checkoutFields['shipping']['shipping_company']['required']) && ($checkoutFields['shipping']['shipping_company']['required'] === true); + return $billingCompanyFieldIsRequiredByWoo || $shippingCompanyFieldIsRequiredByWoo; + } } From c47d3e0c13110afcf26da86c2e0f982036e1b75e Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 9 Jan 2025 11:48:42 +0100 Subject: [PATCH 4/5] Fix cs and psalm --- src/PaymentMethods/Billie.php | 8 ++++---- .../PaymentFieldsStrategies/BillieFieldsStrategy.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/PaymentMethods/Billie.php b/src/PaymentMethods/Billie.php index a75a6404..923b52b1 100644 --- a/src/PaymentMethods/Billie.php +++ b/src/PaymentMethods/Billie.php @@ -82,9 +82,9 @@ public function getFormFields(array $generalFormFields): array * Validate mandatory fields for the Billie payment method. * * @param array $fields - * @param array $errors + * @param $errors */ - public function BillieFieldsMandatory(array $fields, array $errors) + public function BillieFieldsMandatory(array $fields, $errors) { $gatewayName = "mollie_wc_gateway_billie"; $field = 'billing_company_billie'; @@ -114,10 +114,10 @@ public function switchFields(array $data): array * @param array $fields * @param string $gatewayName * @param string $field - * @param array $errors + * @param $errors * @return mixed */ - public function addPaymentMethodMandatoryFields(array $fields, string $gatewayName, string $field, string $fieldLabel, array $errors) + public function addPaymentMethodMandatoryFields(array $fields, string $gatewayName, string $field, string $fieldLabel, $errors) { if ($fields['payment_method'] !== $gatewayName) { return $fields; diff --git a/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php index 7c2bd037..c8734bcc 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php @@ -6,7 +6,7 @@ class BillieFieldsStrategy implements PaymentFieldsStrategyI { - const FIELD_COMPANY = "billing_company_billie"; + public const FIELD_COMPANY = 'billing_company_billie'; public function execute($gateway, $dataHelper) { From 1d010cf34f331ca08c60548b88ef1461ecb69b87 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 10 Jan 2025 09:56:38 +0100 Subject: [PATCH 5/5] Mute psalm bc ignores wc_clean --- src/Payment/MollieObject.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Payment/MollieObject.php b/src/Payment/MollieObject.php index 135e144c..d8054d3f 100644 --- a/src/Payment/MollieObject.php +++ b/src/Payment/MollieObject.php @@ -1108,7 +1108,9 @@ private function checkBillieCompanyField($order) } $isBillieMethodId = $gateway->id === 'mollie_wc_gateway_billie'; if ($isBillieMethodId) { - $company = wc_clean(wp_unslash($_POST["billing_company_billie"] ?? '')) ?: $order->get_billing_company( + //phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + $fieldPosted = wc_clean(wp_unslash($_POST["billing_company_billie"] ?? '')); + $company = $fieldPosted ?: $order->get_billing_company( ) ?: $order->get_shipping_company(); return $company ? $this->maximalFieldLengths($company, self::MAXIMAL_LENGTH_ADDRESS) : null; }