1. Go to this page and download the library: Download sanmai/shipandco-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/ */
sanmai / shipandco-sdk example snippets
$builder = new \ShipAndCoSDK\ClientBuilder();
$builder->setToken($token);
$client = $builder->build();
$request = new \ShipAndCoSDK\Requests\RatesRequest();
// This requests > 0) {
// Will not be printed because count() is zero here.
echo 'Rates received: ', \count($response), "\n";
}
if ($response->hasErrors()) {
// Check for exact errors
foreach ($response->getMessages() as $message) {
if ($message->getErrorCode() !== '') {
// That's the error:
echo "{$message->getErrorCode()}: {$message->getMessage()}\n";
}
}
/** @var \ShipAndCoSDK\Responses\Bad\ErrorResponse $response */
// To get more specific error details use response-specific fields. E.g.:
foreach ($response->details as $detail) {
echo "Error code: {$detail->code}\n\tMessage: {$detail->message}\n\tField: {$detail->field}\n";
}
}
$request = new \ShipAndCoSDK\Requests\CarriersRequest();
$response = $client->sendCarriersRequest($request);
\var_dump(\count($response)); // Should print the number of configured carriers
foreach ($response as $value) {
echo "{$value->id}\t{$value->type}\t{$value->state}\t{$value->created_at->format('Y-m-d')}\n";
foreach ($value->credentials as $key => $value) {
echo "\t$key =\t$value\n";
}
}
$request = new \ShipAndCoSDK\Requests\AddressesRequest();
$response = $client->sendAddressesRequest($request);
\var_dump(\count($response)); // Should print the number of addresses returned
foreach ($response as $value) {
echo "{$value->id}\t{$value->created_at->format('Y-m-d')}\n";
foreach ($value->address as $key => $value) {
echo "\t$key =\t$value\n";
}
}
$request = new \ShipAndCoSDK\Requests\WarehousesRequest();
$response = $client->sendWarehousesRequest($request);
\var_dump(\count($response)); // Should print the number of warehouses returned
foreach ($response as $value) {
echo "{$value->id}\t{$value->created_at->format('Y-m-d')}\t{$value->company}\n";
foreach ($value->address as $key => $value) {
echo "\t$key =\t$value\n";
}
}