940afe9319
API CI/CD / Validate (composer + pint) (push) Successful in 2m7s
API CI/CD / Test (PHPUnit) (push) Failing after 2m23s
API CI/CD / Build frontend assets (push) Successful in 2m18s
API CI/CD / Security audit (push) Successful in 31s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Payments;
|
|
|
|
use App\Models\PaymentTransaction;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class PaymentTransactionService
|
|
{
|
|
public function create(array $payload): PaymentTransaction
|
|
{
|
|
$data = [
|
|
'transaction_id' => $payload['transaction_id'],
|
|
'payment_id' => (int) $payload['payment_id'],
|
|
'transaction_date' => $payload['transaction_date'],
|
|
'amount' => (float) $payload['amount'],
|
|
'payment_method' => $payload['payment_method'],
|
|
'payment_status' => $payload['payment_status'] ?? 'Pending',
|
|
'transaction_fee' => $payload['transaction_fee'] ?? null,
|
|
'payment_reference' => $payload['payment_reference'] ?? null,
|
|
'is_full_payment' => ! empty($payload['is_full_payment']),
|
|
'school_year' => $payload['school_year'] ?? null,
|
|
'semester' => $payload['semester'] ?? null,
|
|
];
|
|
|
|
$columns = array_flip(Schema::getColumnListing('payment_transactions'));
|
|
|
|
return PaymentTransaction::query()->create(array_intersect_key($data, $columns));
|
|
}
|
|
|
|
public function getByPayment(int $paymentId): array
|
|
{
|
|
return PaymentTransaction::getTransactionsByPaymentId($paymentId);
|
|
}
|
|
|
|
public function updateStatus(string $transactionId, string $status): bool
|
|
{
|
|
return PaymentTransaction::updateTransactionStatus($transactionId, $status);
|
|
}
|
|
}
|