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;
|
2023-03-26 22:34:32 +00:00
|
|
|
private $invoice_settings;
|
2023-02-06 20:16:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the event listener.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(InvoiceSettings $invoice_settings)
|
|
|
|
{
|
|
|
|
$this->invoice_enabled = $invoice_settings->enabled;
|
2023-03-26 22:34:32 +00:00
|
|
|
$this->invoice_settings = $invoice_settings;
|
2023-02-06 20:16:54 +00:00
|
|
|
}
|
|
|
|
|
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-03-26 22:34:32 +00:00
|
|
|
$this->createInvoice($event->payment, $event->shopProduct, $this->invoice_settings);
|
2023-01-14 21:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|