From d99d4570880e0a3c633218a55391fd1f288920cb Mon Sep 17 00:00:00 2001 From: SergejSavic Date: Tue, 15 Oct 2024 10:35:40 +0200 Subject: [PATCH] remove hard coded divisors. Make migration transactional. --- src/Controller/Action/Shop/QrCodeAction.php | 10 ++++++++-- src/Migrations/Version20231225151033.php | 10 +--------- src/Resolver/MolliePaymentsMethodResolver.php | 10 ++++++++-- src/Resources/config/services/controller.xml | 1 + src/Resources/config/services/resolver.xml | 1 + 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Controller/Action/Shop/QrCodeAction.php b/src/Controller/Action/Shop/QrCodeAction.php index df26018..e74ca8b 100644 --- a/src/Controller/Action/Shop/QrCodeAction.php +++ b/src/Controller/Action/Shop/QrCodeAction.php @@ -12,6 +12,7 @@ use SyliusMolliePlugin\Entity\OrderInterface; use SyliusMolliePlugin\Logger\MollieLoggerActionInterface; use SyliusMolliePlugin\Resolver\MollieApiClientKeyResolverInterface; +use SyliusMolliePlugin\Helper\IntToStringConverterInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -43,6 +44,9 @@ final class QrCodeAction /** @var RepositoryInterface */ private $methodRepository; + /** @var IntToStringConverterInterface */ + private $intToStringConverter; + /** * QrCodeAction constructor */ @@ -53,7 +57,8 @@ public function __construct( MollieApiClientKeyResolverInterface $apiClientKeyResolver, OrderRepositoryInterface $orderRepository, UrlGeneratorInterface $urlGenerator, - RepositoryInterface $methodRepository + RepositoryInterface $methodRepository, + IntToStringConverterInterface $intToStringConverter ) { $this->loggerAction = $loggerAction; @@ -63,6 +68,7 @@ public function __construct( $this->orderRepository = $orderRepository; $this->urlGenerator = $urlGenerator; $this->methodRepository = $methodRepository; + $this->intToStringConverter = $intToStringConverter; } /** @@ -189,7 +195,7 @@ private function setMolliePaymentIdOnOrder(OrderInterface $order, ?string $molli private function buildPaymentObject(Request $request, OrderInterface $order): MolliePayment { $molliePayment = new MolliePayment(); - $molliePayment->setAmount(new Amount((string)($order->getTotal() / 100), $order->getCurrencyCode())); + $molliePayment->setAmount(new Amount($this->intToStringConverter->convertIntToString($order->getTotal()), $order->getCurrencyCode())); $molliePayment->setMethod($request->get('paymentMethod')); $molliePayment->setDescription((string)$order->getId()); $molliePayment->setIssuer($request->get('issuer') ?? ''); diff --git a/src/Migrations/Version20231225151033.php b/src/Migrations/Version20231225151033.php index 598eb81..695e4a9 100644 --- a/src/Migrations/Version20231225151033.php +++ b/src/Migrations/Version20231225151033.php @@ -47,7 +47,7 @@ public function up(Schema $schema): void /** * @param Schema $schema - * + * * @return void */ public function down(Schema $schema): void @@ -69,14 +69,6 @@ public function down(Schema $schema): void $this->renameTableIfExists($schema, 'mollie_subscription_schedule', 'bitbag_mollie_subscription_schedule'); } - /** - * @return bool - */ - public function isTransactional(): bool - { - return false; - } - /** * @param Schema $schema * @param string $oldTableName diff --git a/src/Resolver/MolliePaymentsMethodResolver.php b/src/Resolver/MolliePaymentsMethodResolver.php index 9825a3a..a340130 100644 --- a/src/Resolver/MolliePaymentsMethodResolver.php +++ b/src/Resolver/MolliePaymentsMethodResolver.php @@ -12,6 +12,7 @@ use SyliusMolliePlugin\Entity\OrderInterface as MollieOrderInterface; use SyliusMolliePlugin\Logger\MollieLoggerActionInterface; use SyliusMolliePlugin\Repository\MollieGatewayConfigRepository; +use SyliusMolliePlugin\Provider\Divisor\DivisorProviderInterface; use SyliusMolliePlugin\Repository\MollieGatewayConfigRepositoryInterface; use SyliusMolliePlugin\Repository\PaymentMethodRepositoryInterface; use SyliusMolliePlugin\Resolver\Order\PaymentCheckoutOrderResolverInterface; @@ -49,6 +50,9 @@ final class MolliePaymentsMethodResolver implements MolliePaymentsMethodResolver /** @var MollieFactoryNameResolverInterface */ private $mollieFactoryNameResolver; + /** @var DivisorProviderInterface */ + private $divisorProvider; + public function __construct( MollieGatewayConfigRepository $mollieGatewayRepository, MollieCountriesRestrictionResolverInterface $countriesRestrictionResolver, @@ -57,7 +61,8 @@ public function __construct( PaymentMethodRepositoryInterface $paymentMethodRepository, MollieAllowedMethodsResolverInterface $allowedMethodsResolver, MollieLoggerActionInterface $loggerAction, - MollieFactoryNameResolverInterface $mollieFactoryNameResolver + MollieFactoryNameResolverInterface $mollieFactoryNameResolver, + DivisorProviderInterface $divisorProvider ) { $this->mollieGatewayRepository = $mollieGatewayRepository; $this->countriesRestrictionResolver = $countriesRestrictionResolver; @@ -67,6 +72,7 @@ public function __construct( $this->allowedMethodsResolver = $allowedMethodsResolver; $this->loggerAction = $loggerAction; $this->mollieFactoryNameResolver = $mollieFactoryNameResolver; + $this->divisorProvider = $divisorProvider; } public function resolve(): array @@ -128,7 +134,7 @@ private function getMolliePaymentOptions(MollieOrderInterface $order, string $co return $this->getDefaultOptions(); } - $allowedMethods = $this->filterPaymentMethods($paymentConfigs, $allowedMethodsIds, (float)$order->getTotal()/100); + $allowedMethods = $this->filterPaymentMethods($paymentConfigs, $allowedMethodsIds, (float)$order->getTotal()/$this->divisorProvider->getDivisor()); if (0 === count($allowedMethods)) { return $this->getDefaultOptions(); diff --git a/src/Resources/config/services/controller.xml b/src/Resources/config/services/controller.xml index 2423f13..640c224 100644 --- a/src/Resources/config/services/controller.xml +++ b/src/Resources/config/services/controller.xml @@ -49,6 +49,7 @@ + diff --git a/src/Resources/config/services/resolver.xml b/src/Resources/config/services/resolver.xml index c66a836..1a9357c 100644 --- a/src/Resources/config/services/resolver.xml +++ b/src/Resources/config/services/resolver.xml @@ -13,6 +13,7 @@ + %images_dir%