feat: ✨ Create PaymentEvent / Listener
This commit is contained in:
parent
3cb42a8b60
commit
10f7e2688e
29
app/Events/PaymentEvent.php
Normal file
29
app/Events/PaymentEvent.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
31
app/Listeners/PaymentListener.php
Normal file
31
app/Listeners/PaymentListener.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Events\PaymentEvent;
|
||||||
use App\Events\UserUpdateCreditsEvent;
|
use App\Events\UserUpdateCreditsEvent;
|
||||||
|
use App\Listeners\PaymentListener;
|
||||||
use App\Listeners\UnsuspendServers;
|
use App\Listeners\UnsuspendServers;
|
||||||
use App\Listeners\Verified;
|
use App\Listeners\Verified;
|
||||||
use Illuminate\Auth\Events\Registered;
|
use Illuminate\Auth\Events\Registered;
|
||||||
|
@ -25,6 +27,9 @@ class EventServiceProvider extends ServiceProvider
|
||||||
UserUpdateCreditsEvent::class => [
|
UserUpdateCreditsEvent::class => [
|
||||||
UnsuspendServers::class,
|
UnsuspendServers::class,
|
||||||
],
|
],
|
||||||
|
PaymentEvent::class => [
|
||||||
|
PaymentListener::class,
|
||||||
|
],
|
||||||
SocialiteWasCalled::class => [
|
SocialiteWasCalled::class => [
|
||||||
// ... other providers
|
// ... other providers
|
||||||
'SocialiteProviders\\Discord\\DiscordExtendSocialite@handle',
|
'SocialiteProviders\\Discord\\DiscordExtendSocialite@handle',
|
||||||
|
|
Loading…
Reference in a new issue