From 38d861ac1e3537bb71e3500306ca32c06e76fd55 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Mon, 18 Nov 2024 16:48:39 +0200 Subject: [PATCH 1/4] PIPRES-488: added additional validation then adding the product which causes incorrect behavior on some themes --- mollie.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mollie.php b/mollie.php index 4e7c91505..fa475f108 100755 --- a/mollie.php +++ b/mollie.php @@ -32,6 +32,7 @@ use Mollie\Subscription\Install\DatabaseTableInstaller; use Mollie\Subscription\Install\HookInstaller; use Mollie\Subscription\Install\Installer; +use Mollie\Subscription\Config\Config as SubscriptionConfig; use Mollie\Subscription\Provider\SubscriptionProductProvider; use Mollie\Subscription\Repository\LanguageRepository as LanguageAdapter; use Mollie\Subscription\Repository\RecurringOrderRepositoryInterface; @@ -1124,6 +1125,19 @@ public function hookActionAjaxDieCartControllerDisplayAjaxUpdateBefore(array $pa return; } + $isSubscriptionEnabled = Configuration::get(Config::MOLLIE_SUBSCRIPTION_ENABLED); + + $groups = Tools::getValue('group'); + if (!(bool)$isSubscriptionEnabled || !is_array($groups)) { + return; + } + + $subscriptionGroup = Configuration::get(SubscriptionConfig::SUBSCRIPTION_ATTRIBUTE_GROUP); + + if (!in_array($subscriptionGroup, $groups, true)) { + return; + } + $response = json_decode($params['value'], true); $hasError = $response['hasError'] ?? false; From b7328a2be1aa7f8f04c2aba15c2cef4662422ab0 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Tue, 19 Nov 2024 11:05:14 +0200 Subject: [PATCH 2/4] improved attribute group check --- mollie.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mollie.php b/mollie.php index fa475f108..23c6c6b20 100755 --- a/mollie.php +++ b/mollie.php @@ -26,13 +26,13 @@ use Mollie\Repository\PaymentMethodRepositoryInterface; use Mollie\Service\ExceptionService; use Mollie\ServiceProvider\LeagueServiceContainerProvider; +use Mollie\Subscription\Config\Config as SubscriptionConfig; use Mollie\Subscription\Handler\CustomerAddressUpdateHandler; use Mollie\Subscription\Handler\UpdateSubscriptionCarrierHandler; use Mollie\Subscription\Install\AttributeInstaller; use Mollie\Subscription\Install\DatabaseTableInstaller; use Mollie\Subscription\Install\HookInstaller; use Mollie\Subscription\Install\Installer; -use Mollie\Subscription\Config\Config as SubscriptionConfig; use Mollie\Subscription\Provider\SubscriptionProductProvider; use Mollie\Subscription\Repository\LanguageRepository as LanguageAdapter; use Mollie\Subscription\Repository\RecurringOrderRepositoryInterface; @@ -1128,13 +1128,14 @@ public function hookActionAjaxDieCartControllerDisplayAjaxUpdateBefore(array $pa $isSubscriptionEnabled = Configuration::get(Config::MOLLIE_SUBSCRIPTION_ENABLED); $groups = Tools::getValue('group'); - if (!(bool)$isSubscriptionEnabled || !is_array($groups)) { + if (!(bool) $isSubscriptionEnabled || !is_array($groups)) { return; } $subscriptionGroup = Configuration::get(SubscriptionConfig::SUBSCRIPTION_ATTRIBUTE_GROUP); - if (!in_array($subscriptionGroup, $groups, true)) { + // Note: groups = ['attribute_group_id => 'attribute_id'] + if (!array_key_exists($subscriptionGroup, $groups)) { return; } From 2ef7d5a2b990202a6f2bd5c469ecd1590f786915 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Mon, 25 Nov 2024 15:59:14 +0200 Subject: [PATCH 3/4] bug: fixed Phone number provider to not break if format is not what mollie expects --- src/Provider/PhoneNumberProvider.php | 33 +++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Provider/PhoneNumberProvider.php b/src/Provider/PhoneNumberProvider.php index 86c016dc6..b7aabbb6d 100644 --- a/src/Provider/PhoneNumberProvider.php +++ b/src/Provider/PhoneNumberProvider.php @@ -23,37 +23,40 @@ final class PhoneNumberProvider implements PhoneNumberProviderInterface { public function getFromAddress(Address $address) { + // Get the phone number from the address (either mobile or regular) $phoneNumber = $this->getMobileOrPhone($address); + // Clean up the phone number by removing spaces and any '+' symbols $phoneNumber = str_replace(' ', '', $phoneNumber); - $phoneNumber = str_replace('+', '', $phoneNumber); - if (empty($phoneNumber) || empty(str_replace(' ', '', $phoneNumber))) { + // If the phone number is empty, return null + if (empty($phoneNumber)) { return null; } - while ('0' === $phoneNumber[0]) { - $phoneNumber = substr($phoneNumber, 1); - - if (empty($phoneNumber) && $phoneNumber !== '0') { - return null; + // If the phone number starts with a '+', validate that it's in E.164 format + if ($phoneNumber[0] === '+') { + // E.164 format: + and should be between 3 and 18 digits total + if (preg_match("/^\+\d{3,18}$/", $phoneNumber)) { + return $phoneNumber; // Return the number if it matches E.164 format + } else { + return null; // Return null if it doesn't match the expected pattern } } - if ('+' !== $phoneNumber[0]) { - $phoneNumber = '+' . $phoneNumber; - } - - $regex = "/^\+\d{3,18}$/"; - if (1 == preg_match($regex, $phoneNumber)) { - return $phoneNumber; - } else { + // If the phone number starts with '0' (a local number), it's considered invalid in E.164 format + // without a valid country code, so return null + if ($phoneNumber[0] === '0') { return null; } + + // we return null as we can't format them into E.164 + return null; } private function getMobileOrPhone(Address $address) { + // Retrieve either the mobile or regular phone number based on the address format $addressFormat = new AddressFormat((int) $address->id_country); if (strpos($addressFormat->format, 'phone_mobile') !== false) { From 71274792871bcadc039089ded59b0c0d0653d757 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Mon, 25 Nov 2024 17:14:40 +0200 Subject: [PATCH 4/4] not needed comments removed --- src/Provider/PhoneNumberProvider.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Provider/PhoneNumberProvider.php b/src/Provider/PhoneNumberProvider.php index b7aabbb6d..7cd885fde 100644 --- a/src/Provider/PhoneNumberProvider.php +++ b/src/Provider/PhoneNumberProvider.php @@ -23,13 +23,10 @@ final class PhoneNumberProvider implements PhoneNumberProviderInterface { public function getFromAddress(Address $address) { - // Get the phone number from the address (either mobile or regular) $phoneNumber = $this->getMobileOrPhone($address); - // Clean up the phone number by removing spaces and any '+' symbols $phoneNumber = str_replace(' ', '', $phoneNumber); - // If the phone number is empty, return null if (empty($phoneNumber)) { return null; } @@ -40,17 +37,15 @@ public function getFromAddress(Address $address) if (preg_match("/^\+\d{3,18}$/", $phoneNumber)) { return $phoneNumber; // Return the number if it matches E.164 format } else { - return null; // Return null if it doesn't match the expected pattern + return null; } } // If the phone number starts with '0' (a local number), it's considered invalid in E.164 format - // without a valid country code, so return null if ($phoneNumber[0] === '0') { return null; } - // we return null as we can't format them into E.164 return null; }