CreateInvoice.php 871 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\PaymentEvent;
  4. use App\Settings\InvoiceSettings;
  5. use App\Traits\Invoiceable;
  6. class CreateInvoice
  7. {
  8. use Invoiceable;
  9. private $invoice_enabled;
  10. private $invoice_settings;
  11. /**
  12. * Create the event listener.
  13. *
  14. * @return void
  15. */
  16. public function __construct(InvoiceSettings $invoice_settings)
  17. {
  18. $this->invoice_enabled = $invoice_settings->enabled;
  19. $this->invoice_settings = $invoice_settings;
  20. }
  21. /**
  22. * Handle the event.
  23. *
  24. * @param \App\Events\PaymentEvent $event
  25. * @return void
  26. */
  27. public function handle(PaymentEvent $event)
  28. {
  29. if ($this->invoice_enabled) {
  30. // create invoice using the trait
  31. $this->createInvoice($event->payment, $event->shopProduct, $this->invoice_settings);
  32. }
  33. }
  34. }