Skip to content

Fix Readme documentation #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
];
```

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/WebhookFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/WebhookSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down