2020use Sylius \Component \Core \Repository \PaymentRepositoryInterface ;
2121use Sylius \PayPalPlugin \Api \CacheAuthorizeClientApiInterface ;
2222use Sylius \PayPalPlugin \Api \IdentityApiInterface ;
23+ use Sylius \PayPalPlugin \Processor \LocaleProcessorInterface ;
2324use Sylius \PayPalPlugin \Provider \AvailableCountriesProviderInterface ;
2425use Symfony \Component \HttpFoundation \Request ;
2526use 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 ,
0 commit comments