Commit 4ef5064b authored by Marco Huber's avatar Marco Huber
Browse files

[TASK] #363 - Improve logging

parent 925455d8
Pipeline #9856 passed with stages
in 5 minutes and 46 seconds
......@@ -2,6 +2,8 @@
declare(strict_types = 1);
namespace T3o\T3oDonation\Controller;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
......@@ -27,8 +29,9 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
* Class \T3o\T3oDonation\Controller\DonationController
* @author Sebastian Diez
*/
class DonationController extends ActionController
class DonationController extends ActionController implements LoggerAwareInterface
{
use LoggerAwareTrait;
/**
* accountRepository
......@@ -110,6 +113,7 @@ class DonationController extends ActionController
*/
public function thankyouAction()
{
$this->logger->info('PayPal donation form filled.');
$this->addFlashMessage(
LocalizationUtility::translate(
'thankyou_message_body',
......@@ -130,22 +134,27 @@ class DonationController extends ActionController
*/
public function ipnLogAction()
{
$this->logger->info('PayPal IPN request incoming.');
$parameters = GeneralUtility::_POST();
$verified = $this->ipnService->verify($parameters, $this->settings['paypal']['action']);
if (!$verified && !isset($parameters['curlDebug'])) {
$this->addFlashMessage('Payment verification failed', 'Paypal transaction', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
$this->logger->info('PayPal payment verification failed');
return;
}
if (!$this->ipnService->isNewCompletedTransaction($parameters, $this->donationRepository)) {
$this->addFlashMessage('isNewCompletedTransaction == false', 'Paypal transaction', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
$this->logger->info('PayPal isNewCompletedTransaction is false');
return;
}
$this->logger->info('PayPal isNewCompletedTransaction is true');
$donation = $this->ipnService->createDonation($parameters);
$this->donationRepository->add($donation);
$this->sendNotificationMail($donation);
$this->sendThankyouMail($donation);
$this->logger->info('PayPal donation record created, notification mail sent, thankyou mail sent.');
//@TODO recuddderring, test address data
}
......
......@@ -2,6 +2,8 @@
declare(strict_types = 1);
namespace T3o\T3oDonation\Service;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use T3o\T3oDonation\Domain\Model\Donation;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
......@@ -23,8 +25,10 @@ use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
* Class \T3o\T3oDonation\Service\PayPalIpn
* @author Sebastian Diez
*/
class PayPalIpn implements \TYPO3\CMS\Core\SingletonInterface
class PayPalIpn implements \TYPO3\CMS\Core\SingletonInterface, LoggerAwareInterface
{
use LoggerAwareTrait;
const STATUS_COMPLETED = 'Completed';
const DATE_FORMAT = 'H:i:s M d, Y T';
......@@ -70,9 +74,7 @@ class PayPalIpn implements \TYPO3\CMS\Core\SingletonInterface
*/
public function verify(array $parameters, string $paypalUrl): bool
{
/** @var $logger \TYPO3\CMS\Core\Log\Logger */
$logger = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
$logger->debug('Verifing PayPal IPN', $parameters);
$this->logger->info('PayPal verifing IPN request parameters', $parameters);
$formData = array_merge($parameters, ['cmd' => '_notify-validate']);
$additionalOptions = [
......@@ -80,20 +82,20 @@ class PayPalIpn implements \TYPO3\CMS\Core\SingletonInterface
];
/* @var $requestFactory \TYPO3\CMS\Core\Http\RequestFactory */
$requestFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\RequestFactory::class);
$logger->debug('Requesting verification from PayPal', $additionalOptions);
$this->logger->info('PayPal requesting verification', $additionalOptions);
$response = $requestFactory->request($paypalUrl, 'POST', $additionalOptions);
if ($response->getStatusCode() !== 200) {
$logger->debug(
'Wrong status code for IPN verification.',
$this->logger->info(
'PayPal wrong status code for IPN verification',
['HTTP status' => $response->getStatusCode()]
);
return false;
}
$paypalResponse = $response->getBody()->getContents();
$logger->debug(
'Got response for IPN verification.',
$this->logger->info(
'PayPal got response for IPN verification',
['body' => $paypalResponse]
);
......
......@@ -59,10 +59,19 @@ Get a PayPal sandbox API account: https://developer.paypal.com/docs/api/sandbox/
Set LogLevel to DEBUG to see the full ipn requests from PayPal:
```
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'] = [
\TYPO3\CMS\Core\Log\LogLevel::DEBUG => [
\TYPO3\CMS\Core\Log\Writer\FileWriter::class => []
]
$GLOBALS['TYPO3_CONF_VARS']['LOG']['T3o']['T3oDonation']['Controller']['writerConfiguration'] = [
\TYPO3\CMS\Core\Log\LogLevel::INFO => [
\TYPO3\CMS\Core\Log\Writer\FileWriter::class => [
'logFile' => \TYPO3\CMS\Core\Core\Environment::getVarPath() . '/log/t3o_donation.log'
]
],
];
$GLOBALS['TYPO3_CONF_VARS']['LOG']['T3o']['T3oDonation']['Service']['writerConfiguration'] = [
\TYPO3\CMS\Core\Log\LogLevel::INFO => [
\TYPO3\CMS\Core\Log\Writer\FileWriter::class => [
'logFile' => \TYPO3\CMS\Core\Core\Environment::getVarPath() . '/log/t3o_donation.log'
]
],
];
```
Watch out for `component="T3o.T3oDonation.Service.PayPalIpn"` in the log file
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment