PHP code example of sarkisyan-m / metaship-php-sdk
1. Go to this page and download the library: Download sarkisyan-m/metaship-php-sdk 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/ */
sarkisyan-m / metaship-php-sdk example snippets
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
$client = new MetaShipAPIClient('URL','api-key', 'api-secet');
use MetaShipRU\MetaShipPHPSDK\Request\Offer\OfferRequest;
use GuzzleHttp\Exception\BadResponseException;
use MetaShipRU\MetaShipPHPSDK\Component\ResponseFormatter\ResponseFormatter;
use MetaShipRU\MetaShipPHPSDK\Component\ResponseFormatter\ErrorFormatter;
use MetaShipRU\MetaShipPHPSDK\MetaShipAPIClient;
$offersRequest = new OfferRequest();
$offersRequest->cityTo = 'Москва';
$offersRequest->zipTo = 115612;
$offersRequest->paymentSum = 1000;
$offersRequest->weight = 1.2;
$offersRequest->length = 10;
$offersRequest->height = 10;
$offersRequest->width = 10;
$offersRequest->deliveryType = 'courier';
try {
$response = $client->getOffers($offersRequest);
$offerResponse = ResponseFormatter::format($response, 'array<MetaShipRU\MetaShipPHPSDK\DTO\Offer\Offer>');
} catch (BadResponseException $exception) {
$offerResponse = ErrorFormatter::format($exception->getResponse(), 'array<MetaShipRU\MetaShipPHPSDK\DTO\Error\Error>');
}