From ead4ceff1640761c8c9aa98ab0bf3a525901aa3c Mon Sep 17 00:00:00 2001 From: Andre Kraus Date: Thu, 24 Feb 2022 15:06:15 +0100 Subject: [PATCH 1/7] [FIX] Establish basic compatibility for TYPO3 v11 --- .../EventListener/Order/Payment/ClearCart.php | 16 +++++++++++++++- Configuration/Services.yaml | 4 ++++ Configuration/TCA/Overrides/sys_template.php | 2 +- .../tx_cart_domain_model_order_transaction.php | 2 +- composer.json | 9 +++++---- ext_localconf.php | 2 +- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Classes/EventListener/Order/Payment/ClearCart.php b/Classes/EventListener/Order/Payment/ClearCart.php index 25f95a6..dc1ef5f 100644 --- a/Classes/EventListener/Order/Payment/ClearCart.php +++ b/Classes/EventListener/Order/Payment/ClearCart.php @@ -10,9 +10,23 @@ */ use Extcode\Cart\Event\Order\EventInterface; +use Extcode\Cart\EventListener\Order\Finish\ClearCart as FinishClearCart; +use Extcode\Cart\Service\SessionHandler; +use Extcode\Cart\Utility\CartUtility; +use Extcode\Cart\Utility\ParserUtility; -class ClearCart extends \Extcode\Cart\EventListener\ProcessOrderCreate\ClearCart +class ClearCart extends FinishClearCart { + public function __construct( + CartUtility $cartUtility, + ParserUtility $parserUtility, + SessionHandler $sessionHandler + ) { + $this->cartUtility = $cartUtility; + $this->parserUtility = $parserUtility; + $this->sessionHandler = $sessionHandler; + } + public function __invoke(EventInterface $event): void { $orderItem = $event->getOrderItem(); diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 95766b8..736aec3 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -17,6 +17,10 @@ services: $paymentRepository: '@Extcode\Cart\Domain\Repository\Order\PaymentRepository' Extcode\CartPaypal\EventListener\Order\Payment\ClearCart: + arguments: + $cartUtility: '@Extcode\Cart\Utility\CartUtility' + $parserUtility: '@Extcode\Cart\Utility\ParserUtility' + $sessionHandler: '@Extcode\Cart\Service\SessionHandler' tags: - name: event.listener identifier: 'cart-paypal--order--payment--clear-cart' diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php index f3e6709..611f5a9 100644 --- a/Configuration/TCA/Overrides/sys_template.php +++ b/Configuration/TCA/Overrides/sys_template.php @@ -1,5 +1,5 @@ =7.2.0 <7.5", "ext-curl": "*", - "typo3/cms-core": "^10.4", - "typo3/cms-extbase": "^10.4", - "typo3/cms-frontend": "^10.4", - "extcode/cart": "^7.4" + "typo3/cms-core": "^11.5", + "typo3/cms-extbase": "^11.5", + "typo3/cms-frontend": "^11.5", + "extcode/cart": "^8.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.14", diff --git a/ext_localconf.php b/ext_localconf.php index a582ece..4baa585 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,6 +1,6 @@ Date: Mon, 25 Apr 2022 16:59:39 +0200 Subject: [PATCH 2/7] [FEATURE] update PayPal notification handling --- Configuration/Services.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 736aec3..dc17ee4 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -39,7 +39,7 @@ services: event: Extcode\Cart\Event\Order\PaymentEvent Extcode\CartPaypal\EventListener\Order\Notify\Email: - class: 'Extcode\Cart\EventListener\ProcessOrderCreate\Email' + class: 'Extcode\Cart\EventListener\Order\Finish\Email' tags: - name: event.listener identifier: 'cart-paypal--order--notify--email' From 2a7542d6c9026e7d966f160b0cfcdd9efd53f010 Mon Sep 17 00:00:00 2001 From: Andre Kraus Date: Mon, 25 Apr 2022 17:52:31 +0200 Subject: [PATCH 3/7] [FIX] response code in controller notificationAction errors --- Classes/Controller/Order/PaymentController.php | 14 +++++--------- .../Private/Templates/Order/Payment/Notify.html | 11 +++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 Resources/Private/Templates/Order/Payment/Notify.html diff --git a/Classes/Controller/Order/PaymentController.php b/Classes/Controller/Order/PaymentController.php index d547d52..2285034 100644 --- a/Classes/Controller/Order/PaymentController.php +++ b/Classes/Controller/Order/PaymentController.php @@ -183,11 +183,10 @@ public function cancelAction(): void } } - public function notifyAction(): void + public function notifyAction() { if ($this->request->getMethod() !== 'POST') { - $this->response->setStatus(405); - exit(); + return $this->htmlResponse()->withStatus(405, 'Method not allowed.'); } $postData = GeneralUtility::_POST(); @@ -208,15 +207,13 @@ public function notifyAction(): void $cartSHash = $postData['custom']; if (empty($cartSHash)) { - $this->response->setStatus(403); - exit(); + return $this->htmlResponse()->withStatus(403, 'Not allowed.'); } $this->loadCartByHash($this->request->getArgument('hash')); if ($this->cart === null) { - $this->response->setStatus(404); - exit(); + return $this->htmlResponse()->withStatus(404, 'Page / Cart not found.'); } $orderItem = $this->cart->getOrderItem(); @@ -231,8 +228,7 @@ public function notifyAction(): void $this->eventDispatcher->dispatch($notifyEvent); } - $this->response->setStatus(200); - exit(); + return $this->htmlResponse()->withStatus(200); } protected function restoreCartSession(): void diff --git a/Resources/Private/Templates/Order/Payment/Notify.html b/Resources/Private/Templates/Order/Payment/Notify.html new file mode 100644 index 0000000..fcb9b98 --- /dev/null +++ b/Resources/Private/Templates/Order/Payment/Notify.html @@ -0,0 +1,11 @@ + + + + + + +
+ +
+
+
From f0e1f7f63f28addba1e845e2a3326d81bd785b86 Mon Sep 17 00:00:00 2001 From: Andre Kraus Date: Fri, 17 Mar 2023 10:55:07 +0100 Subject: [PATCH 4/7] [WIP] compatibility with TYPO3 v11 and PHP v8.1 --- .../Controller/Order/PaymentController.php | 56 ++++++++++++++++++- composer.json | 2 +- ext_emconf.php | 9 --- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/Classes/Controller/Order/PaymentController.php b/Classes/Controller/Order/PaymentController.php index 2285034..5b4be47 100644 --- a/Classes/Controller/Order/PaymentController.php +++ b/Classes/Controller/Order/PaymentController.php @@ -16,7 +16,9 @@ use Extcode\CartPaypal\Event\Order\CancelEvent; use Extcode\CartPaypal\Event\Order\NotifyEvent; use Extcode\CartPaypal\Event\Order\SuccessEvent; +use Psr\Log\LoggerAwareTrait; use Psr\Log\LoggerInterface; +use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\Log\LogManagerInterface; use TYPO3\CMS\Core\Messaging\AbstractMessage; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -28,6 +30,8 @@ class PaymentController extends ActionController { + use LoggerAwareTrait; + const PAYPAL_API_SANDBOX = 'https://www.sandbox.paypal.com/cgi-bin/webscr?'; const PAYPAL_API_LIVE = 'https://www.paypal.com/cgi-bin/webscr?'; @@ -78,7 +82,8 @@ public function __construct( CartRepository $cartRepository, PaymentRepository $paymentRepository ) { - $this->logger = $logManager->getLogger(); + // $this->logger = $logManager->getLogger(); + $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); $this->persistenceManager = $persistenceManager; $this->sessionHandler = $sessionHandler; $this->cartRepository = $cartRepository; @@ -186,6 +191,14 @@ public function cancelAction(): void public function notifyAction() { if ($this->request->getMethod() !== 'POST') { + if ($this->cartPaypalConf['debug']) { + $this->logger->error( + 'Notify Action called without Post vars. ' . ' In class ' . get_class($this) . ':' . __LINE__, + [ + 'order' => ((!empty($_GET['tx_cartpaypal_cart']['order'])) ? $_GET['tx_cartpaypal_cart']['order'] : 'No order ID given') + ] + ); + } return $this->htmlResponse()->withStatus(405, 'Method not allowed.'); } @@ -194,7 +207,7 @@ public function notifyAction() $curlRequest = $this->getCurlRequestFromPostData($postData); if ($this->cartPaypalConf['debug']) { - $this->logger->debug( + $this->logger->error( 'Log Data', [ '$parsedPostData' => $postData, @@ -207,12 +220,36 @@ public function notifyAction() $cartSHash = $postData['custom']; if (empty($cartSHash)) { + // debug + if ($this->cartPaypalConf['debug']) { + $this->logger->error( + 'Notify Action called with empty cartSHash. ' . ' In class ' . get_class($this) . ':' . __LINE__, + [ + 'order' => ((!empty($_GET['tx_cartpaypal_cart']['order'])) ? $_GET['tx_cartpaypal_cart']['order'] : 'No order ID given'), + '$parsedPostData' => $postData, + '$curlRequest' => $curlRequest + ] + ); + } + // end debug return $this->htmlResponse()->withStatus(403, 'Not allowed.'); } $this->loadCartByHash($this->request->getArgument('hash')); if ($this->cart === null) { + // debug + if ($this->cartPaypalConf['debug']) { + $this->logger->error( + 'Notify Action but couldn`t load cart by hash. ' . ' In class ' . get_class($this) . ':' . __LINE__, + [ + 'order' => ((!empty($_GET['tx_cartpaypal_cart']['order'])) ? $_GET['tx_cartpaypal_cart']['order'] : 'No order ID given'), + '$parsedPostData' => $postData, + '$curlRequest' => $curlRequest + ] + ); + } + // end debug return $this->htmlResponse()->withStatus(404, 'Page / Cart not found.'); } @@ -226,6 +263,19 @@ public function notifyAction() $notifyEvent = new NotifyEvent($this->cart->getCart(), $orderItem, $this->cartConf); $this->eventDispatcher->dispatch($notifyEvent); + } else { + // debug + if ($this->cartPaypalConf['debug']) { + $this->logger->error( + 'Notify Action success. ' . ' In class ' . get_class($this) . ':' . __LINE__, + [ + 'order' => ((!empty($_GET['tx_cartpaypal_cart']['order'])) ? $_GET['tx_cartpaypal_cart']['order'] : 'No order ID given'), + '$parsedPostData' => $postData, + '$curlRequest' => $curlRequest + ] + ); + } + // end debug } return $this->htmlResponse()->withStatus(200); @@ -293,7 +343,7 @@ protected function execCurlRequest(string $curlRequest): bool } if ($this->cartPaypalConf['debug']) { - $this->logger->debug( + $this->logger->error( 'paypal-payment-api', [ 'curl_info' => curl_getinfo($ch, CURLINFO_HEADER_OUT), diff --git a/composer.json b/composer.json index 0e3cb3c..36f6c63 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ } }, "require": { - "php": ">=7.2.0 <7.5", + "php": ">=7.2.0 <8.2", "ext-curl": "*", "typo3/cms-core": "^11.5", "typo3/cms-extbase": "^11.5", diff --git a/ext_emconf.php b/ext_emconf.php index 6599737..827542c 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -7,16 +7,7 @@ 'author' => 'Daniel Gohlke', 'author_email' => 'ext.cart@extco.de', 'author_company' => 'extco.de UG (haftungsbeschränkt)', - 'shy' => '', - 'priority' => '', - 'module' => '', 'state' => 'beta', - 'internal' => '', - 'uploadfolder' => '0', - 'createDirs' => '', - 'modify_tables' => '', - 'clearCacheOnLoad' => 0, - 'lockType' => '', 'version' => '5.0.0', 'constraints' => [ 'depends' => [ From cfd8eb76827bc7d2cf0c81edb3ee3f8254d99f7b Mon Sep 17 00:00:00 2001 From: Andre Kraus Date: Sun, 10 Dec 2023 19:28:00 +0100 Subject: [PATCH 5/7] [FIX] little changes for v11.5 --- .../Controller/Order/PaymentController.php | 66 ++++++++++++++++++- composer.json | 2 +- ext_emconf.php | 11 +--- 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/Classes/Controller/Order/PaymentController.php b/Classes/Controller/Order/PaymentController.php index 2285034..7793c05 100644 --- a/Classes/Controller/Order/PaymentController.php +++ b/Classes/Controller/Order/PaymentController.php @@ -16,7 +16,9 @@ use Extcode\CartPaypal\Event\Order\CancelEvent; use Extcode\CartPaypal\Event\Order\NotifyEvent; use Extcode\CartPaypal\Event\Order\SuccessEvent; +use Psr\Log\LoggerAwareTrait; use Psr\Log\LoggerInterface; +use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\Log\LogManagerInterface; use TYPO3\CMS\Core\Messaging\AbstractMessage; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -28,6 +30,8 @@ class PaymentController extends ActionController { + use LoggerAwareTrait; + const PAYPAL_API_SANDBOX = 'https://www.sandbox.paypal.com/cgi-bin/webscr?'; const PAYPAL_API_LIVE = 'https://www.paypal.com/cgi-bin/webscr?'; @@ -66,6 +70,16 @@ class PaymentController extends ActionController */ protected $cartConf = []; + /** + * @var string|bool + */ + protected $curlResult; + + /** + * @var array + */ + protected $curlResults; + /** * @var array */ @@ -78,7 +92,8 @@ public function __construct( CartRepository $cartRepository, PaymentRepository $paymentRepository ) { - $this->logger = $logManager->getLogger(); + // $this->logger = $logManager->getLogger(); + $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); $this->persistenceManager = $persistenceManager; $this->sessionHandler = $sessionHandler; $this->cartRepository = $cartRepository; @@ -186,6 +201,14 @@ public function cancelAction(): void public function notifyAction() { if ($this->request->getMethod() !== 'POST') { + if ($this->cartPaypalConf['debug']) { + $this->logger->error( + 'Notify Action called without Post vars. ' . ' In class ' . get_class($this) . ':' . __LINE__, + [ + 'order' => ((!empty($_GET['tx_cartpaypal_cart']['order'])) ? $_GET['tx_cartpaypal_cart']['order'] : 'No order ID given') + ] + ); + } return $this->htmlResponse()->withStatus(405, 'Method not allowed.'); } @@ -194,7 +217,7 @@ public function notifyAction() $curlRequest = $this->getCurlRequestFromPostData($postData); if ($this->cartPaypalConf['debug']) { - $this->logger->debug( + $this->logger->error( 'Log Data', [ '$parsedPostData' => $postData, @@ -207,12 +230,36 @@ public function notifyAction() $cartSHash = $postData['custom']; if (empty($cartSHash)) { + // debug + if ($this->cartPaypalConf['debug']) { + $this->logger->error( + 'Notify Action called with empty cartSHash. ' . ' In class ' . get_class($this) . ':' . __LINE__, + [ + 'order' => ((!empty($_GET['tx_cartpaypal_cart']['order'])) ? $_GET['tx_cartpaypal_cart']['order'] : 'No order ID given'), + '$parsedPostData' => $postData, + '$curlRequest' => $curlRequest + ] + ); + } + // end debug return $this->htmlResponse()->withStatus(403, 'Not allowed.'); } $this->loadCartByHash($this->request->getArgument('hash')); if ($this->cart === null) { + // debug + if ($this->cartPaypalConf['debug']) { + $this->logger->error( + 'Notify Action but couldn`t load cart by hash. ' . ' In class ' . get_class($this) . ':' . __LINE__, + [ + 'order' => ((!empty($_GET['tx_cartpaypal_cart']['order'])) ? $_GET['tx_cartpaypal_cart']['order'] : 'No order ID given'), + '$parsedPostData' => $postData, + '$curlRequest' => $curlRequest + ] + ); + } + // end debug return $this->htmlResponse()->withStatus(404, 'Page / Cart not found.'); } @@ -226,6 +273,19 @@ public function notifyAction() $notifyEvent = new NotifyEvent($this->cart->getCart(), $orderItem, $this->cartConf); $this->eventDispatcher->dispatch($notifyEvent); + } else { + // debug + if ($this->cartPaypalConf['debug']) { + $this->logger->error( + 'Notify Action success. ' . ' In class ' . get_class($this) . ':' . __LINE__, + [ + 'order' => ((!empty($_GET['tx_cartpaypal_cart']['order'])) ? $_GET['tx_cartpaypal_cart']['order'] : 'No order ID given'), + '$parsedPostData' => $postData, + '$curlRequest' => $curlRequest + ] + ); + } + // end debug } return $this->htmlResponse()->withStatus(200); @@ -293,7 +353,7 @@ protected function execCurlRequest(string $curlRequest): bool } if ($this->cartPaypalConf['debug']) { - $this->logger->debug( + $this->logger->error( 'paypal-payment-api', [ 'curl_info' => curl_getinfo($ch, CURLINFO_HEADER_OUT), diff --git a/composer.json b/composer.json index 0e3cb3c..3e1fa74 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ } }, "require": { - "php": ">=7.2.0 <7.5", + "php": ">=7.4.0 <8.2", "ext-curl": "*", "typo3/cms-core": "^11.5", "typo3/cms-extbase": "^11.5", diff --git a/ext_emconf.php b/ext_emconf.php index 6599737..d5d768f 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -7,20 +7,11 @@ 'author' => 'Daniel Gohlke', 'author_email' => 'ext.cart@extco.de', 'author_company' => 'extco.de UG (haftungsbeschränkt)', - 'shy' => '', - 'priority' => '', - 'module' => '', 'state' => 'beta', - 'internal' => '', - 'uploadfolder' => '0', - 'createDirs' => '', - 'modify_tables' => '', - 'clearCacheOnLoad' => 0, - 'lockType' => '', 'version' => '5.0.0', 'constraints' => [ 'depends' => [ - 'typo3' => '10.4.0-10.4.99', + 'typo3' => '11.5.0-11.5.99', 'cart' => '7.4.0', ], 'conflicts' => [], From a70f185771316ca802335b72180fd05b47383fa3 Mon Sep 17 00:00:00 2001 From: Andre Kraus Date: Sun, 10 Dec 2023 19:28:20 +0100 Subject: [PATCH 6/7] [FIX] PayPal needs rebatt amount as a money value and has to be added twice in typoscript. --- Classes/EventListener/Order/Payment/ProviderRedirect.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Classes/EventListener/Order/Payment/ProviderRedirect.php b/Classes/EventListener/Order/Payment/ProviderRedirect.php index 78c7966..872fcb9 100644 --- a/Classes/EventListener/Order/Payment/ProviderRedirect.php +++ b/Classes/EventListener/Order/Payment/ProviderRedirect.php @@ -12,6 +12,7 @@ use Extcode\Cart\Domain\Model\Cart; use Extcode\Cart\Domain\Model\Cart\Cart as CartCart; use Extcode\Cart\Domain\Model\Cart\CartCoupon; +use Extcode\Cart\Domain\Model\Cart\CartCouponPercentage; use Extcode\Cart\Domain\Model\Order\Item as OrderItem; use Extcode\Cart\Domain\Repository\CartRepository; use Extcode\Cart\Event\Order\PaymentEvent; @@ -229,7 +230,12 @@ protected function addEachCouponFromCartToQuery(): void */ foreach ($this->cart->getCoupons() as $cartCoupon) { if ($cartCoupon->getIsUseable()) { - $discount += $cartCoupon->getDiscount(); + // A.K.: Differentiate between percentage and fixed discount + if ($cartCoupon instanceof CartCouponPercentage) { + $discount += (float)($this->orderItem->getGross() * $cartCoupon->getDiscount()); + } else { + $discount += $cartCoupon->getDiscount(); + } } } From 89d3defb6bde33903e086bdb28aae05191f57b9f Mon Sep 17 00:00:00 2001 From: Andre Kraus Date: Sun, 10 Dec 2023 19:39:43 +0100 Subject: [PATCH 7/7] [TASK] update php-cs-fixer --- composer.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3e1fa74..2b5507a 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,11 @@ }, "config": { "bin-dir": ".build/bin", - "vendor-dir": ".build/vendor" + "vendor-dir": ".build/vendor", + "allow-plugins": { + "typo3/cms-composer-installers": true, + "typo3/class-alias-loader": true + } }, "extra": { "typo3/cms": { @@ -48,7 +52,7 @@ "extcode/cart": "^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.14", + "friendsofphp/php-cs-fixer": "^3.14", "helmich/typo3-typoscript-lint": "^2.0", "overtrue/phplint": "^1.1" },