2017 © Pedro Peláez
 

library statusweb-client

Statusweb API client for PHP

image

jacobdekeizer/statusweb-client

Statusweb API client for PHP

  • Saturday, February 10, 2018
  • by jacobdekeizer
  • Repository
  • 1 Watchers
  • 1 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Statusweb API client for PHP

Packagist Version Packagist Packagist, (*1)

Get your api keys from Statusweb > Help > Statusweb API. On this page you can also get the Statusweb API documentation., (*2)

Installation

You can install this package via composer:, (*3)

composer require jacobdekeizer/statusweb-client

Usage

This readme shows basic usage of this package, for all available options look at the class definitions and the api documentation., (*4)

Create the client, (*5)

$client = (new \JacobDeKeizer\Statusweb\Client())
    ->setApiKey('api_key')
    ->setPassword('password');

Create shipment

$deliveryAddress = (new \JacobDeKeizer\Statusweb\Resources\Address())
    ->setStreet('Lange laan')
    ->setCity('Zevenaar')
    ->setHouseNumber('29A')
    ->setPostalCode('9281EM')
    ->setCountryCode(\JacobDeKeizer\Statusweb\Enums\CountryCode::NETHERLANDS)
    ->setEmail('noreply@example.com')
    ->setToTheAttentionOf('tav')
    ->setPhoneNumber('+31612345678')
    ->setName('Gijs Boersma');

$labelData = (new \JacobDeKeizer\Statusweb\Resources\LabelData())
    ->setLabelFormat(\JacobDeKeizer\Statusweb\Enums\LabelFormat::PDF)
    ->setReturnLabel(true); // return the pdf label in the response

$shipmentRow = (new \JacobDeKeizer\Statusweb\Resources\ShipmentRow())
    ->setAmount(1)
    ->setWeight(10)
    ->setUnit(\JacobDeKeizer\Statusweb\Enums\Unit::COLLI);

$shipment = (new \JacobDeKeizer\Statusweb\Resources\Shipment())
    ->setReference('My reference')
    ->setDeliveryAddress($deliveryAddress)
    ->setType(1) // Statusweb -> Tabellen -> Zendingsoorten
    ->setDirectSend(true) // when true the shipment is confirmed and can't be deleted
    ->setLabelData($labelData)
    ->addShipmentRow($shipmentRow); // ->setShipmentRows accepts an array of ShipmentRows

$shipmentResponse = $client->shipments()->create($shipment);

// Show label pdf
$data = base64_decode($shipmentResponse->getLabels());
header('Content-Type: application/pdf');
echo $data;

Delete shipment

$deleteShipmentResponse = $client->shipments()->delete(12345678); // transportNumber

Send shipments

Sends all shipments where setDirectSend was false, (*6)

$sendShipmentsResponse = $client->shipments()->send();

Get shipment status

This endpoint does only work if the shipment is in transport or has arrived., (*7)

$statusResponse = $client->shipments()->getStatus(12345678); // transportNumber
$statusResponse->getStatuses();

All shipment statuses

This endpoint does only work if the are any shipments in transport or that have arrived., (*8)

$statusResponse = $client->shipments()->getAllStatuses();
$statusResponse->getStatuses();

Get statusweb status url

Get the statusweb status url -> does only work when the shipment is in transport or has arrived, (*9)

$statusLink = $client->shipments()->getStatusUrl(12345678); // transportNumber

Get estimated time of arrival

This endpoint does only work if the shipment is in transport or has arrived., (*10)

$etaResponse = $client->shipments()->getEstimatedTimeOfArrival(12345678); // transportNumber

Get label

This endpoint does only work if the shipment isn't confirmed by the send endpoint and directSend for the shipment was false, (*11)

$labelResponse = $client->labels()->get(9207289743, \JacobDeKeizer\Statusweb\Enums\LabelFormat::PDF);

Exceptions

Each endpoint can throw a StatuswebErrorResponse or StatuswebException. The StatuswebErrorResponse contains the error code and message from statusweb. For example:, (*12)

try {
    $statusLink = $client->shipments()->getStatusUrl(12345678);
} catch (\JacobDeKeizer\Statusweb\Exceptions\StatuswebErrorResponse $statuswebErrorResponse) {
    $hasLink = $statuswebErrorResponse->getCode() === \JacobDeKeizer\Statusweb\Enums\ResponseCode::NO_STATUS_URL_FOR_SHIPMENT;
} catch (\JacobDeKeizer\Statusweb\Exceptions\StatuswebException $statuswebException) {
    $originalException = $statuswebException->getPrevious(); // do something
}

Register your own session store implementation (Optional)

Statusweb session ids are valid for 2 hours. To reduce the amount of sessionId requests you can create your own SessionStore. By default the JacobDeKeizer\Statusweb\Stores\DefaultSessionStore is used., (*13)

use JacobDeKeizer\Statusweb\Contracts\SessionStore;
use JacobDeKeizer\Statusweb\Dto\Session;

class DatabaseSessionStore implements SessionStore
{
    public function put(string $apiKey, Session $session): void
    {
        // save in db
    }

    public function get(string $apiKey): ?Session
    {
        // retrieve from db
    }
}
$client->setSessionStore(new DatabaseSessionStore());

The Versions

10/02 2018

dev-master

9999999-dev https://github.com/jacobdekeizer/statusweb-client

Statusweb API client for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jacob de Keizer

api php statusweb bulstra

10/02 2018

v1.2

1.2.0.0 https://github.com/jacobdekeizer/statusweb-client

Statusweb API client for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jacob de Keizer

api php statusweb bulstra

10/02 2018

v1.1

1.1.0.0 https://github.com/jacobdekeizer/statusweb-client

Statusweb API client for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jacob de Keizer

api php statusweb bulstra

10/02 2018

v1.0

1.0.0.0 https://github.com/jacobdekeizer/statusweb-client

Statusweb API client for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jacob de Keizer

api php statusweb bulstra

09/02 2018

v0.1

0.1.0.0 https://github.com/jacobdekeizer/statusweb-client

Statusweb API client for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jacob de Keizer

api php statusweb bulstra