todstoychev / econt
There is no license information available for the latest version (dev-master) of this package.
This bundle provides integration with ECONT Courier. Module is based on Bozhidar Hristov's vm/econt.
dev-master
2018-03-15 05:29 UTC
Requires
- php: >=5.4
- guzzlehttp/guzzle: >=5.0
This package is not auto-updated.
Last update: 2024-12-22 06:37:07 UTC
README
PHP Component to integrate with ECONT Courier
So far only calculation is possible.
$guzzle = new \GuzzleHttp\Client(); $client = new \Todstoychev\Econt\Client($guzzle, true, 'demo', 'demo'); $parcelRequest = new \Todstoychev\Econt\Request\ParcelRequest(); $parcelRequest->setOnlyCalculate(true); $loading = new \Todstoychev\Econt\Model\Loading(); $sender = new \Todstoychev\Econt\Model\Sender(); $sender->setCountryCode('BRG'); $sender->setCity('София'); $sender->setPostCode('1000'); $loading->setSender($sender); $receiver = new \Todstoychev\Econt\Model\Receiver(); $receiver->setCountryCode('BRG'); $receiver->setCity('Бургас'); $receiver->setPostCode('80001'); $loading->setReceiver($receiver); $shipment = new \Todstoychev\Econt\Model\Shipment(); $shipment->setShipmentType(\Todstoychev\Econt\Model\Shipment::SHIPMENT_TYPE_PACK); $shipment->setPackCount(1); $shipment->setWeight(1); $shipment->setTariffSubCode(\Todstoychev\Econt\Model\Shipment::TARIFF_SUB_CODE_DOOR_DOOR); $loading->setShipment($shipment); $parcelRequest->addLoading($loading); /** @var \Todstoychev\Econt\Response\ParcelResponse $response */ $response = $client->execute($parcelRequest); foreach ($response->getParcelResults() as $parcelResult) { if ($parcelResult->hasError()) { echo 'Грешка: '; foreach ($parcelResult->getError()->getMessages() as $errorMsg) { echo $errorMsg; } } else { echo 'Цена за доставка '.$parcelResult->getLoadingPrice()->getTotal().' '.$parcelResult->getLoadingPrice()->getCurrency()->getName(); } }
Example output with error:
Грешка: получател: Не е намерено населено място с пощенски код 80001
Example output without error:
Цена за доставка 7.8 лв