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,24 @@ 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+ $ this ->localeProcessor = $ localeProcessor ;
55+
56+ if (null === $ localeProcessor ) {
57+ trigger_deprecation (
58+ 'SyliusPayPalPlugin ' ,
59+ '1.7 ' ,
60+ 'Not passing an instance of %s to %s constructor is deprecated and will be required in 3.0. ' ,
61+ LocaleProcessorInterface::class,
62+ self ::class
63+ );
64+ }
5265 }
5366
5467 public function __invoke (Request $ request ): Response
@@ -73,14 +86,15 @@ public function __invoke(Request $request): Response
7386
7487 $ token = $ this ->authorizeClientApi ->authorize ($ paymentMethod );
7588 $ clientToken = $ this ->identityApi ->generateToken ($ token );
89+ $ locale = $ request ->getLocale ();
7690
7791 return new Response ($ this ->twig ->render ('@SyliusPayPalPlugin/payWithPaypal.html.twig ' , [
7892 'available_countries ' => $ this ->countriesProvider ->provide (),
7993 'billing_address ' => $ order ->getBillingAddress (),
8094 'client_id ' => $ clientId ,
8195 'client_token ' => $ clientToken ,
8296 'currency ' => $ order ->getCurrencyCode (),
83- 'locale ' => $ request -> getLocale () ,
97+ 'locale ' => null !== $ this -> localeProcessor ? $ this -> localeProcessor -> process ( $ locale ) : $ locale ,
8498 'merchant_id ' => $ gatewayConfig ->getConfig ()['merchant_id ' ],
8599 'order_token ' => $ order ->getTokenValue (),
86100 'partner_attribution_id ' => $ partnerAttributionId ,
0 commit comments