billing: Rechnungsversand — PDF im Anhang der Zahlungsmail, optionale Rechnungs-E-Mail, Stripe-Rechnungs-PDF direkt aus dem Kundenbereich
Kundenwunsch 06.10.2026: Ein Kunde kam über die Stripe-Rechnungsseite nicht an seine Rechnung und fragte nach Belegen und einer Rechnungs-E-Mail. - Profil ▸ Rechnungsadresse ▸ Rechnungsversand: Schalter „Rechnungs-PDF an die Konto-E-Mail" (Standard an), optionale „E-Mail für Rechnungen" mit Schalter „Rechnungen als PDF an diese Adresse senden" (Standard an). Neue Spalten an billing_addresses (klein, ohne FULLTEXT). - InvoiceDelivery entscheidet Empfänger und Anhang; gleiche Adresse wie das Konto ergibt eine Mail mit PDF. - Zahlungsbestätigung (STR) und Bestandskunden-Rechnung/-Erinnerung (MAN) folgen der Einstellung; die Fassung an die Rechnungs-E-Mail nennt das Konto, ohne Blindkopie und ohne Login-Button. - StripeInvoicePdf holt das Stripe-PDF einmal und legt es lokal ab (storage/app/private/invoices/stripe); Mailversand wiederholt bei Stripe-Ausfall (5 Versuche). - Rechnungsseite: „PDF öffnen" aus pressekonto, „Beleg bei Stripe" für den Zahlungsbeleg auf der Stripe-Seite. Suite 2.340 grün, einer übersprungen; Larastan und Pint ohne Meldung. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
da9411bdab
commit
6d03d8de39
18 changed files with 695 additions and 30 deletions
|
|
@ -4,8 +4,10 @@ namespace App\Mail;
|
|||
|
||||
use App\Models\Invoice;
|
||||
use App\Models\User;
|
||||
use App\Services\Billing\StripeInvoicePdf;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Attachment;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
|
|
@ -18,16 +20,28 @@ use Illuminate\Queue\SerializesModels;
|
|||
*
|
||||
* Transaktionsmail: bewusst ohne Opt-out (analog Kündigungs-/
|
||||
* Widerrufsbestätigungen, siehe EmailNotificationType-Doku).
|
||||
*
|
||||
* Rechnungsversand (06.10.2026): Mit `attachPdf` hängt das Stripe-PDF an;
|
||||
* `forInvoiceRecipient` ist die Fassung an die Rechnungs-E-Mail aus dem
|
||||
* Profil (siehe InvoiceDelivery). Das PDF wird erst beim Versand geholt —
|
||||
* ist Stripe nicht erreichbar, wiederholt die Queue den Versand.
|
||||
*/
|
||||
class BookingPaymentConfirmed extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public int $tries = 5;
|
||||
|
||||
/** @var list<int> */
|
||||
public array $backoff = [60, 300, 900, 3600];
|
||||
|
||||
public string $invoicesUrl;
|
||||
|
||||
public function __construct(
|
||||
public readonly User $user,
|
||||
public readonly Invoice $invoice,
|
||||
public readonly bool $attachPdf = false,
|
||||
public readonly bool $forInvoiceRecipient = false,
|
||||
) {
|
||||
$this->invoicesUrl = route('me.invoices.index');
|
||||
}
|
||||
|
|
@ -36,10 +50,14 @@ class BookingPaymentConfirmed extends Mailable implements ShouldQueue
|
|||
{
|
||||
// Blindkopie an das Rechts-/Service-Postfach: interner Beleg über
|
||||
// jede versendete Zahlungsbestätigung.
|
||||
$bcc = (string) config('legal.contact_email');
|
||||
// Die Fassung an die Rechnungs-E-Mail ist ein Duplikat derselben
|
||||
// Rechnung — eine Blindkopie davon braucht das Postfach nicht.
|
||||
$bcc = $this->forInvoiceRecipient ? '' : (string) config('legal.contact_email');
|
||||
|
||||
return new Envelope(
|
||||
subject: 'Zahlungsbestätigung für Ihre Buchung — Rechnung '.$this->invoice->number,
|
||||
subject: $this->forInvoiceRecipient
|
||||
? 'Rechnung '.$this->invoice->number.' — pressekonto'
|
||||
: 'Zahlungsbestätigung für Ihre Buchung — Rechnung '.$this->invoice->number,
|
||||
bcc: $bcc !== '' ? [$bcc] : [],
|
||||
);
|
||||
}
|
||||
|
|
@ -48,4 +66,21 @@ class BookingPaymentConfirmed extends Mailable implements ShouldQueue
|
|||
{
|
||||
return new Content(view: 'emails.billing.payment-confirmed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
if (! $this->attachPdf || blank($this->invoice->stripe_invoice_id)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$pdf = app(StripeInvoicePdf::class);
|
||||
|
||||
return [
|
||||
Attachment::fromData(fn (): string => $pdf->contents($this->invoice), $pdf->filename($this->invoice))
|
||||
->withMime('application/pdf'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@ use Illuminate\Queue\SerializesModels;
|
|||
*
|
||||
* Transaktionsmail: bewusst ohne Opt-out. Die Bounce-Sperrliste greift
|
||||
* über `GateOutgoingMail`; der Service prüft sie zusätzlich vorab.
|
||||
*
|
||||
* Rechnungsversand (06.10.2026): `attachPdf` folgt der Profileinstellung
|
||||
* (Standard: an); `forInvoiceRecipient` ist die Fassung an die
|
||||
* Rechnungs-E-Mail (siehe InvoiceDelivery), immer mit PDF.
|
||||
*/
|
||||
class ManualInvoiceIssued extends Mailable implements ShouldQueue
|
||||
{
|
||||
|
|
@ -42,6 +46,8 @@ class ManualInvoiceIssued extends Mailable implements ShouldQueue
|
|||
public readonly User $user,
|
||||
public readonly Invoice $invoice,
|
||||
public readonly bool $isReminder = false,
|
||||
public readonly bool $attachPdf = true,
|
||||
public readonly bool $forInvoiceRecipient = false,
|
||||
) {
|
||||
$renderer = app(ManualInvoicePdfRenderer::class);
|
||||
|
||||
|
|
@ -54,7 +60,8 @@ class ManualInvoiceIssued extends Mailable implements ShouldQueue
|
|||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
$bcc = (string) config('legal.contact_email');
|
||||
// Die Fassung an die Rechnungs-E-Mail ist ein Duplikat — ohne Blindkopie.
|
||||
$bcc = $this->forInvoiceRecipient ? '' : (string) config('legal.contact_email');
|
||||
|
||||
$subject = $this->isReminder
|
||||
? 'Zahlungserinnerung — Rechnung '.$this->invoice->number
|
||||
|
|
@ -76,6 +83,10 @@ class ManualInvoiceIssued extends Mailable implements ShouldQueue
|
|||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
if (! $this->attachPdf) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$renderer = app(ManualInvoicePdfRenderer::class);
|
||||
|
||||
return [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue