alexeevdv/sumsub-client
Laravel/PHP client for Sumsub API integration. Provides simple requests and helpers to manage applicants and verifications, submit documents, and handle webhook callbacks/signature validation, making it easier to connect your app to Sumsub KYC/AML workflows.
Installation
composer require alexeevdv/sumsub-client
Add the package to config/app.php under providers (if not auto-discovered):
Alexeevdv\SumsubClient\SumsubServiceProvider::class,
Configuration Publish the config file:
php artisan vendor:publish --provider="Alexeevdv\SumsubClient\SumsubServiceProvider" --tag=config
Update .env with your API key and secret key:
SUMSUB_API_KEY=your_api_key_here
SUMSUB_SECRET_KEY=your_secret_key_here
SUMSUB_API_URL=https://api.sumsub.com
First Use Case: Verify a User
use Alexeevdv\SumsubClient\Facades\Sumsub;
$user = Sumsub::verifyUser([
'email' => 'user@example.com',
'firstName' => 'John',
'lastName' => 'Doe',
'document' => [
'type' => 'PASSPORT',
'file' => fopen('/path/to/passport.jpg', 'r'),
],
]);
User Verification Flow
$verification = Sumsub::verifyUser($userData);
$token = $verification->getToken(); // Redirect user to Sumsub for completion
$status = Sumsub::getVerificationStatus($verification->getId());
$result = Sumsub::getVerificationResult($verification->getId());
if ($result->isSuccess()) {
// Grant access
}
Webhook Integration
verification.completed):
public function handleSumsubWebhook(Request $request) {
$event = Sumsub::parseWebhook($request->getContent());
// Process event (e.g., update DB, send notifications)
}
Document Uploads
$file = fopen('/path/to/document.pdf', 'r');
$upload = Sumsub::uploadDocument($file, 'user@example.com');
$user->update(['verified_at' => now()]);
VerifyUserJob::dispatch($verificationId)->delay(now()->addMinutes(5));
try {
$result = Sumsub::getVerificationResult($id);
} catch (\Alexeevdv\SumsubClient\Exceptions\SumsubException $e) {
Log::error("Sumsub error: " . $e->getMessage());
return back()->withErrors(['verification' => 'Failed']);
}
API Key Exposure
.env or hardcode keys. Use Laravel’s .env or a secure secrets manager.File Upload Limits
if ($request->file('document')->getSize() > 10 * 1024 * 1024) {
throw new \Exception('File too large');
}
Webhook Verification
$isValid = Sumsub::verifyWebhookSignature(
$request->getContent(),
$request->header('X-Sumsup-Signature')
);
Rate Limiting
use Symfony\Component\HttpClient\RetryableHttpClient;
$client = new RetryableHttpClient(
new \Symfony\Component\HttpClient\CurlHttpClient(),
[
'max_retries' => 3,
'delay_factor' => 2,
]
);
SUMSUB_DEBUG=true in .env to log raw API responses.401 Unauthorized: Check API keys/secrets.422 Unprocessable Entity: Validate request data (e.g., missing firstName).500 Server Error: Contact Sumsub support (may be their issue).Custom Verification Logic Extend the client by creating a decorator:
class CustomSumsub extends \Alexeevdv\SumsubClient\SumsubClient {
public function customVerify($data) {
$data['customField'] = 'value';
return parent::verifyUser($data);
}
}
Bind it in AppServiceProvider:
$this->app->bind(\Alexeevdv\SumsubClient\SumsubClient::class, function ($app) {
return new CustomSumsub($app['config']['sumsub']);
});
Mocking for Tests Use Laravel’s HTTP mocking:
$this->mock(\Alexeevdv\SumsubClient\SumsubClient::class)
->shouldReceive('verifyUser')
->andReturn(new \Alexeevdv\SumsubClient\Models\Verification(['id' => 123]));
Local Testing
Use Sumsub’s sandbox environment (replace SUMSUB_API_URL with https://sandbox.sumsub.com).
How can I help you explore Laravel packages today?