namespace App\Jobs\ProAbono;
use Illuminate\Contracts\Queue\ShouldQueue;
use MeilleursBiens\ProAbonoWebhook\Models\ProAbonoWebhookCall;
class HandleStartedSubscription implements ShouldQueue
{
public function __construct(public ProAbonoWebhookCall $webhookCall) {}
public function handle(): void
{
$notification = $this->webhookCall->notification();
$agent = Agent::where('proabono_customer_id', $notification->idCustomer())->first();
$agent?->activateSubscription($notification->idSubscription());
}
}
use Illuminate\Support\Facades\Event;
use MeilleursBiens\ProAbonoWebhook\Models\ProAbonoWebhookCall;
Event::listen('proabono-webhooks::InvoiceDebitPaid', function (ProAbonoWebhookCall $call) {
// ...
});
use MeilleursBiens\ProAbonoWebhook\Events\ProAbonoWebhookReceived;
use MeilleursBiens\ProAbonoWebhook\ProAbonoTrigger;
Event::listen(function (ProAbonoWebhookReceived $event) {
match ($event->trigger()) {
ProAbonoTrigger::SubscriptionStarted => /* ... */,
ProAbonoTrigger::SubscriptionTerminated => /* ... */,
default => null,
};
});
use MeilleursBiens\ProAbonoWebhook\ProAbonoTrigger;
'triggers' => [
ProAbonoTrigger::SubscriptionStarted,
ProAbonoTrigger::SubscriptionTerminated,
ProAbonoTrigger::InvoiceDebitPaid,
],
$notification = $webhookCall->notification();
$notification->id(); // 'trg_42' — ProAbono's id for this trigger
$notification->trigger(); // ProAbonoTrigger::SubscriptionStarted|null
$notification->triggerName(); // 'SubscriptionStarted'
$notification->is(ProAbonoTrigger::SubscriptionStarted); // bool
$notification->idBusiness(); // ?int
$notification->idSegment(); // ?int
$notification->referenceSegment(); // ?string
$notification->dateTrigger(); // ?CarbonImmutable — when the event happened
$notification->customer()?->reference(); // your own customer reference
$notification->customer()?->email();
$notification->customer()?->status(); // 'Enabled', 'Suspended', …
$notification->idCustomer(); // Customer.Id
$notification->referenceCustomer(); // Customer.ReferenceCustomer
$notification->idSubscription(); // Subscription.Id
$notification->idOffer(); // Offer.Id
$notification->idInvoice(); // InvoiceDebit.Id, falling back to InvoiceCredit.Id
$notification->get('Subscription.StateSubscription'); // 'ActiveRunning'
$notification->all(); // the raw body
use MeilleursBiens\ProAbonoWebhook\Models\ProAbonoWebhookCall;
use MeilleursBiens\ProAbonoWebhook\ProAbonoTrigger;
ProAbonoWebhookCall::forTrigger(ProAbonoTrigger::InvoiceDebitPaid)->latest()->get();
ProAbonoWebhookCall::verifications()->latest()->first();
ProAbonoWebhookCall::whereNotNull('exception')->get(); // calls whose job blew up
use Illuminate\Support\Facades\Schedule;
use MeilleursBiens\ProAbonoWebhook\Models\ProAbonoWebhookCall;
Schedule::command('model:prune', [
'--model' => [ProAbonoWebhookCall::class],
])->daily();