PHP code example of dimafe6 / bank-id
1. Go to this page and download the library: Download dimafe6/bank-id library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dimafe6 / bank-id example snippets
// Create BankIDService
$bankIDService = new BankIDService(
'https://appapi2.test.bankid.com/rp/v5.1/',
$_SERVER["REMOTE_ADDR"],
[
'verify' => false,
'cert' => 'PATH_TO_TEST_CERT.pem',
]
);
// OR Create BankIDService with ssl verification
$bankIDService = new BankIDService(
'https://appapi2.test.bankid.com/rp/v5.1/',
$_SERVER["REMOTE_ADDR"],
[
'verify' => 'PATH_TO_TEST_CERT.ca',
'cert' => 'PATH_TO_TEST_CERT.crt',
'ssl_key' => 'PATH_TO_TEST_CERT.key',
]
);
// Signing. Step 1 - Get orderRef
/** @var OrderResponse $response */
$response = $bankIDService->getSignResponse('PERSONAL_NUMBER', 'User visible data', "user non visible data", "user visible data format");
// Signing. Step 2 - Collect orderRef.
// Repeat until $collectResponse->status !== CollectResponse::STATUS_COMPLETED
$collectResponse = $bankIDService->collectResponse($response->orderRef);
if($collectResponse->status === CollectResponse::STATUS_COMPLETED) {
return true; //Signed successfully
}
// Authorize. Step 1 - Get orderRef
$response = $bankIDService->getAuthResponse('PERSONAL_NUMBER');
// Authorize. Step 2 - Collect orderRef.
// Repeat until $authResponse->status !== CollectResponse::STATUS_COMPLETED
$authResponse = $bankIDService->collectResponse($response->orderRef);
if($authResponse->status == CollectResponse::STATUS_COMPLETED) {
return true; //Authorized
}
// Cancel auth or collect order
// Authorize. Step 1 - Get orderRef
$response = $bankIDService->getAuthResponse('PERSONAL_NUMBER');
// Cancel authorize order
if($bankIDService->cancelOrder($response->orderRef)) {
return 'Authorization canceled';
}
// Authorize. Step 1 - Get orderRef
$response = $bankIDService->getAuthResponse();
// Authorize. Step 2 - Collect orderRef.
// Repeat until $authResponse->status !== CollectResponse::STATUS_COMPLETED
$authResponse = $bankIDService->collectResponse($response->orderRef);
if($authResponse->status == CollectResponse::STATUS_COMPLETED) {
echo $authResponse->completionData->user->personalNumber;
return true; //Authorized
}