Skip to content

Commit

Permalink
Merge pull request #2 from quick-order/v1.13.0
Browse files Browse the repository at this point in the history
Upgrade fork to resemble upstream at tag 1.13.0
  • Loading branch information
anfischer committed Jul 30, 2021
2 parents 3f2b1c0 + 67f683c commit 2604972
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 93 deletions.
File renamed without changes.
3 changes: 3 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

If you discover any security related issues, please email [email protected] instead of using the issue tracker.
29 changes: 29 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Check & fix styling

on: [push]

jobs:
style:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Fix style
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs --allow-risky=yes

- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch

- name: Commit changes
uses: stefanzweifel/[email protected]
with:
commit_message: Fix styling
branch: ${{ steps.extract_branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 6 additions & 12 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,23 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.4]
laravel: [7.*, 6.*, 5.8.*]
os: [ubuntu-latest, windows-latest]
php: [8.0, 7.4]
laravel: [8.*, 7.*, 6.*]
os: [ubuntu-latest]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
testbench: 5.*
- laravel: 6.*
testbench: 4.*
- laravel: 5.8.*
testbench: 3.8.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ composer.lock
docs
vendor
coverage
.idea/
.php_cs.cache
.idea/
42 changes: 42 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->notPath('bootstrap/*')
->notPath('storage/*')
->notPath('vendor')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline_array' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method', 'property',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
]
])
->setFinder($finder);
19 changes: 0 additions & 19 deletions .scrutinizer.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .styleci.yml

This file was deleted.

40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@

All notable changes to `laravel-webhook-server` will be documented in this file

## 1.13.0 - 2021-04-28

- add `dispatchSync`

## 1.12.0 - 2021-04-20

- pass Guzzle TransferStats into resulting Event (#81)

## 1.11.3 - 2021-04-02

- fix for missing default headers when using withHeaders (#79)

## 1.11.2 - 2021-03-17

- dispatch should return the PendingDispatch (#74)

## 1.11.1 - 2020-12-15

- fix exception name for invalid signers (#67)

## 1.11.0 - 2020-11-28

- add support for PHP 8

## 1.10.0 - 2020-10-04

- add `getUuid`

## 1.9.3 - 2020-09-09

- support Guzzle 7

## 1.9.2 - 2020-09-09

- support Laravel 8

## 1.9.1 - 2020-04-10

- do not use body in GET request (#43)

## 1.9.0 - 2020-03-19

- add `doNotSign`
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-webhook-server.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-webhook-server)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/spatie/laravel-webhook-server/run-tests?label=tests)
[![Quality Score](https://img.shields.io/scrutinizer/g/spatie/laravel-webhook-server.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/laravel-webhook-server)
[![StyleCI](https://github.styleci.io/repos/191252974/shield?branch=master)](https://github.styleci.io/repos/191252974)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-webhook-server.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-webhook-server)

A webhook is a way for an app to provide information to another app about a particular event. The way the two apps communicate is with a simple HTTP request.
Expand All @@ -14,7 +12,9 @@ If you need to receive and process webhooks take a look at our [laravel-webhook-

## Support us

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-webhook-server.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-webhook-server)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Expand Down Expand Up @@ -115,7 +115,6 @@ WebhookCall::create()
->dispatchNow();
```


### How signing requests works

When setting up, it's common to generate, store, and share a secret between your app and the app that wants to receive webhooks. Generating the secret could be done with `Illuminate\Support\Str::random()`, but it's entirely up to you. The package will use the secret to sign a webhook call.
Expand Down Expand Up @@ -143,7 +142,6 @@ WebhookCall::create()

By calling this method, the `Signature` header will not be set.


### Customizing signing requests

If you want to customize the signing process, you can create your own custom signer. A signer is any class that implements `Spatie\WebhookServer\Signer`.
Expand Down Expand Up @@ -220,7 +218,6 @@ WebhookCall::create()

Under the hood, the retrying of the webhook calls is implemented using [delayed dispatching](https://laravel.com/docs/master/queues#delayed-dispatching). Amazon SQS only has support for a small maximum delay. If you're using Amazon SQS for your queues, make sure you do not configure the package in a way so there are more than 15 minutes between each attempt.


### Customizing the HTTP verb

By default, all webhooks will use the `post` method. You can customize that by specifying the HTTP verb you want in the `http_verb` key of the `webhook-server` config file.
Expand Down Expand Up @@ -289,7 +286,7 @@ WebhookCall::create()
### Exception handling
By default, the package will not log any exceptions that are thrown when sending a webhook.

To handle exceptions you need to create listen for the `Spatie\WebhookServer\Events\WebhookCallFailedEvent` and/or `Spatie\WebhookServer\Events|FinalWebhookCallFailedEvent` events.
To handle exceptions you need to create listeners for the `Spatie\WebhookServer\Events\WebhookCallFailedEvent` and/or `Spatie\WebhookServer\Events\FinalWebhookCallFailedEvent` events.

### Events

Expand Down Expand Up @@ -332,7 +329,7 @@ If you discover any security-related issues, please email [email protected] instea

You're free to use this package, but if it makes it to your production environment, we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
}
],
"require": {
"php": "^7.3",
"php": "^8.0|^7.4",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.0.1",
"illuminate/bus": "^5.8|^6.0|^7.0|^8.0",
"illuminate/queue": "^5.8|^6.0|^7.0|^8.0",
"illuminate/support": "^5.8|^6.0|^7.0|^8.0"
"guzzlehttp/guzzle": "^6.3|^7.0",
"illuminate/bus": "^6.0|^7.0|^8.0",
"illuminate/queue": "^6.0|^7.0|^8.0",
"illuminate/support": "^6.0|^7.0|^8.0"
},
"require-dev": {
"mockery/mockery": "^1.3",
"orchestra/testbench": "^3.8|^4.0|^5.0|^6.0",
"phpunit/phpunit": "^8.4|^9.0",
"spatie/test-time": "^1.0"
"mockery/mockery": "^1.4",
"orchestra/testbench": "^4.0|^5.0|^6.0",
"phpunit/phpunit": "^9.4",
"spatie/test-time": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
37 changes: 14 additions & 23 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Spatie Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="QUEUE_CONNECTION" value="database"/>
</php>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Spatie Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="QUEUE_CONNECTION" value="database"/>
</php>
</phpunit>
20 changes: 15 additions & 5 deletions src/CallWebhookJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\TransferStats;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
Expand Down Expand Up @@ -59,20 +60,28 @@ class CallWebhookJob implements ShouldQueue

private $errorMessage = null;

public function handle() {
private ?TransferStats $transferStats = null;

public function handle()
{
/** @var \GuzzleHttp\Client $client */
$client = app(Client::class);

$lastAttempt = $this->attempts() >= $this->tries;

try {
$this->response = $client->request($this->httpVerb, $this->webhookUrl, [
$body = strtoupper($this->httpVerb) === 'GET'
? ['query' => $this->payload]
: ['body' => json_encode($this->payload)];

$this->response = $client->request($this->httpVerb, $this->webhookUrl, array_merge([
'timeout' => $this->requestTimeout,
'body' => json_encode($this->payload),
'verify' => $this->verifySsl,
'headers' => $this->headers,
]);
'on_stats' => function (TransferStats $stats) {
$this->transferStats = $stats;
},
], $body));

if (! Str::startsWith($this->response->getStatusCode(), 2)) {
throw new Exception('Webhook call failed');
Expand Down Expand Up @@ -135,7 +144,8 @@ private function dispatchEvent(string $eventClass)
$this->response,
$this->errorType,
$this->errorMessage,
$this->uuid
$this->uuid,
$this->transferStats
));
}
}
Loading

0 comments on commit 2604972

Please sign in to comment.