43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/** @property int $id
|
|
* @property int $tenant_id
|
|
* @property int $invoice_id
|
|
* @property int $supplier_bank_detail_id
|
|
* @property int $created_by
|
|
* @property int $amount_minor
|
|
* @property string $status
|
|
* @property string $payload_hash
|
|
* @property array<string,mixed> $bank_snapshot
|
|
*/
|
|
class ExternalPayment extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $attributes = ['status' => 'pending'];
|
|
|
|
protected $hidden = ['external_reference', 'reference_hash', 'payload_hash', 'evidence_reference', 'bank_snapshot', 'review_reason'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['external_reference' => 'encrypted', 'evidence_reference' => 'encrypted', 'bank_snapshot' => 'encrypted:array', 'review_reason' => 'encrypted'];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::updating(function (ExternalPayment $payment) {
|
|
if ($payment->getRawOriginal('status') !== 'pending' || array_diff(array_keys($payment->getDirty()), ['status', 'reviewed_by', 'reviewed_at', 'review_reason', 'updated_at']) !== []) {
|
|
throw new \LogicException('Preservar o registo externo e a conferência.');
|
|
}
|
|
});
|
|
static::deleting(fn () => throw new \LogicException('Preservar o histórico de pagamentos externos.'));
|
|
}
|
|
}
|