Code Monkey home page Code Monkey logo

smartpost-shipping-php's Introduction

Note

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", "[email protected]" ) );
$shipment->setReference( '[MyAwsomeWebShop] - test #1' );
$shipment->setDestination( new ParcelTerminal( 172 ) );
$spApi->addShipment( $shipment );

$shipment = new Shipment();
$shipment->setRecipient( new Recipient( "John Doe2", "56666662", "[email protected]" ) );
$shipment->setReference( '[MyAwsomeWebShop] - test #2' );
$shipment->setDestination( new ParcelTerminal( 171 ) );
$spApi->addShipment( $shipment );

$shipment = new Shipment();
$shipment->setRecipient( new Recipient( "John Doe3", "56666663", "[email protected]" ) );
$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


smartpost-shipping-php's People

Contributors

janar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

karlmuuga

smartpost-shipping-php's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.