2023-01-14 21:37:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
|
|
|
use App\Events\PaymentEvent;
|
2023-02-06 20:16:54 +00:00
|
|
|
use App\Settings\InvoiceSettings;
|
2023-01-14 21:37:23 +00:00
|
|
|
use App\Traits\Invoiceable;
|
|
|
|
|
2023-01-19 15:05:56 +00:00
|
|
|
class CreateInvoice
|
2023-01-14 21:37:23 +00:00
|
|
|
{
|
|
|
|
use Invoiceable;
|
|
|
|
|
2023-02-06 20:16:54 +00:00
|
|
|
private $invoice_enabled;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the event listener.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(InvoiceSettings $invoice_settings)
|
|
|
|
{
|
|
|
|
$this->invoice_enabled = $invoice_settings->enabled;
|
|
|
|
}
|
|
|
|
|
2023-01-14 21:37:23 +00:00
|
|
|
/**
|
|
|
|
* Handle the event.
|
|
|
|
*
|
|
|
|
* @param \App\Events\PaymentEvent $event
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle(PaymentEvent $event)
|
|
|
|
{
|
2023-02-06 20:16:54 +00:00
|
|
|
if ($this->invoice_enabled) {
|
2023-01-14 21:37:23 +00:00
|
|
|
// create invoice using the trait
|
2023-01-20 22:44:49 +00:00
|
|
|
$this->createInvoice($event->payment, $event->shopProduct);
|
2023-01-14 21:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|