From 1d01bf8d2358548a42424c346c61f838b9a2f63c Mon Sep 17 00:00:00 2001 From: "Cyrill N. Kalita" Date: Wed, 26 Jan 2022 15:07:14 -0600 Subject: [PATCH 1/3] Test changes with L9 --- composer.json | 12 ++++++------ src/ProcessMailgunWebhookJob.php | 2 +- tests/MailgunWebhookCallTest.php | 1 + tests/TestCase.php | 12 ++++++------ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 2da92a6..b5e6988 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,13 @@ } ], "require": { - "php": "^7.4|^8.0", + "php": "^8.0", "illuminate/support": "^8.0|^9.0", - "spatie/laravel-webhook-client": "^2.0" + "spatie/laravel-webhook-client": "^3.0" }, "require-dev": { - "orchestra/testbench": "^6.0", - "phpunit/phpunit": "^9.3.3" + "orchestra/testbench": "^6.0|^7.0", + "phpunit/phpunit": "^9.4" }, "autoload": { "psr-4": { @@ -37,7 +37,7 @@ } }, "suggest": { - "binary-cats/laravel-mail-helpers": "^6.0" + "binary-cats/laravel-lob-webhooks": "^9.0" }, "scripts": { "analyze": "./vendor/bin/phpstan analyse src --memory-limit=2G", @@ -50,7 +50,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "9.x-dev" }, "laravel": { "providers": [ diff --git a/src/ProcessMailgunWebhookJob.php b/src/ProcessMailgunWebhookJob.php index 625a0bc..27edd97 100644 --- a/src/ProcessMailgunWebhookJob.php +++ b/src/ProcessMailgunWebhookJob.php @@ -5,7 +5,7 @@ use BinaryCats\MailgunWebhooks\Exceptions\WebhookFailed; use Illuminate\Support\Arr; use Illuminate\Support\Str; -use Spatie\WebhookClient\ProcessWebhookJob; +use Spatie\WebhookClient\Jobs\ProcessWebhookJob; class ProcessMailgunWebhookJob extends ProcessWebhookJob { diff --git a/tests/MailgunWebhookCallTest.php b/tests/MailgunWebhookCallTest.php index 3cfcfd9..978c89b 100644 --- a/tests/MailgunWebhookCallTest.php +++ b/tests/MailgunWebhookCallTest.php @@ -30,6 +30,7 @@ public function setUp(): void 'key' => 'value', ], ], + 'url' => '/webhooks/mailgun.com', ]); $this->processMailgunWebhookJob = new ProcessMailgunWebhookJob($this->webhookCall); diff --git a/tests/TestCase.php b/tests/TestCase.php index 700a696..72b6830 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -28,11 +28,11 @@ public function setUp(): void */ protected function getEnvironmentSetUp($app) { - $app['config']->set('database.default', 'sqlite'); - $app['config']->set('database.connections.sqlite', [ - 'driver' => 'sqlite', + config()->set('database.default', 'sqlite'); + config()->set('database.connections.sqlite', [ + 'driver' => 'sqlite', 'database' => ':memory:', - 'prefix' => '', + 'prefix' => '', ]); config(['mailgun-webhooks.signing_secret' => 'test_signing_secret']); @@ -43,9 +43,9 @@ protected function getEnvironmentSetUp($app) */ protected function setUpDatabase() { - include_once __DIR__.'/../vendor/spatie/laravel-webhook-client/database/migrations/create_webhook_calls_table.php.stub'; + $migration = include __DIR__.'/../vendor/spatie/laravel-webhook-client/database/migrations/create_webhook_calls_table.php.stub'; - (new CreateWebhookCallsTable())->up(); + $migration->up(); } /** From cf22c50365631389e9a3c58a0689c9c538b396cd Mon Sep 17 00:00:00 2001 From: "Cyrill N. Kalita" Date: Wed, 26 Jan 2022 15:17:34 -0600 Subject: [PATCH 2/3] Refresh the docs --- CHANGELOG.md | 10 ++++++++++ README.md | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95a6e6d..1eeedbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to `laravel-mailgun-webhooks` will be documented in this file +## 9.1.0 - 2022-01-26 + +- Drop support for PHP 7 +- Upgrade spatie/laravel-webhook-client to version 2.0 +- Test Laravel 9 integration + +## 9.0.0 - 2022-01-20 + +- Add support for Laravel 9 + ## 1.1.0 - 2020-03-04 - add support for Laravel 7 diff --git a/README.md b/README.md index e4c5e04..4cbd93d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,11 @@ This package will not handle what should be done after the webhook request has b Before using this package we highly recommend reading [the entire documentation on webhooks over at Mailgun](https://documentation.mailgun.com/en/latest/api-webhooks.html). -This package is an almost line-to-line adapted copy of absolutely amazing [spatie/laravel-stripe-webhooks](https://github.com/spatie/laravel-stripe-webhooks) +This package is an adapted copy of absolutely amazing [spatie/laravel-stripe-webhooks](https://github.com/spatie/laravel-stripe-webhooks) + +## Upgrade + +If you are upgrading from previous version, please note that spatie/laravel-webhook-client has been upgraded to ^3.0 - which adds an extra field into the webhooks table. Read [upgrading instructions](https://github.com/spatie/laravel-webhook-client/blob/main/UPGRADING.md) for more details. ## Installation @@ -47,6 +51,9 @@ return [ * * You can find a list of Mailgun webhook types here: * https://documentation.mailgun.com/en/latest/api-webhooks.html#webhooks. + * + * The package will automatically convert the keys to lowercase, but you should + * be congnisant of the fact that array keys are case sensitive */ 'jobs' => [ // 'delivered' => \BinaryCats\MailgunWebhooks\Jobs\HandleDelivered::class, @@ -112,6 +119,8 @@ If something goes wrong during the webhook request the thrown exception will be There are two ways this package enables you to handle webhook requests: you can opt to queue a job or listen to the events the package will fire. +**Due to the apparent differences between MailGun sandbox and production environment event casing, the package will ALWAYS cast mailgun events to lowercase - so your configured keys must be lowercase, too** + **The package does not handle legacy webhooks, as they have a different schema.** Let me know if this is something that is needed. ### Handling webhook requests using jobs From 082ca1bb69e90544f8333b3d96a2b1a4fcfeb66d Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 26 Jan 2022 21:18:10 +0000 Subject: [PATCH 3/3] Apply fixes from StyleCI --- src/Event.php | 6 +++--- src/Exceptions/UnexpectedValueException.php | 2 +- src/Exceptions/WebhookFailed.php | 3 ++- src/Jobs/HandleDelivered.php | 2 +- src/MailgunSignatureValidator.php | 7 +++---- src/MailgunWebhooksController.php | 4 ++-- src/ProcessMailgunWebhookJob.php | 4 ++-- src/Webhook.php | 7 ++++--- src/WebhookSignature.php | 6 +++--- tests/DummyJob.php | 2 +- tests/TestCase.php | 7 +++---- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Event.php b/src/Event.php index 1a68dda..ac2915f 100644 --- a/src/Event.php +++ b/src/Event.php @@ -16,7 +16,7 @@ final class Event implements WebhookEvent /** * Create new Event. * - * @param mixed[] $attributes + * @param mixed[] $attributes */ public function __construct(array $attributes) { @@ -24,9 +24,9 @@ public function __construct(array $attributes) } /** - * Static event constructor + * Static event constructor. * - * @param mixed[] $data + * @param mixed[] $data * @return static */ public static function constructFrom(array $data): self diff --git a/src/Exceptions/UnexpectedValueException.php b/src/Exceptions/UnexpectedValueException.php index 822554c..3aedbbf 100644 --- a/src/Exceptions/UnexpectedValueException.php +++ b/src/Exceptions/UnexpectedValueException.php @@ -7,7 +7,7 @@ class UnexpectedValueException extends BaseUnexpectedValueException { /** - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response */ public function render($request) diff --git a/src/Exceptions/WebhookFailed.php b/src/Exceptions/WebhookFailed.php index 1bd761e..aabf353 100644 --- a/src/Exceptions/WebhookFailed.php +++ b/src/Exceptions/WebhookFailed.php @@ -41,8 +41,9 @@ public static function missingType(WebhookCall $webhookCall): self { return new static("Webhook call id `{$webhookCall->getKey()}` did not contain a type. Valid Mailgun webhook calls should always contain a type."); } + /** - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response */ public function render($request) diff --git a/src/Jobs/HandleDelivered.php b/src/Jobs/HandleDelivered.php index 2af92d1..ff2231a 100644 --- a/src/Jobs/HandleDelivered.php +++ b/src/Jobs/HandleDelivered.php @@ -20,7 +20,7 @@ class HandleDelivered /** * Create new Job. * - * @param \Spatie\WebhookClient\Models\WebhookCall $webhookCall + * @param \Spatie\WebhookClient\Models\WebhookCall $webhookCall */ public function __construct(WebhookCall $webhookCall) { diff --git a/src/MailgunSignatureValidator.php b/src/MailgunSignatureValidator.php index d75353e..18caa15 100644 --- a/src/MailgunSignatureValidator.php +++ b/src/MailgunSignatureValidator.php @@ -12,9 +12,8 @@ class MailgunSignatureValidator implements SignatureValidator /** * True if the signature has been valiates. * - * @param \Illuminate\Http\Request $request - * @param \Spatie\WebhookClient\WebhookConfig $config - * + * @param \Illuminate\Http\Request $request + * @param \Spatie\WebhookClient\WebhookConfig $config * @return bool */ public function isValid(Request $request, WebhookConfig $config): bool @@ -38,7 +37,7 @@ public function isValid(Request $request, WebhookConfig $config): bool /** * Validate the incoming signature' schema. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return string[] */ protected function signature(Request $request): array diff --git a/src/MailgunWebhooksController.php b/src/MailgunWebhooksController.php index 8100e84..0a9e6af 100644 --- a/src/MailgunWebhooksController.php +++ b/src/MailgunWebhooksController.php @@ -12,8 +12,8 @@ class MailgunWebhooksController /** * Invoke controller method. * - * @param \Illuminate\Http\Request $request - * @param string|null $configKey + * @param \Illuminate\Http\Request $request + * @param string|null $configKey * @return \Illuminate\Http\Response */ public function __invoke(Request $request, string $configKey = null) diff --git a/src/ProcessMailgunWebhookJob.php b/src/ProcessMailgunWebhookJob.php index 27edd97..17dbb49 100644 --- a/src/ProcessMailgunWebhookJob.php +++ b/src/ProcessMailgunWebhookJob.php @@ -25,7 +25,7 @@ public function handle() { $type = Arr::get($this->webhookCall, "payload.{$this->key}"); - if (!$type) { + if (! $type) { throw WebhookFailed::missingType($this->webhookCall); } @@ -37,7 +37,7 @@ public function handle() return; } - if (!class_exists($jobClass)) { + if (! class_exists($jobClass)) { throw WebhookFailed::jobClassDoesNotExist($jobClass, $this->webhookCall); } diff --git a/src/Webhook.php b/src/Webhook.php index 3326949..9e6d5f5 100644 --- a/src/Webhook.php +++ b/src/Webhook.php @@ -9,10 +9,11 @@ class Webhook /** * Validate and raise an appropriate event. * - * @param mixed[] $payload - * @param string[] $signature - * @param string $secret + * @param mixed[] $payload + * @param string[] $signature + * @param string $secret * @return \BinaryCats\MailgunWebhooks\Event + * * @throws WebhookFailed */ public static function constructEvent(array $payload, array $signature, string $secret): Event diff --git a/src/WebhookSignature.php b/src/WebhookSignature.php index 60f6426..7718b3f 100644 --- a/src/WebhookSignature.php +++ b/src/WebhookSignature.php @@ -27,7 +27,7 @@ final class WebhookSignature * @param string[] $signatureArray * @param string $secret */ - public function __construct(array $signatureArray , string $secret) + public function __construct(array $signatureArray, string $secret) { $this->signatureArray = $signatureArray; $this->secret = $secret; @@ -37,7 +37,7 @@ public function __construct(array $signatureArray , string $secret) * Static accessor into the class constructor. * * @param string[] $signatureArray - * @param string $secret + * @param string $secret * @return WebhookSignature static */ public static function make($signatureArray, string $secret) @@ -73,7 +73,7 @@ protected function computeSignature() /** * Magically access items from signature array. * - * @param string $attribute + * @param string $attribute * @return mixed */ public function __get($attribute) diff --git a/tests/DummyJob.php b/tests/DummyJob.php index 3506715..c24de23 100644 --- a/tests/DummyJob.php +++ b/tests/DummyJob.php @@ -16,7 +16,7 @@ class DummyJob /** * Create new Job. * - * @param \Spatie\WebhookClient\Models\WebhookCall $webhookCall + * @param \Spatie\WebhookClient\Models\WebhookCall $webhookCall */ public function __construct(WebhookCall $webhookCall) { diff --git a/tests/TestCase.php b/tests/TestCase.php index 72b6830..cb425b9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,6 @@ namespace Tests; use BinaryCats\MailgunWebhooks\MailgunWebhooksServiceProvider; -use CreateWebhookCallsTable; use Exception; use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler; @@ -24,7 +23,7 @@ public function setUp(): void /** * Set up the environment. * - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app */ protected function getEnvironmentSetUp($app) { @@ -43,13 +42,13 @@ protected function getEnvironmentSetUp($app) */ protected function setUpDatabase() { - $migration = include __DIR__.'/../vendor/spatie/laravel-webhook-client/database/migrations/create_webhook_calls_table.php.stub'; + $migration = include __DIR__.'/../vendor/spatie/laravel-webhook-client/database/migrations/create_webhook_calls_table.php.stub'; $migration->up(); } /** - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app * @return array */ protected function getPackageProviders($app)