Events
Peak dispatches several useful events throughout the billing and support systems that you can listen to and respond to with your own custom logic (e.g., logging, notifications, integrations).
To listen to these events, register your listeners in your EventServiceProvider
:
// app/Providers/EventServiceProvider.php
protected $listen = [
\Qoraiche\Peak\Events\Billing\InvoicePaymentSucceeded::class => [
\App\Listeners\SendInvoicePaidNotification::class,
],
];
Billing Events
These events are dispatched automatically during subscription and invoice lifecycle events:
Event | Description |
---|---|
Qoraiche\Peak\Events\Billing\InvoicePaymentFailed($billable, Invoice $invoice) | Fired when an invoice payment fails. |
Qoraiche\Peak\Events\Billing\InvoicePaymentRefunded($billable, Invoice $invoice) | Fired when an invoice payment is refunded. |
Qoraiche\Peak\Events\Billing\InvoicePaymentSucceeded($billable, Invoice $invoice) | Fired when an invoice is paid successfully. |
Qoraiche\Peak\Events\Billing\SubscriptionCancelled($billable, $subscription) | Fired when a subscription is cancelled. |
Qoraiche\Peak\Events\Billing\SubscriptionCreated($subscription) | Fired when a new subscription is created. |
Qoraiche\Peak\Events\Billing\SubscriptionUpdated($billable, $subscription) | Fired when a subscription is updated. |
UI Events
Event | Description |
---|---|
Qoraiche\Peak\Events\ThemeChanged(public string $theme) | Fired when the user changes the site theme (e.g., dark/light mode). |
Support Events
Event | Description |
---|---|
Qoraiche\Peak\Events\TicketCreated(Ticket $ticket) | Fired when a new support ticket is created. |
Qoraiche\Peak\Events\TicketUpdated(Ticket $ticket) | Fired when a support ticket is updated. |
Creating a Listener
Example listener to send a Slack message when a payment succeeds:
// app/Listeners/SendSlackNotificationOnInvoicePaid.php
use Qoraiche\Peak\Events\Billing\InvoicePaymentSucceeded;
class SendSlackNotificationOnInvoicePaid
{
public function handle(InvoicePaymentSucceeded $event)
{
$user = $event->billable;
$invoice = $event->invoice;
// Send notification
Slack::to('#billing')->send("💰 Invoice #{$invoice->id} paid by {$user->email}");
}
}
Let me know if you want these listeners auto-registered using discovery or need example test cases.