This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
216 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bvtterfly\Replay\Contracts; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
|
||
interface Policy | ||
{ | ||
public function isIdempotentRequest(Request $request): bool; | ||
|
||
public function isRecordableResponse(Response $response): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bvtterfly\Replay\Exceptions; | ||
|
||
use Exception; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bvtterfly\Replay; | ||
|
||
use Spatie\LaravelPackageTools\Package; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Bvtterfly\Replay; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class RequestHelper | ||
{ | ||
public static function signature(Request $request): string | ||
{ | ||
$hashAlgo = 'md5'; | ||
|
||
if (in_array('xxh3', hash_algos())) { | ||
$hashAlgo = 'xxh3'; | ||
} | ||
|
||
return hash($hashAlgo, json_encode( | ||
[ | ||
$request->ip(), | ||
$request->path(), | ||
$request->all(), | ||
$request->headers->all(), | ||
] | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bvtterfly\Replay; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
|
||
class StripePolicy implements Contracts\Policy | ||
{ | ||
public function isIdempotentRequest(Request $request): bool | ||
{ | ||
return $request->isMethod('POST') | ||
&& $request->hasHeader(config('replay.header_name')); | ||
} | ||
|
||
public function isRecordableResponse(Response $response): bool | ||
{ | ||
return $response->isSuccessful() | ||
|| $response->isServerError(); | ||
} | ||
} |
Oops, something went wrong.