Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Apr 30, 2020
1 parent 693a9d1 commit 6682918
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ return [
/*
* This class determines the response on a valid webhook call.
*/
'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultResponse::class,
'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,

/*
* The classname of the model to be used to store call. The class should be equal
Expand Down Expand Up @@ -218,17 +218,17 @@ You should specify the class name of your job in the `process_webhook_job` of th

### Creating your own webhook response

A webhook response is any class that implements `\Spatie\WebhookClient\WebhookResponse\WebhookResponse`. This is what that interface looks like:
A webhook response is any class that implements `\Spatie\WebhookClient\WebhookResponse\RespondsToWebhook`. This is what that interface looks like:

```php
namespace Spatie\WebhookClient\WebhookResponse;

use Illuminate\Http\Request;
use Spatie\WebhookClient\WebhookConfig;

interface WebhookResponse
interface RespondsToWebhook
{
public function respondToValidWebhookRequest(Request $request, WebhookConfig $config);
public function respondToValidWebhook(Request $request, WebhookConfig $config);
}
```

Expand All @@ -248,7 +248,7 @@ return [
'signature_header_name' => 'Signature-for-app-1',
'signature_validator' => \Spatie\WebhookClient\SignatureValidator\DefaultSignatureValidator::class,
'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultResponse::class,
'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,
'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
'process_webhook_job' => '',
],
Expand All @@ -258,7 +258,7 @@ return [
'signature_header_name' => 'Signature-for-app-2',
'signature_validator' => \Spatie\WebhookClient\SignatureValidator\DefaultSignatureValidator::class,
'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultResponse::class,
'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,
'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
'process_webhook_job' => '',
],
Expand Down Expand Up @@ -288,7 +288,7 @@ $webhookConfig = new \Spatie\WebhookClient\WebhookConfig([
'signature_header_name' => 'Signature',
'signature_validator' => \Spatie\WebhookClient\SignatureValidator\DefaultSignatureValidator::class,
'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultResponse::class,
'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,
'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
'process_webhook_job' => '',
]);
Expand Down
2 changes: 1 addition & 1 deletion config/webhook-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/*
* This class determines the response on a valid webhook call.
*/
'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultResponse::class,
'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,

/*
* The classname of the model to be used to store call. The class should be equal
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/InvalidConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\WebhookClient\ProcessWebhookJob;
use Spatie\WebhookClient\SignatureValidator\SignatureValidator;
use Spatie\WebhookClient\WebhookProfile\WebhookProfile;
use Spatie\WebhookClient\WebhookResponse\WebhookResponse;
use Spatie\WebhookClient\WebhookResponse\RespondsToWebhook;

class InvalidConfig extends Exception
{
Expand All @@ -31,7 +31,7 @@ public static function invalidWebhookProfile(string $webhookProfile): InvalidCon

public static function invalidWebhookResponse(string $webhookResponse): InvalidConfig
{
$webhookResponseInterface = WebhookResponse::class;
$webhookResponseInterface = RespondsToWebhook::class;

return new static("`{$webhookResponse}` is not a valid webhook response class. A valid webhook response is a class that implements `{$webhookResponseInterface}`.");
}
Expand Down
6 changes: 3 additions & 3 deletions src/WebhookConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Spatie\WebhookClient\Exceptions\InvalidConfig;
use Spatie\WebhookClient\SignatureValidator\SignatureValidator;
use Spatie\WebhookClient\WebhookProfile\WebhookProfile;
use Spatie\WebhookClient\WebhookResponse\WebhookResponse;
use Spatie\WebhookClient\WebhookResponse\RespondsToWebhook;

class WebhookConfig
{
Expand All @@ -19,7 +19,7 @@ class WebhookConfig

public WebhookProfile $webhookProfile;

public WebhookResponse $webhookResponse;
public RespondsToWebhook $webhookResponse;

public string $webhookModel;

Expand All @@ -43,7 +43,7 @@ public function __construct(array $properties)
}
$this->webhookProfile = app($properties['webhook_profile']);

if (! is_subclass_of($properties['webhook_response'], WebhookResponse::class)) {
if (! is_subclass_of($properties['webhook_response'], RespondsToWebhook::class)) {
throw InvalidConfig::invalidWebhookResponse($properties['webhook_response']);
}
$this->webhookResponse = app($properties['webhook_response']);
Expand Down
2 changes: 1 addition & 1 deletion src/WebhookProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ protected function processWebhook(WebhookCall $webhookCall): void

protected function createResponse()
{
return $this->config->webhookResponse->respondToValidWebhookRequest($this->request, $this->config);
return $this->config->webhookResponse->respondToValidWebhook($this->request, $this->config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use Spatie\WebhookClient\WebhookConfig;
use Symfony\Component\HttpFoundation\Response;

class DefaultResponse implements WebhookResponse
class DefaultRespondsTo implements RespondsToWebhook
{
public function respondToValidWebhookRequest(Request $request, WebhookConfig $config): Response
public function respondToValidWebhook(Request $request, WebhookConfig $config): Response
{
return response()->json(['message' => 'ok']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\WebhookClient\WebhookConfig;
use Symfony\Component\HttpFoundation\Response;

interface WebhookResponse
interface RespondsToWebhook
{
public function respondToValidWebhookRequest(Request $request, WebhookConfig $config): Response;
public function respondToValidWebhook(Request $request, WebhookConfig $config): Response;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Illuminate\Http\Request;
use Spatie\WebhookClient\WebhookConfig;
use Spatie\WebhookClient\WebhookResponse\WebhookResponse;
use Spatie\WebhookClient\WebhookResponse\RespondsToWebhook;
use Symfony\Component\HttpFoundation\Response;

class CustomWebhookResponse implements WebhookResponse
class CustomRespondsToWebhook implements RespondsToWebhook
{
public function respondToValidWebhookRequest(Request $request, WebhookConfig $config): Response
public function respondToValidWebhook(Request $request, WebhookConfig $config): Response
{
return response()->json(['foo' => 'bar']);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/WebhookConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Spatie\WebhookClient\Tests\TestClasses\ProcessWebhookJobTestClass;
use Spatie\WebhookClient\WebhookConfig;
use Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile;
use Spatie\WebhookClient\WebhookResponse\DefaultResponse;
use Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo;

class WebhookConfigTest extends TestCase
{
Expand Down Expand Up @@ -80,7 +80,7 @@ protected function getValidConfig(): array
'signature_header_name' => 'Signature',
'signature_validator' => DefaultSignatureValidator::class,
'webhook_profile' => ProcessEverythingWebhookProfile::class,
'webhook_response' => DefaultResponse::class,
'webhook_response' => DefaultRespondsTo::class,
'webhook_model' => WebhookCall::class,
'process_webhook_job' => ProcessWebhookJobTestClass::class,
];
Expand Down
4 changes: 2 additions & 2 deletions tests/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Support\Facades\Route;
use Spatie\WebhookClient\Events\InvalidSignatureEvent;
use Spatie\WebhookClient\Models\WebhookCall;
use Spatie\WebhookClient\Tests\TestClasses\CustomWebhookResponse;
use Spatie\WebhookClient\Tests\TestClasses\CustomRespondsToWebhook;
use Spatie\WebhookClient\Tests\TestClasses\EverythingIsValidSignatureValidator;
use Spatie\WebhookClient\Tests\TestClasses\NothingIsValidSignatureValidator;
use Spatie\WebhookClient\Tests\TestClasses\ProcessNothingWebhookProfile;
Expand Down Expand Up @@ -146,7 +146,7 @@ public function it_can_work_with_an_alternative_model()
/** @test */
public function it_can_respond_with_custom_response()
{
config()->set('webhook-client.configs.0.webhook_response', CustomWebhookResponse::class);
config()->set('webhook-client.configs.0.webhook_response', CustomRespondsToWebhook::class);

$this
->postJson('incoming-webhooks', $this->payload, $this->headers)
Expand Down

0 comments on commit 6682918

Please sign in to comment.