diff --git a/src/Controller/StoreApi/Config/ConfigControllerBase.php b/src/Controller/StoreApi/Config/ConfigControllerBase.php
index 0df653d54..909f8374a 100644
--- a/src/Controller/StoreApi/Config/ConfigControllerBase.php
+++ b/src/Controller/StoreApi/Config/ConfigControllerBase.php
@@ -4,7 +4,7 @@
use Kiener\MolliePayments\Controller\StoreApi\Config\Response\ConfigResponse;
use Kiener\MolliePayments\Service\ConfigService;
-use Kiener\MolliePayments\Service\SalesChannel\SalesChannelLocale;
+use Kiener\MolliePayments\Service\MollieLocaleService;
use Kiener\MolliePayments\Service\SettingsService;
use Psr\Log\LoggerInterface;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
@@ -25,9 +25,9 @@ class ConfigControllerBase
private $configService;
/**
- * @var SalesChannelLocale
+ * @var MollieLocaleService
*/
- private $salesChannelLocale;
+ private $mollieLocaleService;
/**
* @var LoggerInterface
@@ -37,14 +37,14 @@ class ConfigControllerBase
/**
* @param SettingsService $settingsService
* @param ConfigService $configService
- * @param SalesChannelLocale $salesChannelLocale
+ * @param MollieLocaleService $mollieLocaleService
* @param LoggerInterface $logger
*/
- public function __construct(SettingsService $settingsService, ConfigService $configService, SalesChannelLocale $salesChannelLocale, LoggerInterface $logger)
+ public function __construct(SettingsService $settingsService, ConfigService $configService, MollieLocaleService $mollieLocaleService, LoggerInterface $logger)
{
$this->settingsService = $settingsService;
$this->configService = $configService;
- $this->salesChannelLocale = $salesChannelLocale;
+ $this->mollieLocaleService = $mollieLocaleService;
$this->logger = $logger;
}
@@ -63,7 +63,7 @@ public function getConfig(SalesChannelContext $context): StoreApiResponse
$settings = $this->settingsService->getSettings($scId);
$profileId = (string)$settings->getProfileId();
- $locale = $this->salesChannelLocale->getLocale($context);
+ $locale = $this->mollieLocaleService->getLocale($context);
if (empty($profileId)) {
# if its somehow not yet loaded (plugin config in admin when clicking save)
diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml
index 6687293a7..7f61d88d6 100644
--- a/src/Resources/config/services.xml
+++ b/src/Resources/config/services.xml
@@ -149,7 +149,7 @@
-
+
diff --git a/src/Resources/config/services/builder.xml b/src/Resources/config/services/builder.xml
index f1bcbb870..ff974da4d 100644
--- a/src/Resources/config/services/builder.xml
+++ b/src/Resources/config/services/builder.xml
@@ -14,6 +14,7 @@
+
diff --git a/src/Resources/config/services/controller.xml b/src/Resources/config/services/controller.xml
index 35c6b0c3d..eae98a8e7 100644
--- a/src/Resources/config/services/controller.xml
+++ b/src/Resources/config/services/controller.xml
@@ -212,7 +212,7 @@
-
+
diff --git a/src/Resources/config/services/services.xml b/src/Resources/config/services/services.xml
index 0007e36d9..935d2dfdc 100644
--- a/src/Resources/config/services/services.xml
+++ b/src/Resources/config/services/services.xml
@@ -156,7 +156,7 @@
-
+
diff --git a/src/Service/MollieApi/Builder/MollieOrderBuilder.php b/src/Service/MollieApi/Builder/MollieOrderBuilder.php
index 8c37d69f1..12669de93 100644
--- a/src/Service/MollieApi/Builder/MollieOrderBuilder.php
+++ b/src/Service/MollieApi/Builder/MollieOrderBuilder.php
@@ -8,6 +8,7 @@
use Kiener\MolliePayments\Handler\PaymentHandler;
use Kiener\MolliePayments\Service\MollieApi\MollieOrderCustomerEnricher;
use Kiener\MolliePayments\Service\MollieApi\OrderDataExtractor;
+use Kiener\MolliePayments\Service\MollieLocaleService;
use Kiener\MolliePayments\Service\Router\RoutingBuilder;
use Kiener\MolliePayments\Service\SettingsService;
use Kiener\MolliePayments\Setting\MollieSettingStruct;
@@ -62,6 +63,11 @@ class MollieOrderBuilder
*/
private $urlBuilder;
+ /**
+ * @var MollieLocaleService
+ */
+ private $mollieLocaleService;
+
/**
* @var EventDispatcherInterface
*/
@@ -81,10 +87,11 @@ class MollieOrderBuilder
* @param MollieOrderAddressBuilder $addressBuilder
* @param MollieOrderCustomerEnricher $customerEnricher
* @param RoutingBuilder $urlBuilder
+ * @param MollieLocaleService $mollieLocaleService
* @param EventDispatcherInterface $eventDispatcher
* @param LoggerInterface $logger
*/
- public function __construct(SettingsService $settingsService, OrderDataExtractor $extractor, MollieOrderPriceBuilder $priceBuilder, MollieLineItemBuilder $lineItemBuilder, MollieOrderAddressBuilder $addressBuilder, MollieOrderCustomerEnricher $customerEnricher, RoutingBuilder $urlBuilder, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger)
+ public function __construct(SettingsService $settingsService, OrderDataExtractor $extractor, MollieOrderPriceBuilder $priceBuilder, MollieLineItemBuilder $lineItemBuilder, MollieOrderAddressBuilder $addressBuilder, MollieOrderCustomerEnricher $customerEnricher, RoutingBuilder $urlBuilder, MollieLocaleService $mollieLocaleService, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger)
{
$this->settingsService = $settingsService;
$this->extractor = $extractor;
@@ -93,6 +100,7 @@ public function __construct(SettingsService $settingsService, OrderDataExtractor
$this->addressBuilder = $addressBuilder;
$this->customerEnricher = $customerEnricher;
$this->urlBuilder = $urlBuilder;
+ $this->mollieLocaleService = $mollieLocaleService;
$this->eventDispatcher = $eventDispatcher;
$this->logger = $logger;
}
@@ -141,6 +149,7 @@ public function buildOrderPayload(OrderEntity $order, string $transactionId, str
$currency = $this->extractor->extractCurrency($order, $salesChannelContext);
$locale = $this->extractor->extractLocale($order, $salesChannelContext);
$localeCode = ($locale instanceof LocaleEntity) ? $locale->getCode() : self::MOLLIE_DEFAULT_LOCALE_CODE;
+ $localeCode = $this->mollieLocaleService->getMollieLocale($localeCode);
$lineItems = $order->getLineItems();
$isVerticalTaxCalculation = $this->isVerticalTaxCalculation($salesChannelContext);
diff --git a/src/Service/SalesChannel/SalesChannelLocale.php b/src/Service/MollieLocaleService.php
similarity index 89%
rename from src/Service/SalesChannel/SalesChannelLocale.php
rename to src/Service/MollieLocaleService.php
index 172d63b40..90a39ea37 100644
--- a/src/Service/SalesChannel/SalesChannelLocale.php
+++ b/src/Service/MollieLocaleService.php
@@ -1,11 +1,12 @@
repoLanguages = $repoLanguages;
}
-
/**
* @param SalesChannelContext $salesChannelContext
* @return string
@@ -64,6 +59,11 @@ public function getLocale(SalesChannelContext $salesChannelContext): string
$locale = $language->getLocale()->getCode();
}
+ return $this->getMollieLocale($locale);
+ }
+
+ public function getMollieLocale(?string $locale): string
+ {
# Set the locale based on the current storefront.
if ($locale !== null && $locale !== '') {
$locale = str_replace('-', '_', $locale);
diff --git a/src/Subscriber/CheckoutConfirmPageSubscriber.php b/src/Subscriber/CheckoutConfirmPageSubscriber.php
index 52f5673bf..e1a73e0f2 100644
--- a/src/Subscriber/CheckoutConfirmPageSubscriber.php
+++ b/src/Subscriber/CheckoutConfirmPageSubscriber.php
@@ -9,6 +9,7 @@
use Kiener\MolliePayments\Service\CustomerService;
use Kiener\MolliePayments\Service\CustomFieldService;
use Kiener\MolliePayments\Service\MandateServiceInterface;
+use Kiener\MolliePayments\Service\MollieLocaleService;
use Kiener\MolliePayments\Service\SalesChannel\SalesChannelLocale;
use Kiener\MolliePayments\Service\SettingsService;
use Kiener\MolliePayments\Setting\MollieSettingStruct;
@@ -45,9 +46,9 @@ class CheckoutConfirmPageSubscriber implements EventSubscriberInterface
private $settings;
/**
- * @var SalesChannelLocale
+ * @var MollieLocaleService
*/
- private $salesChannelLocale;
+ private $mollieLocaleService;
/**
* @var MandateServiceInterface
@@ -82,15 +83,15 @@ public static function getSubscribedEvents(): array
* @param SettingsService $settingsService
* @param MandateServiceInterface $mandateService
* @param MollieGatewayInterface $mollieGateway
- * @param SalesChannelLocale $salesChannelLocale
+ * @param MollieLocaleService $mollieLocaleService
*/
- public function __construct(MollieApiFactory $apiFactory, SettingsService $settingsService, MandateServiceInterface $mandateService, MollieGatewayInterface $mollieGateway, SalesChannelLocale $salesChannelLocale)
+ public function __construct(MollieApiFactory $apiFactory, SettingsService $settingsService, MandateServiceInterface $mandateService, MollieGatewayInterface $mollieGateway, MollieLocaleService $mollieLocaleService)
{
$this->apiFactory = $apiFactory;
$this->settingsService = $settingsService;
$this->mandateService = $mandateService;
$this->mollieGateway = $mollieGateway;
- $this->salesChannelLocale = $salesChannelLocale;
+ $this->mollieLocaleService = $mollieLocaleService;
}
@@ -137,7 +138,7 @@ private function addMollieLocaleVariableToPage($args): void
{
$salesChannelContext = $args->getSalesChannelContext();
- $locale = $this->salesChannelLocale->getLocale($salesChannelContext);
+ $locale = $this->mollieLocaleService->getLocale($salesChannelContext);
$args->getPage()->assign([
'mollie_locale' => $locale,
diff --git a/tests/PHPUnit/Service/MollieApi/Builder/AbstractMollieOrderBuilder.php b/tests/PHPUnit/Service/MollieApi/Builder/AbstractMollieOrderBuilder.php
index 95ed126ec..423ebecc0 100644
--- a/tests/PHPUnit/Service/MollieApi/Builder/AbstractMollieOrderBuilder.php
+++ b/tests/PHPUnit/Service/MollieApi/Builder/AbstractMollieOrderBuilder.php
@@ -6,6 +6,7 @@
use Kiener\MolliePayments\Facade\MolliePaymentFinalize;
use Kiener\MolliePayments\Handler\PaymentHandler;
use Kiener\MolliePayments\Hydrator\MollieLineItemHydrator;
+use Kiener\MolliePayments\Repository\Language\LanguageRepositoryInterface;
use Kiener\MolliePayments\Service\CustomerService;
use Kiener\MolliePayments\Service\MollieApi\Builder\MollieLineItemBuilder;
use Kiener\MolliePayments\Service\MollieApi\Builder\MollieOrderAddressBuilder;
@@ -17,6 +18,7 @@
use Kiener\MolliePayments\Service\MollieApi\MollieOrderCustomerEnricher;
use Kiener\MolliePayments\Service\MollieApi\OrderDataExtractor;
use Kiener\MolliePayments\Service\MollieApi\PriceCalculator;
+use Kiener\MolliePayments\Service\MollieLocaleService;
use Kiener\MolliePayments\Service\Router\RoutingBuilder;
use Kiener\MolliePayments\Service\Router\RoutingDetector;
use Kiener\MolliePayments\Service\SettingsService;
@@ -26,8 +28,10 @@
use MolliePayments\Tests\Fakes\FakeCompatibilityGateway;
use MolliePayments\Tests\Fakes\FakeEventDispatcher;
use MolliePayments\Tests\Fakes\FakePluginSettings;
+use MolliePayments\Tests\Fakes\Repositories\FakeLanguageRepository;
use MolliePayments\Tests\Traits\OrderTrait;
use MolliePayments\Tests\Utils\Traits\PaymentBuilderTrait;
+use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
@@ -47,7 +51,7 @@ abstract class AbstractMollieOrderBuilder extends TestCase
use PaymentBuilderTrait;
/**
- * @var \PHPUnit\Framework\MockObject\MockObject|SettingsService
+ * @var MockObject|SettingsService
*/
protected $settingsService;
/**
@@ -55,11 +59,11 @@ abstract class AbstractMollieOrderBuilder extends TestCase
*/
protected $loggerService;
/**
- * @var OrderDataExtractor|\PHPUnit\Framework\MockObject\MockObject
+ * @var OrderDataExtractor|MockObject
*/
protected $orderDataExtractor;
/**
- * @var \PHPUnit\Framework\MockObject\MockObject|RouterInterface
+ * @var MockObject|RouterInterface
*/
protected $router;
/**
@@ -67,7 +71,7 @@ abstract class AbstractMollieOrderBuilder extends TestCase
*/
protected $builder;
/**
- * @var \PHPUnit\Framework\MockObject\MockObject|SalesChannelContext
+ * @var MockObject|SalesChannelContext
*/
protected $salesChannelContext;
/**
@@ -95,15 +99,15 @@ abstract class AbstractMollieOrderBuilder extends TestCase
*/
protected $localeCode;
/**
- * @var MolliePaymentDoPay|\PHPUnit\Framework\MockObject\MockObject
+ * @var MolliePaymentDoPay|MockObject
*/
protected $mollieDoPaymentFacade;
/**
- * @var MolliePaymentFinalize|\PHPUnit\Framework\MockObject\MockObject
+ * @var MolliePaymentFinalize|MockObject
*/
protected $molliePaymentFinalize;
/**
- * @var \PHPUnit\Framework\MockObject\MockObject|TransactionTransitionServiceInterface
+ * @var MockObject|TransactionTransitionServiceInterface
*/
protected $transitionService;
/**
@@ -111,6 +115,11 @@ abstract class AbstractMollieOrderBuilder extends TestCase
*/
protected $settingStruct;
+ /**
+ * @var MollieLocaleService|MockObject
+ */
+ private $mollieLocaleService;
+
public function setUp(): void
{
$this->address = $this->getDummyAddress();
@@ -160,7 +169,9 @@ public function setUp(): void
$routingDetector,
new FakePluginSettings(''),
''
- );
+ );;
+
+ $this->mollieLocaleService = new MollieLocaleService($this->createMock(LanguageRepositoryInterface::class));
$this->builder = new MollieOrderBuilder(
$this->settingsService,
@@ -178,6 +189,7 @@ public function setUp(): void
new MollieOrderAddressBuilder(),
new MollieOrderCustomerEnricher($this->createMock(CustomerService::class)),
$routingBuilder,
+ $this->mollieLocaleService,
new FakeEventDispatcher(),
$this->loggerService
);
diff --git a/tests/PHPUnit/Service/SalesChannel/SalesChannelLocaleTest.php b/tests/PHPUnit/Service/MollieLocaleServiceTest.php
similarity index 70%
rename from tests/PHPUnit/Service/SalesChannel/SalesChannelLocaleTest.php
rename to tests/PHPUnit/Service/MollieLocaleServiceTest.php
index a2a287fb3..a8a46c9ae 100644
--- a/tests/PHPUnit/Service/SalesChannel/SalesChannelLocaleTest.php
+++ b/tests/PHPUnit/Service/MollieLocaleServiceTest.php
@@ -1,15 +1,15 @@
getAvailableLocales());
- $this->assertEquals($expected, SalesChannelLocale::AVAILABLE_LOCALES);
+ $this->assertEquals($expected, MollieLocaleService::AVAILABLE_LOCALES);
}
@@ -95,7 +95,7 @@ public function testAvailableLocalesAreFound(string $locale): void
$repoLanguages = new FakeLanguageRepository($scLanguage);
- $service = new SalesChannelLocale($repoLanguages);
+ $service = new MollieLocaleService($repoLanguages);
$detectedLocale = $service->getLocale($this->fakeSalesChannelContext);
@@ -112,7 +112,7 @@ public function testInvalidLocaleLeadsToEnglishDefault(): void
$repoLanguages = new FakeLanguageRepository($scLanguage);
- $service = new SalesChannelLocale($repoLanguages);
+ $service = new MollieLocaleService($repoLanguages);
$detectedLocale = $service->getLocale($this->fakeSalesChannelContext);
@@ -129,7 +129,7 @@ public function testSalesChannelWithoutLocale(): void
{
$repoLanguages = new FakeLanguageRepository(null);
- $service = new SalesChannelLocale($repoLanguages);
+ $service = new MollieLocaleService($repoLanguages);
$detectedLocale = $service->getLocale($this->fakeSalesChannelContext);
@@ -155,4 +155,39 @@ private function buildSalesChannelLanguage(string $locale): LanguageEntity
return $scLanguage;
}
+ /**
+ * @dataProvider mollieLocaleDataProvider
+ */
+ public function testProvidesMollieLocale(string $input, string $expected): void
+ {
+ $service = new MollieLocaleService(new FakeLanguageRepository(null));
+
+ $this->assertEquals($expected, $service->getMollieLocale($input));
+ }
+
+ public function mollieLocaleDataProvider(): array
+ {
+ return [
+ 'en_US' => ['en-US', 'en_US'],
+ 'en_GB' => ['en-GB', 'en_GB'],
+ 'nl_NL' => ['nl-NL', 'nl_NL'],
+ 'fr_FR' => ['fr-FR', 'fr_FR'],
+ 'it_IT' => ['it-IT', 'it_IT'],
+ 'de_DE' => ['de-DE', 'de_DE'],
+ 'de_AT' => ['de-AT', 'de_AT'],
+ 'de_CH' => ['de-CH', 'de_CH'],
+ 'es_ES' => ['es-ES', 'es_ES'],
+ 'ca_ES' => ['ca-ES', 'ca_ES'],
+ 'nb_NO' => ['nb-NO', 'nb_NO'],
+ 'pt_PT' => ['pt-PT', 'pt_PT'],
+ 'sv_SE' => ['sv-SE', 'sv_SE'],
+ 'fi_FI' => ['fi-FI', 'fi_FI'],
+ 'da_DK' => ['da-DK', 'da_DK'],
+ 'is_IS' => ['is-IS', 'is_IS'],
+ 'hu_HU' => ['hu-HU', 'hu_HU'],
+ 'pl_PL' => ['pl-PL', 'pl_PL'],
+ 'lv_LV' => ['lv-LV', 'lv_LV'],
+ 'lt_LT' => ['lt-LT', 'lt_LT']
+ ];
+ }
}