PHP code example of snapshotpl / shipx-php-sdk

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

    

snapshotpl / shipx-php-sdk example snippets


$client = new \MB\ShipXSDK\Client\Client(
    'https://sandbox-api-shipx-pl.easypack24.net',
    'y0urs3cr3tc0d3'
);

$addressForm = new \MB\ShipXSDK\Model\AddressForm();
$addressForm->city = 'Warszawa';
$addressForm->post_code = '01-234';
$addressForm->country_code = 'PL';
$addressForm->street = 'Testowa 11';
$addressForm->building_number = '12/23';

$receiver = new \MB\ShipXSDK\Model\TransactionPartyForm();
$receiver->phone = '123456789';
$receiver->email = '[email protected]';
$receiver->first_name = 'Michał';
$receiver->last_name = 'Testowy';
$receiver->address = $addressForm;

$dimensions = new \MB\ShipXSDK\Model\DimensionsSimple();
$dimensions->height = 21.5;
$dimensions->length = 2.1;
$dimensions->width = 1.7;

$weight = new \MB\ShipXSDK\Model\WeightSimple();
$weight->amount = 2.0;

$parcel = new \MB\ShipXSDK\Model\ParcelsSimple();
$parcel->dimensions = $dimensions;
$parcel->weight = $weight;
$parcel->is_non_standard = false;

$shipmentOfferForm = new \MB\ShipXSDK\Model\ShipmentOfferForm();
$shipmentOfferForm->receiver = $receiver;
$shipmentOfferForm->parcels = [$parcel];
$shipmentOfferForm->additional_services = [];
        
$response = $client->callMethod(
new \MB\ShipXSDK\Method\Shipment\CreateOffer(),
    ['organization_id' => '1234'],
    [],
    $shipmentOfferForm
);
if ($response->getSuccess()) {
    /** @var \MB\ShipXSDK\Model\Shipment $payload */
    $payload = $response->getPayload();
    echo 'Shipment ID is ' . $payload->id;
}

composer