From 9096e4e18ae53ab67d06bb23e945fe021e7aa41a Mon Sep 17 00:00:00 2001 From: Cyrill Kalita Date: Wed, 29 Jan 2020 19:18:30 -0600 Subject: [PATCH 1/2] Fix Readme documentation --- README.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 0e41ba8..2b39ad8 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,9 @@ return [ /* * The classname of the model to be used. The class should equal or extend - * BinaryCats\MailgunWebhooks\WebhookCall which is a child of Spatie\WebhookClient\Models\WebhookCall + * Spatie\WebhookClient\Models\WebhookCall */ - 'model' => \BinaryCats\MailgunWebhooks\WebhookCall::class, + 'model' => \Spatie\WebhookClient\Models\WebhookCall::class, /* * The classname of the model to be used. The class should equal or extend @@ -77,17 +77,18 @@ php artisan migrate ### Routing Finally, take care of the routing: At [the Mailgun dashboard](https://app.mailgun.com/app/sending/domains) you must configure at what url Mailgun webhooks should hit your app. In the routes file of your app you must pass that route to `Route::mailgunWebhooks()`: -I like to group functionality by domain, so would suggest `webwooks\mailgun` +I like to group functionality by domain, so I would suggest `webwooks/mailgun` (especially if you plan to have more webhooks), but it is up to you. ```php -Route::mailgunWebhooks('webwooks\mailgun'); +# routes\web.php +Route::mailgunWebhooks('webwooks/mailgun'); ``` Behind the scenes this will register a `POST` route to a controller provided by this package. Because Mailgun has no way of getting a csrf-token, you must add that route to the `except` array of the `VerifyCsrfToken` middleware: ```php protected $except = [ - 'webwooks\mailgun', + 'webwooks/mailgun', ]; ``` @@ -118,13 +119,13 @@ use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -use BinaryCats\MailgunWebhooks\WebhookCall; +use Spatie\WebhookClient\Models\WebhookCall; -class HandleDeliveredSource implements ShouldQueue +class HandleDelivered implements ShouldQueue { use InteractsWithQueue, Queueable, SerializesModels; - /** @var \BinaryCats\MailgunWebhooks\WebhookCall */ + /** @var \Spatie\WebhookClient\Models\WebhookCall */ public $webhookCall; public function __construct(WebhookCall $webhookCall) @@ -206,7 +207,7 @@ The above example is only one way to handle events in Laravel. To learn the othe All incoming webhook requests are written to the database. This is incredibly valuable when something goes wrong while handling a webhook call. You can easily retry processing the webhook call, after you've investigated and fixed the cause of failure, like this: ```php -use BinaryCats\MailgunWebhooks\WebhookCall; +use Spatie\WebhookClient\Models\WebhookCall; use BinaryCats\MailgunWebhooks\ProcessMailgunWebhookJob; dispatch(new ProcessMailgunWebhookJob(WebhookCall::find($id))); @@ -240,24 +241,24 @@ When needed might want to the package to handle multiple endpoints and secrets. If you are using the `Route::mailgunWebhooks` macro, you can append the `configKey` as follows: ```php -Route::mailgunWebhooks('webhook-url/{configKey}'); +Route::mailgunWebhooks('webwooks/mailgun/{configKey}'); ``` Alternatively, if you are manually defining the route, you can add `configKey` like so: ```php -Route::post('webhook-url/{configKey}', 'BinaryCats\MailgunWebhooks\MailgunWebhooksController'); +Route::post('webwooks/mailgun/{configKey}', 'BinaryCats\MailgunWebhooks\MailgunWebhooksController'); ``` -If this route parameter is present the verify middleware will look for the secret using a different config key, by appending the given the parameter value to the default config key. E.g. If Mailgun posts to `webhook-url/my-named-secret` you'd add a new config named `signing_secret_my-named-secret`. +If this route parameter is present the verify middleware will look for the secret using a different config key, by appending the given the parameter value to the default config key. E.g. If Mailgun posts to `webwooks/mailgun/my-named-secret` you'd add a new config named `signing_secret_my-named-secret`. Example config might look like: ```php -// secret for when Mailgun posts to webhook-url/account +// secret for when Mailgun posts to webwooks/mailgun/account 'signing_secret_account' => 'whsec_abc', -// secret for when Mailgun posts to webhook-url/connect -'signing_secret_connect' => 'whsec_123', +// secret for when Mailgun posts to webwooks/mailgun/my-named-secret +'signing_secret_my-named-secret' => 'whsec_123', ``` ### About Mailgun From 59430fccfd22427bc3e5c25a33703ad457590a6a Mon Sep 17 00:00:00 2001 From: Cyrill Kalita Date: Wed, 29 Jan 2020 19:21:36 -0600 Subject: [PATCH 2/2] Apply stylefix --- src/Event.php | 2 +- src/Exceptions/WebhookFailed.php | 2 +- src/Webhook.php | 2 +- src/WebhookSignature.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Event.php b/src/Event.php index da818f8..8ff6d62 100644 --- a/src/Event.php +++ b/src/Event.php @@ -28,7 +28,7 @@ public function __construct($attributes) * * @return Event */ - public static function constructFrom($data) : self + public static function constructFrom($data): self { return new static($data); } diff --git a/src/Exceptions/WebhookFailed.php b/src/Exceptions/WebhookFailed.php index 7200d99..6b95858 100644 --- a/src/Exceptions/WebhookFailed.php +++ b/src/Exceptions/WebhookFailed.php @@ -7,7 +7,7 @@ class WebhookFailed extends Exception { - public static function signingSecretNotSet() : self + public static function signingSecretNotSet(): self { return new static('The webhook signing secret is not set. Make sure that the `signing_secret` config key is set to the correct value.'); } diff --git a/src/Webhook.php b/src/Webhook.php index c399527..feed5bc 100644 --- a/src/Webhook.php +++ b/src/Webhook.php @@ -12,7 +12,7 @@ class Webhook * @param string $secret * @return BinaryCats\MailgunWebhooks\Event */ - public static function constructEvent(array $payload, array $signature, string $secret) : Event + public static function constructEvent(array $payload, array $signature, string $secret): Event { // verify we are good, else throw an expection WebhookSignature::make($signature, $secret)->verify(); diff --git a/src/WebhookSignature.php b/src/WebhookSignature.php index 2de5098..94849b6 100644 --- a/src/WebhookSignature.php +++ b/src/WebhookSignature.php @@ -49,7 +49,7 @@ public static function make($signatureArray, string $secret) * * @return bool */ - public function verify() : bool + public function verify(): bool { return hash_equals($this->signature, $this->computeSignature()); }