Skip to content

Commit 2d06bae

Browse files
authored
Merge pull request #47 from Nelfia/main
module's adaptation for php 8.0
2 parents a051cc3 + 24e57a8 commit 2d06bae

File tree

7 files changed

+185
-133
lines changed

7 files changed

+185
-133
lines changed

.DS_Store

6 KB
Binary file not shown.

Config/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<language>en_US</language>
2121
<language>fr_FR</language>
2222
</languages>
23-
<version>4.0.2</version>
23+
<version>4.0.3</version>
2424
<authors>
2525
<author>
2626
<name>gbarral</name>

Service/Base/PayPalBaseService.php

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace PayPal\Service\Base;
2525

26+
use Exception;
2627
use Monolog\Logger;
2728
use PayPal\Api\Amount;
2829
use PayPal\Api\FuturePayment;
@@ -40,6 +41,7 @@
4041
use PayPal\PayPal;
4142
use PayPal\Rest\ApiContext;
4243
use PayPal\Service\PayPalLoggerService;
44+
use Propel\Runtime\Exception\PropelException;
4345
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
4446
use Symfony\Component\HttpFoundation\RequestStack;
4547
use Symfony\Component\Routing\RouterInterface;
@@ -50,22 +52,23 @@
5052
use Thelia\Model\Cart;
5153
use Thelia\Model\Country;
5254
use Thelia\Model\Currency;
55+
use Thelia\Model\Lang;
5356
use Thelia\Model\Order;
5457
use Thelia\Model\OrderAddressQuery;
5558

5659
class 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
}

Service/MyOwnSQLHandler.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*************************************************************************************/
3+
/* Copyright (c) OpenStudio */
4+
/* web : https://www.openstudio.fr */
5+
/* */
6+
/* For the full copyright and license information, please view the LICENSE */
7+
/* file that was distributed with this source code. */
8+
/*************************************************************************************/
9+
10+
namespace PayPal\Service;
11+
12+
use Monolog\Logger;
13+
use MySQLHandler\MySQLHandler;
14+
use PDO;
15+
use Propel\Runtime\Connection\ConnectionInterface;
16+
17+
/**
18+
* Created by Franck Allimant, OpenStudio <[email protected]>
19+
* Projet: parquets-et-lambris-de-vallereuil.com
20+
* Date: 16/03/2023
21+
*/
22+
class MyOwnSQLHandler extends MySQLHandler
23+
{
24+
public function __construct(PDO|ConnectionInterface $pdo = null, string $table, array $additionalFields = [], bool|int $level = Logger::DEBUG, bool $bubble = true)
25+
{
26+
$this->pdo = $pdo;
27+
28+
parent::__construct(null, $table, $additionalFields, $level, $bubble);
29+
}
30+
}

0 commit comments

Comments
 (0)