PHP code example of qurban-ali / pescheck-wrapper

1. Go to this page and download the library: Download qurban-ali/pescheck-wrapper 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/ */

    

qurban-ali / pescheck-wrapper example snippets




use QurbanAli\PescheckWrapper\Client;

// Basic initialization with default environment (staging)
$client = new Client([
    'email' => 'your-email',
    'password' => 'your-password',
]);

// Initialize with a specific environment
$client = new Client([
    'email' => 'your-email',
    'password' => 'your-password',
    'environment' => 'production', // Options: 'production', 'staging', 'testing', 'development'
]);

// Or specify a custom base URI
$client = new Client([
    'email' => 'your-email',
    'password' => 'your-password',
    'base_uri' => 'https://your-custom-api-endpoint.com/api'
]);

// Switch to production
$client->getConfig()->setEnvironment('production');

// Switch to testing
$client->getConfig()->setEnvironment('testing');

// Get available environments
$environments = $client->getConfig()->getAvailableEnvironments();
// Returns: ['production', 'staging', 'testing', 'development']

// Add a custom environment
$client->getConfig()->addEnvironment('local', 'http://localhost:8000/api');
$client->getConfig()->setEnvironment('local');

// Login to get access token (automatically stored in the client)
$authResponse = $client->auth()->login();

// If you need to refresh the token
$refreshResponse = $client->auth()->refresh();

// Get all available packages
$packages = $client->packages()->all();

// Get a specific package
$package = $client->packages()->get('package-id');

// Create a new screening
$screening = $client->screenings()->create([
    'email' => '[email protected]',
    'first_name' => 'John',
    'last_name' => 'Doe',
    'package_id' => 'package-uuid'
]);

// Get all screenings (with optional filters)
$allScreenings = $client->screenings()->all([
    'status' => 'completed',
    'page' => 1
]);

// Get a specific screening
$screening = $client->screenings()->get('screening-id');

// Get documents for a screening
$documents = $client->screenings()->getDocuments('screening-id');

// Get all divisions
$divisions = $client->divisions()->all();

// Get all available checks
$checks = $client->checks()->all();



use QurbanAli\PescheckWrapper\Exception\AuthenticationException;
use QurbanAli\PescheckWrapper\Exception\RequestException;
use QurbanAli\PescheckWrapper\Exception\InvalidArgumentException;

try {
    $client->auth()->login();
    $screenings = $client->screenings()->all();
} catch (AuthenticationException $e) {
    // Handle authentication errors
    echo "Authentication failed: " . $e->getMessage();
} catch (RequestException $e) {
    // Handle API request errors
    echo "API request failed: " . $e->getMessage();
} catch (InvalidArgumentException $e) {
    // Handle invalid arguments
    echo "Invalid argument: " . $e->getMessage();
} catch (\Exception $e) {
    // Handle other exceptions
    echo "Error: " . $e->getMessage();
}

// Paginated responses implement IteratorAggregate and Countable
$screenings = $client->screenings()->all();

// Get total count
$total = $screenings->getCount();

// Iterate through results
foreach ($screenings as $screening) {
    echo $screening['id'] . "\n";
}

// Get all results as array
$results = $screenings->getResults();

// Check if there are more pages
$nextPageUrl = $screenings->getNext();
$previousPageUrl = $screenings->getPrevious();