Files
mtdb_movie/common/Billing/Invoices/CreateInvoice.php
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

32 lines
750 B
PHP
Executable File

<?php
namespace Common\Billing\Invoices;
use Common\Billing\Notifications\NewInvoiceAvailable;
use Common\Billing\Subscription;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
class CreateInvoice
{
public function execute(array $data): Invoice
{
$invoice = new Invoice([
'subscription_id' => $data['subscription_id'],
'paid' => $data['paid'],
'uuid' => $data['uuid'] ?? Str::random(10),
'notes' => Arr::get($data, 'notes'),
]);
$invoice->save();
if ($data['paid']) {
Subscription::find($data['subscription_id'])->user->notify(
new NewInvoiceAvailable($invoice),
);
}
return $invoice;
}
}