ax7-cmd/sumsub
PHP example project for integrating Sumsub verification: install via Composer, set SUMSUB_SECRET_KEY and SUMSUB_APP_TOKEN, then run example.php. Demonstrates authorization, creating applicants, uploading ID documents, checking status, and generating SDK access tokens.
Installation
composer require ax7-cmd/sumsub
Publish the config file:
php artisan vendor:publish --provider="Ax7\Sumsub\SumsubServiceProvider"
Configure .env with your SumSub API credentials:
SUMSUB_API_KEY=your_api_key_here
SUMSUB_SECRET_KEY=your_secret_key_here
First Use Case: Verification Flow Initialize the client in a service or controller:
use Ax7\Sumsub\Facades\Sumsub;
$verification = Sumsub::verification()->create([
'token' => 'user_unique_token',
'flowId' => 'id_doc', // or 'id_video', 'id_phone', etc.
'email' => 'user@example.com',
'phone' => '+1234567890', // optional
'firstName' => 'John',
'lastName' => 'Doe',
]);
Key Files to Review
config/sumsub.php: API endpoints, default settings.src/Facades/Sumsub.php: Main facade for quick access.src/Exceptions/: Custom exceptions (e.g., SumsubException).Initiate Verification Use the facade or service container to trigger a flow:
$verification = Sumsub::verification()->create([
'token' => Str::uuid()->toString(),
'flowId' => 'id_doc',
// ...other fields
]);
Store the token in your DB to track status later.
Poll for Status Check verification status periodically (e.g., via queue job):
$status = Sumsub::verification()->getStatus($token);
Handle states like pending, completed, or failed.
Webhook Handling
Configure a route to handle SumSub webhooks (e.g., /sumsub/webhook):
Route::post('/sumsub/webhook', [SumsubWebhookController::class, 'handle']);
Use the SumsubWebhook class to validate and parse payloads:
use Ax7\Sumsub\SumsubWebhook;
public function handle(Request $request) {
$webhook = new SumsubWebhook($request->getContent());
if ($webhook->isValid()) {
$event = $webhook->getEvent();
// Process event (e.g., update DB, send notifications)
}
}
Document Upload/Download For document flows, handle file attachments:
// Upload a document (e.g., passport)
$filePath = 'path/to/document.pdf';
$document = Sumsub::document()->upload($filePath, $token);
// Download a verified document
$file = Sumsub::document()->download($documentId);
VerificationsCheckJob).VerificationCompleted) for decoupled handling.verified() middleware:
public function handle($request, Closure $next) {
if (!Sumsub::verification()->isVerified($request->user()->token)) {
abort(403);
}
return $next($request);
}
Token Management
user_id_flow_type).Webhook Validation
secretKey.SumsubWebhook::isValid() before processing.Rate Limits
Flow Expiry
expireIn in config).Enable Logging
Add to config/sumsub.php:
'debug' => env('SUMSUB_DEBUG', false),
Logs will appear in storage/logs/laravel.log.
API Response Inspection
Use Sumsub::getLastResponse() to debug raw API responses:
$response = Sumsub::verification()->create([...]);
if ($response->failed()) {
logger()->error(Sumsub::getLastResponse());
}
Custom Flows
Extend the Flow class to add domain-specific logic:
namespace App\Services;
use Ax7\Sumsub\Flow;
class CustomFlow extends Flow {
public function __construct() {
parent::__construct('custom_flow_id');
}
public function getAdditionalData() {
return ['custom_field' => 'value'];
}
}
Webhook Extensions
Override the SumsubWebhook class to add custom event handlers:
namespace App\Services;
use Ax7\Sumsub\SumsubWebhook;
class CustomWebhook extends SumsubWebhook {
protected function handleEvent($event) {
if ($event['type'] === 'verification.completed') {
// Custom logic
}
}
}
Mocking for Tests
Use the SumsubMock trait in tests:
use Ax7\Sumsub\Tests\SumsubMock;
class VerificationTest {
use SumsubMock;
public function test_verification_flow() {
$this->mockSumsubResponse('verification.create', ['token' => 'test_token']);
// Test logic
}
}
config/sumsub.php:
'endpoints' => [
'verification' => 'https://custom-api.sumsub.com/verification',
],
'default_flow_id' => 'id_doc',
How can I help you explore Laravel packages today?