-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send an email with the paymentOrder form to confirmation persons, aft…
…er an paymentOrder was confirmed
- Loading branch information
Showing
10 changed files
with
273 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace App\Event; | ||
|
||
use App\Entity\PaymentOrder; | ||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
/** | ||
* Represents the event that is triggered, if a payment order has been confirmed by all responsible persons, | ||
* and is now ready for the next steps. | ||
*/ | ||
final class PaymentOrderConfirmedEvent extends Event implements PaymentOrderEventInterface | ||
{ | ||
public const NAME = 'payment_order.confirmed'; | ||
|
||
public function __construct(private readonly PaymentOrder $paymentOrder) | ||
{ | ||
} | ||
|
||
public function getPaymentOrder(): PaymentOrder | ||
{ | ||
return $this->paymentOrder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace App\Event; | ||
|
||
use App\Entity\PaymentOrder; | ||
|
||
interface PaymentOrderEventInterface | ||
{ | ||
public function getPaymentOrder(): PaymentOrder; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/EventSubscriber/PaymentOrderPDFGenerationSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace App\EventSubscriber; | ||
|
||
use App\Audit\UserProvider; | ||
use App\Event\PaymentOrderConfirmedEvent; | ||
use App\Event\PaymentOrderSubmittedEvent; | ||
use App\Services\PDF\PaymentOrderPDFGenerator; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
|
||
class PaymentOrderPDFGenerationSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private readonly PaymentOrderPDFGenerator $paymentOrderPDFGenerator, | ||
private readonly EntityManagerInterface $entityManager, | ||
private readonly UserProvider $userProvider,) | ||
{ | ||
|
||
} | ||
|
||
public function generatePDF(PaymentOrderSubmittedEvent|PaymentOrderConfirmedEvent $event): void | ||
{ | ||
$payment_order = $event->getPaymentOrder(); | ||
$pdf_content = $this->paymentOrderPDFGenerator->generatePDF($payment_order); | ||
|
||
//Create temporary file | ||
$tmpfname = tempnam(sys_get_temp_dir(), 'stura'); | ||
file_put_contents($tmpfname, $pdf_content); | ||
|
||
$file = new UploadedFile($tmpfname, 'form.pdf', null, null, true); | ||
|
||
$payment_order->setPrintedFormFile($file); | ||
|
||
$this->userProvider->setManualUsername('[Automatic form generation]', UserProvider::INTERNAL_USER_IDENTIFIER); | ||
|
||
//Save to database and let VichUploadBundle handle everything else (it will also remove the temp file) | ||
$this->entityManager->flush(); | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
//The priorities here need to be high, so that the PDF is generated before the emails are sent | ||
return [ | ||
//Generate a draft version of the PDF when a payment order is submitted | ||
PaymentOrderSubmittedEvent::NAME => [ | ||
['generatePDF', 1000], | ||
], | ||
//Generae the final version of the PDF when a payment order is confirmed | ||
PaymentOrderConfirmedEvent::NAME => [ | ||
['generatePDF', 1000] | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/MessageHandler/PaymentOrder/PaymentOrderDeletedNotificationHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2020 Jan Böhmer | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace App\MessageHandler\PaymentOrder; | ||
|
||
use App\Message\PaymentOrder\PaymentOrderDeletedNotification; | ||
use App\Services\ReplyEmailDecisonMaker; | ||
use Symfony\Bridge\Twig\Mime\TemplatedEmail; | ||
use Symfony\Component\Mailer\MailerInterface; | ||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
use Symfony\Component\Mime\Email; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
#[AsMessageHandler] | ||
final readonly class PaymentOrderDeletedNotificationHandler | ||
{ | ||
|
||
public function __construct( | ||
private MailerInterface $mailer, | ||
private ReplyEmailDecisonMaker $reply_decision_maker, | ||
private TranslatorInterface $translator | ||
) | ||
{ | ||
} | ||
|
||
public function __invoke(PaymentOrderDeletedNotification $message): void | ||
{ | ||
$paymentOrder = $message->getPaymentOrder(); | ||
|
||
$email = new TemplatedEmail(); | ||
$email->priority(Email::PRIORITY_HIGH); | ||
$reply_to_email = $this->reply_decision_maker->getReplyToMailForPaymentOrder($paymentOrder); | ||
$email->replyTo($reply_to_email); | ||
|
||
$email->subject( | ||
$this->translator->trans( | ||
'payment_order.deletion_email.subject', | ||
[ | ||
'%project%' => $paymentOrder->getProjectName(), | ||
] | ||
)); | ||
|
||
$email->htmlTemplate('mails/deletion_notification.html.twig'); | ||
$email->context([ | ||
'payment_order' => $paymentOrder, | ||
'blame_user' => $message->getBlameUser(), | ||
'deleted_where' => $message->getDeletedWhere(), | ||
]); | ||
|
||
//Send the email to the FSR officers and the HHV/FSB | ||
$email_addresses = array_merge( | ||
$paymentOrder->getDepartment()->getEmailHhv(), | ||
$paymentOrder->getDepartment()->getEmailTreasurer(), | ||
[$reply_to_email] | ||
); | ||
|
||
$email->addBcc(...$email_addresses); | ||
|
||
|
||
//Send email | ||
$this->mailer->send($email); | ||
} | ||
} |
Oops, something went wrong.