PHP code example of trunkrs / sdk

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

    

trunkrs / sdk example snippets



\Trunkrs\SDK\Settings::setApiKey("your-trunkrs-api-key");

\Trunkrs\SDK\Settings::useStaging();

$details = new \Trunkrs\SDK\ShipmentDetails();

$parcel = new \Trunkrs\SDK\Parcel();
// Set the reference of the parcel. This is arcel,
];

$details->sender = new \Trunkrs\SDK\Address();
// Set the pickup address properties.

$details->recipient = new \Trunkrs\SDK\Address();
// Set the delivery address properties.

$shipments = \Trunkrs\SDK\Shipment::create($details);

$shipment = \Trunkrs\SDK\Shipment::find('4000002123');

$shipments = \Trunkrs\SDK\Shipment::retrieve();

\Trunkrs\SDK\Shipment::cancelByTrunkrsNr('4000002123');

$shipment = \Trunkrs\SDK\Shipment::find('4000002123');

$shipment->cancel();

$status = \Trunkrs\SDK\ShipmentState::forShipment('4000002123');

$webhook = new \Trunkrs\SDK\Webhook();
$webhook->callbackUrl = "https://your.web.service/shipments/webhook";
$webhook->sessionHeaderName = 'X-SESSION-TOKEN';
$webhook->sessionToken = "your-secret-session-token";
$webhook->event = \Trunkrs\SDK\Enum\WebhookEvent::ON_STATE_UPDATE;

\Trunkrs\SDK\Webhook::register($webhook);

$webhooks = \Trunkrs\SDK\Webhook::retrieve();

$webhookId = 100;

\Trunkrs\SDK\Webhook::removeById($webhookId);

$webhook = \Trunkrs\SDK\Webhook::find(100);

$webhook->remove();