PHP code example of daika7ana / innoship-php-sdk

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

    

daika7ana / innoship-php-sdk example snippets


use Daika7ana\Innoship\Client;
use Daika7ana\Innoship\Config\ClientConfig;
use Daika7ana\Innoship\DTOs\Orders\OrderContent;
use Daika7ana\Innoship\DTOs\Orders\OrderParcel;
use Daika7ana\Innoship\DTOs\Orders\OrderParcelSize;
use Daika7ana\Innoship\DTOs\Orders\OrderRequest;
use Daika7ana\Innoship\DTOs\Orders\OrderRequestAddress;
use Daika7ana\Innoship\Enums\ParcelType;
use Daika7ana\Innoship\Enums\PaymentType;

$client = Client::create(config: new ClientConfig(apiKey: 'your-api-key'));

$today = (new DateTimeImmutable('today'))->format('Y-m-d');

$request = new OrderRequest(
    serviceId: 1,
    shipmentDate: $today,
    shipmentDateEnd: $today,
    externalClientLocation: 'RO',
    addressFrom: new OrderRequestAddress(
        name: 'Warehouse SRL',
        contactPerson: 'Warehouse SRL',
        country: 'RO',
        countyId: 10,
        localityId: 3502,
        addressText: 'Str. Depozitului 5',
        postalCode: '010864',
        phone: '+40734123456',
        email: '[email protected]',
    ),
    addressTo: new OrderRequestAddress(
        name: 'Jane Doe',
        contactPerson: 'Jane Doe',
        country: 'RO',
        countyId: 10,
        localityId: 3502,
        addressText: 'Str. Exemplu 10',
        postalCode: '010101',
        phone: '+40734123456',
        email: '[email protected]',
    ),
    payment: PaymentType::Sender,
    content: new OrderContent(
        parcelsCount: 1,
        totalWeight: 1.0,
        contents: 'Books',
        parcels: [
            new OrderParcel(
                sequenceNo: 1,
                weight: 1.0,
                type: ParcelType::Parcel,
                size: new OrderParcelSize(width: 20.0, height: 10.0, length: 30.0),
            ),
        ],
    ),
);

$order = $client->orders()->create($request);

echo $order->courierShipmentId;
echo $order->price?->totalAmount;

$prices = $client->prices()->getPrices($request);

foreach ($prices->rates as $rate) {
    echo $rate->carrier . ': ' . $rate->rateTotalAmount . ' ' . $rate->rateCurrency;
}

$label = $client->labels()->downloadLabel(
    courierId: $order->courier,
    awb: (string) $order->courierShipmentId,
);

file_put_contents('label.pdf', $label->contents());

use Daika7ana\Innoship\Config\ClientConfig;

$config = new ClientConfig(
    baseUrl: 'https://api.innoship.com',
    apiKey: 'your-api-key',
    apiVersion: '1.0',
    acceptLanguage: 'en',
);

$client = Client::create(); // reads INNOSHIP_API_KEY

$client = Client::create(config: new ClientConfig(apiKey: 'your-api-key'));

$client = Client::create()->setApiKey('rotated-key');

$client->request('GET', '/api/ClientLocation', null, [], 2.5);

use Daika7ana\Innoship\Client;
use Daika7ana\Innoship\Http\HttpClientInterface;

/** @var HttpClientInterface $customClient */
$client = Client::create(httpClient: $customClient);
bash
composer