hasMany(Payment::class, 'transaction_id'); } /** * Document the payer was settling. */ public function invoice(): BelongsTo { return $this->belongsTo(Invoice::class, 'invoice_id'); } /** * Company the attempt was made against. */ public function company(): BelongsTo { return $this->belongsTo(Company::class, 'company_id'); } /** * Whether the payer's link has gone stale. * * Three things have to line up: the company has to have asked for public * links to expire at all, the attempt has to have succeeded, and more days * than the configured window have to have gone by. Two of those are worth * spelling out, because both are deliberate and neither is what the name * suggests. The clock runs from the row's last update rather than from * when it was opened, so anything that touches the row pushes the deadline * out; and only a successful attempt ever expires, leaving a refused one * reachable for good. Both dates are compared as plain calendar days. */ public function isExpired(): bool { $window = (int) CompanySetting::getSetting('link_expiry_days', $this->company_id); $expiryEnabled = CompanySetting::getSetting('automatically_expire_public_links', $this->company_id); $deadline = $this->updated_at->addDays($window); if ($expiryEnabled != 'YES' || $this->status != self::SUCCESS) { return false; } return Carbon::now()->format('Y-m-d') > $deadline->format('Y-m-d'); } }