From f86b29732f8644052641ac22826bd218340296e9 Mon Sep 17 00:00:00 2001 From: MarijusDilys Date: Mon, 29 Sep 2025 09:41:00 +0300 Subject: [PATCH 1/5] init --- .../B2bPaymentMethodRestrictionValidator.php | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php index 049bab609..9acfa822a 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php @@ -60,14 +60,6 @@ public function isValid(MolPaymentMethod $paymentMethod): bool return false; } - if (!$this->isIdentificationNumberValid()) { - return false; - } - - if (!$this->isVatNumberValid()) { - return false; - } - return true; } @@ -79,39 +71,6 @@ public function supports(MolPaymentMethod $paymentMethod): bool return $paymentMethod->getPaymentMethodName() === PaymentMethod::BILLIE; } - private function isIdentificationNumberValid(): bool - { - $customerId = $this->context->getCustomerId(); - - /** @var \Customer $customer */ - $customer = $this->customerRepository->findOneBy([ - 'id_customer' => $customerId, - ]); - - return !empty($customer->siret); - } - - private function isVatNumberValid(): bool - { - $billingAddressId = $this->context->getInvoiceAddressId(); - - /** @var \Address $billingAddress */ - $billingAddress = $this->addressRepository->findOneBy([ - 'id_address' => (int) $billingAddressId, - ]); - - /** @var \AddressFormat $addressFormat */ - $addressFormat = $this->addressFormatRepository->findOneBy([ - 'id_country' => $billingAddress->id_country, - ]); - - if (!str_contains($addressFormat->getFormat($billingAddress->id_country), 'vat_number')) { - return true; - } - - return !empty($billingAddress->vat_number); - } - private function isB2bEnabled(): bool { return (bool) (int) $this->configuration->get('PS_B2B_ENABLE'); From b42663196a0be62e8204ab6ea294c2c695120871 Mon Sep 17 00:00:00 2001 From: MarijusDilys Date: Tue, 30 Sep 2025 16:10:31 +0300 Subject: [PATCH 2/5] fkjx --- .../B2bPaymentMethodRestrictionValidator.php | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php index 9acfa822a..c10ff85c5 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php @@ -26,29 +26,11 @@ class B2bPaymentMethodRestrictionValidator implements PaymentMethodRestrictionValidatorInterface { - /** @var Context */ - private $context; - /** @var AddressRepositoryInterface */ - private $addressRepository; - /** @var CustomerRepositoryInterface */ - private $customerRepository; /** @var ConfigurationAdapter */ private $configuration; - /** @var AddressFormatRepositoryInterface */ - private $addressFormatRepository; - public function __construct( - Context $context, - AddressRepositoryInterface $addressRepository, - CustomerRepositoryInterface $customerRepository, - ConfigurationAdapter $configuration, - AddressFormatRepositoryInterface $addressFormatRepository - ) { - $this->context = $context; - $this->addressRepository = $addressRepository; - $this->customerRepository = $customerRepository; + public function __construct(ConfigurationAdapter $configuration) { $this->configuration = $configuration; - $this->addressFormatRepository = $addressFormatRepository; } /** From 0cc7c2b00a7b8a51ca9ec739603c788d6c4d01f9 Mon Sep 17 00:00:00 2001 From: MarijusDilys Date: Wed, 1 Oct 2025 10:40:14 +0300 Subject: [PATCH 3/5] remove useless tests --- .../B2bPaymentMethodRestrictionValidator.php | 3 +- ...bPaymentMethodRestrictionValidatorTest.php | 199 ------------------ 2 files changed, 2 insertions(+), 200 deletions(-) diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php index c10ff85c5..0472c4ce8 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php @@ -29,7 +29,8 @@ class B2bPaymentMethodRestrictionValidator implements PaymentMethodRestrictionVa /** @var ConfigurationAdapter */ private $configuration; - public function __construct(ConfigurationAdapter $configuration) { + public function __construct(ConfigurationAdapter $configuration) + { $this->configuration = $configuration; } diff --git a/tests/Integration/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidatorTest.php b/tests/Integration/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidatorTest.php index 90000cf62..1ca3d2acf 100644 --- a/tests/Integration/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidatorTest.php +++ b/tests/Integration/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidatorTest.php @@ -46,57 +46,6 @@ public function testItSuccessfullyValidatedIsValid(): void $molPaymentMethod = new \MolPaymentMethod(); $molPaymentMethod->id_method = PaymentMethod::BILLIE; - $customer = CustomerFactory::create([ - 'siret' => 'test-siret-number', - ]); - - $billingAddress = AddressFactory::create([ - 'vat_number' => 'vat-number', - ]); - - CartFactory::initialize()->create([ - 'id_customer' => $customer->id, - 'id_address_invoice' => $billingAddress->id, - ]); - - /** @var B2bPaymentMethodRestrictionValidator $b2bPaymentMethodRestrictionValidator */ - $b2bPaymentMethodRestrictionValidator = $this->getService(B2bPaymentMethodRestrictionValidator::class); - - $supports = $b2bPaymentMethodRestrictionValidator->supports($molPaymentMethod); - - $valid = $b2bPaymentMethodRestrictionValidator->isValid($molPaymentMethod); - - $this->assertEquals(true, $supports); - $this->assertEquals(true, $valid); - } - - public function testItSuccessfullyValidatedIsValidMissingVatNumberInFormat(): void - { - Configuration::set('PS_B2B_ENABLE', 1); - - $molPaymentMethod = new \MolPaymentMethod(); - $molPaymentMethod->id_method = PaymentMethod::BILLIE; - - $customer = CustomerFactory::create([ - 'siret' => 'test-siret-number', - ]); - - $billingAddress = AddressFactory::create([ - 'vat_number' => 'vat-number', - ]); - - $addressFormat = new \AddressFormat($billingAddress->id_country); - - $originalCountryFormat = $addressFormat->format; - - $addressFormat->format = 'test-format'; - $addressFormat->save(); - - CartFactory::initialize()->create([ - 'id_customer' => $customer->id, - 'id_address_invoice' => $billingAddress->id, - ]); - /** @var B2bPaymentMethodRestrictionValidator $b2bPaymentMethodRestrictionValidator */ $b2bPaymentMethodRestrictionValidator = $this->getService(B2bPaymentMethodRestrictionValidator::class); @@ -104,76 +53,10 @@ public function testItSuccessfullyValidatedIsValidMissingVatNumberInFormat(): vo $valid = $b2bPaymentMethodRestrictionValidator->isValid($molPaymentMethod); - $addressFormat->format = $originalCountryFormat; - $addressFormat->save(); - $this->assertEquals(true, $supports); $this->assertEquals(true, $valid); } - public function testItUnsuccessfullyValidatedIsValidMethodNotSupported(): void - { - Configuration::set('PS_B2B_ENABLE', 1); - - $molPaymentMethod = new \MolPaymentMethod(); - $molPaymentMethod->id_method = 'not-supported-method'; - - $customer = CustomerFactory::create([ - 'siret' => 'test-siret-number', - ]); - - $billingAddress = AddressFactory::create([ - 'vat_number' => 'vat-number', - ]); - - CartFactory::initialize()->create([ - 'id_customer' => $customer->id, - 'id_address_invoice' => $billingAddress->id, - ]); - - /** @var B2bPaymentMethodRestrictionValidator $b2bPaymentMethodRestrictionValidator */ - $b2bPaymentMethodRestrictionValidator = $this->getService(B2bPaymentMethodRestrictionValidator::class); - - $supports = $b2bPaymentMethodRestrictionValidator->supports($molPaymentMethod); - - $valid = $b2bPaymentMethodRestrictionValidator->isValid($molPaymentMethod); - - $this->assertEquals(false, $supports); - $this->assertEquals(true, $valid); - } - - public function testItUnsuccessfullyValidatedIsValidMissingSiretNumber(): void - { - Configuration::set('PS_B2B_ENABLE', 1); - - $molPaymentMethod = new \MolPaymentMethod(); - $molPaymentMethod->id_method = PaymentMethod::BILLIE; - - $customer = CustomerFactory::create([ - 'siret' => '', - ]); - - $billingAddress = AddressFactory::create([ - 'vat_number' => 'vat-number', - ]); - - CartFactory::initialize()->create([ - 'id_customer' => $customer->id, - 'id_address_delivery' => $billingAddress->id, - 'id_address_invoice' => $billingAddress->id, - ]); - - /** @var B2bPaymentMethodRestrictionValidator $b2bPaymentMethodRestrictionValidator */ - $b2bPaymentMethodRestrictionValidator = $this->getService(B2bPaymentMethodRestrictionValidator::class); - - $supports = $b2bPaymentMethodRestrictionValidator->supports($molPaymentMethod); - - $valid = $b2bPaymentMethodRestrictionValidator->isValid($molPaymentMethod); - - $this->assertEquals(true, $supports); - $this->assertEquals(false, $valid); - } - public function testItUnsuccessfullyValidatedIsValidB2bNotEnabled(): void { Configuration::set('PS_B2B_ENABLE', 0); @@ -181,88 +64,6 @@ public function testItUnsuccessfullyValidatedIsValidB2bNotEnabled(): void $molPaymentMethod = new \MolPaymentMethod(); $molPaymentMethod->id_method = PaymentMethod::BILLIE; - $customer = CustomerFactory::create([ - 'siret' => 'test-siret', - ]); - - $billingAddress = AddressFactory::create([ - 'vat_number' => 'vat-number', - ]); - - CartFactory::initialize()->create([ - 'id_customer' => $customer->id, - 'id_address_delivery' => $billingAddress->id, - 'id_address_invoice' => $billingAddress->id, - ]); - - /** @var B2bPaymentMethodRestrictionValidator $b2bPaymentMethodRestrictionValidator */ - $b2bPaymentMethodRestrictionValidator = $this->getService(B2bPaymentMethodRestrictionValidator::class); - - $supports = $b2bPaymentMethodRestrictionValidator->supports($molPaymentMethod); - - $valid = $b2bPaymentMethodRestrictionValidator->isValid($molPaymentMethod); - - $this->assertEquals(true, $supports); - $this->assertEquals(false, $valid); - } - - public function testItUnsuccessfullyValidatedIsValidMissingVatNumberInBothAddresses(): void - { - Configuration::set('PS_B2B_ENABLE', 1); - - $molPaymentMethod = new \MolPaymentMethod(); - $molPaymentMethod->id_method = PaymentMethod::BILLIE; - - $customer = CustomerFactory::create([ - 'siret' => 'test-siret', - ]); - - $billingAddress = AddressFactory::create([ - 'vat_number' => '', - ]); - - CartFactory::initialize()->create([ - 'id_customer' => $customer->id, - 'id_address_delivery' => $billingAddress->id, - 'id_address_invoice' => $billingAddress->id, - ]); - - /** @var B2bPaymentMethodRestrictionValidator $b2bPaymentMethodRestrictionValidator */ - $b2bPaymentMethodRestrictionValidator = $this->getService(B2bPaymentMethodRestrictionValidator::class); - - $supports = $b2bPaymentMethodRestrictionValidator->supports($molPaymentMethod); - - $valid = $b2bPaymentMethodRestrictionValidator->isValid($molPaymentMethod); - - $this->assertEquals(true, $supports); - $this->assertEquals(false, $valid); - } - - public function testItUnsuccessfullyValidatedIsValidMissingVatNumberInBillingAddress(): void - { - Configuration::set('PS_B2B_ENABLE', 1); - - $molPaymentMethod = new \MolPaymentMethod(); - $molPaymentMethod->id_method = PaymentMethod::BILLIE; - - $customer = CustomerFactory::create([ - 'siret' => 'test-siret', - ]); - - $billingAddress = AddressFactory::create([ - 'vat_number' => '', - ]); - - $shippingAddress = AddressFactory::create([ - 'vat_number' => 'test-vat-number', - ]); - - CartFactory::initialize()->create([ - 'id_customer' => $customer->id, - 'id_address_delivery' => $billingAddress->id, - 'id_address_invoice' => $billingAddress->id, - ]); - /** @var B2bPaymentMethodRestrictionValidator $b2bPaymentMethodRestrictionValidator */ $b2bPaymentMethodRestrictionValidator = $this->getService(B2bPaymentMethodRestrictionValidator::class); From e6a252bebb7c49ea134a2c034744cceca391b6ee Mon Sep 17 00:00:00 2001 From: MarijusDilys Date: Wed, 1 Oct 2025 10:42:00 +0300 Subject: [PATCH 4/5] fix --- .../B2bPaymentMethodRestrictionValidatorTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Integration/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidatorTest.php b/tests/Integration/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidatorTest.php index 1ca3d2acf..ec7174e32 100644 --- a/tests/Integration/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidatorTest.php +++ b/tests/Integration/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidatorTest.php @@ -16,9 +16,6 @@ use Mollie\Api\Types\PaymentMethod; use Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation\B2bPaymentMethodRestrictionValidator; use Mollie\Tests\Integration\BaseTestCase; -use Mollie\Tests\Integration\Factory\AddressFactory; -use Mollie\Tests\Integration\Factory\CartFactory; -use Mollie\Tests\Integration\Factory\CustomerFactory; class B2bPaymentMethodRestrictionValidatorTest extends BaseTestCase { From 5237d7e578e5b9ba57fbaf7a04423d0059a4e6af Mon Sep 17 00:00:00 2001 From: MarijusDilys Date: Wed, 1 Oct 2025 10:44:33 +0300 Subject: [PATCH 5/5] fix --- .../B2bPaymentMethodRestrictionValidator.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php index 0472c4ce8..2d9891b1d 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php @@ -13,11 +13,7 @@ namespace Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation; use Mollie\Adapter\ConfigurationAdapter; -use Mollie\Adapter\Context; use Mollie\Api\Types\PaymentMethod; -use Mollie\Repository\AddressFormatRepositoryInterface; -use Mollie\Repository\AddressRepositoryInterface; -use Mollie\Repository\CustomerRepositoryInterface; use MolPaymentMethod; if (!defined('_PS_VERSION_')) {