stripe_invoice_id)) { throw new RuntimeException(sprintf('Rechnung %s hat keine Stripe-Rechnung.', $invoice->number)); } $disk = Storage::disk('local'); $path = $this->path($invoice); if ($disk->exists($path)) { return (string) $disk->get($path); } $pdfUrl = Cashier::stripe()->invoices->retrieve($invoice->stripe_invoice_id)->invoice_pdf; if (blank($pdfUrl)) { throw new RuntimeException(sprintf('Stripe liefert für Rechnung %s kein PDF.', $invoice->number)); } $pdf = Http::timeout(30)->get($pdfUrl)->throw()->body(); if (! str_starts_with($pdf, '%PDF')) { throw new RuntimeException(sprintf('Stripe-PDF zu Rechnung %s ist kein PDF.', $invoice->number)); } if (! $disk->put($path, $pdf)) { report(new RuntimeException(sprintf('Stripe-PDF zu Rechnung %s konnte nicht abgelegt werden.', $invoice->number))); } return $pdf; } public function filename(Invoice $invoice): string { return 'Rechnung-'.$invoice->number.'.pdf'; } public function inlineResponse(Invoice $invoice): Response { return response($this->contents($invoice), Response::HTTP_OK, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; filename="'.$this->filename($invoice).'"', 'Cache-Control' => 'private, max-age=0, must-revalidate', ]); } private function path(Invoice $invoice): string { return 'invoices/stripe/'.$invoice->number.'.pdf'; } }