Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Client library for Itella Smartpost API written in PHP (http://smartpost.ee)

Notifications You must be signed in to change notification settings

karlmuuga/smartpost-shipping-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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


About

Client library for Itella Smartpost API written in PHP (http://smartpost.ee)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%