PHP code example of gdinko / econt

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

    

gdinko / econt example snippets


Econt::setAccount('user', 'pass');
Econt::setBaseUrl('endpoint');
Econt::setTimeout(99);
Econt::addAccountToStore('AccountUser', 'AccountPass');
Econt::getAccountFromStore('AccountUser');
Econt::setAccountFromStore('AccountUser');

public function boot()
{
    Econt::addAccountToStore(
        'AccountUser',
        'AccountPass'
    );

    Econt::addAccountToStore(
        'AccountUser_XXX',
        'AccountPass_XXX'
    );
}


//Nomenclatures
Econt::getCountries();
Econt::getCities();
Econt::getOffices();
Econt::getStreets();
Econt::getQuarters();

//Labels
Econt::createLabel();
Econt::createLabels();
Econt::updateLabel();
Econt::deleteLabels();

//Misc
Econt::requestCourier();
Econt::getRequestCourierStatus();
Econt::getShipmentStatuses();
Econt::getClientProfiles();
Econt::paymentReport();

CarrierEcontCountry
CarrierEcontCity
CarrierEcontOffice
CarrierEcontStreet
CarrierEcontQuarter
CarrierEcontPayment
CarrierEcontApiStatus
CarrierEcontTracking
CarrierCityMap

CarrierEcontTrackingEvent
CarrierEcontPaymentEvent

Event::listen(function (CarrierEcontTrackingEvent $event) {
    echo $event->account;
    dd($event->tracking);
});

use Gdinko\Econt\Commands\TrackCarrierEcontBase;

class TrackCarrierEcontSetup extends TrackCarrierEcontBase
{
    protected function setup()
    {
        //define parcel selection logic here
        // $this->parcels = [];
    }
}

try {
    $address = new Address([
        'city' => [
            'name' => 'София'
        ],
        'street' => 'България',
        'num' => '100'
    ]);

    dd(Econt::validateAddress($address));
} catch (EcontValidationException $eve) {
    echo $eve->getMessage();
    echo $eve->getCode();
    print_r($eve->getErrors());
} catch (EcontException $ee) {
    echo $ee->getMessage();
    echo $ee->getCode();
    print_r($ee->getErrors());
}

try {
    $address = new Address([
        'city' => [
            'name' => 'София'
        ],
        'street' => 'България',
        'num' => '100'
    ]);

    dd(Econt::getNearestOffices($address));
} catch (EcontValidationException $eve) {
    echo $eve->getMessage();
    echo $eve->getCode();
    print_r($eve->getErrors());
} catch (EcontException $ee) {
    echo $ee->getMessage();
    echo $ee->getCode();
    print_r($ee->getErrors());
}

$labelData = [
    'senderClient' => [
        'name' => 'Иван Иванов',
        'phones' => [
            0 => '0888888888',
        ],
    ],
    'senderAddress' => [
        'city' => [
            'country' => [
                'code3' => 'BGR',
            ],
            'name' => 'София',
            'postCode' => 1000,
        ],
    ],
    'senderOfficeCode' => '1127',
    'receiverAddress' => [
        'city' => [
            'country' => [
                'code3' => 'BGR',
            ],
            'name' => 'София',
            'postCode' => 1000,
        ],
        'street' => 'България',
        'num' => '100',
    ],
    'packCount' => 1,
    'shipmentType' => ShipmentType::PACK,
    'weight' => 3.4,
    'shipmentDescription' => 'обувки',
    'services' => [
        'cdAmount' => 122.59,
        'cdType' => 'get',
        'cdCurrency' => 'BGN',
        'smsNotification' => true,
    ],
    'payAfterAccept' => false,
    'payAfterTest' => false,
];

$label = new Label(
    $labelData,
    LabelMode::CALCULATE
);

$result = Econt::createLabel($label);

$labelData = [
    'senderClient' => [
        'name' => 'Иван Иванов',
        'phones' => [
            0 => '0888888888',
        ],
    ],
    'senderAddress' => [
        'city' => [
            'country' => [
                'code3' => 'BGR',
            ],
            'name' => 'София',
            'postCode' => 1000,
        ],
    ],
    'senderOfficeCode' => '1127',
    'receiverClient' =>
    [
        'name' => 'Димитър Димитров',
        'phones' =>
        [
            0 => '0876543210',
        ],
    ],
    'receiverAddress' => [
        'city' => [
            'country' => [
                'code3' => 'BGR',
            ],
            'name' => 'София',
            'postCode' => '1000',
        ],
        'street' => 'България',
        'num' => 100,
    ],
    'packCount' => 1,
    'shipmentType' => ShipmentType::PACK,
    'weight' => 3.4,
    'shipmentDescription' => 'обувки',
    'services' => [
        'cdAmount' => '122.59',
        'cdType' => 'get',
        'cdCurrency' => 'BGN',
        'smsNotification' => true,
    ],
    'payAfterAccept' => false,
    'payAfterTest' => false,
    'holidayDeliveryDay' => 'workday',
];

$label = new Label(
    $labelData,
    LabelMode::CREATE
);

$result = Econt::createLabel($label);

try {
    $curierRequest = [
        'requestTimeFrom' => '2022-05-05 16:00:00',
        'requestTimeTo' => '2022-05-05 17:00:00',
        'shipmentType' => 'PACK',
        'shipmentPackCount' => '1',
        'shipmentWeight' => '2',
        'senderClient' => [
            'name' => 'Иван Иванов',
            'phones' => [
                0 => '0888888888',
            ],
        ],
        'senderAddress' => [
            'city' => [
                'country' => [
                    'code3' => 'BGR',
                ],
                'postCode' => '7012',
                'name' => 'Русе',
            ],
            'fullAddress' => 'Алея Младост 7',
        ],
    ];

    dd(
        Econt::requestCourier(
            new Courier($curierRequest)
        )
    );
} catch (EcontValidationException $eve) {
    echo $eve->getMessage();
    echo $eve->getCode();
    print_r($eve->getErrors());
} catch (EcontException $ee) {
    echo $ee->getMessage();
    echo $ee->getCode();
    print_r($ee->getErrors());
}

try {
    dd(
        Econt::paymentReport(new Payment([
            'dateFrom' => '2022-05-01',
            'dateTo' => '2022-05-05'
        ]))
    );
} catch (EcontValidationException $eve) {
    echo $eve->getMessage();
    echo $eve->getCode();
    print_r($eve->getErrors());
} catch (EcontException $ee) {
    echo $ee->getMessage();
    echo $ee->getCode();
    print_r($ee->getErrors());
}
bash
php artisan migrate
bash
php artisan vendor:publish --tag=econt-config
bash
php artisan vendor:publish --tag=econt-migrations
bash
php artisan vendor:publish --tag=econt-models
bash
php artisan vendor:publish --tag=econt-commands
bash
php artisan make:command TrackCarrierEcont
bash
php artisan econt:track