Skip to content

Commit

Permalink
Merge pull request #18 from superbrave/transaction-status-fix
Browse files Browse the repository at this point in the history
Transaction status fix
  • Loading branch information
kiettran authored Jan 19, 2021
2 parents a92445e + c53a7cd commit e843e10
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
21 changes: 12 additions & 9 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public function getData(): array
* Send the request to the API of the Payment Service Provider.
* The base url and the authentication headers are automatically added.
*
* @param string $method
* @param string $urlPath
* @param array $data
* @param string $method
* @param string $urlPath
* @param array|null $data
*
* @return ResponseInterface
*/
protected function sendRequest(string $method, string $urlPath, array $data): ResponseInterface
protected function sendRequest(string $method, string $urlPath, ?array $data = null): ResponseInterface
{
$securityHash = $this->getSecurityHash($method, $urlPath, $data);
$headers = $this->getAuthenticationHeaders($securityHash);
Expand Down Expand Up @@ -76,10 +76,10 @@ protected function getResponseBody(): array
/**
* Safety hash from icepay, to be generated after putting in all the data.
*
* @param string $requestMethod
* @param string $urlPath
* @param array|\stdClass $data
* @param bool $urlIsFullUrl = false. True to have $urlPath be the absolute (full) url
* @param string $requestMethod
* @param string $urlPath
* @param array|\stdClass|null $data
* @param bool $urlIsFullUrl = false. True to have $urlPath be the absolute (full) url
*
* @return string
*/
Expand All @@ -96,7 +96,10 @@ protected function getSecurityHash(
$fullUrl = $urlPath;
}

$toBeHashed = $fullUrl.$requestMethod.$contractProfileId.json_encode($data);
$toBeHashed = $fullUrl.$requestMethod.$contractProfileId;
if ($data !== null) {
$toBeHashed .= json_encode($data);
}

$hash = hash_hmac(
'sha256',
Expand Down
5 changes: 2 additions & 3 deletions src/Message/CompleteAuthoriseAndCaptureRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ public function getData(): array
public function sendData($data): ResponseInterface
{
$this->sendRequest(
Request::METHOD_POST,
Request::METHOD_GET,
sprintf(
'/transaction/%s',
$this->getTransactionReference()
),
$data
)
);

return new CompleteAuthoriseAndCaptureResponse(
Expand Down
5 changes: 2 additions & 3 deletions src/Message/TransactionStatusRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ public function sendData($data): ResponseInterface
}

$this->sendRequest(
Request::METHOD_POST,
Request::METHOD_GET,
sprintf(
'/transaction/%s',
$this->getTransactionReference()
),
$data
)
);

return new TransactionStatusResponse(
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/CompleteAuthoriseAndCaptureRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testSendData(): void
$this->assertInstanceOf(CompleteAuthoriseAndCaptureResponse::class, $response);

$expectedRequest = new Request(
SymfonyRequest::METHOD_POST,
SymfonyRequest::METHOD_GET,
'https://www.superbrave.nl/transaction/e7ca29c8-f1f4-4a4c-a968-0f9667d0519d'
);

Expand Down
2 changes: 1 addition & 1 deletion tests/Message/TransactionStatusRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testSendData(): void
$this->assertInstanceOf(TransactionStatusResponse::class, $response);

$expectedRequest = new Request(
SymfonyRequest::METHOD_POST,
SymfonyRequest::METHOD_GET,
'https://www.superbrave.nl/transaction/e7ca29c8-f1f4-4a4c-a968-0f9667d0519d'
);

Expand Down

0 comments on commit e843e10

Please sign in to comment.