From a297f399d2798d2e5f719de814ff739b0f522780 Mon Sep 17 00:00:00 2001 From: mandan2 <61560082+mandan2@users.noreply.github.com> Date: Tue, 24 Oct 2023 17:05:31 +0300 Subject: [PATCH 1/3] PIPRES-352: Billie payment method validation (#16) --- src/Config/Config.php | 5 + src/Entity/MolPaymentMethod.php | 4 +- src/Repository/AbstractRepository.php | 2 +- src/Repository/AddressFormatRepository.php | 11 + .../AddressFormatRepositoryInterface.php | 7 + src/Repository/CustomerRepository.php | 11 + .../CustomerRepositoryInterface.php | 7 + src/Repository/MolCustomerRepository.php | 4 + src/Repository/PaymentMethodRepository.php | 6 +- src/Repository/PendingOrderCartRepository.php | 4 + ...mountPaymentMethodRestrictionValidator.php | 5 +- ...lePayPaymentMethodRestrictionValidator.php | 13 +- .../B2bPaymentMethodRestrictionValidator.php | 104 +++++++ .../BasePaymentMethodRestrictionValidator.php | 10 +- ...cificPaymentMethodRestrictionValidator.php | 7 +- ...entMethodRestrictionValidatorInterface.php | 10 +- ...ucherPaymentMethodRestrictionValidator.php | 7 +- src/ServiceProvider/BaseServiceProvider.php | 44 ++- ...questApplePayPaymentSessionHandlerTest.php | 9 +- tests/Integration/Factory/AddressFactory.php | 28 ++ tests/Integration/Factory/CarrierFactory.php | 55 ++++ tests/Integration/Factory/CartFactory.php | 24 ++ tests/Integration/Factory/CustomerFactory.php | 24 ++ .../Integration/Factory/FactoryInterface.php | 8 + ...bPaymentMethodRestrictionValidatorTest.php | 263 ++++++++++++++++++ ...plePayPaymentRestrictionValidationTest.php | 8 +- 26 files changed, 618 insertions(+), 62 deletions(-) create mode 100644 src/Repository/AddressFormatRepository.php create mode 100644 src/Repository/AddressFormatRepositoryInterface.php create mode 100644 src/Repository/CustomerRepository.php create mode 100644 src/Repository/CustomerRepositoryInterface.php create mode 100644 src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php create mode 100644 tests/Integration/Factory/AddressFactory.php create mode 100644 tests/Integration/Factory/CarrierFactory.php create mode 100644 tests/Integration/Factory/CartFactory.php create mode 100644 tests/Integration/Factory/CustomerFactory.php create mode 100644 tests/Integration/Factory/FactoryInterface.php create mode 100644 tests/Integration/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidatorTest.php diff --git a/src/Config/Config.php b/src/Config/Config.php index f9dd481a1..2d04d8844 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -239,6 +239,11 @@ class Config const MOLLIE_VOUCHER_METHOD_ID = 'voucher'; const MOLLIE_in3_METHOD_ID = 'in3'; + /** + * @see https://www.mollie.com/en/payments/billie + */ + const MOLLIE_PAYMENT_METHOD_BILLIE = 'billie'; + const MOLLIE_VOUCHER_CATEGORY_NULL = 'null'; const MOLLIE_VOUCHER_CATEGORY_MEAL = 'meal'; const MOLLIE_VOUCHER_CATEGORY_GIFT = 'gift'; diff --git a/src/Entity/MolPaymentMethod.php b/src/Entity/MolPaymentMethod.php index f960ca063..8c175099c 100644 --- a/src/Entity/MolPaymentMethod.php +++ b/src/Entity/MolPaymentMethod.php @@ -139,8 +139,8 @@ class MolPaymentMethod extends ObjectModel ], ]; - public function getPaymentMethodName() + public function getPaymentMethodName(): string { - return $this->id_method; + return (string) $this->id_method; } } diff --git a/src/Repository/AbstractRepository.php b/src/Repository/AbstractRepository.php index 749912f0e..a926bf857 100644 --- a/src/Repository/AbstractRepository.php +++ b/src/Repository/AbstractRepository.php @@ -26,7 +26,7 @@ class AbstractRepository implements ReadOnlyRepositoryInterface /** * @param string $fullyClassifiedClassName */ - public function __construct($fullyClassifiedClassName) + public function __construct(string $fullyClassifiedClassName) { $this->fullyClassifiedClassName = $fullyClassifiedClassName; } diff --git a/src/Repository/AddressFormatRepository.php b/src/Repository/AddressFormatRepository.php new file mode 100644 index 000000000..de9cad0a6 --- /dev/null +++ b/src/Repository/AddressFormatRepository.php @@ -0,0 +1,11 @@ +getValue($sql); diff --git a/src/Repository/PendingOrderCartRepository.php b/src/Repository/PendingOrderCartRepository.php index 2b9aa54b1..9be7ac5f6 100644 --- a/src/Repository/PendingOrderCartRepository.php +++ b/src/Repository/PendingOrderCartRepository.php @@ -14,4 +14,8 @@ final class PendingOrderCartRepository extends AbstractRepository { + public function __construct() + { + parent::__construct(\MolPendingOrderCart::class); + } } diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/AmountPaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/AmountPaymentMethodRestrictionValidator.php index 6276aa587..b18512be3 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/AmountPaymentMethodRestrictionValidator.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/AmountPaymentMethodRestrictionValidator.php @@ -37,7 +37,6 @@ namespace Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation; use Mollie\Adapter\Context; -use MolPaymentMethod; use PrestaShop\Decimal\Number; /** Validator to check if cart total is valid for amount restrictions */ @@ -55,7 +54,7 @@ public function __construct( /** * {@inheritDoc} */ - public function isValid(MolPaymentMethod $paymentMethod) + public function isValid(\MolPaymentMethod $paymentMethod): bool { $orderTotal = $this->context->getCart()->getOrderTotal(); @@ -77,7 +76,7 @@ public function isValid(MolPaymentMethod $paymentMethod) /** * {@inheritDoc} */ - public function supports(MolPaymentMethod $paymentMethod) + public function supports(\MolPaymentMethod $paymentMethod): bool { return true; } diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/ApplePayPaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/ApplePayPaymentMethodRestrictionValidator.php index 8da680e41..d83fcf7bc 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/ApplePayPaymentMethodRestrictionValidator.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/ApplePayPaymentMethodRestrictionValidator.php @@ -37,8 +37,7 @@ namespace Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation; use Mollie\Adapter\ConfigurationAdapter; -use Mollie\Config\Config; -use MolPaymentMethod; +use Mollie\Api\Types\PaymentMethod; class ApplePayPaymentMethodRestrictionValidator implements PaymentMethodRestrictionValidatorInterface { @@ -56,7 +55,7 @@ public function __construct( /** * {@inheritDoc} */ - public function isValid(MolPaymentMethod $paymentMethod) + public function isValid(\MolPaymentMethod $paymentMethod): bool { if (!$this->isSslEnabledEverywhere()) { return false; @@ -72,15 +71,15 @@ public function isValid(MolPaymentMethod $paymentMethod) /** * {@inheritDoc} */ - public function supports(MolPaymentMethod $paymentMethod) + public function supports(\MolPaymentMethod $paymentMethod): bool { - return $paymentMethod->getPaymentMethodName() == Config::MOLLIE_METHOD_ID_APPLE_PAY; + return $paymentMethod->getPaymentMethodName() === PaymentMethod::APPLEPAY; } /** * @return bool */ - private function isSslEnabledEverywhere() + private function isSslEnabledEverywhere(): bool { return (bool) $this->configurationAdapter->get('PS_SSL_ENABLED_EVERYWHERE'); } @@ -88,7 +87,7 @@ private function isSslEnabledEverywhere() /** * @return bool */ - private function isPaymentMethodInCookie() + private function isPaymentMethodInCookie(): bool { if (!isset($_COOKIE['isApplePayMethod'])) { return false; diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php new file mode 100644 index 000000000..8c1338e25 --- /dev/null +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php @@ -0,0 +1,104 @@ +context = $context; + $this->addressRepository = $addressRepository; + $this->customerRepository = $customerRepository; + $this->configuration = $configuration; + $this->addressFormatRepository = $addressFormatRepository; + } + + /** + * {@inheritDoc} + */ + public function isValid(\MolPaymentMethod $paymentMethod): bool + { + if (!$this->isB2bEnabled()) { + return false; + } + + if (!$this->isIdentificationNumberValid()) { + return false; + } + + if (!$this->isVatNumberValid()) { + return false; + } + + return true; + } + + /** + * {@inheritDoc} + */ + public function supports(\MolPaymentMethod $paymentMethod): bool + { + return $paymentMethod->getPaymentMethodName() === Config::MOLLIE_PAYMENT_METHOD_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->getAddressInvoiceId(); + + /** @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'); + } +} diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/BasePaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/BasePaymentMethodRestrictionValidator.php index 8dafb669f..e5415d983 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/BasePaymentMethodRestrictionValidator.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/BasePaymentMethodRestrictionValidator.php @@ -36,15 +36,13 @@ namespace Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation; -use MolPaymentMethod; - /** Validator to check all cases for every payment method */ class BasePaymentMethodRestrictionValidator implements PaymentMethodRestrictionValidatorInterface { /** * {@inheritDoc} */ - public function isValid(MolPaymentMethod $paymentMethod) + public function isValid(\MolPaymentMethod $paymentMethod): bool { if (!$this->isPaymentMethodEnabled($paymentMethod)) { return false; @@ -56,17 +54,17 @@ public function isValid(MolPaymentMethod $paymentMethod) /** * {@inheritDoc} */ - public function supports(MolPaymentMethod $paymentMethod) + public function supports(\MolPaymentMethod $paymentMethod): bool { return true; } /** - * @param MolPaymentMethod $paymentMethod + * @param \MolPaymentMethod $paymentMethod * * @return bool */ - private function isPaymentMethodEnabled($paymentMethod) + private function isPaymentMethodEnabled(\MolPaymentMethod $paymentMethod): bool { return (bool) $paymentMethod->enabled; } diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/EnvironmentVersionSpecificPaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/EnvironmentVersionSpecificPaymentMethodRestrictionValidator.php index 71d49b106..29072b3f2 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/EnvironmentVersionSpecificPaymentMethodRestrictionValidator.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/EnvironmentVersionSpecificPaymentMethodRestrictionValidator.php @@ -39,7 +39,6 @@ use Mollie\Adapter\Context; use Mollie\Provider\EnvironmentVersionProviderInterface; use Mollie\Repository\MethodCountryRepository; -use MolPaymentMethod; /** Validator to check specific cases by environment version for every payment method */ class EnvironmentVersionSpecificPaymentMethodRestrictionValidator implements PaymentMethodRestrictionValidatorInterface @@ -72,7 +71,7 @@ public function __construct( /** * {@inheritDoc} */ - public function isValid(MolPaymentMethod $paymentMethod) + public function isValid(\MolPaymentMethod $paymentMethod): bool { if (version_compare($this->prestashopVersionProvider->getPrestashopVersion(), '1.6.0.9', '>')) { if (!$this->isCountryAvailable($paymentMethod)) { @@ -86,12 +85,12 @@ public function isValid(MolPaymentMethod $paymentMethod) /** * {@inheritDoc} */ - public function supports(MolPaymentMethod $paymentMethod) + public function supports(\MolPaymentMethod $paymentMethod): bool { return true; } - private function isCountryAvailable(MolPaymentMethod $paymentMethod) + private function isCountryAvailable(\MolPaymentMethod $paymentMethod) { if ($paymentMethod->is_countries_applicable) { return $this->methodCountryRepository->checkIfMethodIsAvailableInCountry( diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/PaymentMethodRestrictionValidatorInterface.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/PaymentMethodRestrictionValidatorInterface.php index 102a6aa3d..b721815f7 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/PaymentMethodRestrictionValidatorInterface.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/PaymentMethodRestrictionValidatorInterface.php @@ -36,25 +36,23 @@ namespace Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation; -use MolPaymentMethod; - interface PaymentMethodRestrictionValidatorInterface { /** * Returns if payment is valid * - * @param MolPaymentMethod $paymentMethod + * @param \MolPaymentMethod $paymentMethod * * @return bool */ - public function isValid(MolPaymentMethod $paymentMethod); + public function isValid(\MolPaymentMethod $paymentMethod): bool; /** * Returns if payment restriction validator is supported by payment name * - * @param MolPaymentMethod $paymentMethod + * @param \MolPaymentMethod $paymentMethod * * @return bool */ - public function supports(MolPaymentMethod $paymentMethod); + public function supports(\MolPaymentMethod $paymentMethod): bool; } diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/VoucherPaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/VoucherPaymentMethodRestrictionValidator.php index a04b45b32..6d2e51a3e 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/VoucherPaymentMethodRestrictionValidator.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/VoucherPaymentMethodRestrictionValidator.php @@ -39,7 +39,6 @@ use Mollie\Adapter\Context; use Mollie\Config\Config; use Mollie\Validator\VoucherValidator; -use MolPaymentMethod; class VoucherPaymentMethodRestrictionValidator implements PaymentMethodRestrictionValidatorInterface { @@ -63,7 +62,7 @@ public function __construct(Context $context, VoucherValidator $voucherValidator * TODO extract voucher validator internals into this class + tests. * {@inheritDoc} */ - public function isValid(MolPaymentMethod $paymentMethod) + public function isValid(\MolPaymentMethod $paymentMethod): bool { if (!$this->voucherValidator->validate($this->context->getCart()->getProducts())) { return false; @@ -75,8 +74,8 @@ public function isValid(MolPaymentMethod $paymentMethod) /** * {@inheritDoc} */ - public function supports(MolPaymentMethod $paymentMethod) + public function supports(\MolPaymentMethod $paymentMethod): bool { - return $paymentMethod->getPaymentMethodName() == Config::MOLLIE_VOUCHER_METHOD_ID; + return $paymentMethod->getPaymentMethodName() === Config::MOLLIE_VOUCHER_METHOD_ID; } } diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index d574272c2..fb08fa359 100644 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -43,17 +43,23 @@ use Mollie\Provider\Shipment\AutomaticShipmentSenderStatusesProviderInterface; use Mollie\Provider\UpdateMessageProvider; use Mollie\Provider\UpdateMessageProviderInterface; +use Mollie\Repository\AddressFormatRepository; +use Mollie\Repository\AddressFormatRepositoryInterface; use Mollie\Repository\AddressRepository; use Mollie\Repository\AddressRepositoryInterface; use Mollie\Repository\CartRuleRepository; use Mollie\Repository\CartRuleRepositoryInterface; use Mollie\Repository\CurrencyRepository; use Mollie\Repository\CurrencyRepositoryInterface; +use Mollie\Repository\CustomerRepository; +use Mollie\Repository\CustomerRepositoryInterface; use Mollie\Repository\GenderRepository; use Mollie\Repository\GenderRepositoryInterface; use Mollie\Repository\MolCustomerRepository; use Mollie\Repository\MolOrderPaymentFeeRepository; use Mollie\Repository\MolOrderPaymentFeeRepositoryInterface; +use Mollie\Repository\OrderCartRuleRepository; +use Mollie\Repository\OrderCartRuleRepositoryInterface; use Mollie\Repository\OrderRepository; use Mollie\Repository\OrderRepositoryInterface; use Mollie\Repository\PaymentMethodRepository; @@ -67,6 +73,8 @@ use Mollie\Repository\TaxRulesGroupRepository; use Mollie\Repository\TaxRulesGroupRepositoryInterface; use Mollie\Service\ApiKeyService; +use Mollie\Service\ApiService; +use Mollie\Service\ApiServiceInterface; use Mollie\Service\Content\SmartyTemplateParser; use Mollie\Service\Content\TemplateParserInterface; use Mollie\Service\EntityManager\EntityManagerInterface; @@ -74,6 +82,7 @@ use Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation; use Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation\AmountPaymentMethodRestrictionValidator; use Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation\ApplePayPaymentMethodRestrictionValidator; +use Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation\B2bPaymentMethodRestrictionValidator; use Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation\BasePaymentMethodRestrictionValidator; use Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation\EnvironmentVersionSpecificPaymentMethodRestrictionValidator; use Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidation\VoucherPaymentMethodRestrictionValidator; @@ -112,15 +121,27 @@ public function register(Container $container) $this->addService($container, RetryHandlerInterface::class, $container->get(RetryHandler::class)); + $this->addService($container, UninstallerInterface::class, $container->get(DatabaseTableUninstaller::class)); + + $this->addService($container, DecoderInterface::class, JsonDecoder::class); + + $this->addService($container, AddressRepositoryInterface::class, $container->get(AddressRepository::class)); + $this->addService($container, TaxRulesGroupRepositoryInterface::class, $container->get(TaxRulesGroupRepository::class)); + $this->addService($container, TaxRuleRepositoryInterface::class, $container->get(TaxRuleRepository::class)); + $this->addService($container, TaxRepositoryInterface::class, $container->get(TaxRepository::class)); + $this->addService($container, CustomerRepositoryInterface::class, CustomerRepository::class); + $this->addService($container, AddressFormatRepositoryInterface::class, AddressFormatRepository::class); + $this->addService($container, PendingOrderCartRuleRepositoryInterface::class, $container->get(PendingOrderCartRuleRepository::class)); + $this->addService($container, CartRuleRepositoryInterface::class, $container->get(CartRuleRepository::class)); + $this->addService($container, OrderRepositoryInterface::class, $container->get(OrderRepository::class)); + $this->addService($container, CurrencyRepositoryInterface::class, $container->get(CurrencyRepository::class)); + $this->addService($container, MolOrderPaymentFeeRepositoryInterface::class, $container->get(MolOrderPaymentFeeRepository::class)); $this->addService($container, PaymentMethodRepositoryInterface::class, $container->get(PaymentMethodRepository::class)); $this->addService($container, GenderRepositoryInterface::class, $container->get(GenderRepository::class)); + $this->addService($container, OrderCartRuleRepositoryInterface::class, $container->get(OrderCartRuleRepository::class)); $this->addService($container, MolCustomerRepository::class, MolCustomerRepository::class) ->withArgument('MolCustomer'); - $this->addService($container, UninstallerInterface::class, $container->get(DatabaseTableUninstaller::class)); - - $this->addService($container, DecoderInterface::class, JsonDecoder::class); - /* shipping */ $this->addService($container, PaymentTypeIdentificationProviderInterface::class, $container->get(RegularPaymentTypeIdentification::class)); $this->addService($container, ShipmentServiceInterface::class, $container->get(ShipmentService::class)); @@ -137,23 +158,13 @@ public function register(Container $container) ] ); - $this->addService($container, AddressRepositoryInterface::class, $container->get(AddressRepository::class)); - $this->addService($container, TaxRulesGroupRepositoryInterface::class, $container->get(TaxRulesGroupRepository::class)); - $this->addService($container, TaxRuleRepositoryInterface::class, $container->get(TaxRuleRepository::class)); - $this->addService($container, TaxRepositoryInterface::class, $container->get(TaxRepository::class)); + $this->addService($container, CartRuleQuantityChangeHandlerInterface::class, $container->get(CartRuleQuantityChangeHandler::class)); $this->addService($container, OrderTotalProviderInterface::class, $container->get(OrderTotalProvider::class)); $this->addService($container, PaymentFeeProviderInterface::class, $container->get(PaymentFeeProvider::class)); $this->addService($container, EnvironmentVersionProviderInterface::class, $container->get(EnvironmentVersionProvider::class)); - $this->addService($container, PendingOrderCartRuleRepositoryInterface::class, $container->get(PendingOrderCartRuleRepository::class)); - $this->addService($container, CartRuleRepositoryInterface::class, $container->get(CartRuleRepository::class)); - $this->addService($container, OrderRepositoryInterface::class, $container->get(OrderRepository::class)); - $this->addService($container, CurrencyRepositoryInterface::class, $container->get(CurrencyRepository::class)); - $this->addService($container, MolOrderPaymentFeeRepositoryInterface::class, $container->get(MolOrderPaymentFeeRepository::class)); - $this->addService($container, CartRuleQuantityChangeHandlerInterface::class, $container->get(CartRuleQuantityChangeHandler::class)); - $this->addService($container, TemplateParserInterface::class, SmartyTemplateParser::class); $this->addService($container, UpdateMessageProviderInterface::class, $container->get(UpdateMessageProvider::class)); @@ -167,8 +178,11 @@ public function register(Container $container) $container->get(EnvironmentVersionSpecificPaymentMethodRestrictionValidator::class), $container->get(ApplePayPaymentMethodRestrictionValidator::class), $container->get(AmountPaymentMethodRestrictionValidator::class), + $container->get(B2bPaymentMethodRestrictionValidator::class), ]); + $this->addService($container, ApiServiceInterface::class, $container->get(ApiService::class)); + $this->addService($container, CustomLogoProviderInterface::class, $container->get(CreditCardLogoProvider::class)); $this->addService($container, PaymentMethodPositionHandlerInterface::class, PaymentMethodPositionHandler::class) diff --git a/tests/Integration/Application/CommandHandler/RequestApplePayPaymentSessionHandlerTest.php b/tests/Integration/Application/CommandHandler/RequestApplePayPaymentSessionHandlerTest.php index 5aca037a2..35aa30672 100644 --- a/tests/Integration/Application/CommandHandler/RequestApplePayPaymentSessionHandlerTest.php +++ b/tests/Integration/Application/CommandHandler/RequestApplePayPaymentSessionHandlerTest.php @@ -1,7 +1,10 @@ getService(ModuleFactory::class); $apiServiceMock = new ApiServiceMock(); - $handler = new RequestApplePayPaymentSessionHandler($mollie, $apiServiceMock); + $handler = new RequestApplePayPaymentSessionHandler($moduleFactory, $apiServiceMock); $result = $handler->handle($command); $this->assertArrayHasKey('cartId', $result); diff --git a/tests/Integration/Factory/AddressFactory.php b/tests/Integration/Factory/AddressFactory.php new file mode 100644 index 000000000..7d3321697 --- /dev/null +++ b/tests/Integration/Factory/AddressFactory.php @@ -0,0 +1,28 @@ +firstname = $data['first_name'] ?? 'test-first-name'; + $address->lastname = $data['last_name'] ?? 'test-last-name'; + $address->country = $data['country'] ?? 'test-country'; + $address->id_country = $data['id_country'] ?? \Configuration::get('PS_COUNTRY_DEFAULT'); + $address->city = $data['city'] ?? 'test-city'; + $address->postcode = $data['postcode'] ?? '97222'; //max 12 chars + $address->address1 = $data['address1'] ?? 'test-address1'; + $address->address2 = $data['address2'] ?? 'test-address2'; + $address->phone_mobile = $data['phone_mobile'] ?? '5555555'; //letters or symbols cause errors + $address->alias = $data['alias'] ?? 'test-alias'; + $address->vat_number = $data['vat_number'] ?? 'test-vat'; + $address->company = $data['company'] ?? 'test-company'; + + $address->save(); + + return $address; + } +} diff --git a/tests/Integration/Factory/CarrierFactory.php b/tests/Integration/Factory/CarrierFactory.php new file mode 100644 index 000000000..e77ce0852 --- /dev/null +++ b/tests/Integration/Factory/CarrierFactory.php @@ -0,0 +1,55 @@ +name = $data['name'] ?? 'test-name'; + $carrier->active = $data['active'] ?? true; + $carrier->delay = $data['delay'] ?? '28 days later'; + + //NOTE to if true would add PS_SHIPPING_HANDLING from configuration to shipping price. + $carrier->shipping_handling = $data['shipping_handling'] ?? false; + + //NOTE need to do it like this because otherwise it would not show up as option. + if (isset($data['price']) && !empty((int) $data['price'])) { + $carrier->shipping_method = \Carrier::SHIPPING_METHOD_PRICE; + } else { + $carrier->shipping_method = \Carrier::SHIPPING_METHOD_FREE; + } + + $carrier->shipping_method = $data['shipping_method'] ?? $carrier->shipping_method; + + $carrier->save(); + + $rangePrice = new \RangePrice(); + $rangePrice->id_carrier = $carrier->id; + $rangePrice->delimiter1 = 0; + $rangePrice->delimiter2 = 1; + + $rangePrice->save(); + + $zones = \Zone::getZones(); + $prices = []; + + foreach ($zones as $zone) { + $carrier->addZone($zone['id_zone']); + + $prices[] = [ + 'id_range_price' => $rangePrice->id, + 'id_range_weight' => null, + 'id_carrier' => (int) $carrier->id, + 'id_zone' => (int) $zone['id_zone'], + 'price' => $data['price'] ?? 0, + ]; + } + // enable all zones + $carrier->addDeliveryPrice($prices); + + return $carrier; + } +} diff --git a/tests/Integration/Factory/CartFactory.php b/tests/Integration/Factory/CartFactory.php new file mode 100644 index 000000000..54698b77c --- /dev/null +++ b/tests/Integration/Factory/CartFactory.php @@ -0,0 +1,24 @@ +id_lang = $data['id_lang'] ?? \Configuration::get('PS_LANG_DEFAULT'); + $cart->id_currency = $data['id_currency'] ?? \Configuration::get('PS_CURRENCY_DEFAULT'); + $cart->id_carrier = $data['id_carrier'] ?? CarrierFactory::create()->id; + $cart->id_address_delivery = $data['id_address_delivery'] ?? AddressFactory::create()->id; + $cart->id_address_invoice = $data['id_address_invoice'] ?? AddressFactory::create()->id; + $cart->id_customer = $data['id_customer'] ?? CustomerFactory::create()->id; + + $cart->save(); + + \Context::getContext()->cart = $cart; + + return $cart; + } +} diff --git a/tests/Integration/Factory/CustomerFactory.php b/tests/Integration/Factory/CustomerFactory.php new file mode 100644 index 000000000..0906629b4 --- /dev/null +++ b/tests/Integration/Factory/CustomerFactory.php @@ -0,0 +1,24 @@ +firstname = $data['first_name'] ?? 'test-first-name'; + $customer->lastname = $data['last_name'] ?? 'test-last-name'; + $customer->email = $data['email'] ?? 'test-email@email.com'; + $customer->passwd = $data['passwd'] ?? 'test-passwd'; + $customer->is_guest = $data['is_guest'] ?? false; + $customer->siret = $data['siret'] ?? 'test-siret'; + + $customer->save(); + + \Context::getContext()->customer = $customer; + + return $customer; + } +} diff --git a/tests/Integration/Factory/FactoryInterface.php b/tests/Integration/Factory/FactoryInterface.php new file mode 100644 index 000000000..2b91d48c9 --- /dev/null +++ b/tests/Integration/Factory/FactoryInterface.php @@ -0,0 +1,8 @@ +originalB2bValue = (int) Configuration::get('PS_B2B_ENABLE'); + + parent::setUp(); + } + + public function tearDown() + { + Configuration::set('PS_B2B_ENABLE', $this->originalB2bValue); + + parent::tearDown(); + } + + public function testItSuccessfullyValidatedIsValid() + { + Configuration::set('PS_B2B_ENABLE', 1); + + $molPaymentMethod = new \MolPaymentMethod(); + $molPaymentMethod->id_method = Config::MOLLIE_PAYMENT_METHOD_BILLIE; + + $customer = CustomerFactory::create([ + 'siret' => 'test-siret-number', + ]); + + $billingAddress = AddressFactory::create([ + 'vat_number' => 'vat-number', + ]); + + $this->contextBuilder->setCart(CartFactory::create()); + $this->contextBuilder->getContext()->cart->id_address_invoice = $billingAddress->id; + $this->contextBuilder->getContext()->cart->id_customer = $customer->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() + { + Configuration::set('PS_B2B_ENABLE', 1); + + $molPaymentMethod = new \MolPaymentMethod(); + $molPaymentMethod->id_method = Config::MOLLIE_PAYMENT_METHOD_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(); + + $this->contextBuilder->setCart(CartFactory::create()); + $this->contextBuilder->getContext()->cart->id_address_invoice = $billingAddress->id; + $this->contextBuilder->getContext()->cart->id_customer = $customer->id; + + /** @var B2bPaymentMethodRestrictionValidator $b2bPaymentMethodRestrictionValidator */ + $b2bPaymentMethodRestrictionValidator = $this->getService(B2bPaymentMethodRestrictionValidator::class); + + $supports = $b2bPaymentMethodRestrictionValidator->supports($molPaymentMethod); + + $valid = $b2bPaymentMethodRestrictionValidator->isValid($molPaymentMethod); + + $addressFormat->format = $originalCountryFormat; + $addressFormat->save(); + + $this->assertEquals(true, $supports); + $this->assertEquals(true, $valid); + } + + public function testItUnsuccessfullyValidatedIsValidMethodNotSupported() + { + 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', + ]); + + $this->contextBuilder->setCart(CartFactory::create()); + $this->contextBuilder->getContext()->cart->id_address_invoice = $billingAddress->id; + $this->contextBuilder->getContext()->cart->id_customer = $customer->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() + { + Configuration::set('PS_B2B_ENABLE', 1); + + $molPaymentMethod = new \MolPaymentMethod(); + $molPaymentMethod->id_method = Config::MOLLIE_PAYMENT_METHOD_BILLIE; + + $customer = CustomerFactory::create([ + 'siret' => '', + ]); + + $billingAddress = AddressFactory::create([ + 'vat_number' => 'vat-number', + ]); + + $this->contextBuilder->setCart(CartFactory::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() + { + Configuration::set('PS_B2B_ENABLE', 0); + + $molPaymentMethod = new \MolPaymentMethod(); + $molPaymentMethod->id_method = Config::MOLLIE_PAYMENT_METHOD_BILLIE; + + $customer = CustomerFactory::create([ + 'siret' => 'test-siret', + ]); + + $billingAddress = AddressFactory::create([ + 'vat_number' => 'vat-number', + ]); + + $this->contextBuilder->setCart(CartFactory::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() + { + Configuration::set('PS_B2B_ENABLE', 1); + + $molPaymentMethod = new \MolPaymentMethod(); + $molPaymentMethod->id_method = Config::MOLLIE_PAYMENT_METHOD_BILLIE; + + $customer = CustomerFactory::create([ + 'siret' => 'test-siret', + ]); + + $billingAddress = AddressFactory::create([ + 'vat_number' => '', + ]); + + $this->contextBuilder->setCart(CartFactory::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() + { + Configuration::set('PS_B2B_ENABLE', 1); + + $molPaymentMethod = new \MolPaymentMethod(); + $molPaymentMethod->id_method = Config::MOLLIE_PAYMENT_METHOD_BILLIE; + + $customer = CustomerFactory::create([ + 'siret' => 'test-siret', + ]); + + $billingAddress = AddressFactory::create([ + 'vat_number' => '', + ]); + + $shippingAddress = AddressFactory::create([ + 'vat_number' => 'test-vat-number', + ]); + + $this->contextBuilder->setCart(CartFactory::create([ + 'id_customer' => $customer->id, + 'id_address_delivery' => $shippingAddress->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); + } +} diff --git a/tests/Unit/Service/PaymentMethod/PaymentMethodRestrictionValidation/ApplePayPaymentRestrictionValidationTest.php b/tests/Unit/Service/PaymentMethod/PaymentMethodRestrictionValidation/ApplePayPaymentRestrictionValidationTest.php index db90a1b49..50b3ee69c 100644 --- a/tests/Unit/Service/PaymentMethod/PaymentMethodRestrictionValidation/ApplePayPaymentRestrictionValidationTest.php +++ b/tests/Unit/Service/PaymentMethod/PaymentMethodRestrictionValidation/ApplePayPaymentRestrictionValidationTest.php @@ -1,6 +1,7 @@ getMockBuilder(Context::class) - ->disableOriginalConstructor() - ->getMock(); $applePayValidation = new ApplePayPaymentMethodRestrictionValidator( - $contextMock, $configurationAdapter ); @@ -60,7 +57,6 @@ public function getApplePayPaymentRestrictionValidationDataProvider() public function testIsSupported($paymentName, $expectedResult) { $applePayValidation = new ApplePayPaymentMethodRestrictionValidator( - $this->mockContext('AT', 'AUD'), $this->mockConfigurationAdapter([ 'PS_SSL_ENABLED_EVERYWHERE' => true, ]) From da2f38f8eb21c95c2620253e2b10123be54f8b55 Mon Sep 17 00:00:00 2001 From: mandan2 <61560082+mandan2@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:34:33 +0200 Subject: [PATCH 2/3] PIPRES-352: Billie payment method setup (#17) * PIPRES-352: Billie payment method setup * fix * DI missing service fix --- src/Builder/FormBuilder.php | 12 +-- src/Config/Config.php | 26 ++--- .../ApplePayDirectCertificateHandler.php | 5 +- src/Handler/Order/OrderCreationHandler.php | 4 +- src/Install/OrderStateInstaller.php | 10 +- src/Presenter/OrderListActionBuilder.php | 5 +- .../BancontactPaymentOptionProvider.php | 5 +- .../BasePaymentOptionProvider.php | 5 +- .../CreditCardPaymentOptionProvider.php | 5 +- ...itCardSingleClickPaymentOptionProvider.php | 5 +- .../IdealPaymentOptionProvider.php | 5 +- src/Service/ConfigFieldService.php | 98 ++++++++++--------- src/Service/CustomerService.php | 5 +- src/Service/OrderStatusService.php | 2 +- src/Service/SettingsSaveService.php | 40 ++++---- src/Service/TransactionService.php | 35 ++++--- src/ServiceProvider/BaseServiceProvider.php | 3 +- src/Validator/OrderConfMailValidator.php | 2 +- .../Install/OrderStateInstallerTest.php | 4 +- upgrade/Upgrade-4.2.0.php | 12 +-- upgrade/Upgrade-5.4.3.php | 79 +++++++++++++++ views/templates/admin/invoice_description.tpl | 4 +- 22 files changed, 237 insertions(+), 134 deletions(-) diff --git a/src/Builder/FormBuilder.php b/src/Builder/FormBuilder.php index 5414a6a63..cc660f0fc 100644 --- a/src/Builder/FormBuilder.php +++ b/src/Builder/FormBuilder.php @@ -406,8 +406,6 @@ protected function getAccountSettingsSection($isApiKeyProvided) 'customLogoUrl' => $this->creditCardLogoProvider->getLogoPathUri() . "?{$dateStamp}", 'customLogoExist' => $this->creditCardLogoProvider->logoExists(), 'voucherCategory' => $this->configurationAdapter->get(Config::MOLLIE_VOUCHER_CATEGORY), - 'klarnaPayments' => Config::KLARNA_PAYMENTS, - 'klarnaStatuses' => [Config::MOLLIE_STATUS_KLARNA_AUTHORIZED, Config::MOLLIE_STATUS_KLARNA_SHIPPED], 'applePayDirectProduct' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_PRODUCT), 'applePayDirectCart' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_CART), 'applePayDirectStyle' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE), @@ -481,22 +479,22 @@ protected function getAdvancedSettingsSection() $input[] = [ 'type' => 'select', - 'label' => $this->module->l('Select when to create the Klarna invoice', self::FILE_NAME), + 'label' => $this->module->l('Select when to create the Order invoice', self::FILE_NAME), 'desc' => $this->module->display($this->module->getPathUri(), 'views/templates/admin/invoice_description.tpl'), 'tab' => $advancedSettings, - 'name' => Config::MOLLIE_KLARNA_INVOICE_ON, + 'name' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, 'options' => [ 'query' => [ [ - 'id' => Config::MOLLIE_STATUS_DEFAULT, + 'id' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT, 'name' => $this->module->l('Default', self::FILE_NAME), ], [ - 'id' => Config::MOLLIE_STATUS_KLARNA_AUTHORIZED, + 'id' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, 'name' => $this->module->l('Authorised', self::FILE_NAME), ], [ - 'id' => Config::MOLLIE_STATUS_KLARNA_SHIPPED, + 'id' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, 'name' => $this->module->l('Shipped', self::FILE_NAME), ], ], diff --git a/src/Config/Config.php b/src/Config/Config.php index 2d04d8844..3756672de 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -144,11 +144,11 @@ class Config const MOLLIE_STATUS_INITIATED = 'MOLLIE_STATUS_INITIATED'; const MOLLIE_STATUS_PARTIALLY_SHIPPED = 'MOLLIE_PARTIALLY_SHIPPED'; const MOLLIE_STATUS_ORDER_COMPLETED = 'MOLLIE_STATUS_ORDER_COMPLETED'; - const MOLLIE_STATUS_DEFAULT = 'MOLLIE_STATUS_DEFAULT'; - const MOLLIE_STATUS_KLARNA_AUTHORIZED = 'MOLLIE_STATUS_KLARNA_AUTHORIZED'; - const MOLLIE_STATUS_KLARNA_SHIPPED = 'MOLLIE_STATUS_KLARNA_SHIPPED'; + const MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT = 'MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT'; + const MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED = 'MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED'; + const MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED = 'MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED'; const MOLLIE_STATUS_CHARGEBACK = 'MOLLIE_STATUS_CHARGEBACK'; - const MOLLIE_KLARNA_INVOICE_ON = 'MOLLIE_KLARNA_INVOICE_ON'; + const MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS = 'MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS'; const MOLLIE_APPLE_PAY_DIRECT_PRODUCT = 'MOLLIE_APPLE_PAY_DIRECT_PRODUCT'; const MOLLIE_APPLE_PAY_DIRECT_CART = 'MOLLIE_APPLE_PAY_DIRECT_CART'; @@ -262,16 +262,18 @@ class Config const RESTORE_CART_BACKTRACE_MEMORIZATION_SERVICE = 'memo'; const RESTORE_CART_BACKTRACE_RETURN_CONTROLLER = 'return'; - const KLARNA_PAYMENTS = [ + const AUTHORIZABLE_PAYMENTS = [ PaymentMethod::KLARNA_PAY_LATER, PaymentMethod::KLARNA_SLICE_IT, PaymentMethod::KLARNA_PAY_NOW, + self::MOLLIE_PAYMENT_METHOD_BILLIE, ]; const ORDER_API_ONLY_METHODS = [ PaymentMethod::KLARNA_PAY_LATER, PaymentMethod::KLARNA_SLICE_IT, PaymentMethod::KLARNA_PAY_NOW, + self::MOLLIE_PAYMENT_METHOD_BILLIE, self::MOLLIE_VOUCHER_METHOD_ID, self::MOLLIE_in3_METHOD_ID, ]; @@ -309,6 +311,7 @@ class Config 'voucher' => 'Voucher', 'klarnapaynow' => 'Klarna Pay now.', 'in3' => 'in3', + 'billie' => 'Billie', ]; const MOLLIE_BUTTON_ORDER_TOTAL_REFRESH = 'MOLLIE_BUTTON_ORDER_TOTAL_REFRESH'; @@ -318,14 +321,15 @@ class Config public static function getStatuses() { - $isKlarnaDefault = Configuration::get(Config::MOLLIE_KLARNA_INVOICE_ON) === Config::MOLLIE_STATUS_DEFAULT; + $isAuthorizablePaymentInvoiceOnStatusDefault = + Configuration::get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS) === Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT; return [ self::MOLLIE_AWAITING_PAYMENT => Configuration::get(self::MOLLIE_STATUS_AWAITING), PaymentStatus::STATUS_PAID => Configuration::get(self::MOLLIE_STATUS_PAID), OrderStatus::STATUS_COMPLETED => Configuration::get(self::MOLLIE_STATUS_COMPLETED), - PaymentStatus::STATUS_AUTHORIZED => $isKlarnaDefault ? - Configuration::get(self::MOLLIE_STATUS_PAID) : Configuration::get(self::MOLLIE_STATUS_KLARNA_AUTHORIZED), + PaymentStatus::STATUS_AUTHORIZED => $isAuthorizablePaymentInvoiceOnStatusDefault ? + Configuration::get(self::MOLLIE_STATUS_PAID) : Configuration::get(self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED), PaymentStatus::STATUS_CANCELED => Configuration::get(self::MOLLIE_STATUS_CANCELED), PaymentStatus::STATUS_EXPIRED => Configuration::get(self::MOLLIE_STATUS_EXPIRED), RefundStatus::STATUS_REFUNDED => Configuration::get(self::MOLLIE_STATUS_REFUNDED), @@ -338,7 +342,7 @@ public static function getStatuses() self::STATUS_PAID_ON_BACKORDER => Configuration::get('PS_OS_OUTOFSTOCK_PAID'), self::STATUS_PENDING_ON_BACKORDER => Configuration::get('PS_OS_OUTOFSTOCK_UNPAID'), self::STATUS_ON_BACKORDER => Configuration::get('PS_OS_OUTOFSTOCK'), - self::MOLLIE_STATUS_KLARNA_SHIPPED => Configuration::get(self::MOLLIE_STATUS_KLARNA_SHIPPED), + self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED => Configuration::get(self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED), self::MOLLIE_CHARGEBACK => Configuration::get(self::MOLLIE_STATUS_CHARGEBACK), ]; } @@ -360,8 +364,8 @@ public static function getMollieOrderStatuses() self::MOLLIE_STATUS_PARTIAL_REFUND, self::MOLLIE_STATUS_AWAITING, self::MOLLIE_STATUS_ORDER_COMPLETED, - self::MOLLIE_STATUS_KLARNA_AUTHORIZED, - self::MOLLIE_STATUS_KLARNA_SHIPPED, + self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, + self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, self::MOLLIE_STATUS_CHARGEBACK, ]; } diff --git a/src/Handler/Certificate/ApplePayDirectCertificateHandler.php b/src/Handler/Certificate/ApplePayDirectCertificateHandler.php index bf871b219..56bccab30 100644 --- a/src/Handler/Certificate/ApplePayDirectCertificateHandler.php +++ b/src/Handler/Certificate/ApplePayDirectCertificateHandler.php @@ -13,6 +13,7 @@ namespace Mollie\Handler\Certificate; use Mollie; +use Mollie\Factory\ModuleFactory; use Mollie\Handler\Certificate\Exception\ApplePayDirectCertificateCreation; use Mollie\Utility\FileUtility; @@ -30,9 +31,9 @@ class ApplePayDirectCertificateHandler implements CertificateHandlerInterface private $mollie; private $serverRoot; - public function __construct(Mollie $mollie) + public function __construct(ModuleFactory $moduleFactory) { - $this->mollie = $mollie; + $this->mollie = $moduleFactory->getModule(); $this->serverRoot = $_SERVER['DOCUMENT_ROOT']; } diff --git a/src/Handler/Order/OrderCreationHandler.php b/src/Handler/Order/OrderCreationHandler.php index 0770682ac..b22b85574 100644 --- a/src/Handler/Order/OrderCreationHandler.php +++ b/src/Handler/Order/OrderCreationHandler.php @@ -99,9 +99,9 @@ public function __construct( * * @throws \Exception */ - public function createOrder($apiPayment, int $cartId, bool $isKlarnaOrder = false): int + public function createOrder($apiPayment, int $cartId, bool $isAuthorizablePayment = false): int { - $orderStatus = $isKlarnaOrder ? + $orderStatus = $isAuthorizablePayment ? (int) Config::getStatuses()[PaymentStatus::STATUS_AUTHORIZED] : (int) Config::getStatuses()[PaymentStatus::STATUS_PAID]; diff --git a/src/Install/OrderStateInstaller.php b/src/Install/OrderStateInstaller.php index 9a07dcac7..d2bfb9a5e 100644 --- a/src/Install/OrderStateInstaller.php +++ b/src/Install/OrderStateInstaller.php @@ -33,7 +33,7 @@ public function __construct( /** * @throws CouldNotInstallModule */ - public function install() + public function install(): bool { $this->installOrderState( Config::MOLLIE_STATUS_PARTIAL_REFUND, @@ -69,9 +69,9 @@ public function install() ); $this->installOrderState( - Config::MOLLIE_STATUS_KLARNA_AUTHORIZED, + Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, new OrderStateData( - 'Klarna payment authorized', + 'Order payment authorized', '#8A2BE2', true, true, @@ -85,9 +85,9 @@ public function install() ); $this->installOrderState( - Config::MOLLIE_STATUS_KLARNA_SHIPPED, + Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, new OrderStateData( - 'Klarna payment shipped', + 'Order payment shipped', '#8A2BE2', true, true, diff --git a/src/Presenter/OrderListActionBuilder.php b/src/Presenter/OrderListActionBuilder.php index 5e2f476ca..8d6543711 100644 --- a/src/Presenter/OrderListActionBuilder.php +++ b/src/Presenter/OrderListActionBuilder.php @@ -13,6 +13,7 @@ namespace Mollie\Presenter; use Mollie; +use Mollie\Factory\ModuleFactory; use Smarty_Data; class OrderListActionBuilder @@ -23,9 +24,9 @@ class OrderListActionBuilder */ private $mollie; - public function __construct(Mollie $mollie) + public function __construct(ModuleFactory $moduleFactory) { - $this->mollie = $mollie; + $this->mollie = $moduleFactory->getModule(); } public function buildOrderPaymentResendButton(Smarty_Data $smarty, $orderId) diff --git a/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php b/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php index 6bfec0ce4..0ce649bd4 100644 --- a/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php @@ -39,6 +39,7 @@ use Mollie; use Mollie\Adapter\Context; use Mollie\Api\Types\PaymentMethod; +use Mollie\Factory\ModuleFactory; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; @@ -79,14 +80,14 @@ class BancontactPaymentOptionProvider implements PaymentOptionProviderInterface private $orderTotalProvider; public function __construct( - Mollie $module, + ModuleFactory $moduleFactory, Context $context, CreditCardLogoProvider $creditCardLogoProvider, PaymentFeeProviderInterface $paymentFeeProvider, LanguageService $languageService, OrderTotalProviderInterface $orderTotalProvider ) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); $this->context = $context; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->paymentFeeProvider = $paymentFeeProvider; diff --git a/src/Provider/PaymentOption/BasePaymentOptionProvider.php b/src/Provider/PaymentOption/BasePaymentOptionProvider.php index 2296d821b..1d40c86bf 100644 --- a/src/Provider/PaymentOption/BasePaymentOptionProvider.php +++ b/src/Provider/PaymentOption/BasePaymentOptionProvider.php @@ -38,6 +38,7 @@ use Mollie; use Mollie\Adapter\Context; +use Mollie\Factory\ModuleFactory; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; @@ -78,14 +79,14 @@ class BasePaymentOptionProvider implements PaymentOptionProviderInterface private $orderTotalProvider; public function __construct( - Mollie $module, + ModuleFactory $moduleFactory, Context $context, CreditCardLogoProvider $creditCardLogoProvider, PaymentFeeProviderInterface $paymentFeeProvider, LanguageService $languageService, OrderTotalProviderInterface $orderTotalProvider ) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); $this->context = $context; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->paymentFeeProvider = $paymentFeeProvider; diff --git a/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php b/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php index 238ea2c21..017c2a079 100644 --- a/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php @@ -41,6 +41,7 @@ use Mollie\Adapter\ConfigurationAdapter; use Mollie\Adapter\Context; use Mollie\Config\Config; +use Mollie\Factory\ModuleFactory; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; @@ -92,7 +93,7 @@ class CreditCardPaymentOptionProvider implements PaymentOptionProviderInterface private $configurationAdapter; public function __construct( - Mollie $module, + ModuleFactory $moduleFactory, Context $context, CreditCardLogoProvider $creditCardLogoProvider, OrderTotalProviderInterface $orderTotalProvider, @@ -101,7 +102,7 @@ public function __construct( MolCustomerRepository $customerRepository, ConfigurationAdapter $configurationAdapter ) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); $this->context = $context; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->orderTotalProvider = $orderTotalProvider; diff --git a/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php b/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php index 87eb54593..f508df453 100644 --- a/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php @@ -41,6 +41,7 @@ use Mollie\Adapter\ConfigurationAdapter; use Mollie\Adapter\Context; use Mollie\Config\Config; +use Mollie\Factory\ModuleFactory; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; @@ -92,7 +93,7 @@ class CreditCardSingleClickPaymentOptionProvider implements PaymentOptionProvide private $configurationAdapter; public function __construct( - Mollie $module, + ModuleFactory $moduleFactory, Context $context, CreditCardLogoProvider $creditCardLogoProvider, OrderTotalProviderInterface $orderTotalProvider, @@ -101,7 +102,7 @@ public function __construct( MolCustomerRepository $customerRepository, ConfigurationAdapter $configurationAdapter ) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); $this->context = $context; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->orderTotalProvider = $orderTotalProvider; diff --git a/src/Provider/PaymentOption/IdealPaymentOptionProvider.php b/src/Provider/PaymentOption/IdealPaymentOptionProvider.php index e73f4b2f2..d1ed01dd7 100644 --- a/src/Provider/PaymentOption/IdealPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/IdealPaymentOptionProvider.php @@ -39,6 +39,7 @@ use Mollie; use Mollie\Adapter\Context; use Mollie\Builder\Content\PaymentOption\IdealDropdownInfoBlock; +use Mollie\Factory\ModuleFactory; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; @@ -90,7 +91,7 @@ class IdealPaymentOptionProvider implements PaymentOptionProviderInterface private $orderTotalProvider; public function __construct( - Mollie $module, + ModuleFactory $moduleFactory, Context $context, CreditCardLogoProvider $creditCardLogoProvider, PaymentFeeProviderInterface $paymentFeeProvider, @@ -99,7 +100,7 @@ public function __construct( LanguageService $languageService, OrderTotalProviderInterface $orderTotalProvider ) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); $this->context = $context; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->paymentFeeProvider = $paymentFeeProvider; diff --git a/src/Service/ConfigFieldService.php b/src/Service/ConfigFieldService.php index 96bc13206..306a5951f 100644 --- a/src/Service/ConfigFieldService.php +++ b/src/Service/ConfigFieldService.php @@ -12,12 +12,12 @@ namespace Mollie\Service; -use Configuration; use Mollie; use Mollie\Adapter\ConfigurationAdapter; use Mollie\Config\Config; use Mollie\Factory\ModuleFactory; use Mollie\Repository\CountryRepository; +use Mollie\Utility\EnvironmentUtility; class ConfigFieldService { @@ -54,67 +54,71 @@ public function __construct( public function getConfigFieldsValues() { $configFields = [ - Config::MOLLIE_ENVIRONMENT => Configuration::get(Config::MOLLIE_ENVIRONMENT), - Config::MOLLIE_API_KEY => Configuration::get(Config::MOLLIE_API_KEY), - Config::MOLLIE_API_KEY_TEST => Configuration::get(Config::MOLLIE_API_KEY_TEST), - Config::MOLLIE_PAYMENTSCREEN_LOCALE => Configuration::get(Config::MOLLIE_PAYMENTSCREEN_LOCALE), - Config::MOLLIE_SEND_ORDER_CONFIRMATION => Configuration::get(Config::MOLLIE_SEND_ORDER_CONFIRMATION), + Config::MOLLIE_ENVIRONMENT => $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT), + Config::MOLLIE_API_KEY => $this->configurationAdapter->get(Config::MOLLIE_API_KEY), + Config::MOLLIE_API_KEY_TEST => $this->configurationAdapter->get(Config::MOLLIE_API_KEY_TEST), + Config::MOLLIE_PAYMENTSCREEN_LOCALE => $this->configurationAdapter->get(Config::MOLLIE_PAYMENTSCREEN_LOCALE), + Config::MOLLIE_SEND_ORDER_CONFIRMATION => $this->configurationAdapter->get(Config::MOLLIE_SEND_ORDER_CONFIRMATION), Config::MOLLIE_IFRAME[(int) $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT) ? 'production' : 'sandbox'] => $this->configurationAdapter->get(Config::MOLLIE_IFRAME), Config::MOLLIE_SINGLE_CLICK_PAYMENT[(int) $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT) ? 'production' : 'sandbox'] => $this->configurationAdapter->get(Config::MOLLIE_SINGLE_CLICK_PAYMENT), - Config::MOLLIE_CSS => Configuration::get(Config::MOLLIE_CSS), - Config::MOLLIE_IMAGES => Configuration::get(Config::MOLLIE_IMAGES), - Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK => Configuration::get(Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK), + Config::MOLLIE_CSS => $this->configurationAdapter->get(Config::MOLLIE_CSS), + Config::MOLLIE_IMAGES => $this->configurationAdapter->get(Config::MOLLIE_IMAGES), + Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK => $this->configurationAdapter->get(Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK), Config::MOLLIE_ISSUERS[(int) $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT) ? 'production' : 'sandbox'] => $this->configurationAdapter->get(Config::MOLLIE_ISSUERS), - Config::MOLLIE_METHOD_COUNTRIES => Configuration::get(Config::MOLLIE_METHOD_COUNTRIES), - Config::MOLLIE_METHOD_COUNTRIES_DISPLAY => Configuration::get(Config::MOLLIE_METHOD_COUNTRIES_DISPLAY), - - Config::MOLLIE_STATUS_OPEN => Configuration::get(Config::MOLLIE_STATUS_OPEN), - Config::MOLLIE_STATUS_AWAITING => Configuration::get(Config::MOLLIE_STATUS_AWAITING), - Config::MOLLIE_STATUS_PAID => Configuration::get(Config::MOLLIE_STATUS_PAID), - Config::MOLLIE_STATUS_COMPLETED => Configuration::get(Config::MOLLIE_STATUS_COMPLETED), - Config::MOLLIE_STATUS_CANCELED => Configuration::get(Config::MOLLIE_STATUS_CANCELED), - Config::MOLLIE_STATUS_EXPIRED => Configuration::get(Config::MOLLIE_STATUS_EXPIRED), - Config::MOLLIE_STATUS_PARTIAL_REFUND => Configuration::get(Config::MOLLIE_STATUS_PARTIAL_REFUND), - Config::MOLLIE_STATUS_REFUNDED => Configuration::get(Config::MOLLIE_STATUS_REFUNDED), - Config::MOLLIE_STATUS_CHARGEBACK => Configuration::get(Config::MOLLIE_STATUS_CHARGEBACK), - Config::MOLLIE_MAIL_WHEN_OPEN => Configuration::get(Config::MOLLIE_MAIL_WHEN_OPEN), - Config::MOLLIE_MAIL_WHEN_AWAITING => Configuration::get(Config::MOLLIE_MAIL_WHEN_AWAITING), - Config::MOLLIE_MAIL_WHEN_PAID => Configuration::get(Config::MOLLIE_MAIL_WHEN_PAID), - Config::MOLLIE_MAIL_WHEN_COMPLETED => Configuration::get(Config::MOLLIE_MAIL_WHEN_COMPLETED), - Config::MOLLIE_MAIL_WHEN_CANCELED => Configuration::get(Config::MOLLIE_MAIL_WHEN_CANCELED), - Config::MOLLIE_MAIL_WHEN_EXPIRED => Configuration::get(Config::MOLLIE_MAIL_WHEN_EXPIRED), - Config::MOLLIE_MAIL_WHEN_REFUNDED => Configuration::get(Config::MOLLIE_MAIL_WHEN_REFUNDED), - Config::MOLLIE_MAIL_WHEN_CHARGEBACK => Configuration::get(Config::MOLLIE_MAIL_WHEN_CHARGEBACK), - Config::MOLLIE_ACCOUNT_SWITCH => Configuration::get(Config::MOLLIE_ACCOUNT_SWITCH), - - Config::MOLLIE_DISPLAY_ERRORS => Configuration::get(Config::MOLLIE_DISPLAY_ERRORS), - Config::MOLLIE_DEBUG_LOG => Configuration::get(Config::MOLLIE_DEBUG_LOG), - Config::MOLLIE_API => Configuration::get(Config::MOLLIE_API), - - Config::MOLLIE_AUTO_SHIP_MAIN => Configuration::get(Config::MOLLIE_AUTO_SHIP_MAIN), - - Config::MOLLIE_STATUS_SHIPPING => Configuration::get(Config::MOLLIE_STATUS_SHIPPING), - Config::MOLLIE_MAIL_WHEN_SHIPPING => Configuration::get(Config::MOLLIE_MAIL_WHEN_SHIPPING), - Config::MOLLIE_KLARNA_INVOICE_ON => Configuration::get(Config::MOLLIE_KLARNA_INVOICE_ON), + Config::MOLLIE_METHOD_COUNTRIES => $this->configurationAdapter->get(Config::MOLLIE_METHOD_COUNTRIES), + Config::MOLLIE_METHOD_COUNTRIES_DISPLAY => $this->configurationAdapter->get(Config::MOLLIE_METHOD_COUNTRIES_DISPLAY), + + Config::MOLLIE_STATUS_OPEN => $this->configurationAdapter->get(Config::MOLLIE_STATUS_OPEN), + Config::MOLLIE_STATUS_AWAITING => $this->configurationAdapter->get(Config::MOLLIE_STATUS_AWAITING), + Config::MOLLIE_STATUS_PAID => $this->configurationAdapter->get(Config::MOLLIE_STATUS_PAID), + Config::MOLLIE_STATUS_COMPLETED => $this->configurationAdapter->get(Config::MOLLIE_STATUS_COMPLETED), + Config::MOLLIE_STATUS_CANCELED => $this->configurationAdapter->get(Config::MOLLIE_STATUS_CANCELED), + Config::MOLLIE_STATUS_EXPIRED => $this->configurationAdapter->get(Config::MOLLIE_STATUS_EXPIRED), + Config::MOLLIE_STATUS_PARTIAL_REFUND => $this->configurationAdapter->get(Config::MOLLIE_STATUS_PARTIAL_REFUND), + Config::MOLLIE_STATUS_REFUNDED => $this->configurationAdapter->get(Config::MOLLIE_STATUS_REFUNDED), + Config::MOLLIE_STATUS_CHARGEBACK => $this->configurationAdapter->get(Config::MOLLIE_STATUS_CHARGEBACK), + Config::MOLLIE_MAIL_WHEN_OPEN => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_OPEN), + Config::MOLLIE_MAIL_WHEN_AWAITING => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_AWAITING), + Config::MOLLIE_MAIL_WHEN_PAID => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_PAID), + Config::MOLLIE_MAIL_WHEN_COMPLETED => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_COMPLETED), + Config::MOLLIE_MAIL_WHEN_CANCELED => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_CANCELED), + Config::MOLLIE_MAIL_WHEN_EXPIRED => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_EXPIRED), + Config::MOLLIE_MAIL_WHEN_REFUNDED => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_REFUNDED), + Config::MOLLIE_MAIL_WHEN_CHARGEBACK => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_CHARGEBACK), + Config::MOLLIE_ACCOUNT_SWITCH => $this->configurationAdapter->get(Config::MOLLIE_ACCOUNT_SWITCH), + + Config::MOLLIE_DISPLAY_ERRORS => $this->configurationAdapter->get(Config::MOLLIE_DISPLAY_ERRORS), + Config::MOLLIE_DEBUG_LOG => $this->configurationAdapter->get(Config::MOLLIE_DEBUG_LOG), + Config::MOLLIE_API => $this->configurationAdapter->get(Config::MOLLIE_API), + + Config::MOLLIE_AUTO_SHIP_MAIN => $this->configurationAdapter->get(Config::MOLLIE_AUTO_SHIP_MAIN), + + Config::MOLLIE_STATUS_SHIPPING => $this->configurationAdapter->get(Config::MOLLIE_STATUS_SHIPPING), + Config::MOLLIE_MAIL_WHEN_SHIPPING => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_SHIPPING), + Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS => $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS), ]; - if (Mollie\Utility\EnvironmentUtility::getApiKey() && $this->module->getApiClient() !== null) { + if (EnvironmentUtility::getApiKey() && $this->module->getApiClient() !== null) { foreach ($this->apiService->getMethodsForConfig($this->module->getApiClient()) as $method) { $countryIds = $this->countryRepository->getMethodCountryIds($method['id']); + if ($countryIds) { - $configFields = array_merge($configFields, [Config::MOLLIE_COUNTRIES . $method['id'] . '[]' => $countryIds]); + $configFields[Config::MOLLIE_COUNTRIES . $method['id'] . '[]'] = $countryIds; + continue; } - $configFields = array_merge($configFields, [Config::MOLLIE_COUNTRIES . $method['id'] . '[]' => []]); + + $configFields[Config::MOLLIE_COUNTRIES . $method['id'] . '[]'] = []; } } $checkStatuses = []; - if (Configuration::get(Config::MOLLIE_AUTO_SHIP_STATUSES)) { - $checkConfs = @json_decode(Configuration::get(Config::MOLLIE_AUTO_SHIP_STATUSES), true); + if ($this->configurationAdapter->get(Config::MOLLIE_AUTO_SHIP_STATUSES)) { + $checkConfs = @json_decode($this->configurationAdapter->get(Config::MOLLIE_AUTO_SHIP_STATUSES), true); } + if (!isset($checkConfs) || !is_array($checkConfs)) { $checkConfs = []; } @@ -123,8 +127,6 @@ public function getConfigFieldsValues() $checkStatuses[Config::MOLLIE_AUTO_SHIP_STATUSES . '_' . (int) $conf] = true; } - $configFields = array_merge($configFields, $checkStatuses); - - return $configFields; + return array_merge($configFields, $checkStatuses); } } diff --git a/src/Service/CustomerService.php b/src/Service/CustomerService.php index 73bd4c4d9..0ecb0bbab 100644 --- a/src/Service/CustomerService.php +++ b/src/Service/CustomerService.php @@ -16,6 +16,7 @@ use Mollie; use Mollie\Config\Config; use Mollie\Exception\MollieException; +use Mollie\Factory\ModuleFactory; use Mollie\Repository\MolCustomerRepository; use Mollie\Utility\CustomerUtility; @@ -31,9 +32,9 @@ class CustomerService */ private $customerRepository; - public function __construct(Mollie $mollie, MolCustomerRepository $customerRepository) + public function __construct(ModuleFactory $moduleFactory, MolCustomerRepository $customerRepository) { - $this->mollie = $mollie; + $this->mollie = $moduleFactory->getModule(); $this->customerRepository = $customerRepository; } diff --git a/src/Service/OrderStatusService.php b/src/Service/OrderStatusService.php index 1d4c26d0e..33c1ea8d1 100644 --- a/src/Service/OrderStatusService.php +++ b/src/Service/OrderStatusService.php @@ -157,6 +157,6 @@ private function isStatusPaid($statusId) { return ((int) $statusId === (int) Configuration::get(Config::MOLLIE_STATUS_PAID)) || ((int) $statusId === (int) Configuration::get(Config::STATUS_PS_OS_OUTOFSTOCK_PAID)) || - ((int) $statusId === (int) Configuration::get(Config::MOLLIE_STATUS_KLARNA_AUTHORIZED)); + ((int) $statusId === (int) Configuration::get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED)); } } diff --git a/src/Service/SettingsSaveService.php b/src/Service/SettingsSaveService.php index 9e722021c..7df3662f1 100644 --- a/src/Service/SettingsSaveService.php +++ b/src/Service/SettingsSaveService.php @@ -13,7 +13,6 @@ namespace Mollie\Service; use Carrier; -use Configuration; use Exception; use Mollie; use Mollie\Adapter\ConfigurationAdapter; @@ -126,7 +125,7 @@ public function __construct( */ public function saveSettings(&$errors = []) { - $oldEnvironment = (int) Configuration::get(Config::MOLLIE_ENVIRONMENT); + $oldEnvironment = (int) $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT); $environment = (int) Tools::getValue(Config::MOLLIE_ENVIRONMENT); $mollieApiKey = Tools::getValue(Config::MOLLIE_API_KEY); $mollieApiKeyTest = Tools::getValue(Config::MOLLIE_API_KEY_TEST); @@ -281,9 +280,9 @@ public function saveSettings(&$errors = []) } } try { - $this->handleKlarnaInvoiceStatus(); + $this->handleAuthorizablePaymentInvoiceStatus(); } catch (Exception $e) { - $errors[] = $this->module->l('There are issues with your Klarna statuses, please try resetting Mollie module.', self::FILE_NAME); + $errors[] = $this->module->l('There are issues with your authorizable payment statuses, please try resetting Mollie module.', self::FILE_NAME); } if (empty($errors)) { @@ -384,30 +383,33 @@ private function getStatusesValue($key) return $statesEnabled; } - private function handleKlarnaInvoiceStatus() + private function handleAuthorizablePaymentInvoiceStatus() { - $klarnaInvoiceStatus = Tools::getValue(Config::MOLLIE_KLARNA_INVOICE_ON); - $this->configurationAdapter->updateValue(Config::MOLLIE_KLARNA_INVOICE_ON, $klarnaInvoiceStatus); - if (Config::MOLLIE_STATUS_KLARNA_SHIPPED === $klarnaInvoiceStatus) { - $this->updateKlarnaStatuses(true); + $authorizablePaymentInvoiceOnStatus = (string) Tools::getValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS); + + $this->configurationAdapter->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, $authorizablePaymentInvoiceOnStatus); + + if (Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED === $authorizablePaymentInvoiceOnStatus) { + $this->updateAuthorizablePaymentOrderStatus(true); return; } - $this->updateKlarnaStatuses(false); + $this->updateAuthorizablePaymentOrderStatus(false); } - private function updateKlarnaStatuses($isShipped = true) + private function updateAuthorizablePaymentOrderStatus(bool $isShipped = true) { - $klarnaInvoiceShippedId = Configuration::get(Config::MOLLIE_STATUS_KLARNA_SHIPPED); - $klarnaInvoiceShipped = new OrderState((int) $klarnaInvoiceShippedId); - $klarnaInvoiceShipped->invoice = $isShipped; - $klarnaInvoiceShipped->update(); + $authorizablePaymentStatusShippedId = $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED); + $authorizablePaymentStatusShipped = new OrderState((int) $authorizablePaymentStatusShippedId); + + $authorizablePaymentStatusShipped->invoice = $isShipped; + $authorizablePaymentStatusShipped->update(); - $klarnaInvoiceAcceptedId = Configuration::get(Config::MOLLIE_STATUS_KLARNA_AUTHORIZED); - $klarnaInvoiceAccepted = new OrderState((int) $klarnaInvoiceAcceptedId); + $authorizablePaymentStatusAuthorizedId = $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED); + $authorizablePaymentStatusAuthorized = new OrderState((int) $authorizablePaymentStatusAuthorizedId); - $klarnaInvoiceAccepted->invoice = !$isShipped; - $klarnaInvoiceAccepted->update(); + $authorizablePaymentStatusAuthorized->invoice = !$isShipped; + $authorizablePaymentStatusAuthorized->update(); } } diff --git a/src/Service/TransactionService.php b/src/Service/TransactionService.php index 381229130..24802c9b6 100644 --- a/src/Service/TransactionService.php +++ b/src/Service/TransactionService.php @@ -13,10 +13,10 @@ namespace Mollie\Service; use Cart; -use Configuration; use Currency; use Db; use Mollie; +use Mollie\Adapter\ConfigurationAdapter; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Order as MollieOrderAlias; use Mollie\Api\Resources\Payment; @@ -79,6 +79,8 @@ class TransactionService private $logger; /** @var ExceptionService */ private $exceptionService; + /** @var ConfigurationAdapter */ + private $configurationAdapter; public function __construct( ModuleFactory $moduleFactory, @@ -90,7 +92,8 @@ public function __construct( OrderPaymentFeeHandler $orderPaymentFeeHandler, ShipmentSenderHandlerInterface $shipmentSenderHandler, PrestaLoggerInterface $logger, - ExceptionService $exceptionService + ExceptionService $exceptionService, + ConfigurationAdapter $configurationAdapter ) { $this->module = $moduleFactory->getModule(); $this->orderStatusService = $orderStatusService; @@ -102,6 +105,7 @@ public function __construct( $this->shipmentSenderHandler = $shipmentSenderHandler; $this->logger = $logger; $this->exceptionService = $exceptionService; + $this->configurationAdapter = $configurationAdapter; } /** @@ -121,7 +125,7 @@ public function __construct( public function processTransaction($apiPayment) { if (empty($apiPayment)) { - if (Configuration::get(Config::MOLLIE_DEBUG_LOG) >= Config::DEBUG_LOG_ERRORS) { + if ($this->configurationAdapter->get(Config::MOLLIE_DEBUG_LOG) >= Config::DEBUG_LOG_ERRORS) { PrestaShopLogger::addLog(__METHOD__ . ' said: Received webhook request without proper transaction ID.', Config::WARNING); } @@ -199,10 +203,10 @@ public function processTransaction($apiPayment) throw new TransactionException('Cart id is missing in transaction metadata', HttpStatusCode::HTTP_UNPROCESSABLE_ENTITY); } - $isKlarnaOrder = in_array($apiPayment->method, Config::KLARNA_PAYMENTS, false); + $isAuthorizablePayment = in_array($apiPayment->method, Config::AUTHORIZABLE_PAYMENTS, false); if (!$orderId && $isPaymentFinished) { - $orderId = $this->orderCreationHandler->createOrder($apiPayment, $cart->id, $isKlarnaOrder); + $orderId = $this->orderCreationHandler->createOrder($apiPayment, $cart->id, $isAuthorizablePayment); if (!$orderId) { throw new TransactionException('Order is already created', HttpStatusCode::HTTP_METHOD_NOT_ALLOWED); @@ -257,9 +261,16 @@ public function processTransaction($apiPayment) $this->handleOrderDescription($apiPayment); } } else { - $isKlarnaDefault = Configuration::get(Config::MOLLIE_KLARNA_INVOICE_ON) === Config::MOLLIE_STATUS_DEFAULT; - if (in_array($apiPayment->method, Config::KLARNA_PAYMENTS) && !$isKlarnaDefault && $apiPayment->status === OrderStatus::STATUS_COMPLETED) { - $this->orderStatusService->setOrderStatus($orderId, Config::MOLLIE_STATUS_KLARNA_SHIPPED); + $isAuthorizablePaymentInvoiceOnStatusDefault = + $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS) + === Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT; + + if ( + !$isAuthorizablePaymentInvoiceOnStatusDefault + && $apiPayment->status === OrderStatus::STATUS_COMPLETED + && in_array($apiPayment->method, Config::AUTHORIZABLE_PAYMENTS, true) + ) { + $this->orderStatusService->setOrderStatus($orderId, Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED); } else { $this->orderStatusService->setOrderStatus($orderId, $apiPayment->status); } @@ -284,7 +295,7 @@ public function processTransaction($apiPayment) $this->savePaymentStatus($apiPayment->id, $apiPayment->status, $orderId); // Log successful webhook requests in extended log mode only - if (Config::DEBUG_LOG_ALL == Configuration::get(Config::MOLLIE_DEBUG_LOG)) { + if (Config::DEBUG_LOG_ALL == $this->configurationAdapter->get(Config::MOLLIE_DEBUG_LOG)) { PrestaShopLogger::addLog(__METHOD__ . ' said: Received webhook request for order ' . (int) $orderId . ' / transaction ' . $apiPayment->id, Config::NOTICE); } @@ -368,7 +379,7 @@ private function savePaymentStatus($transactionId, $status, $orderId) throw $e; } - if (!$result && Configuration::get(Config::MOLLIE_DEBUG_LOG) >= Config::DEBUG_LOG_ERRORS) { + if (!$result && $this->configurationAdapter->get(Config::MOLLIE_DEBUG_LOG) >= Config::DEBUG_LOG_ERRORS) { PrestaShopLogger::addLog(__METHOD__ . ' said: Could not save Mollie payment status for transaction "' . $transactionId . '". Reason: ' . Db::getInstance()->getMsgError(), Config::WARNING); } @@ -446,7 +457,7 @@ private function updateOrderPayments(array $transactionInfos, $orderReference) private function updateOrderDescription(MollieOrderAlias $apiPayment, int $orderId) { - $environment = (int) Configuration::get(Mollie\Config\Config::MOLLIE_ENVIRONMENT); + $environment = (int) $this->configurationAdapter->get(Mollie\Config\Config::MOLLIE_ENVIRONMENT); $paymentMethodId = $this->paymentMethodRepository->getPaymentMethodIdByMethodId($apiPayment->method, $environment); $paymentMethodObj = new MolPaymentMethod((int) $paymentMethodId); $orderNumber = TextGeneratorUtility::generateDescriptionFromCart($paymentMethodObj->description, $orderId); @@ -472,7 +483,7 @@ private function updatePaymentDescription(Payment $apiPayment, int $orderId): Pa if (!$orderId) { throw new TransactionException('Order does not exist', HttpStatusCode::HTTP_METHOD_NOT_ALLOWED); } - $environment = (int) Configuration::get(Mollie\Config\Config::MOLLIE_ENVIRONMENT); + $environment = (int) $this->configurationAdapter->get(Mollie\Config\Config::MOLLIE_ENVIRONMENT); $paymentMethodId = $this->paymentMethodRepository->getPaymentMethodIdByMethodId($apiPayment->method, $environment); $paymentMethodObj = new MolPaymentMethod((int) $paymentMethodId); $apiPayment->description = TextGeneratorUtility::generateDescriptionFromCart($paymentMethodObj->description, $orderId); diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index fb08fa359..891ebd7b5 100644 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -188,8 +188,7 @@ public function register(Container $container) $this->addService($container, PaymentMethodPositionHandlerInterface::class, PaymentMethodPositionHandler::class) ->withArgument(PaymentMethodRepositoryInterface::class); - $this->addService($container, CertificateHandlerInterface::class, ApplePayDirectCertificateHandler::class) - ->withArgument(Mollie::class); + $this->addService($container, CertificateHandlerInterface::class, $container->get(ApplePayDirectCertificateHandler::class)); $this->addService($container, ProfileIdProviderInterface::class, ProfileIdProvider::class); diff --git a/src/Validator/OrderConfMailValidator.php b/src/Validator/OrderConfMailValidator.php index a8901029e..3823dce05 100644 --- a/src/Validator/OrderConfMailValidator.php +++ b/src/Validator/OrderConfMailValidator.php @@ -59,7 +59,7 @@ private function validateOrderState($orderStateId) return true; } - if ((int) $this->configurationAdapter->get(Config::MOLLIE_STATUS_KLARNA_AUTHORIZED) === $orderStateId) { + if ((int) $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED) === $orderStateId) { return true; } diff --git a/tests/Integration/Install/OrderStateInstallerTest.php b/tests/Integration/Install/OrderStateInstallerTest.php index a6f5598ae..efe13004b 100644 --- a/tests/Integration/Install/OrderStateInstallerTest.php +++ b/tests/Integration/Install/OrderStateInstallerTest.php @@ -86,7 +86,7 @@ public function requiredOrderStatusesDataProvider() 'pdfInvoice' => false, ], [ - 'key' => Config::MOLLIE_STATUS_KLARNA_AUTHORIZED, + 'key' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, 'color' => '#8A2BE2', 'sendEmail' => true, 'logable' => true, @@ -97,7 +97,7 @@ public function requiredOrderStatusesDataProvider() 'pdfInvoice' => true, ], [ - 'key' => Config::MOLLIE_STATUS_KLARNA_SHIPPED, + 'key' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, 'color' => '#8A2BE2', 'sendEmail' => true, 'logable' => true, diff --git a/upgrade/Upgrade-4.2.0.php b/upgrade/Upgrade-4.2.0.php index 69fb17797..ea901920d 100644 --- a/upgrade/Upgrade-4.2.0.php +++ b/upgrade/Upgrade-4.2.0.php @@ -11,6 +11,7 @@ use Mollie\Config\Config; use Mollie\Install\Installer; +use Mollie\Install\OrderStateInstaller; use Mollie\Service\OrderStateImageService; if (!defined('_PS_VERSION_')) { @@ -30,14 +31,13 @@ function upgrade_module_4_2_0($module) $segment->setMessage('Mollie upgrade 4.2.0'); $segment->track(); - /** @var Installer $installer */ - $installer = $module->getService(Installer::class); + /** @var OrderStateInstaller $orderStateInstaller */ + $orderStateInstaller = $module->getService(OrderStateInstaller::class); - $installer->klarnaPaymentAuthorizedState(); - $installer->klarnaPaymentShippedState(); + $orderStateInstaller->install(); - $acceptedStatusId = Configuration::get(Config::MOLLIE_STATUS_KLARNA_AUTHORIZED); - Configuration::updateValue(Config::MOLLIE_KLARNA_INVOICE_ON, $acceptedStatusId); + $acceptedStatusId = Configuration::get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED); + Configuration::updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, $acceptedStatusId); $module->registerHook('actionOrderGridQueryBuilderModifier'); $module->registerHook('actionOrderGridDefinitionModifier'); diff --git a/upgrade/Upgrade-5.4.3.php b/upgrade/Upgrade-5.4.3.php index 6f8594846..568dec529 100644 --- a/upgrade/Upgrade-5.4.3.php +++ b/upgrade/Upgrade-5.4.3.php @@ -10,6 +10,8 @@ * @see https://github.com/mollie/PrestaShop */ +use Mollie\Adapter\ConfigurationAdapter; +use Mollie\Config\Config; use Mollie\Install\ModuleTabInstaller; use Mollie\Logger\PrestaLoggerInterface; use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder; @@ -38,6 +40,9 @@ function upgrade_module_5_4_3(Mollie $module): bool return false; } + updateConfigurationValues543($module); + updateOrderStatusNames543($module); + return installPsAccounts543($module) && installCloudSync543($module); } @@ -95,3 +100,77 @@ function installCloudSync543(Mollie $module): bool return true; } + +function updateConfigurationValues543(Mollie $module) +{ + /** @var ConfigurationAdapter $configuration */ + $configuration = $module->getService(ConfigurationAdapter::class); + + if ( + !empty($configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED)) + && !empty($configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED)) + && !empty($configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS)) + && empty($configuration->get('MOLLIE_STATUS_KLARNA_AUTHORIZED')) + && empty($configuration->get('MOLLIE_STATUS_KLARNA_SHIPPED')) + && empty($configuration->get('MOLLIE_KLARNA_INVOICE_ON')) + ) { + return; + } + + $klarnaInvoiceOn = $configuration->get('MOLLIE_KLARNA_INVOICE_ON'); + + switch ($klarnaInvoiceOn) { + case 'MOLLIE_STATUS_KLARNA_AUTHORIZED': + $configuration->updateValue( + Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, + Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED + ); + break; + case 'MOLLIE_STATUS_KLARNA_SHIPPED': + $configuration->updateValue( + Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, + Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED + ); + break; + default: + $configuration->updateValue( + Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, + Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT + ); + } + + $configuration->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, (int) $configuration->get('MOLLIE_STATUS_KLARNA_AUTHORIZED')); + $configuration->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, (int) $configuration->get('MOLLIE_STATUS_KLARNA_SHIPPED')); + + $configuration->delete('MOLLIE_STATUS_KLARNA_AUTHORIZED'); + $configuration->delete('MOLLIE_STATUS_KLARNA_SHIPPED'); + $configuration->delete('MOLLIE_KLARNA_INVOICE_ON'); +} + +function updateOrderStatusNames543(Mollie $module) +{ + /** @var ConfigurationAdapter $configuration */ + $configuration = $module->getService(ConfigurationAdapter::class); + + $authorizablePaymentStatusShippedId = (int) $configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED); + $authorizablePaymentStatusShipped = new OrderState((int) $authorizablePaymentStatusShippedId); + + if (is_array($authorizablePaymentStatusShipped->name)) { + foreach ($authorizablePaymentStatusShipped->name as $langId => $name) { + $authorizablePaymentStatusShipped->name[$langId] = 'Order payment shipped'; + } + } + + $authorizablePaymentStatusShipped->save(); + + $authorizablePaymentStatusAuthorizedId = (int) $configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED); + $authorizablePaymentStatusAuthorized = new OrderState((int) $authorizablePaymentStatusAuthorizedId); + + if (is_array($authorizablePaymentStatusAuthorized->name)) { + foreach ($authorizablePaymentStatusAuthorized->name as $langId => $name) { + $authorizablePaymentStatusAuthorized->name[$langId] = 'Order payment authorized'; + } + } + + $authorizablePaymentStatusAuthorized->save(); +} diff --git a/views/templates/admin/invoice_description.tpl b/views/templates/admin/invoice_description.tpl index 59a508daa..03aeeec98 100644 --- a/views/templates/admin/invoice_description.tpl +++ b/views/templates/admin/invoice_description.tpl @@ -7,10 +7,10 @@ * @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md *}
- {l s='Select when to send Klarna invoices' mod='mollie'} + {l s='Select when to create the Order invoice' mod='mollie'}
- {l s='Default: The invoice is created based on Order settings > Statuses. There is no custom status created for Klarna.' mod='mollie'} + {l s='Default: The invoice is created based on Order settings > Statuses. There is no custom status created.' mod='mollie'}
{l s='Authorised: Create a full invoice when the order is authorized. Custom status is created.' mod='mollie'} From 7c78f13bdf59acef914b51310c7a4795b1ee32c6 Mon Sep 17 00:00:00 2001 From: mandan2 <61560082+mandan2@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:59:22 +0200 Subject: [PATCH 3/3] PIPRES-352: Billie payment method additional data send (#18) --- src/Adapter/Context.php | 2 +- src/DTO/Object/Company.php | 58 +++++++ src/DTO/Object/Payment.php | 142 ++++++++++++++++++ src/DTO/OrderData.php | 19 ++- .../B2bPaymentMethodRestrictionValidator.php | 4 +- src/Service/PaymentMethodService.php | 47 ++++-- src/ServiceProvider/BaseServiceProvider.php | 1 - 7 files changed, 250 insertions(+), 23 deletions(-) create mode 100644 src/DTO/Object/Company.php create mode 100644 src/DTO/Object/Payment.php diff --git a/src/Adapter/Context.php b/src/Adapter/Context.php index 3d733e644..a90ce7546 100644 --- a/src/Adapter/Context.php +++ b/src/Adapter/Context.php @@ -160,7 +160,7 @@ public function getModuleLink( ); } - public function getAddressInvoiceId(): int + public function getInvoiceAddressId(): int { return (int) $this->getContext()->cart->id_address_invoice; } diff --git a/src/DTO/Object/Company.php b/src/DTO/Object/Company.php new file mode 100644 index 000000000..29ce3b578 --- /dev/null +++ b/src/DTO/Object/Company.php @@ -0,0 +1,58 @@ +vatNumber; + } + + /** + * @param string $vatNumber + * + * @maps vatNumber + */ + public function setVatNumber(string $vatNumber) + { + $this->vatNumber = $vatNumber; + } + + /** + * @return string + */ + public function getRegistrationNumber(): string + { + return $this->registrationNumber; + } + + /** + * @param string $registrationNumber + * + * @maps registrationNumber + */ + public function setRegistrationNumber(string $registrationNumber) + { + $this->registrationNumber = $registrationNumber; + } + + public function jsonSerialize() + { + $json = []; + $json['vatNumber'] = $this->getVatNumber(); + $json['registrationNumber'] = $this->getRegistrationNumber(); + + return array_filter($json, static function ($val) { + return $val !== null && $val !== ''; + }); + } +} diff --git a/src/DTO/Object/Payment.php b/src/DTO/Object/Payment.php new file mode 100644 index 000000000..78a601b9e --- /dev/null +++ b/src/DTO/Object/Payment.php @@ -0,0 +1,142 @@ +cardToken; + } + + /** + * @param string $cardToken + * + * @maps cardToken + */ + public function setCardToken(string $cardToken) + { + $this->cardToken = $cardToken; + } + + /** + * @return string + */ + public function getWebhookUrl(): string + { + return $this->webhookUrl; + } + + /** + * @param string $webhookUrl + * + * @maps webhookUrl + */ + public function setWebhookUrl(string $webhookUrl) + { + $this->webhookUrl = $webhookUrl; + } + + /** + * @return ?string + */ + public function getIssuer() + { + return $this->issuer; + } + + /** + * @param string $issuer + * + * @maps issuer + */ + public function setIssuer(string $issuer) + { + $this->issuer = $issuer; + } + + /** + * @return ?string + */ + public function getCustomerId() + { + return $this->customerId; + } + + /** + * @param string $customerId + * + * @maps customerId + */ + public function setCustomerId(string $customerId) + { + $this->customerId = $customerId; + } + + /** + * @return ?string + */ + public function getApplePayPaymentToken() + { + return $this->applePayPaymentToken; + } + + /** + * @param string $applePayPaymentToken + * + * @maps applePayPaymentToken + */ + public function setApplePayPaymentToken(string $applePayPaymentToken) + { + $this->applePayPaymentToken = $applePayPaymentToken; + } + + /** + * @return ?Company + */ + public function getCompany() + { + return $this->company; + } + + /** + * @param \Mollie\DTO\Object\Company $company + * + * @maps company + */ + public function setCompany(Company $company) + { + $this->company = $company; + } + + public function jsonSerialize() + { + $result = []; + $result['cardToken'] = $this->getCardToken(); + $result['webhookUrl'] = $this->getWebhookUrl(); + $result['issuer'] = $this->getIssuer(); + $result['customerId'] = $this->getCustomerId(); + $result['applePayPaymentToken'] = $this->getApplePayPaymentToken(); + $result['company'] = $this->getCompany() ? $this->getCompany()->jsonSerialize() : null; + + return array_filter($result, static function ($val) { + return $val !== null && $val !== ''; + }); + } +} diff --git a/src/DTO/OrderData.php b/src/DTO/OrderData.php index 28671b792..1397314f9 100644 --- a/src/DTO/OrderData.php +++ b/src/DTO/OrderData.php @@ -16,6 +16,7 @@ use Country; use JsonSerializable; use Mollie\DTO\Object\Amount; +use Mollie\DTO\Object\Payment; class OrderData implements JsonSerializable { @@ -85,7 +86,7 @@ class OrderData implements JsonSerializable private $lines; /** - * @var array + * @var Payment */ private $payment; @@ -358,17 +359,19 @@ public function setLines($lines) } /** - * @return array + * @return Payment */ - public function getPayment() + public function getPayment(): Payment { return $this->payment; } /** - * @param array $payment + * @param \Mollie\DTO\Object\Payment $payment + * + * @maps payment */ - public function setPayment($payment) + public function setPayment(Payment $payment) { $this->payment = $payment; } @@ -448,7 +451,7 @@ public function jsonSerialize() 'locale' => $this->getLocale(), 'orderNumber' => $this->getOrderNumber(), 'lines' => $lines, - 'payment' => $this->getPayment(), + 'payment' => $this->getPayment()->jsonSerialize(), 'consumerDateOfBirth' => $this->getConsumerDateOfBirth(), ]; @@ -460,7 +463,9 @@ public function jsonSerialize() $result['shippingAddress']['phone'] = $this->deliveryPhoneNumber; } - return $result; + return array_filter($result, static function ($val) { + return $val !== null && $val !== ''; + }); } private function cleanUpInput($input, $defaultValue = 'N/A') diff --git a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php index 8c1338e25..dbf312463 100644 --- a/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php +++ b/src/Service/PaymentMethod/PaymentMethodRestrictionValidation/B2bPaymentMethodRestrictionValidator.php @@ -78,11 +78,11 @@ private function isIdentificationNumberValid(): bool private function isVatNumberValid(): bool { - $billingAddressId = $this->context->getAddressInvoiceId(); + $billingAddressId = $this->context->getInvoiceAddressId(); /** @var \Address $billingAddress */ $billingAddress = $this->addressRepository->findOneBy([ - 'id_address' => (int) $billingAddressId, + 'id_address' => $billingAddressId, ]); /** @var \AddressFormat $addressFormat */ diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index c84de5816..eddab8d84 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -27,6 +27,8 @@ use Mollie\Api\Types\PaymentMethod; use Mollie\Config\Config; use Mollie\DTO\Object\Amount; +use Mollie\DTO\Object\Company; +use Mollie\DTO\Object\Payment; use Mollie\DTO\OrderData; use Mollie\DTO\PaymentData; use Mollie\Exception\OrderCreationException; @@ -352,14 +354,27 @@ public function getPaymentData( if (isset($cart->id_address_invoice)) { $billingAddress = new Address((int) $cart->id_address_invoice); + $company = new Company(); + + if (!empty($billingAddress->vat_number)) { + $company->setVatNumber($billingAddress->vat_number); + } + + if (!empty($customer->siret)) { + $company->setRegistrationNumber($customer->siret); + } + $orderData->setBillingAddress($billingAddress); $orderData->setBillingPhoneNumber($this->phoneNumberProvider->getFromAddress($billingAddress)); } + if (isset($cart->id_address_delivery)) { $shippingAddress = new Address((int) $cart->id_address_delivery); + $orderData->setShippingAddress($shippingAddress); $orderData->setDeliveryPhoneNumber($this->phoneNumberProvider->getFromAddress($shippingAddress)); } + $orderData->setOrderNumber($orderReference); $orderData->setLocale($this->getLocale($molPaymentMethod->method)); $orderData->setEmail($customer->email); @@ -391,30 +406,38 @@ public function getPaymentData( (bool) Configuration::get('PS_GIFT_WRAPPING'), $selectedVoucherCategory )); - $payment = []; - if ($cardToken) { - $payment['cardToken'] = $cardToken; + + $payment = new Payment(); + + if (!empty($cardToken)) { + $payment->setCardToken($cardToken); } - $payment['webhookUrl'] = $this->context->getModuleLink( + + $payment->setWebhookUrl($this->context->getModuleLink( 'mollie', 'webhook', [], true - ); + )); - if ($issuer) { - $payment['issuer'] = $issuer; + if (!empty($issuer)) { + $payment->setIssuer($issuer); } if ($molPaymentMethod->id_method === PaymentMethod::CREDITCARD) { $molCustomer = $this->handleCustomerInfo($cart->id_customer, $saveCard, $useSavedCard); - if ($molCustomer) { - $payment['customerId'] = $molCustomer->customer_id; + + if ($molCustomer && !empty($molCustomer->customer_id)) { + $payment->setCustomerId($molCustomer->customer_id); } } - if ($molPaymentMethod->id_method === PaymentMethod::APPLEPAY && $applePayToken) { - $payment['applePayPaymentToken'] = $applePayToken; + if ($molPaymentMethod->id_method === PaymentMethod::APPLEPAY && !empty($applePayToken)) { + $payment->setApplePayPaymentToken($applePayToken); + } + + if (isset($company)) { + $payment->setCompany($company); } $orderData->setPayment($payment); @@ -466,7 +489,7 @@ private function removeNotSupportedMethods($methods, $mollieMethods) private function getSupportedMollieMethods() { - $address = new Address($this->context->getAddressInvoiceId()); + $address = new Address($this->context->getInvoiceAddressId()); $country = new Country($address->id_country); $cartAmount = $this->orderTotalProvider->getOrderTotal(); diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index 891ebd7b5..3a36412aa 100644 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -3,7 +3,6 @@ namespace Mollie\ServiceProvider; use League\Container\Container; -use Mollie; use Mollie\Builder\ApiTestFeedbackBuilder; use Mollie\Config\Config; use Mollie\Factory\ModuleFactory;