Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TYPO3 v11 PHP 81 support and PayPal rebatt amount #28

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 68 additions & 12 deletions Classes/Controller/Order/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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?';

Expand Down Expand Up @@ -66,6 +70,16 @@ class PaymentController extends ActionController
*/
protected $cartConf = [];

/**
* @var string|bool
*/
protected $curlResult;

/**
* @var array
*/
protected $curlResults;

/**
* @var array
*/
Expand All @@ -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;
Expand Down Expand Up @@ -183,19 +198,26 @@ public function cancelAction(): void
}
}

public function notifyAction(): void
public function notifyAction()
{
if ($this->request->getMethod() !== 'POST') {
$this->response->setStatus(405);
exit();
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.');
}

$postData = GeneralUtility::_POST();

$curlRequest = $this->getCurlRequestFromPostData($postData);

if ($this->cartPaypalConf['debug']) {
$this->logger->debug(
$this->logger->error(
'Log Data',
[
'$parsedPostData' => $postData,
Expand All @@ -208,15 +230,37 @@ public function notifyAction(): void

$cartSHash = $postData['custom'];
if (empty($cartSHash)) {
$this->response->setStatus(403);
exit();
// 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) {
$this->response->setStatus(404);
exit();
// 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.');
}

$orderItem = $this->cart->getOrderItem();
Expand All @@ -229,10 +273,22 @@ public function notifyAction(): void

$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
}

$this->response->setStatus(200);
exit();
return $this->htmlResponse()->withStatus(200);
}

protected function restoreCartSession(): void
Expand Down Expand Up @@ -297,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),
Expand Down
16 changes: 15 additions & 1 deletion Classes/EventListener/Order/Payment/ClearCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion Classes/EventListener/Order/Payment/ProviderRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -35,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'
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TCA/Overrides/sys_template.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
defined('TYPO3_MODE') or die();
defined('TYPO3') or die();

call_user_func(function () {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

defined('TYPO3_MODE') or die();
defined('TYPO3') or die();

$_LLL = 'LLL:EXT:cart_paypal/Resources/Private/Language/locallang_db.xlf';

Expand Down
11 changes: 11 additions & 0 deletions Resources/Private/Templates/Order/Payment/Notify.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<f:layout name="Default"/>

<f:section name="main">
<f:flashMessages/>

<f:if condition="{orderItem}">
<div class="col-sm-12 col-md-12 col-lg-12">
<f:translate key="tx_cart.controller.order.action.payment_cancel.thank_you"/>
</div>
</f:if>
</f:section>
19 changes: 12 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"PayPal",
"cart"
],
"version": "5.1.0",
"authors": [
{
"name": "Daniel Gohlke",
Expand All @@ -29,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": {
Expand All @@ -39,15 +44,15 @@
}
},
"require": {
"php": ">=7.2.0 <7.5",
"php": ">=7.4.0 <8.2",
"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",
"friendsofphp/php-cs-fixer": "^3.14",
"helmich/typo3-typoscript-lint": "^2.0",
"overtrue/phplint": "^1.1"
},
Expand Down
11 changes: 1 addition & 10 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@
'author' => 'Daniel Gohlke',
'author_email' => '[email protected]',
'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' => [],
Expand Down
2 changes: 1 addition & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

defined('TYPO3_MODE') or die();
defined('TYPO3') or die();

// configure plugins

Expand Down