Integration Guide on PHP
To integrate your PHP web application with the Lacuna Scanner Service, follow the steps in this article.
Before you start, see the integration overview.
First, add the lacuna/scanner-client package to your project.
With the endpoint and the API Key at hand, create a ScannerClient:
$options = new ScannerOptions();
$options->endpoint = '...';
$options->apiKey = '...';
$scanner = new ScannerClient($options);
Call the createScanSession($returnUrl) method, passing the returnUrl, to start a session:
$createResponse = $scanner->createScanSession("https://your-return-url/");
Use the value returned in the redirectUrl field to redirect the user on the frontend:
location.href = '<?= $createResponse->redirectUrl ?>';
When you detect that the user has returned to your site (look for the scanSessionId argument in the URL), call the getScanSession($scanSessionId) method to get the scanned documents:
$scanSession = $scanner->getScanSession($scanSessionId);
if ($scanSession->result == ScanSessionResults::SUCCESS) {
$document = $scanSession->documents[0];
$stream = $document->openRead();
file_put_contents('...', $stream);
$stream->close();
}
Multifile sessions
You can let the user scan multiple documents. To do so, pass true as the second parameter, multifile, when creating the session:
$response = $scanner->createScanSession("https://your-return-url/", true);
At the end of the process, instead of taking only the first document, iterate over the list of scanned documents:
$scanSession = $scanner->getScanSession($scanSessionId);
if ($scanSession->result == ScanSessionResults::SUCCESS) {
foreach ($scanSession->documents as $document) {
// ...
}
}