feat: Create PaymentEvent / Listener

This commit is contained in:
IceToast 2023-01-14 22:37:23 +01:00
parent 3cb42a8b60
commit 10f7e2688e
3 changed files with 65 additions and 0 deletions

View file

@ -0,0 +1,29 @@
<?php
namespace App\Events;
use App\Models\Payment;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class PaymentEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @var User
*/
public Payment $payment;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Payment $payment)
{
$this->payment = $payment;
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace App\Listeners;
use App\Events\PaymentEvent;
use App\Traits\Invoiceable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class PaymentListener
{
use Invoiceable;
/**
* Handle the event.
*
* @param \App\Events\PaymentEvent $event
* @return void
*/
public function handle(PaymentEvent $event)
{
if (config('SETTINGS::INVOICE:ENABLED') == 'true') {
// get user from payment which does hold the user_id
$user = $event->payment->user;
// create invoice using the trait
$this->createInvoice($user, $event->payment);
}
}
}

View file

@ -2,7 +2,9 @@
namespace App\Providers;
use App\Events\PaymentEvent;
use App\Events\UserUpdateCreditsEvent;
use App\Listeners\PaymentListener;
use App\Listeners\UnsuspendServers;
use App\Listeners\Verified;
use Illuminate\Auth\Events\Registered;
@ -25,6 +27,9 @@ class EventServiceProvider extends ServiceProvider
UserUpdateCreditsEvent::class => [
UnsuspendServers::class,
],
PaymentEvent::class => [
PaymentListener::class,
],
SocialiteWasCalled::class => [
// ... other providers
'SocialiteProviders\\Discord\\DiscordExtendSocialite@handle',