PHP code example of softc / evotor-certificates

1. Go to this page and download the library: Download softc/evotor-certificates 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/ */

    

softc / evotor-certificates example snippets




oftC\Evotor\Certificates\Api\Domain\CertificateActivate;
use SoftC\Evotor\Certificates\Api\Domain\CertificateCreate;
use SoftC\Evotor\Certificates\Api\Domain\CertificatePay;
use SoftC\Evotor\Certificates\Api\Entities\CertificateType;
use SoftC\Evotor\Certificates\Api\Enums\EntityStatus;
use SoftC\Evotor\Certificates\Api\Requests\CertificatesActivateRequest;
use SoftC\Evotor\Certificates\Api\Requests\CertificatesCreateRequest;
use SoftC\Evotor\Certificates\Api\Requests\CertificatesPayRequest;

$token = 'api-token';
$client = new Client($token);

// получить виды сертификатов
$types = $client->SelectTypes();
// оставляем только активные виды сертификатов с указанным номиналом
$types = array_filter($types, static fn(CertificateType $item) => $item->status === EntityStatus::ACTIVE && $item->value > 0);

// используем первый вид
$type = $types[0];

// создаем сертификат с произвольным номером
$number = bin2hex(random_bytes(16));
$certs = $client->CreateCertificates(new CertificatesCreateRequest([
    new CertificateCreate($number, $type->uuid)
]));

// получаем ИД созданного сертификата
$uuid = $certs[0];

// также можно найти сертификат по номеру
// $cert = $client->GetCertificateByNumber($number);

// активируем сертификат
$client->ActivateCertificates(new CertificatesActivateRequest(
    bin2hex(random_bytes(18)),
    [
        new CertificateActivate($uuid, $type->uuid)
    ]
));

// гасим сертификат
$client->PayCertificates(new CertificatesPayRequest(
    bin2hex(random_bytes(18)),
    [
        new CertificatePay($uuid, $type->value ?? 0)
    ]
));