PHP code example of binary-cats / laravel-surveymonkey-webhooks

1. Go to this page and download the library: Download binary-cats/laravel-surveymonkey-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-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,
];

Route::surveyMonkeyWebhooks('webwooks/survey-monkey');

protected $except = [
    'webwooks/survey-monkey',
];



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`
    }
}

// config/surveymonkey-webhooks.php

'jobs' => [
    'response_completed' => \BinaryCats\SurveyMonkeyWebhooks\Jobs\HandleResponseCompleted::class,
],

/**
 * 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
    }
}

Route::surveymonkeyWebhooks('webhooks/survey-monkey/{configKey}');

Route::post('webhook/survey-monkey/{configKey}', 'BinaryCats\SurveyMonkeyWebhooks\SurveyMonkeyWebhooksController');

// 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',
bash
php artisan vendor:publish --provider="BinaryCats\SurveyMonkeyWebhooks\SurveyMonkeyWebhooksServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="migrations"
bash
php artisan migrate