Skip to content

Commit c5eda5b

Browse files
[Maintenance] Add missing locale processor argument and cover pay form locale resolving
1 parent 53d7518 commit c5eda5b

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/Controller/PayWithPayPalFormAction.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Sylius\Component\Core\Repository\PaymentRepositoryInterface;
2121
use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface;
2222
use Sylius\PayPalPlugin\Api\IdentityApiInterface;
23+
use Sylius\PayPalPlugin\Processor\LocaleProcessorInterface;
2324
use Sylius\PayPalPlugin\Provider\AvailableCountriesProviderInterface;
2425
use Symfony\Component\HttpFoundation\Request;
2526
use Symfony\Component\HttpFoundation\Response;
@@ -43,12 +44,23 @@ public function __construct(
4344
AvailableCountriesProviderInterface $countriesProvider,
4445
CacheAuthorizeClientApiInterface $authorizeClientApi,
4546
IdentityApiInterface $identityApi,
47+
private ?LocaleProcessorInterface $localeProcessor = null,
4648
) {
4749
$this->twig = $twig;
4850
$this->paymentRepository = $paymentRepository;
4951
$this->countriesProvider = $countriesProvider;
5052
$this->authorizeClientApi = $authorizeClientApi;
5153
$this->identityApi = $identityApi;
54+
55+
if (null === $this->localeProcessor) {
56+
trigger_deprecation(
57+
'SyliusPayPalPlugin',
58+
'1.7',
59+
'Not passing an instance of %s to %s constructor is deprecated and will be required in 3.0.',
60+
LocaleProcessorInterface::class,
61+
self::class,
62+
);
63+
}
5264
}
5365

5466
public function __invoke(Request $request): Response
@@ -73,14 +85,15 @@ public function __invoke(Request $request): Response
7385

7486
$token = $this->authorizeClientApi->authorize($paymentMethod);
7587
$clientToken = $this->identityApi->generateToken($token);
88+
$locale = $request->getLocale();
7689

7790
return new Response($this->twig->render('@SyliusPayPalPlugin/payWithPaypal.html.twig', [
7891
'available_countries' => $this->countriesProvider->provide(),
7992
'billing_address' => $order->getBillingAddress(),
8093
'client_id' => $clientId,
8194
'client_token' => $clientToken,
8295
'currency' => $order->getCurrencyCode(),
83-
'locale' => $request->getLocale(),
96+
'locale' => null !== $this->localeProcessor ? $this->localeProcessor->process($locale) : $locale,
8497
'merchant_id' => $gatewayConfig->getConfig()['merchant_id'],
8598
'order_token' => $order->getTokenValue(),
8699
'partner_attribution_id' => $partnerAttributionId,

src/Resources/config/services.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@
189189
<service
190190
id="Sylius\PayPalPlugin\Processor\LocaleProcessorInterface"
191191
class="Sylius\PayPalPlugin\Processor\LocaleProcessor"
192-
/>
192+
>
193+
<argument type="service" id="sylius_paypal.resolver.supported_locale" />
194+
</service>
193195
<service id="sylius_paypal.processor.locale" alias="Sylius\PayPalPlugin\Processor\LocaleProcessorInterface" />
194196

195197
<service

src/Resources/config/services/controller.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
<argument type="service" id="sylius_paypal.provider.available_countries" />
133133
<argument type="service" id="sylius_paypal.api.cache_authorize_client" />
134134
<argument type="service" id="sylius_paypal.api.identity" />
135+
<argument type="service" id="sylius_paypal.resolver.supported_locale" />
135136
</service>
136137
<service id="sylius_paypal.controller.pay_with_paypal_form" alias="Sylius\PayPalPlugin\Controller\PayWithPayPalFormAction" />
137138

0 commit comments

Comments
 (0)