Commit d7fb4ee7 authored by Thomas Löffler's avatar Thomas Löffler

Add 'html/typo3conf/ext/t3o_donation/' from commit 'fd1b2f85'

git-subtree-dir: html/typo3conf/ext/t3o_donation
git-subtree-mainline: 3f90a1cf
git-subtree-split: fd1b2f85
parents 3f90a1cf fd1b2f85
<?php
namespace T3o\T3oDonation\Controller;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Class \T3o\T3oDonation\Controller\DonationController
* @author Sebastian Diez
*/
class DonationController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
/**
* configurationUtility
*
* @var \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility
* @inject
* @lazy
*/
protected $configurationUtility = null;
/**
* accountRepository
*
* @var \T3o\T3oDonation\Domain\Repository\AccountRepository
* @inject
* @lazy
*/
protected $accountRepository = null;
/**
* donationRepository
*
* @var \T3o\T3oDonation\Domain\Repository\DonationRepository
* @inject
* @lazy
*/
protected $donationRepository;
/**
* ipnService
*
* @var \T3o\T3oDonation\Service\PayPalIpn
* @inject
* @lazy
*/
protected $ipnService;
/**
* mailService
*
* @var \T3o\T3oDonation\Service\Mail
* @inject
* @lazy
*/
protected $mailService;
/**
* Adds custom JS to page.
*/
public function initializeAction()
{
/* @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addJsFooterFile(
ExtensionManagementUtility::siteRelPath($this->request->getControllerExtensionKey())
. 'Resources/Public/JavaScript/donation.js'
);
parent::initializeAction();
}
/**
* @param string $optionName
* @return string
*/
protected function getConfigurationOption($optionName)
{
$config = $this->configurationUtility->getCurrentConfiguration('t3o_donation');
if (!isset($config[$optionName])) {
return '';
}
if (!isset($config[$optionName]['value'])) {
return '';
}
return $config[$optionName]['value'];
}
/**
* action list
*
* @return void
*/
public function listAction()
{
$donations = $this->donationRepository->findAll();
$this->view->assign('donations', $donations);
}
/**
* action form
*
* @return void
*/
public function formAction()
{
$account = $this->accountRepository->findByUid($this->settings['payPalAccount']);
$this->view->assign('account', $account);
$this->view->assign('actionUrl', $this->settings['paypal']['action']);
if ($GLOBALS['TSFE']->fe_user && $GLOBALS['TSFE']->fe_user->user['uid']) {
$userId = $GLOBALS['TSFE']->fe_user->user['uid'];
} else {
$userId = 0;
}
$this->view->assign('userId', $userId);
}
/**
* action thankyou
*
* @return void
*/
public function thankyouAction()
{
$this->addFlashMessage(
LocalizationUtility::translate(
'thankyou_message_body',
't3o_donation'
),
LocalizationUtility::translate(
'thankyou_message_title',
't3o_donation'
),
FlashMessage::OK,
true
);
$this->forward('form');
}
/**
* action ipn log
*
* @return void
*/
public function ipnLogAction()
{
$parameters = GeneralUtility::_POST();
$verified = $this->ipnService->verify($parameters, $this->getConfigurationOption('paypal.action'));
if (!$verified) {
$this->addFlashMessage('Payment verification failed','Paypal transaction',\TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
return;
}
if (!$this->ipnService->isNewCompletedTransaction($parameters, $this->donationRepository)) {
$this->addFlashMessage('isNewCompletedTransaction == false','Paypal transaction',\TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
return;
}
$donation = $this->ipnService->createDonation($parameters);
$this->donationRepository->add($donation);
$this->sendNotificationMail($donation);
$this->sendThankyouMail($donation);
//@TODO recuddderring, test address data
}
/**
* @param \T3o\T3oDonation\Domain\Model\Donation $donation
* @return bool
*/
protected function sendNotificationMail($donation)
{
if (isset($this->settings['fromName']) && $this->settings['fromName'] !== '') {
$from = array($this->settings['fromAddress'] => $this->settings['fromName']);
} else {
$from = array($this->settings['fromAddress']);
}
if (isset($this->settings['replyToName']) && $this->settings['replyToName'] !== '') {
$replyTo = array($this->settings['replyToAddress'] => $this->settings['replyToName']);
} elseif (isset($this->settings['replyToAddress']) && $this->settings['replyToAddress'] !== '') {
$replyTo = array($this->settings['replyToAddress']);
} else {
$replyTo = array();
}
return $this->mailService->sendDonationNotification(
$donation,
$from,
$replyTo
);
}
/**
* @param \T3o\T3oDonation\Domain\Model\Donation $donation
* @return bool
*/
protected function sendThankyouMail($donation)
{
if (isset($this->settings['fromName']) && $this->settings['fromName'] !== '') {
$from = array($this->settings['fromAddress'] => $this->settings['fromName']);
} else {
$from = array($this->settings['fromAddress']);
}
if (isset($this->settings['replyToName']) && $this->settings['replyToName'] !== '') {
$replyTo = array($this->settings['replyToAddress'] => $this->settings['replyToName']);
} elseif (isset($this->settings['replyToAddress']) && $this->settings['replyToAddress'] !== '') {
$replyTo = array($this->settings['replyToAddress']);
} else {
$replyTo = array();
}
return $this->mailService->sendDonationThankyou(
$donation,
$this->settings['thankyouSubject'],
$this->settings['thankyouText'],
$from,
$replyTo
);
}
}
<?php
namespace T3o\T3oDonation\Domain\Model;
/**
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Class \T3o\T3oDonation\Domain\Model\Account
* @author Sebastian Diez
*/
class Account extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* @validate NotEmpty
* @var string
*/
protected $name;
/**
* @validate NotEmpty
* @validate EmailAddress
* @var string
*/
protected $emailNotification;
/**
* @validate NotEmpty
* @validate EmailAddress
* @var string
*/
protected $emailPaypal;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getEmailNotification()
{
return $this->emailNotification;
}
/**
* @param string $email
*/
public function setEmailNotification($email)
{
$this->emailNotification = $email;
}
/**
* @return string
*/
public function getEmailPaypal()
{
return $this->emailPaypal;
}
/**
* @param string $email
*/
public function setEmailPaypal($email)
{
$this->emailPaypal = $email;
}
}
<?php
namespace T3o\T3oDonation\Domain\Model;
/**
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Class \T3o\T3oDonation\Domain\Model\Donation
* @author Sebastian Diez
*/
class Donation extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* @var bool
*/
protected $hidden;
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $company;
/**
* @var string
*/
protected $addressStreet;
/**
* @var string
*/
protected $addressZip;
/**
* @var string
*/
protected $addressCity;
/**
* @var string
*/
protected $addressState;
/**
* @var string
*/
protected $addressCountry;
/**
* @var string
*/
protected $addressCountryCode;
/**
* @validate NotEmpty
* @validate EmailAddress
* @var string
*/
protected $email;
/**
* @var string
*/
protected $url;
/**
* @var float
*/
protected $amount;
/**
* @var float
*/
protected $fee;
/**
* @var string
*/
protected $currency;
/**
* @var \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
*/
protected $feUser;
/**
* @var string
*/
protected $comment;
/**
* @var \T3o\T3oDonation\Domain\Model\Account
*/
protected $account;
/**
* @var string
*/
protected $paypalTransactionId;
/**
* @var \DateTime
*/
protected $date;
/**
* @var \DateTime
*/
protected $crdate;
/**
* @return bool
*/
public function getHidden()
{
return $this->hidden;
}
/**
* @param bool $hidden
*/
public function setHidden($hidden)
{
$this->hidden = $hidden;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return float
*/
public function getAmount()
{
return $this->amount;
}
/**
* @param float $amount
*/
public function setAmount($amount)
{
$this->amount = (float)$amount;
}
/**
* @return float
*/
public function getFee()
{
return $this->fee;
}
/**
* @param float $fee
*/
public function setFee($fee)
{
$this->fee = (float)$fee;
}
/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* @param string $currency
*/
public function setCurrency($currency)
{
$this->currency = $currency;
}
/**
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser feUser
*/
public function setFeUser($feUser)
{
$this->feUser = $feUser;
}
/**
* @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
*/
public function getFeUser()
{
return $this->feUser;
}
/**
* @param string $comment
*/
public function setComment($comment)
{
$this->comment = $comment;
}
/**
* @return string
*/
public function getComment()
{
return $this->comment;
}
/**
* @param \T3o\T3oDonation\Domain\Model\Account $account
*/
public function setAccount(Account $account)
{
$this->account = $account;
}
/**
* @return \T3o\T3oDonation\Domain\Model\Account
*/
public function getAccount()
{
return $this->account;
}
/**
* @param string $url
*/
public function setUrl($url)
{
$this->url = $url;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $transactionId
*/
public function setPaypalTransactionId($transactionId)
{
$this->paypalTransactionId = $transactionId;
}
/**
* @return string
*/
public function getPaypalTransactionId()
{
return $this->paypalTransactionId;
}
/**
* @param $company
*/
public function setCompany($company)
{
$this->company = $company;
}
/**
* @return string
*/
public function getCompany()
{
return $this->company;
}
/**
* @param string $addressCity
*/
public function setAddressCity($addressCity)
{
$this->addressCity = $addressCity;
}
/**
* @return string
*/
public function getAddressCity()
{
return $this->addressCity;
}
/**
* @param string $addressCountry
*/
public function setAddressCountry($addressCountry)
{
$this->addressCountry = $addressCountry;
}
/**
* @return string
*/
public function getAddressCountry()
{
return $this->addressCountry;
}
/**
* @param string $addressCountryCode
*/
public function setAddressCountryCode($addressCountryCode)
{
$this->addressCountryCode = $addressCountryCode;
}
/**
* @return string
*/
public function getAddressCountryCode()
{
return $this->addressCountryCode;
}
/**
* @param string $addressState
*/
public function setAddressState($addressState)
{
$this->addressState = $addressState;
}
/**
* @return string