PHP code example of binary-cats / laravel-lob-webhooks
1. Go to this page and download the library: Download binary-cats/laravel-lob-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/ */
binary-cats / laravel-lob-webhooks example snippets
return [
/*
* Lob.com will sign each webhook using a secret. You can find the used secret at the
* webhook configuration settings: https://dashboard.lob.com/#/webhooks/create.
*/
'signing_secret' => env('LOB_WEBHOOK_SECRET'),
/*
* You can define the job that should be run when a certain webhook hits your application
* here. The key is the name of the Lob.com event type with the `.` replaced by a `_`.
*
* You can find a list of Lob.com webhook types here:
* https://lob.com/docs#all_event_types
*
* The package will automatically convert the keys to lowercase, but you should
* be congnisant of the fact that array keys are case sensitive
*/
'jobs' => [
// 'letter_delivered' => \BinaryCats\LobWebhooks\Jobs\HandleDelivered::class,
],
/*
* The classname of the model to be used. The class should equal or extend
* Spatie\WebhookClient\Models\WebhookCall
*/
'model' => \Spatie\WebhookClient\Models\WebhookCall::class,
/*
* The classname of the model to be used. The class should equal or extend
* BinaryCats\LobWebhooks\ProcessLobWebhookJob
*/
'process_webhook_job' => \BinaryCats\LobWebhooks\ProcessLobWebhookJob::class,
];
Route::lobWebhooks('webhooks/lob');
protected $except = [
'webhooks/lob',
];
namespace App\Jobs\LobWebhooks;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;
class HandleDeliveredSource implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/** @var \Spatie\WebhookClient\Models\WebhookCall */
public $webhookCall;
public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}
public function handle()
{
// do your work here
// you can access the payload of the webhook call with `$this->webhookCall->payload`
}
}
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'lob-webhooks::letter.created' => [
App\Listeners\LetterCreatedListener::class,
],
];
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;
class LetterCreatedListener implements ShouldQueue
{
public function handle(WebhookCall $webhookCall)
{
// do your work here
// you can access the payload of the webhook call with `$webhookCall->payload`
}
}
use BinaryCats\LobWebhooks\ProcessLobWebhookJob;
use Spatie\WebhookClient\Models\WebhookCall;
dispatch(new ProcessLobWebhookJob(WebhookCall::find($id)));
use BinaryCats\LobWebhooks\ProcessLobWebhookJob;
class MyCustomLobWebhookJob extends ProcessLobWebhookJob
{
public function handle()
{
// do custom stuff beforehand
parent::handle();
// do custom stuff afterwards
}
}
// secret for when Lob.com posts to webhooks/lob/account
'signing_secret_account' => 'whsec_abc',
// secret for when Lob.com posts to webhooks/lob/connect
'signing_secret_connect' => 'whsec_123',