Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Bank Id Laravel Package

dimafe6/bank-id

Laravel package for working with BankID: send authentication/sign requests, collect results, and handle statuses. Includes configurable client setup, helpers, and examples for integrating BankID flows into your PHP app.

View on GitHub
Deep Wiki
Context7

Bank-ID

Library for connect Swedish BankID to your application. This library implements BankID API V5. If your needed library for a BankID API V4 please use version 1.*

codecov Latest Stable Version Latest Unstable Version Total Downloads license Build Status

Requirements

Install

Via Composer

$ composer require dimafe6/bank-id

Usage

Either you let the user enter their personal number and pass to BankID or you only pass the order ref and receive the personal number from the response from BankID.

<?php
// 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',
    ]
);
Example with personal number
// 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';
}
Example without personal number
// 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
}

Testing

  1. Copy phpunit.xml.dist to phpunit.xml
$ cp phpunit.xml.dist phpunit.xml
  1. Execute
$ ./vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity