Jede Zahlung und jede Erstattung wird in derselben Transaktion wie der Bestellstatus unveränderlich gebucht: Zeitpunkt, Betrag, Beleg beim Anbieter (Session, pi_, re_), handelnde Person, Begründung und Zahler samt Rechnungsadresse zum Zeitpunkt. Testzahlungen zählen nie als Umsatz. Verwaltung: Verkauf, Einnahmen und Erstattungen mit Zeitraum, Summen und Export. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Commerce;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use LogicException;
|
|
|
|
/**
|
|
* Eine Geldbewegung im Zahlungsjournal (Zahlungseingang oder Erstattung). Unveränderlich: Eine Zeile wird nur
|
|
* angelegt, nie geändert oder gelöscht. Eine Korrektur ist eine neue Gegenbuchung. Beträge sind vorzeichenbehaftet
|
|
* (Eingang positiv, Erstattung negativ), sodass die Summe den Saldo ergibt.
|
|
*/
|
|
class LedgerEntry extends Model
|
|
{
|
|
public const KIND_PAYMENT = 'eingang';
|
|
|
|
public const KIND_REFUND = 'erstattung';
|
|
|
|
public const UPDATED_AT = null;
|
|
|
|
protected $table = 'payment_ledger';
|
|
|
|
protected $guarded = [];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'occurred_at' => 'datetime',
|
|
'amount_cents' => 'integer',
|
|
'live' => 'boolean',
|
|
'derived' => 'boolean',
|
|
'payer' => 'array',
|
|
'order_snapshot' => 'array',
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::updating(function (): never {
|
|
throw new LogicException('Das Zahlungsjournal ist unveränderlich. Korrekturen sind neue Gegenbuchungen.');
|
|
});
|
|
static::deleting(function (): never {
|
|
throw new LogicException('Das Zahlungsjournal ist unveränderlich. Einträge werden nie gelöscht.');
|
|
});
|
|
}
|
|
|
|
public function order(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Order::class);
|
|
}
|
|
|
|
public function isRefund(): bool
|
|
{
|
|
return $this->kind === self::KIND_REFUND;
|
|
}
|
|
}
|