2323
2424namespace PayPal \Service \Base ;
2525
26+ use Exception ;
2627use Monolog \Logger ;
2728use PayPal \Api \Amount ;
2829use PayPal \Api \FuturePayment ;
4041use PayPal \PayPal ;
4142use PayPal \Rest \ApiContext ;
4243use PayPal \Service \PayPalLoggerService ;
44+ use Propel \Runtime \Exception \PropelException ;
4345use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
4446use Symfony \Component \HttpFoundation \RequestStack ;
4547use Symfony \Component \Routing \RouterInterface ;
5052use Thelia \Model \Cart ;
5153use Thelia \Model \Country ;
5254use Thelia \Model \Currency ;
55+ use Thelia \Model \Lang ;
5356use Thelia \Model \Order ;
5457use Thelia \Model \OrderAddressQuery ;
5558
5659class PayPalBaseService
5760{
5861 /** @var EventDispatcherInterface */
59- protected $ dispatcher ;
62+ protected EventDispatcherInterface $ dispatcher ;
6063
6164 /** @var RequestStack */
62- protected $ requestStack ;
65+ protected RequestStack $ requestStack ;
6366
6467 /** @var RouterInterface */
65- protected $ router ;
68+ protected RouterInterface $ router ;
6669
6770 /** @var OAuthTokenCredential */
68- protected $ authTokenCredential ;
71+ protected OAuthTokenCredential $ authTokenCredential ;
6972
7073 /**
7174 * PayPalBaseService constructor.
@@ -84,9 +87,10 @@ public function __construct(EventDispatcherInterface $dispatcher, RequestStack $
8487
8588 /**
8689 * @param Order $order
87- * @param string| null $creditCardId
88- * @param PaypalPlanifiedPayment $planifiedPayment
90+ * @param null $creditCardId
91+ * @param PaypalPlanifiedPayment|null $planifiedPayment
8992 * @return PayPalOrderEvent
93+ * @throws PropelException
9094 */
9195 public function generatePayPalOrder (Order $ order , $ creditCardId = null , PaypalPlanifiedPayment $ planifiedPayment = null )
9296 {
@@ -101,7 +105,7 @@ public function generatePayPalOrder(Order $order, $creditCardId = null, PaypalPl
101105 }
102106
103107 if (null !== $ planifiedPayment ) {
104- /** @var \Thelia\Model\ Lang $lang */
108+ /** @var Lang $lang */
105109 $ lang = $ this ->requestStack ->getCurrentRequest ()->getSession ()->get ('thelia.current.lang ' );
106110 $ planifiedPayment ->getTranslation ($ lang ->getLocale ());
107111
@@ -129,7 +133,7 @@ public function generatePayPalOrder(Order $order, $creditCardId = null, PaypalPl
129133 * @param string|null $agreementId
130134 * @return PayPalOrderEvent
131135 */
132- public function updatePayPalOrder (PaypalOrder $ payPalOrder , $ state , $ paymentId = null , $ agreementId = null )
136+ public function updatePayPalOrder (PaypalOrder $ payPalOrder , $ state , string $ paymentId = null , string $ agreementId = null )
133137 {
134138 $ payPalOrder ->setState ($ state );
135139
@@ -174,10 +178,10 @@ public function getCurrentPayPalCart()
174178 /**
175179 * @param string $method
176180 * @param array $fundingInstruments
177- * @param PayerInfo $payerInfo
181+ * @param PayerInfo|null $payerInfo
178182 * @return Payer
179183 */
180- public static function generatePayer ($ method = PayPal::PAYPAL_METHOD_PAYPAL , $ fundingInstruments = [], PayerInfo $ payerInfo = null )
184+ public static function generatePayer (string $ method = PayPal::PAYPAL_METHOD_PAYPAL , array $ fundingInstruments = [], PayerInfo $ payerInfo = null )
181185 {
182186 $ payer = new Payer ();
183187 $ payer ->setPaymentMethod ($ method );
@@ -196,11 +200,13 @@ public static function generatePayer($method = PayPal::PAYPAL_METHOD_PAYPAL, $fu
196200
197201 public static function generatePayerInfo ($ data = [])
198202 {
199- $ payerInfo = new PayerInfo ($ data );
200-
201- return $ payerInfo ;
203+ return new PayerInfo ($ data );
202204 }
203205
206+ /**
207+ * @throws PropelException
208+ * @throws Exception
209+ */
204210 public static function generateShippingAddress (Order $ order )
205211 {
206212 if (null !== $ orderAddress = OrderAddressQuery::create ()->findOneById ($ order ->getDeliveryOrderAddressId ())) {
@@ -231,33 +237,30 @@ public static function generateShippingAddress(Order $order)
231237 $ shippingAddress ->setLine2 ($ orderAddress ->getAddress3 ());
232238 }
233239
234- if (null !== $ orderAddress ->getStateId ()) {
235- //$shippingAddress->setState($orderAddress->getState()->getIsocode());
236- }
237-
238240 return $ shippingAddress ;
239- } else {
240- $ message = Translator::getInstance ()->trans (
241- 'Order address no found to generate PayPal shipping address ' ,
242- [],
243- PayPal::DOMAIN_NAME
244- );
245- PayPalLoggerService::log (
246- $ message ,
247- [
248- 'customer_id ' => $ order ->getCustomerId (),
249- 'order_id ' => $ order ->getId ()
250- ],
251- Logger::ERROR
252- );
253- throw new \Exception ($ message );
254241 }
242+
243+ $ message = Translator::getInstance ()->trans (
244+ 'Order address no found to generate PayPal shipping address ' ,
245+ [],
246+ PayPal::DOMAIN_NAME
247+ );
248+ PayPalLoggerService::log (
249+ $ message ,
250+ [
251+ 'customer_id ' => $ order ->getCustomerId (),
252+ 'order_id ' => $ order ->getId ()
253+ ],
254+ Logger::ERROR
255+ );
256+ throw new Exception ($ message );
255257 }
256258
257259 /**
258260 * @param Order $order
259261 * @param Currency $currency
260262 * @return Amount
263+ * @throws PropelException
261264 */
262265 public function generateAmount (Order $ order , Currency $ currency )
263266 {
@@ -273,6 +276,7 @@ public function generateAmount(Order $order, Currency $currency)
273276 * @param Cart $cart
274277 * @param Currency $currency
275278 * @return Amount
279+ * @throws PropelException
276280 */
277281 public function generateAmountFromCart (Cart $ cart , Currency $ currency )
278282 {
@@ -286,10 +290,10 @@ public function generateAmountFromCart(Cart $cart, Currency $currency)
286290
287291 /**
288292 * @param Amount $amount
289- * @param string $description
293+ * @param string|null $description
290294 * @return Transaction
291295 */
292- public function generateTransaction (Amount $ amount , $ description = '' )
296+ public function generateTransaction (Amount $ amount , ? string $ description = '' )
293297 {
294298 // ###Transaction
295299 // A transaction defines the contract of a
@@ -352,7 +356,7 @@ public static function getApiContext()
352356 */
353357 public static function getLogin ()
354358 {
355- if (PayPal::getConfigValue ('sandbox ' ) == 1 ) {
359+ if (( bool ) PayPal::getConfigValue ('sandbox ' ) = == 1 ) {
356360 $ login = PayPal::getConfigValue ('sandbox_login ' );
357361 } else {
358362 $ login = PayPal::getConfigValue ('login ' );
@@ -366,7 +370,7 @@ public static function getLogin()
366370 */
367371 public static function getPassword ()
368372 {
369- if (PayPal::getConfigValue ('sandbox ' ) == 1 ) {
373+ if (( bool ) PayPal::getConfigValue ('sandbox ' ) = == 1 ) {
370374 $ password = PayPal::getConfigValue ('sandbox_password ' );
371375 } else {
372376 $ password = PayPal::getConfigValue ('password ' );
@@ -380,7 +384,7 @@ public static function getPassword()
380384 */
381385 public static function getMerchantId ()
382386 {
383- if (PayPal::getConfigValue ('sandbox ' ) == 1 ) {
387+ if (( bool ) PayPal::getConfigValue ('sandbox ' ) = == 1 ) {
384388 $ login = PayPal::getConfigValue ('sandbox_merchant_id ' );
385389 } else {
386390 $ login = PayPal::getConfigValue ('merchant_id ' );
@@ -394,7 +398,7 @@ public static function getMerchantId()
394398 */
395399 public static function getMode ()
396400 {
397- if (PayPal::getConfigValue ('sandbox ' ) == 1 ) {
401+ if (( bool ) PayPal::getConfigValue ('sandbox ' ) = == 1 ) {
398402 $ mode = 'sandbox ' ;
399403 } else {
400404 $ mode = 'live ' ;
@@ -407,8 +411,8 @@ public static function isSandboxMode()
407411 {
408412 if (self ::getMode () === 'live ' ) {
409413 return false ;
410- } else {
411- return true ;
412414 }
415+
416+ return true ;
413417 }
414418}
0 commit comments