PHP code example of sarissaops / enviatodo-php

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

    

sarissaops / enviatodo-php example snippets




use SarissaOps\Enviatodo\Enviatodo;

// Sandbox (default endpoint: https://apiqav2.enviatodo.mx/index.php/)
$client = Enviatodo::create('your-sandbox-token');

// Production endpoint: confirm the current base URL in the official
// API docs before pointing production traffic at it.
$client = Enviatodo::create('your-token', 'https://api.enviatodo.mx/index.php/');

use SarissaOps\Enviatodo\HttpClient\HttpClientConfigurator;

$configurator = (new HttpClientConfigurator())
    ->setToken('your-token')
    ->setEndpoint('https://apiqav2.enviatodo.mx/index.php/')
    ->setHttpClient($psr18Client);

$client = new Enviatodo($configurator);

$balance = $client->balance()->show();

echo $balance->getBalance(); // e.g. 758.13 (MXN)

$zip = $client->zipCode()->show('64000');

foreach ($zip->getItems() as $item) {
    echo $item['suburb_name'] . PHP_EOL;
}

// Quote all carriers, then create the order from the returned UUID.
$quote = $client->quote()->all($quotePayload);

foreach ($quote->getRates() as $rate) {
    echo "{$rate->getServiceName()}" . PHP_EOL;
}

$order = $client->order()->create(
    uuid: $quote->getTransactionUuid(),
    providerId: '9',
    serviceId: '11',
    insurance: false,
);

foreach ($order->getGuides() as $guide) {
    echo $guide->getTrackingId() . PHP_EOL;
}

use SarissaOps\Enviatodo\Exception\EnviatodoException;
use SarissaOps\Enviatodo\Exception\HttpClientException;
use SarissaOps\Enviatodo\Exception\HttpServerException;

try {
    $quote = $client->quote()->all($quote);
} catch (HttpClientException $e) {
    echo $e->getResponseCode();          // HTTP status
    print_r($e->getResponseBody());      // decoded envelope
    $e->getResponse();                   // raw PSR-7 response
} catch (HttpServerException | EnviatodoException $e) {
    echo $e->getMessage();
}

$client->getLastResponse(); // last raw PSR-7 response, for logging

use SarissaOps\Enviatodo\Enviatodo;
use SarissaOps\Enviatodo\HttpClient\HttpClientConfigurator;
use SarissaOps\Enviatodo\Hydrator\ArrayHydrator;

$configurator = (new HttpClientConfigurator())->setToken('your-token');

$client = new Enviatodo($configurator, new ArrayHydrator());

$data = $client->balance()->show();
// $data is now the plain unwrapped `data` payload

use SarissaOps\Enviatodo\Hydrator\NoopHydrator;

$client = new Enviatodo($configurator, new NoopHydrator());
$response = $client->balance()->show();
// $response is a Psr\Http\Message\ResponseInterface
echo $response->getStatusCode();

use SarissaOps\Enviatodo\HttpClient\HttpClientConfigurator;
use SarissaOps\Enviatodo\Hydrator\NoopHydrator;

$configurator = (new HttpClientConfigurator())
    ->setEndpoint('https://your-bin.example/abc123') // replace with your bin URL
    ->setToken('your-token')
    ->setDebug(true);

$client = new Enviatodo($configurator, new NoopHydrator());
$client->balance()->show();
bash
composer 
bash
git clone [email protected]:sarissaops/enviatodo-php.git
cd enviatodo-php
composer install
composer validate
composer test
vendor/bin/phpunit tests/Api/BalanceApiTest.php
vendor/bin/phpstan analyse --level=max src tests
vendor/bin/php-cs-fixer fix --dry-run --diff