45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Platform\app\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Modules\Platform\app\Models\Company;
|
|
use Modules\Platform\app\Models\Payment;
|
|
|
|
class PaymentController extends Controller
|
|
{
|
|
/**
|
|
* Display company payments.
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('platform::payments.index', [
|
|
'companies' => Company::orderBy('name')->get(),
|
|
'payments' => Payment::with('company')->latest()->paginate(20),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Add a manual payment or admin override record.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$data = $request->validate([
|
|
'company_id' => ['required', 'exists:companies,id'],
|
|
'amount' => ['required', 'integer', 'min:0'],
|
|
'currency' => ['required', 'string', 'size:3'],
|
|
'status' => ['required', 'in:pending,paid,failed,refunded,override'],
|
|
'description' => ['nullable', 'string', 'max:255'],
|
|
]);
|
|
|
|
Payment::create([
|
|
...$data,
|
|
'paid_at' => in_array($data['status'], ['paid', 'override'], true) ? now() : null,
|
|
'metadata' => ['source' => 'manual_admin'],
|
|
]);
|
|
|
|
return back()->with('status', 'Payment record created.');
|
|
}
|
|
}
|