Skip to content

v9.1 Drop PHP 7 and test-ready for L9 #20

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 4 commits into from
Jan 26, 2022
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand All @@ -50,7 +50,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
"dev-master": "9.x-dev"
},
"laravel": {
"providers": [
Expand Down
6 changes: 3 additions & 3 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ final class Event implements WebhookEvent
/**
* Create new Event.
*
* @param mixed[] $attributes
* @param mixed[] $attributes
*/
public function __construct(array $attributes)
{
$this->attributes = $attributes;
}

/**
* Static event constructor
* Static event constructor.
*
* @param mixed[] $data
* @param mixed[] $data
* @return static
*/
public static function constructFrom(array $data): self
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/UnexpectedValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/Exceptions/WebhookFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/HandleDelivered.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 3 additions & 4 deletions src/MailgunSignatureValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/MailgunWebhooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/ProcessMailgunWebhookJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -25,7 +25,7 @@ public function handle()
{
$type = Arr::get($this->webhookCall, "payload.{$this->key}");

if (!$type) {
if (! $type) {
throw WebhookFailed::missingType($this->webhookCall);
}

Expand All @@ -37,7 +37,7 @@ public function handle()
return;
}

if (!class_exists($jobClass)) {
if (! class_exists($jobClass)) {
throw WebhookFailed::jobClassDoesNotExist($jobClass, $this->webhookCall);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/WebhookSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/DummyJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions tests/MailgunWebhookCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function setUp(): void
'key' => 'value',
],
],
'url' => '/webhooks/mailgun.com',
]);

$this->processMailgunWebhookJob = new ProcessMailgunWebhookJob($this->webhookCall);
Expand Down
17 changes: 8 additions & 9 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Tests;

use BinaryCats\MailgunWebhooks\MailgunWebhooksServiceProvider;
use CreateWebhookCallsTable;
use Exception;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Foundation\Exceptions\Handler;
Expand All @@ -24,15 +23,15 @@ public function setUp(): void
/**
* Set up the environment.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
*/
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']);
Expand All @@ -43,13 +42,13 @@ 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();
}

/**
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageProviders($app)
Expand Down