PHP code example of ankurk91 / laravel-ses-webhooks
1. Go to this page and download the library: Download ankurk91/laravel-ses-webhooks library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Jobs\Webhooks\SES;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
use Spatie\WebhookClient\Models\WebhookCall;
class BounceHandlerJob implements ShouldQueue
{
use SerializesModels;
public function __construct(protected WebhookCall $webhookCall)
{
//
}
public function handle()
{
$message = $this->webhookCall->payload['Message'];
if (Arr::get($message, 'bounce.bounceType') !== 'Permanent') return;
foreach ($message['bounce']['bouncedRecipients'] as $recipient) {
// todo do something with $recipient['emailAddress']
}
}
}
namespace App\Listeners\SES;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;
class ComplaintListener implements ShouldQueue
{
public function handle(WebhookCall $webhookCall)
{
$message = $webhookCall->payload['Message'];
foreach ($message['complaint']['complainedRecipients'] as $recipient) {
// todo do something with $recipient['emailAddress']
}
}
}
use Illuminate\Database\Console\PruneCommand;
use Spatie\WebhookClient\Models\WebhookCall;
$schedule->command(PruneCommand::class, [
'--model' => [WebhookCall::class]
])
->onOneServer()
->daily()
->description('Prune webhook_calls.');