Skip to content

Commit

Permalink
Force checking response signature (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati committed Jun 15, 2023
1 parent 115544b commit 53a0b45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ $response = $client->init($request);
if ($response->getRc() !== RC::TRANSACTION_OK || $response->isError() || $response->getRedirectURL() === '') {
throw new \Exception('Transaction failed: ' . $response->getErrorDesc());
}
$response->checkSignature('Your kSig digital signature');
```

At this point, you you have a succesfull initialization response.
Expand Down Expand Up @@ -113,9 +112,6 @@ $response = $client->verify($request);
if ($response->getRc() !== RC::TRANSACTION_OK || $response->isError()) {
throw new \Exception('Transaction failed: ' . $response->getErrorDesc());
}

$response->checkSignature('Your kSig digital signature');

```

## Server2Server communication (callback URL)
Expand Down
12 changes: 10 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ public function init(Init\Request $request)
if (!$rawResponse->is2xx()) {
throw new Exception\InvalidHttpResponseCode($rawResponse);
}
$response = $this->getInitUnserializer()->unserialize($rawResponse->getBody());
if (!$response->isError() || $response->getSignature() !== '') {
$response->checkSignature($this->signatureKey);
}

return $this->getInitUnserializer()->unserialize($rawResponse->getBody());
return $response;
}

/**
Expand All @@ -119,8 +123,12 @@ public function verify(Verify\Request $request)
if (!$rawResponse->is2xx()) {
throw new Exception\InvalidHttpResponseCode($rawResponse);
}
$response = $this->getVerifyUnserializer()->unserialize($rawResponse->getBody());
if (!$response->isError() || $response->getSignature() !== '') {
$response->checkSignature($this->signatureKey);
}

return $this->getVerifyUnserializer()->unserialize($rawResponse->getBody());
return $response;
}

/**
Expand Down

0 comments on commit 53a0b45

Please sign in to comment.