ctrlpanel/app/Listeners/CreateInvoice.php

41 lines
871 B
PHP
Raw Normal View History

<?php
namespace App\Listeners;
use App\Events\PaymentEvent;
2023-02-06 20:16:54 +00:00
use App\Settings\InvoiceSettings;
use App\Traits\Invoiceable;
class CreateInvoice
{
use Invoiceable;
2023-02-06 20:16:54 +00:00
private $invoice_enabled;
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;
$this->invoice_settings = $invoice_settings;
2023-02-06 20:16:54 +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) {
// create invoice using the trait
$this->createInvoice($event->payment, $event->shopProduct, $this->invoice_settings);
}
}
}