PHP code example of kloutit / kloutit-sdk-php

1. Go to this page and download the library: Download kloutit/kloutit-sdk-php 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/ */

    

kloutit / kloutit-sdk-php example snippets



Kloutit\Configuration as KloutitConfiguration;
use Kloutit\Api\KloutitCaseApi;
use Kloutit\Model\ClientsCreateCaseRequestDto;
use Kloutit\Model\CaseSector;
use Kloutit\Model\Currencies;

$apiKey = 'YOUR_API_KEY';
$client = new GuzzleHttp\Client();

// Configure API key authentication
$config = KloutitConfiguration::getDefaultConfiguration()
    ->setApiKey($apiKey);

// Create KloutitCaseApi instance
$kloutitCase = new KloutitCaseApi($client, $config);

try {
    echo "Creating new case\n";
    $newCaseBody = new ClientsCreateCaseRequestDto([
        'expedientNumber' => 'UNIQUE_CASE_ID',
        'sector' => CaseSector::TECHNOLOGY,
        'chargebackAmount' => [
            'value' => 100,
            'currency' => Currencies::EUR,
        ],
        'chargebackDate' => '2025-01-01T10:00:00.000Z',
        'reasonCode' => '4855',
        // Additional fields based on sector 


// Configure API key authentication
$config = KloutitConfiguration::getDefaultConfiguration()
    ->setApiKey('YOUR_API_KEY');

// Create KloutitCaseApi instance
$kloutitCase = new KloutitCaseApi(new GuzzleHttp\Client(), $config);

$expedientNumber = 'CASE_EXPEDIENT_NUMBER';

// Update case with additional information
$kloutitCaseBody = new UpdateCaseParams([
    'sector' => CaseSector::TECHNOLOGY,
    'filialIdentifier' => 'B12345678', // If you do not have filials in your organization, leave this field empty
    'transactionDate' => (new DateTime())->format(DateTime::ATOM), // UTC date in ISO 8601 format, e.g: '2025-01-01T10:00:00.000Z'
    'bankName' => 'Sample Bank Name',
    'cardBrand' => 'Sample card brand',
    'last4Digits' => '1234',
    'is3DSPurchase' => true,
    'purchaseDate' => '2025-01-01T10:00:00.000Z',
    'purchaseAmount' => [
        'currency' => Currencies::EUR,
        'value' => 100
    ],
    'isChargeRefundable' => false,
    'customerName' => 'PHP SDK sample',
    'customerEmail' => '[email protected]',
    'customerPhone' => '612345678',
    'additionalInfo' => 'Some optional additional info',
    'communications' => [
        [
            'sender' => 'Sender name',
            'content' => 'Communication content',
            'date' => '2025-01-01T10:00:00.000Z',
        ]
    ],
    'product' => 'Sample product',
    'service' => 'Sample Service Name',
    'shippingCity' => 'Barcelona',
    'shippingProvince' => 'Barcelona',
    'shippingPostalCode' => '08000',
    'deliveryConfirmation' => true,
    'shippingDate' => '2025-01-01T10:00:00.000Z',
    'deliveryDate' => '2025-01-01T10:00:00.000Z',
    'deliveryCompany' => 'Sample delivery company',
]);

try {
    echo "Updating existing case\n";
    $updatedCase = $kloutitCase->updateCase($expedientNumber, $kloutitCaseBody);
    echo "Case updated successfully!\n";
} catch (Exception $e) {
    echo "Error updating case: " . $e->getMessage() . "\n";
    throw $e;
}


use Kloutit\Model\FileCategoryEnum;

try {
    echo "Uploading file to case\n";
    $file = new SplFileObject('/path/to/your/file.pdf');
    $uploadedFile = $kloutitCase->uploadFile(
        'CASE_EXPEDIENT_NUMBER',
        $file,
        FileCategoryEnum::INVOICE
    );
    echo "File uploaded successfully!\n";
} catch (Exception $e) {
    echo "Error uploading file: " . $e->getMessage() . "\n";
    throw $e;
}


try {
    echo "Checking case completeness\n";
    $caseStatus = $kloutitCase->checkCase('CASE_EXPEDIENT_NUMBER');
    echo "Case status retrieved successfully!\n";
} catch (Exception $e) {
    echo "Error checking case: " . $e->getMessage() . "\n";
    throw $e;
}


try {
    echo "Submitting completed case\n";
    $kloutitCase->submitCompletedCase('CASE_EXPEDIENT_NUMBER');
    echo "Case submitted successfully!\n";
} catch (Exception $e) {
    echo "Error submitting case: " . $e->getMessage() . "\n";
    throw $e;
}


try {
    echo "Verifying webhook event\n";
    $kloutitCase->verifyEvent($webhookEventData);
    echo "Event verified successfully!\n";
} catch (Exception $e) {
    echo "Event verification failed: " . $e->getMessage() . "\n";
    throw $e;
}


try {
    echo "Downloading case defense\n";
    $defenseDocument = $kloutitCase->downloadCaseDefense(
        'PDF', // Format: PDF, DOCX, etc.
        'CASE_EXPEDIENT_NUMBER'
    );
    echo "Defense downloaded successfully!\n";
} catch (Exception $e) {
    echo "Error downloading defense: " . $e->getMessage() . "\n";
    throw $e;
}


Kloutit\Configuration as KloutitConfiguration;
use Kloutit\Api\KloutitCaseApi;
use Kloutit\Model\ClientsCreateCaseRequestDto;
use Kloutit\Model\UpdateCaseParams;
use Kloutit\Model\CaseSector;
use Kloutit\Model\Currencies;
use Kloutit\Model\FileCategoryEnum;

// Configure API
$config = KloutitConfiguration::getDefaultConfiguration()
    ->setApiKey('YOUR_API_KEY');
$kloutitCase = new KloutitCaseApi(new GuzzleHttp\Client(), $config);

try {
    // 1. Create a new case
    $newCaseBody = new ClientsCreateCaseRequestDto([
        'expedientNumber' => 'CASE_001',
        'sector' => CaseSector::TECHNOLOGY,
        'chargebackAmount' => ['value' => 299.99, 'currency' => Currencies::EUR],
        'chargebackDate' => '2025-01-15T09:00:00.000Z',
        'reasonCode' => '4855'
    ]);
    $newCase = $kloutitCase->createCase($newCaseBody);
    
    // 2. Upload supporting documents
    $invoiceFile = new SplFileObject('/path/to/invoice.pdf');
    $kloutitCase->uploadFile('CASE_001', $invoiceFile, FileCategoryEnum::INVOICE);
    
    // 3. Update case with additional information
    $updateBody = new UpdateCaseParams([
        'purchaseDate' => '2025-01-10T14:30:00.000Z',
        'purchaseAmount' => ['value' => 299.99, 'currency' => Currencies::EUR],
        'service' => 'Premium Software License',
        // ... other sector-specific fields
    ]);
    $kloutitCase->updateCase('CASE_001', $updateBody);
    
    // 4. Check case completeness
    $caseStatus = $kloutitCase->checkCase('CASE_001');
    
    // 5. Submit completed case for defense generation
    if (empty($caseStatus)) {
        $kloutitCase->submitCompletedCase('CASE_001');
    }
    
    // 6. Download defense when ready
    $defense = $kloutitCase->downloadCaseDefense('PDF', 'CASE_001');
    
    echo "Workflow completed successfully!\n";
    
} catch (Exception $e) {
    echo "Workflow error: " . $e->getMessage() . "\n";
    throw $e;
}

composer