PHP code example of asciisd / kyc-core

1. Go to this page and download the library: Download asciisd/kyc-core library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asciisd / kyc-core example snippets


// Webhook endpoints (no authentication  // Main webhook handler
POST   /api/kyc/webhook/callback        // Alternative webhook endpoint
GET    /api/kyc/verification/complete   // Verification completion callback
GET    /api/kyc/health                  // Health check endpoint

// Backward compatibility (without /api prefix)
POST   /kyc/webhook
POST   /kyc/webhook/callback
GET    /kyc/verification/complete
GET    /kyc/health

    use Asciisd\KycCore\Traits\HasKycVerification;

    class User extends Model
    {
        use HasKycVerification;
    }
    

use Asciisd\KycCore\Facades\Kyc;
use Asciisd\KycCore\DTOs\KycVerificationRequest;

// Create a verification request
$request = new KycVerificationRequest(
    email: '[email protected]',
    country: 'US',
    language: 'en'
);

// Start verification
$response = Kyc::createVerification($user, $request);

// Process webhook
$webhookResponse = Kyc::processWebhook($payload, $headers);

use Asciisd\KycCore\Traits\HasKycVerification;

class User extends Model
{
    use HasKycVerification;

    // Your model code...
}

// Check if user can start KYC
if ($user->canStartKyc()) {
    // Start verification process
}

// Check if user has completed KYC
if ($user->hasCompletedKyc()) {
    // User is verified
}

// Get current KYC status
$status = $user->getKycStatus();

use Asciisd\KycCore\Events\VerificationStarted;
use Asciisd\KycCore\Events\VerificationCompleted;
use Asciisd\KycCore\Events\VerificationFailed;

// Listen for events
Event::listen(VerificationStarted::class, function ($event) {
    Log::info('Verification started for user: ' . $event->user->id);
});

use Asciisd\KycCore\Enums\KycStatusEnum;

// Check status properties
if ($status->isCompleted()) {
    // Handle completed verification
}

if ($status->needsAction()) {
    // User needs to take action
}

// Get human-readable label
$label = $status->label(); // "KYC Completed"
$color = $status->color(); // "green"

interface KycDriverInterface
{
    // Core verification methods
    public function createVerification(Model $user, KycVerificationRequest $request): KycVerificationResponse;
    public function retrieveVerification(string $reference): KycVerificationResponse;
    public function processWebhook(array $payload, array $headers = []): KycVerificationResponse;
    public function downloadDocuments(Model $user, string $reference): array;

    // Driver information
    public function getName(): string;
    public function isEnabled(): bool;
    public function getCapabilities(): array;

    // 🆕 NEW: Provider-specific status mapping
    public function mapEventToStatus(string $event): KycStatusEnum;
}

// ShuftiPro Driver
public function mapEventToStatus(string $event): KycStatusEnum
{
    return match ($event) {
        'verification.completed' => KycStatusEnum::Completed,
        'verification.declined' => KycStatusEnum::Rejected,
        'verification.pending' => KycStatusEnum::InProgress,
        // ... ShuftiPro-specific events
    };
}

// Jumio Driver (example)
public function mapEventToStatus(string $event): KycStatusEnum
{
    return match ($event) {
        'SUCCESS' => KycStatusEnum::Completed,
        'ERROR' => KycStatusEnum::VerificationFailed,
        'INITIATED' => KycStatusEnum::InProgress,
        // ... Jumio-specific events
    };
}

// config/kyc.php
return [
    'default_driver' => 'shuftipro',
    'drivers' => [
        'shuftipro' => [
            'enabled' => true,
            'class' => 'Asciisd\\KycShuftiPro\\Drivers\\ShuftiProDriver',
            // ...
        ],
    ],
    'settings' => [
        '
bash
php artisan vendor:publish --tag=kyc-config
bash
php artisan vendor:publish --tag=kyc-migrations
bash
php artisan migrate
bash
    php artisan vendor:publish --tag=kyc-migrations
    php artisan migrate