dbp/relay-authentic-documents-bundle
Installation Add the bundle via Composer (if available in a public registry or via private setup):
composer require dbp/relay-authentic-documents-bundle
Register the bundle in config/app.php under providers:
DigitalBlueprint\RelayAuthenticDocumentsBundle\RelayAuthenticDocumentsBundle::class,
Configuration Publish the bundle’s config and migrations:
php artisan vendor:publish --provider="DigitalBlueprint\RelayAuthenticDocumentsBundle\RelayAuthenticDocumentsBundle" --tag="config"
php artisan migrate
Review config/relay_authentic_documents.php for required API keys, endpoints, or service configurations.
First Use Case: Document Upload Use the bundle’s service to authenticate and upload a document via the Relay API:
use DigitalBlueprint\RelayAuthenticDocumentsBundle\Service\DocumentService;
$documentService = app(DocumentService::class);
$response = $documentService->uploadDocument(
$filePath, // Path to local file
['metadata' => ['user_id' => 123]] // Optional metadata
);
Check the documentation for the exact method signatures and expected payloads.
Pre-Upload Validation Validate documents before submission using the bundle’s validator:
use DigitalBlueprint\RelayAuthenticDocumentsBundle\Validator\DocumentValidator;
$validator = new DocumentValidator();
$errors = $validator->validate($filePath, ['type' => 'passport']);
if ($errors->count() > 0) {
// Handle validation errors
}
Integration with Laravel Storage Store processed documents in Laravel’s filesystem (e.g., S3) while keeping Relay’s metadata:
$documentService->uploadAndStore(
$filePath,
'public_documents',
['relay_id' => $response['id']]
);
Event-Driven Extensions
Listen for document events (e.g., DocumentUploaded) to trigger side effects:
use DigitalBlueprint\RelayAuthenticDocumentsBundle\Events\DocumentUploaded;
DocumentUploaded::subscribe(function ($event) {
// Send notification, log, or update a CRM
});
API Wrapper Usage Use the bundle’s HTTP client to interact with Relay’s API directly:
$client = app(\DigitalBlueprint\RelayAuthenticDocumentsBundle\Client\RelayClient::class);
$documents = $client->listDocuments(['user_id' => 123]);
DocumentService or RelayClient into controllers/services.RelayClient in tests to avoid hitting the real API:
$this->app->instance(RelayClient::class, Mockery::mock(RelayClient::class));
API Rate Limits The bundle does not handle Relay’s rate limits by default. Implement a retry mechanism with exponential backoff:
use Symfony\Component\HttpClient\RetryableHttpClient;
$client = new RetryableHttpClient(
$baseClient,
[
'max_retries' => 3,
'delay' => 100,
'multiplier' => 2,
'statuses' => [429],
]
);
File Size Limits Relay may reject large files. Validate file sizes before upload:
if ($file->getSize() > 10 * 1024 * 1024) { // 10MB
throw new \RuntimeException('File too large');
}
Metadata Handling
Relay’s API may enforce strict metadata schemas. Use the bundle’s DocumentMetadata class to ensure consistency:
$metadata = new \DigitalBlueprint\RelayAuthenticDocumentsBundle\Model\DocumentMetadata();
$metadata->setUserId(123)->setType('passport');
Archived Status The bundle is not production-ready. Expect breaking changes. Fork and extend if critical for your project.
RelayClient to log requests/responses:
$client->setDebug(true);
4XX for validation errors). Handle them explicitly:
try {
$response = $documentService->uploadDocument($filePath);
} catch (\DigitalBlueprint\RelayAuthenticDocumentsBundle\Exception\RelayValidationException $e) {
// Handle validation errors
}
Custom Document Types
Extend the DocumentType enum or create a custom validator for niche document types.
Webhook Integration
Implement a webhook listener for Relay’s document events (e.g., document.processed):
use DigitalBlueprint\RelayAuthenticDocumentsBundle\Events\RelayWebhookReceived;
RelayWebhookReceived::listen(function ($event) {
// Process webhook payload
});
Storage Adapters Override the default storage handler to support custom backends (e.g., Google Cloud Storage):
$documentService->setStorageAdapter(new CustomStorageAdapter());
Testing Relay Mocks
Use the bundle’s RelayClientMock for unit tests:
$mock = new RelayClientMock();
$mock->shouldReceive('upload')->once()->andReturn(['id' => '123']);
```markdown
## Additional Notes for Laravel Developers
- **Service Container Binding**: Bind custom implementations of `RelayClientInterface` for testing or feature extensions.
- **Queue Jobs**: Offload document processing to Laravel queues to avoid timeouts:
```php
Dispatch(new ProcessDocumentJob($filePath, $metadata));
translations config or use Laravel’s json locale files.How can I help you explore Laravel packages today?