-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
360 additions
and
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
vendor/* | ||
.env | ||
index.php | ||
tests/* | ||
callback-tripay.json | ||
CallbackHandler.php |
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,49 @@ | ||
<?php | ||
|
||
namespace Reactmore\Tripay\Services; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class Callback | ||
{ | ||
|
||
public $request, $privateKey; | ||
|
||
|
||
public function __construct($data) | ||
{ | ||
$this->privateKey = $data->credential['privateKey']; | ||
$this->request = Request::createFromGlobals(); | ||
} | ||
|
||
|
||
public function get() | ||
{ | ||
return $this->request->getContent(); | ||
} | ||
|
||
public function signature() | ||
{ | ||
return hash_hmac('sha256', $this->get(), $this->privateKey); | ||
} | ||
|
||
|
||
public function callbackSignature() | ||
{ | ||
return isset($_SERVER['HTTP_X_CALLBACK_SIGNATURE']) ? $_SERVER['HTTP_X_CALLBACK_SIGNATURE'] : ''; | ||
} | ||
|
||
public function callEvent() | ||
{ | ||
return isset($_SERVER['HTTP_X_CALLBACK_EVENT']) ? $_SERVER['HTTP_X_CALLBACK_EVENT'] : ''; | ||
} | ||
|
||
public function validateSignature(): bool | ||
{ | ||
if ($this->callbackSignature() !== $this->signature()) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
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
Oops, something went wrong.