Creating Participation refunds
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail\ParticipantRefundMails;
|
||||
|
||||
use App\Models\EventParticipant;
|
||||
use App\Models\ParticipantRefund;
|
||||
use App\Support\Iban;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Attachment;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
|
||||
/**
|
||||
* Bestätigt dem Teili die erfassten Angaben und liefert den Beleg als PDF mit.
|
||||
*
|
||||
* Der Beleg wird nicht hier erzeugt, sondern übergeben: er entsteht einmal in
|
||||
* {@see \App\Domains\ParticipantRefund\Actions\AcceptRefund\AcceptRefundCommand} und geht an beide
|
||||
* Empfänger. Scheitert die Erzeugung, geht die Mail ohne Anhang raus statt gar nicht.
|
||||
*/
|
||||
class RefundAcceptedMail extends Mailable
|
||||
{
|
||||
public function __construct(
|
||||
private EventParticipant $participant,
|
||||
private ParticipantRefund $refund,
|
||||
private ?string $pdfContent = null,
|
||||
private ?string $pdfFilename = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: sprintf(
|
||||
'Deine Angaben zur Rückerstattung für %s',
|
||||
$this->participant->event()->first()->name
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
$event = $this->participant->event()->first();
|
||||
|
||||
return new Content(
|
||||
view: 'emails.events.refund_accepted',
|
||||
with: [
|
||||
'name' => $this->participant->getNicename(),
|
||||
'eventTitle' => $event->name,
|
||||
'eventEmail' => $event->email,
|
||||
'amount' => $this->refund->amount?->toString() ?? '0,00 Euro',
|
||||
'reason' => $this->refund->reasonLabel(),
|
||||
'accountOwner' => $this->refund->account_owner,
|
||||
'accountIban' => Iban::format((string) $this->refund->account_iban),
|
||||
'hasDocument' => $this->pdfContent !== null,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
if ($this->pdfContent === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
Attachment::fromData(fn (): string => $this->pdfContent, $this->pdfFilename ?? 'Rueckerstattung.pdf')
|
||||
->withMime('application/pdf'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user