1. Go to this page and download the library: Download jgroup/laravel-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/ */
jgroup / laravel-bank-id example snippets
// routes/web.php
use App\Models\User;
use Illuminate\Http\Response;
use Jgroup\BankID\Facades\BankID;
use Illuminate\Support\Facades\Route;
Route::post('/auth/bankid', function(Request $request) {
return BankID::auth(
$request->getClientIp(),
'Text to display to the user'
);
});
Route::post('/auth/bankid/collect', function(Request $request) {
$response = BankID::collect();
if ($response->getStatus() === 'complete') {
$personalNumber = $response->getCollectResult()
->getCompletionResult()
->getPersonalNumber();
$user = User::where('pnr', $personalNumber)->firstOrFail();
// clear session transaction when completed
BankID::setSessionTransaction(null);
Auth::login($user);
}
return $response;
});
// routes/web.php
use Illuminate\Http\Response;
use Illuminate\Validation\Rule;
use Jgroup\BankID\Facades\BankID;
use Jgroup\BankID\Rules\SignCompleted;
use Illuminate\Support\Facades\Route;
const SIGN_TEXT = 'Text to sign';
Route::post('/bankid/collect', function(Request $request) {
return BankID::collect();
});
Route::post('/submit-form/sign', function(Request $request) {
return BankID::sign(
$request->getClientIp(),
SIGN_TEXT
);
});
Route::post('/submit-form', function(Request $request) {
$request->validate([
// transactionId should be sent along with the form data
'transactionId' => [
new SignCompleted(SIGN_TEXT)
],
// your validation rules
]);
// logic for handling form submission
// clear session transaction if submission was processed successfully
BankID::setSessionTransaction(null);
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.