e13df69885
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 4m53s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 59s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
82 lines
2.4 KiB
PHP
82 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
class PaymentTransaction extends BaseModel
|
|
{
|
|
protected $table = 'payment_transactions';
|
|
|
|
// Legacy table has no created_at/updated_at columns.
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = ['transaction_id', 'payment_id', 'transaction_date', 'amount', 'payment_method', 'payment_status', 'transaction_fee', 'school_year', 'semester'];
|
|
|
|
protected $casts = [
|
|
'payment_id' => 'integer',
|
|
'amount' => 'decimal:2', // adjust precision if needed
|
|
'transaction_fee' => 'decimal:2', // adjust precision if needed
|
|
'transaction_date' => 'datetime',
|
|
'is_full_payment' => 'boolean',
|
|
];
|
|
|
|
/* Optional relationship */
|
|
public function payment()
|
|
{
|
|
return $this->belongsTo(Payment::class, 'payment_id');
|
|
}
|
|
|
|
/* =========================
|
|
* legacy method equivalents
|
|
* ========================= */
|
|
|
|
public static function getTransactionsByPaymentId(int $paymentId): array
|
|
{
|
|
return static::query()
|
|
->where('payment_id', $paymentId)
|
|
->orderByDesc('transaction_date')
|
|
->get()
|
|
->toArray();
|
|
}
|
|
|
|
public static function getTransactionById(string $transactionId): ?self
|
|
{
|
|
return static::query()
|
|
->where('transaction_id', $transactionId)
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* Update payment_status by transaction_id (not PK).
|
|
*/
|
|
public static function updateTransactionStatus(string $transactionId, string $status): bool
|
|
{
|
|
return static::query()
|
|
->where('transaction_id', $transactionId)
|
|
->update(['payment_status' => $status]) >= 0;
|
|
}
|
|
|
|
public static function getTotalPaidByPaymentId(int $paymentId): float
|
|
{
|
|
$sum = static::query()
|
|
->where('payment_id', $paymentId)
|
|
->sum('amount');
|
|
|
|
return (float) $sum;
|
|
}
|
|
|
|
public static function updateTransactionFee(string $transactionId, float $transactionFee): bool
|
|
{
|
|
return static::query()
|
|
->where('transaction_id', $transactionId)
|
|
->update(['transaction_fee' => $transactionFee]) >= 0;
|
|
}
|
|
|
|
public static function getLatestTransactionByPaymentId(int $paymentId): ?self
|
|
{
|
|
return static::query()
|
|
->where('payment_id', $paymentId)
|
|
->orderByDesc('transaction_date')
|
|
->first();
|
|
}
|
|
}
|