whereHas('order', fn ($orders) => $orders->where('user_id', $request->user()->id)) ->orderByDesc('occurred_at') ->orderByDesc('id') ->get(); return view('member.payments', [ 'rows' => $entries->map(fn (LedgerEntry $entry): array => [ 'id' => $entry->id, 'order' => $entry->order_id, 'refund' => $entry->isRefund(), 'date' => PaymentJournal::local($entry->occurred_at)->format('d.m.Y'), 'products' => collect((array) (($entry->order_snapshot ?? [])['lines'] ?? []))->pluck('name')->filter()->values()->all(), 'amount' => $entry->amount_cents, 'provider' => PaymentJournal::providerLabel($entry->provider), 'test' => ! $entry->live, 'receipt' => PaymentReceipt::available($entry), ])->all(), ]); } public function receipt(Request $request, LedgerEntry $entry): Response { $entry->loadMissing('order'); abort_unless($entry->order?->user_id === $request->user()->id, 403); abort_unless(PaymentReceipt::available($entry), 404); return response(PaymentReceipt::render($entry), 200, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="'.PaymentReceipt::filename($entry).'"', 'Cache-Control' => 'private, no-store', 'X-Content-Type-Options' => 'nosniff', ]); } }