receiptBehind($emailLog)->getGeneratedPDFOrStream('payment'); } /** * Serve the same receipt as JSON. */ public function getPayment(EmailLog $emailLog) { return PaymentResource::make($this->receiptBehind($emailLog)); } /** * Trade an email-log token for the receipt it was minted for. * * Two things stand between the token and the disclosure, in this order: a * log row minted for some other kind of mail is a miss rather than a * forbidden read, however the ids happen to line up; and the link must * still fall inside the issuing company's expiry window. */ private function receiptBehind(EmailLog $emailLog): Payment { $receipt = $emailLog->mailable; if (! $receipt instanceof Payment) { abort(404); } if ($emailLog->isExpired()) { abort(403, 'Link Expired.'); } return $receipt; } }