Search by

tusdatos-dev / tusdatos-sdk

AndersonC

SDK to consume the Tusdatos background check API

Package info

bitbucket.org/anderson1405/tusdatos-sdk

pkg:composer/tusdatos-dev/tusdatos-sdk

Statistics

Installs: 609

Dependents: 0

Suggesters: 0

dev-main 2026-10-22 14:32 UTC

README

PHP SDK to consume the Tusdatos background check API, built on top of placetopay/tangram.

Requirements

  • PHP 8.2 or higher
  • ext-json and ext-mbstring

Installation

Add the PlacetoPay repository to your composer.json:

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://repository.placetopay.com"
        }
    ]
}

Then install the package:

composer require tusdatos-dev/tusdatos-sdk

Configuration

use Placetopay\TusdatosSdk\Gateway;

$gateway = new Gateway([
    'url' => 'https://docs.tusdatos.co/api/',
    'username' => 'your-username',
    'password' => 'your-password',
]);
SettingTypeRequiredDefaultDescription
urlstringYesBase URL of the Tusdatos API.
usernamestringYesTusdatos username, sent with HTTP basic authentication.
passwordstringYesTusdatos password, sent with HTTP basic authentication.
timeoutint\|floatNo30Seconds to wait for Tusdatos before failing the request.
simulatorModeboolNofalseUses the built-in simulator instead of the real API.
providerNamestringNoTusdatosName used to identify the provider in the logs.
clientGuzzleHttp\ClientInterfaceNoGuzzle client or simulatorCustom HTTP client.
loggerarrayNovia (Psr\Log\LoggerInterface, required), name, path, debug.

Invalid settings throw PlacetoPay\Tangram\Exceptions\InvalidSettingException.

When a logger is configured, every request, response and error is logged and the Authorization header is always masked.

Operations

MethodTransactionTusdatos endpointResult getter
launch()LaunchTransactionPOST launchgetLaunchData()
checkStatus()CheckStatusTransactionGET results/{jobId}getCheckStatusData()
formatJson()FormatJsonTransactionGET report_json/{id}getFormatJsonData()
queryDocumentStatus()StatusDocumentTransactionPOST launch/verifygetQueryDocumentData()

The result getters return the decoded Tusdatos payload exactly as the provider sends it, or an empty array when the operation fails.

use Placetopay\TusdatosSdk\Entities\CheckStatusTransaction;
use Placetopay\TusdatosSdk\Entities\FormatJsonTransaction;
use Placetopay\TusdatosSdk\Entities\LaunchTransaction;

$launch = $gateway->launch(new LaunchTransaction([
    'type' => 'CC',
    'number' => '1032456789',
    'expeditionDate' => '01/12/2017',
]));

$status = $gateway->checkStatus(new CheckStatusTransaction($launch->getLaunchData()['jobid']));

if ($status->getCheckStatusData()['estado'] === 'finalizado') {
    $report = $gateway->formatJson(new FormatJsonTransaction($status->getCheckStatusData()['id']));
}

Handling failures

Provider failures never throw. They are reported through the transaction, so the integrating system can log them:

$report = $gateway->formatJson(new FormatJsonTransaction($id));

if (! $report->status()->isSuccessful()) {
    $logger->warning($report->status()->message(), [
        'reason' => $report->status()->reason(),
        'httpStatusCode' => $report->httpStatusCode(),
    ]);
}
ScenarioReason codeHTTP status codeMessage example
Successful response00200Background check report retrieved successfully
Invalid credentials (401, 403)XX invalid setting401Tusdatos responded with HTTP 401 Unauthorized: Invalid credentials
Rejected request (other 4xx)X3 invalid request422Tusdatos responded with HTTP 422 Unprocessable Entity: field required (body.doc)
Provider error (5xx)XR invalid response502Tusdatos responded with HTTP 502 Bad Gateway: 502 Bad Gateway
Empty or non JSON object bodyXR invalid response200Tusdatos responded with HTTP 200 OK but the response body is not a JSON object (null given)
Connection error or timeoutXH invalid hostnullUnable to connect to Tusdatos: cURL error 28: Operation timed out after 30001 milliseconds

Exceptions are only thrown for integration errors, and all of them extend Placetopay\TusdatosSdk\Exceptions\TusdatosSdkException:

ExceptionWhen
InvalidTransactionExceptionA required field is missing, for example The job id is required to execute the Tusdatos checkStatus operation.
ParserExceptionThe operation passed to process() is not supported.
TusdatosSdkExceptionAny unexpected error, wrapped with the operation name and the original exception as previous.

Simulator

With simulatorMode enabled the SDK answers locally. These values trigger specific scenarios:

OperationValueScenario
Anyusername = ClientSimulator::REJECTED_USERNAME401 invalid credentials
launchLaunchBehaviour::INVALID_DOCUMENT422 validation error
launchLaunchBehaviour::SERVER_ERROR_DOCUMENT500 HTML error page
launchLaunchBehaviour::CACHED_DOCUMENTReport id of a previous check
checkStatusCheckStatusBehaviour::NOT_FOUND_JOB404 job not found
checkStatusCheckStatusBehaviour::PROCESSING_JOBCheck still in progress
formatJsonFormatJsonBehaviour::NOT_FOUND_REPORT404 report not found
formatJsonFormatJsonBehaviour::NULL_BODY_REPORT200 with a null body
formatJsonFormatJsonBehaviour::EMPTY_BODY_REPORT200 with an empty body
formatJsonFormatJsonBehaviour::MALFORMED_BODY_REPORT200 with malformed JSON
formatJsonFormatJsonBehaviour::INVALID_UTF8_REPORT200 with invalid UTF-8 characters
formatJsonFormatJsonBehaviour::SERVER_ERROR_REPORT500 HTML error page
queryDocumentStatusQueryStatusDocumentBehaviour::INVALID_DOCUMENT422 validation error

Development

composer test
composer phpstan
composer phpcs-validate