janar/smartpost-shipping-php

There is no license information available for the latest version (0.91) of this package.

Simple client library for PHP to create shipments using smartpost web service

0.91 2016-08-19 17:54 UTC

This package is not auto-updated.

Last update: 2024-05-09 17:12:06 UTC


README

API changed in 2023 Q1 https://smartpost.sendsmaily.net/templates/e4e01c50-639d-4b3b-9d16-e9401d60a7ec/html/ I have not tested that does this implementation here still work.

Client library for Itella Smartpost API written in PHP.

Simple PHP client for creating Itella Smartpost (http://uus.smartpost.ee/) parcels via web API. Can be used to automate parcel creation and getting shipping labels for them.

Communication is done using XML. Original Smartpost API documents can be found here: http://uus.smartpost.ee/ariklient/ostukorvi-rippmenuu-lisamise-opetus/automaatse-andmevahetuse-opetus

Currently this library is in development, but shipments to parcel terminals (Estonia and Finland) work. Also you can request shipping labels from API. So you would never have to enter Smartpost client area.

  • Uses CURL for requests.
  • Many requests and features not here yet.

Installation

Easiest way to install the library is through Composer:

$ composer require janar/smartpost-shipping-php

Basic usage

Most basic and useful feature in this library would be creating shipments on your own server. Removes need for manual exporting/importing CSV files to Smartpost environment.

Creating shipments:

$spApi = new Client( "smartpost username", "smartpost password" );

//create shipments
$shipment = new Shipment();
$shipment->setRecipient( new Recipient( "John Doe", "56666661", "john.doe@doe123.com" ) );
$shipment->setReference( '[MyAwsomeWebShop] - test #1' );
$shipment->setDestination( new ParcelTerminal( 172 ) );
$spApi->addShipment( $shipment );

$shipment = new Shipment();
$shipment->setRecipient( new Recipient( "John Doe2", "56666662", "john.doe2@doe123.com" ) );
$shipment->setReference( '[MyAwsomeWebShop] - test #2' );
$shipment->setDestination( new ParcelTerminal( 171 ) );
$spApi->addShipment( $shipment );

$shipment = new Shipment();
$shipment->setRecipient( new Recipient( "John Doe3", "56666663", "john.doe3@doe123.com" ) );
$shipment->setDestination( new ParcelTerminal( null, "3202", "00215" ) );
$spApi->addShipment( $shipment );

$result = $spApi->postShipments();

Creating shipments result:

Alt text

Shipments in Smartpost dashboard:

Alt text

3. Retrieving shipping labels (as pdf document)

Shipping labels are generated on Smartpost side and they are in pdf format. Only format and barcode(s) / tracking codes are needed to get labels on pdf. Formats are following:

Format Description
A5 1 label on A5 sized paper
A6 1 label on A6 sized paper
A6-4 4 labels fitted on A6 sized paper
A7 1 label on A7 sized paper
A7-8 8 labels fitted on A7 sized paper
A6 1 label on A6 sized paper

Labels are on one continuous pdf document. You can choose what to do with result. Save as file or view in browser.

$spApi = new Client( "smartpost username", "smartpost password" );
$trackingCodes = array( '6895100008876963', '6895100008876964' );
$result = $spApi->getShippingLabels( $trackingCodes, 'A6-4' );

if( $result === false  ){
  echo $spApi->getLastError() . "<br />";
} else {
  //Here we stream pdf directly to browser, but you may also save returned content as file for local use. 
  header("Content-type:application/pdf");
  header("Content-Disposition:inline;filename='shipping-labels.pdf'");
  echo $result;
  exit;
}

Results would look something like this:

Alt text