<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
binary-cats / laravel-surveymonkey-webhooks example snippets
return [
/*
* Survey Monkey is an online survey development cloud-based software as a service company.
* You can find the used secret after creating Survey Monkey App: https://developer.surveymonkey.com/
*/
'signing_secret' => env('SURVEYMONKEY_API_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 Survey Monkey event type with the `.` replaced by a `_`.
*
* You can find a list of Survey Monkey webhook types here:
* https://developer.surveymonkey.com/api/v3/#webhook-callbacks
*/
'jobs' => [
// Example:
// 'response_completed' => \BinaryCats\SurveyMonkeyWebhooks\Jobs\HandleResponseCompleted::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\SurveyMonkeyWebhooks\ProcessSurveyMonkeyWebhookJob
*/
'process_webhook_job' => \BinaryCats\SurveyMonkeyWebhooks\ProcessSurveyMonkeyWebhookJob::class,
];
namespace App\Jobs\SurveyMonkeyWebhooks;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;
class HandleResponseCompleted 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 = [
'surveymonkey-webhooks::response_completed' => [
App\Listeners\ResponseCompletedIstener::class,
],
];
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;
class ResponseCompletedIstener implements ShouldQueue
{
/** @param Spatie\WebhookClient\Models\WebhookCall */
public function handle(WebhookCall $webhookCall)
{
// do your work here
// you can access the payload of the webhook call with `$webhookCall->payload`
}
}
use Spatie\WebhookClient\Models\WebhookCall;
use BinaryCats\SurveyMonkeyWebhooks\ProcessSurveyMonkeyWebhookJob;
dispatch(new ProcessSurveyMonkeyWebhookJob(WebhookCall::find($id)));
use BinaryCats\SurveyMonkeyWebhooks\ProcessSurveyMonkeyWebhookJob;
class MyCustomSurvkeyMonkeyWebhookJob extends ProcessSurveyMonkeyWebhookJob
{
public function handle()
{
// do custom stuff beforehand
parent::handle();
// do custom stuff afterwards
}
}
// secret for when Survey Monkey posts to webhooks/survey-monkey/account
'signing_secret_account' => 'whsec_abc',
// secret for when Survey Monkey posts to webhooks/survey-monkey/my-named-secret
'signing_secret_my-named-secret' => 'whsec_123',