PHP code example of seisigmasrl / dgii-rnc-validator

1. Go to this page and download the library: Download seisigmasrl/dgii-rnc-validator 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/ */

    

seisigmasrl / dgii-rnc-validator example snippets


use Seisigma\DgiiRncValidator\DgiiRncValidator;

// 132620951 is a valid RNC
$validatedRnc = DgiiRncValidator::check("132620951");
var_dump($validatedRnc);

// array(4) {
//    ["rnc"]=> string(9) "132620951"
//    ["name"]=> string(29) "KOI CORPORATION BY SAIKOV SRL"
//    ["commercial_name"]=> string(25) "KOI CORPORATION BY SAIKOV"
//    ["status"]=> string(6) "ACTIVO"
// }

// 123456789 is not registered in DGII
$validatedRnc = DgiiRncValidator::check("123456789");
var_dump($validatedRnc); // bool(false)

use Seisigma\DgiiRncValidator\DgiiRncValidator;

$validatedRnc = DgiiRncValidator::validateRNC("132620951");
var_dump($validatedRnc); // bool(true) - valid 9-digit RNC format

$validatedRnc = DgiiRncValidator::validateRNC("12345678901");
var_dump($validatedRnc); // bool(true) - valid 11-digit Cedula format

$validatedRnc = DgiiRncValidator::validateRNC("12345");
var_dump($validatedRnc); // bool(false) - invalid format

use Seisigma\DgiiRncValidator\DgiiRncValidator;
use Seisigma\DgiiRncValidator\helpers\Types;

// 9-digit identifier = RNC (business)
$rncType = DgiiRncValidator::rncType("132620951");
var_dump($rncType); // enum(Types::RNC)

// 11-digit identifier = Cedula (person)
$rncType = DgiiRncValidator::rncType("04800009577");
var_dump($rncType); // enum(Types::CEDULA)

// Invalid format returns false
$rncType = DgiiRncValidator::rncType("12345");
var_dump($rncType); // bool(false)

var_dump(Types::RNC->toString()) // string(RNC)

var_dump(Types::RNC->toCode()) // string(01)

use Seisigma\DgiiRncValidator\helpers\Status;

// Convert a string to Status enum
$status = Status::fromString("ACTIVO");
var_dump($status); // enum(Status::ACTIVE)

// Get the string representation
var_dump(Status::ACTIVE->toString()); // string(6) "ACTIVO"

use Seisigma\DgiiRncValidator\helpers\Utils;

$results = Utils::getNumbers("abc123456");
var_dump($results); // string(6) "123456"

$results = Utils::getNumbers("asdfasdfs");
var_dump($results); // bool(false)

use Seisigma\DgiiRncValidator\helpers\Utils;

$result = Utils::luhnAlgorithmValidation("79927398713");
var_dump($result); // bool(true)

$result = Utils::luhnAlgorithmValidation("79927398715");
var_dump($result); // bool(false)

use Seisigma\DgiiRncValidator\helpers\Utils;

$result = Utils::validateDominicanCitizenId("04800009575");
var_dump($result); // bool(true)

$result = Utils::validateDominicanCitizenId("04800009577");
var_dump($result); // bool(false)

use Seisigma\DgiiRncValidator\DgiiRncValidator;
use Seisigma\DgiiRncValidator\Exceptions\DgiiServiceException;

try {
    $result = DgiiRncValidator::check("132620951");
} catch (InvalidArgumentException $e) {
    // Invalid RNC format provided
} catch (DgiiServiceException $e) {
    // Service-related error (connection failed, access denied, timeout, etc.)
    echo $e->getMessage();
}