Files
Paymenter-Version-Tracks/app/Models/InvoiceTransaction.php
Muhammad Tamir 85c03cef82 v1.3.4
2025-11-14 10:57:49 +07:00

60 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use App\Classes\Price;
use App\Observers\InvoiceTransactionObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use OwenIt\Auditing\Contracts\Auditable;
#[ObservedBy([InvoiceTransactionObserver::class])]
class InvoiceTransaction extends Model implements Auditable
{
use \App\Models\Traits\Auditable, HasFactory;
protected $fillable = [
'invoice_id',
'gateway_id',
'amount',
'fee',
'transaction_id',
];
protected $casts = [
'amount' => 'decimal:2',
'fee' => 'decimal:2',
];
public function invoice()
{
return $this->belongsTo(Invoice::class);
}
public function gateway()
{
return $this->belongsTo(Gateway::class);
}
/**
* Formatted remaining amount of the invoice.
*/
public function formattedFee(): Attribute
{
return Attribute::make(
get: fn () => new Price(['price' => $this->fee, 'currency' => $this->invoice->currency])
);
}
/**
* Formatted remaining amount of the invoice.
*/
public function formattedAmount(): Attribute
{
return Attribute::make(
get: fn () => new Price(['price' => $this->amount, 'currency' => $this->invoice->currency])
);
}
}