Files
InvoiceShelf/app/Services/TransactionService.php
Darko Gjorgjijoski 8f29e8f5de Extract business logic from remaining models to services
New services:
- ExchangeRateProviderService: CRUD, API status checks, currency converter
  URL resolution (extracted 122 lines from ExchangeRateProvider model)
- FileDiskService: create, update, setAsDefault, validateCredentials
  (extracted 97 lines from FileDisk model)
- ItemService: create/update with tax handling (extracted from Item model)
- TransactionService: create/complete/fail (extracted from Transaction model)
- CustomFieldService: create/update with slug generation (extracted from
  CustomField model)

Controllers updated to use constructor-injected services:
ExchangeRateProviderController, DiskController, ItemsController,
CustomFieldsController.
2026-04-03 19:32:37 +02:00

31 lines
703 B
PHP

<?php
namespace App\Services;
use App\Facades\Hashids;
use App\Models\Transaction;
class TransactionService
{
public function create(array $data): Transaction
{
$transaction = Transaction::create($data);
$transaction->unique_hash = Hashids::connection(Transaction::class)->encode($transaction->id);
$transaction->save();
return $transaction;
}
public function complete(Transaction $transaction): void
{
$transaction->status = Transaction::SUCCESS;
$transaction->save();
}
public function fail(Transaction $transaction): void
{
$transaction->status = Transaction::FAILED;
$transaction->save();
}
}