PHP code example of beaub / laravel-easypost-webhooks
1. Go to this page and download the library: Download beaub/laravel-easypost-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/ */
beaub / laravel-easypost-webhooks example snippets
return [
/*
* You can define the job that should be run when a certain webhook hits your application
* here. The key is the name of the Easypost event description with the `.` replaced by a `_`.
*
* You can find a list of Easypost webhook description types here:
* https://www.easypost.com/docs/api#possible-event-types.
*/
'jobs' => [
// 'refund_successful' => \App\Jobs\EasypostWebhooks\HandleSuccessfulRefund::class,
// 'tracker_created' => \App\Jobs\EasypostWebhooks\HandleTrackerCreated::class,
],
/*
* The classname of the model to be used. The class should equal or extend
* BeauB\EasypostWebhooks\EasypostWebhookCall.
*/
'model' => BeauB\EasypostWebhooks\EasypostWebhookCall::class,
];
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use BeauB\EasypostWebhooks\EasypostWebhookCall;
class HandleChargeableSource implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/** @var \BeauB\EasypostWebhooks\EasypostWebhookCall */
public $webhookCall;
public function __construct(EasypostWebhookCall $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 = [
'easypost-webhooks::tracker.created' => [
App\Listeners\TrackerCreated::class,
],
];
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use BeauB\EasypostWebhooks\EasypostWebhookCall;
class TrackerCreated implements ShouldQueue
{
public function handle(EasypostWebhookCall $webhookCall)
{
// do your work here
// you can access the payload of the webhook call with `$webhookCall->payload`
}
}
use BeauB\EasypostWebhooks\EasypostWebhookCall;
EasypostWebhookCall::find($id)->process();
use BeauB\EasypostWebhooks\EasypostWebhookCall;
class MyCustomWebhookCall extends EasyposteWebhookCall
{
public function process()
{
// do some custom stuff beforehand
parent::process();
// do some custom stuff afterwards
}
}