Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V5.1 #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

V5.1 #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor
composer.lock
.idea
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "library",
"license": "MIT",
"require": {
"php": "^7.1",
"php": "^7.1 || ^8.1",
"guzzlehttp/guzzle": "^6.3 | ^7.0.1",
"ext-json": "*"
},
Expand Down
85 changes: 42 additions & 43 deletions src/BankID.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct($environment = self::ENVIRONMENT_TEST, $certificate
}

$httpOptions = [
'base_uri' => 'https://'.self::HOSTS[$environment].'/rp/v5/',
'base_uri' => 'https://'.self::HOSTS[$environment].'/rp/v5.1/',
'cert' => $certificate,
'verify' => $caCertificate,
'headers' => [
Expand All @@ -58,16 +58,16 @@ public function __construct($environment = self::ENVIRONMENT_TEST, $certificate
$this->httpClient = new Client($httpOptions);
}

/**
* Authenticate a user using their personal number.
*
* @param $personalNumber
* @param $ip
*
* @return BankIDResponse
*/
public function authenticate($personalNumber, $ip)
{
/**
* Authenticate a user using their personal number.
*
* @param $personalNumber
* @param $ip
*
* @return BankIDResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function authenticate($personalNumber, $ip): BankIDResponse {
$payload['endUserIp'] = $ip;

if (!empty($personalNumber)) {
Expand All @@ -89,18 +89,18 @@ public function authenticate($personalNumber, $ip)
return new BankIDResponse(BankIDResponse::STATUS_PENDING, $httpResponseBody);
}

/**
* Request a signing order for a user.
*
* @param $personalNumber
* @param $ip
* @param $userVisibleData
* @param $userNonVisibleData
*
* @return BankIDResponse
*/
public function sign($personalNumber, $ip, $userVisibleData = '', $userNonVisibleData = NULL)
{
/**
* Request a signing order for a user.
*
* @param $personalNumber
* @param $ip
* @param $userVisibleData
* @param $userNonVisibleData
*
* @return BankIDResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function sign($personalNumber, $ip, $userVisibleData = '', $userNonVisibleData = NULL): BankIDResponse {
try {
$parameters = [
'endUserIp' => $ip,
Expand All @@ -127,15 +127,15 @@ public function sign($personalNumber, $ip, $userVisibleData = '', $userNonVisibl
return new BankIDResponse(BankIDResponse::STATUS_PENDING, $httpResponseBody);
}

/**
* Collect an ongoing user request.
*
* @param $orderReference
*
* @return BankIDResponse
*/
public function collect($orderReference)
{
/**
* Collect an ongoing user request.
*
* @param $orderReference
*
* @return BankIDResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function collect($orderReference): BankIDResponse {
try {
$httpResponse = $this->httpClient->post('collect', [
RequestOptions::JSON => [
Expand All @@ -151,15 +151,15 @@ public function collect($orderReference)
return new BankIDResponse($httpResponseBody['status'], $httpResponseBody);
}

/**
* Cancel an ongoing order per the users request.
*
* @param $orderReference
*
* @return BankIDResponse
*/
public function cancel($orderReference)
{
/**
* Cancel an ongoing order per the users request.
*
* @param $orderReference
*
* @return BankIDResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function cancel($orderReference): BankIDResponse {
try {
$httpResponse = $this->httpClient->post('cancel', [
RequestOptions::JSON => [
Expand All @@ -182,8 +182,7 @@ public function cancel($orderReference)
*
* @return BankIDResponse
*/
private function requestExceptionToBankIDResponse(RequestException $e)
{
private function requestExceptionToBankIDResponse(RequestException $e): BankIDResponse {
$body = $e->hasResponse() ? $e->getResponse()->getBody() : null;

if ($body) {
Expand Down
24 changes: 8 additions & 16 deletions src/BankIDResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,40 +142,35 @@ public function __construct($status, $body = null)
/**
* @return string
*/
public function getMessage()
{
public function getMessage(): string {
return $this->message;
}

/**
* @return null|array
*/
public function getBody()
{
public function getBody(): ?array {
return $this->body;
}

/**
* @return string
*/
public function getStatus()
{
public function getStatus(): string {
return $this->status;
}

/**
* @return null|string
*/
public function getOrderRef()
{
public function getOrderRef(): ?string {
return $this->body['orderRef'] ?? null;
}

/**
* @return null|string
*/
public function getPersonalNumber()
{
public function getPersonalNumber(): ?string {
return $this->body['completionData']['user']['personalNumber'] ?? null;
}

Expand All @@ -190,24 +185,21 @@ public function getErrorCode()
/**
* @return null|string
*/
public function getErrorDetails()
{
public function getErrorDetails(): ?string {
return $this->body['details'] ?? null;
}

/**
* @return null|string
*/
public function getHintCode()
{
public function getHintCode(): ?string {
return $this->body['hintCode'] ?? null;
}

/**
* @return null|string
*/
public function getAutoStartToken()
{
public function getAutoStartToken(): ?string {
return $this->body['autoStartToken'] ?? null;
}
}