GithubHelp home page GithubHelp logo

pakkelabels-php-sdk's Introduction

Pakkelabels.dk's official PHP library (DEPRECATED)

This library is deprecated. For any future updates please use shipmondo_php_sdk.

This SDK supports Pakkelabels.dk API v3.

Specification: https://app.pakkelabels.dk/api/public/v3/specification

The previous SDK supporting Pakkelabels.dk API v2 can be found under the branch for_api_v2

Getting started

Below is a simple PHP script which illustrate the minimum amount of code needed to getting started.

<?php
  try {
    $client = new Pakkelabels('api_user', 'api_key');
  } catch (PakkelabelsException $e) {
    echo $e->getMessage();
  }
?>

Once the $client object is created, you can begin to use the API.

Examples

Get current balance

<?php
  echo $client->account_balance();
?>

Get outstanding payment requests

<?php
  $params = array(
    'created_at_min' => '2017-06-19',
    'page' => 1
  );
  echo $client->account_payment_requests($params);
?>

Get available products

<?php
  $params = array(
    'country_code' => 'DK',
    'carrier_code' => 'gls',
    'page' => 1
  );
  echo $client->products($params);
?>

Pagination is supported

Get available / nearest pickup points

<?php
  $params = array(
    'country_code' => 'DK',
    'carrier_code' => 'gls',
    'zipcode' => '5000'
  );
  echo $client->pickup_points($params);
?>

Get shipments

<?php
  $params = array(
    'page' => 1,
    'carrier_code' => 'dao'
  );
  echo $client->shipments($params);
?>

Pagination is supported

Get shipment by id:

<?php
  $id = 5545625;
  echo $client->shipment($id);  
?>

Get label(s) for shipment

<?php
  $shipment_id = 5545625;
  $params = array(
    'label_format' => '10x19_pdf'
  );
  echo $client->shipment_labels($shipment_id, $params);  
?>

Create shipment

<?php
  $params = array(
    "test_mode" => true,
    "own_agreement" => true,
    "label_format" => "a4_pdf",
    "product_code" => "GLSDK_HD",
    "service_codes" => "EMAIL_NT,SMS_NT",
    "order_id" => "10001",
    "reference" => "Webshop 10001",
    "sender" => array(
      "name" => "Pakkelabels.dk ApS",
      "address1" => "Strandvejen 6",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5240",
      "city" => "Odense NØ",
      "attention" => null,
      "email" => "[email protected]",
      "telephone" => "70400407",
      "mobile" => "70400407"       
    ),
    "receiver" => array(
      "name" => "Lene Jensen",
      "address1" => "Vindegade 112",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5000",
      "city" => "Odense C",
      "attention" => null,
      "email" => "[email protected]",
      "telephone" => "50607080",
      "mobile" => "50607080",
      "instruction" => null
    ),
    "parcels" => array(
      array(
      "weight" => 1000
      )
    ),
  );
  echo $client->create_shipment($params);
?>

Get shipment monitor statuses

<?php
  $params = array(
    'ids' => '5546689,5546696',
    'page' => 1
  );
  echo $client->shipment_monitor_statuses($params);  
?>

Get print queue entries

<?php
  $params = array(
    'page' => 1
  );
  echo print_r($client->print_queue_entries($params);
?>

Get return portals

<?php
  $params = array(
    'page' => 1
  );
  echo $client->return_portals($params);  
?>

Get return portal by id

<?php
  $id = 4766;
  echo $client->return_portal($id);  
?>

Get return shipments for return portal

<?php
  $return_portal_id = 4766;
  $params = array(
    'page' => 1
  );
  echo $client->return_portal_shipments($return_portal_id, $params);  
?>

Pagination is supported

Get imported shipments

<?php
  $params = array(
    'page' => 1
  );
  echo $client->imported_shipments($params);
?>

Pagination is supported

Get imported shipment by id

<?php
  $id = 75545625;
  echo $client->imported_shipment($id);
?>

Create imported shipment

<?php
  $params = array(
    "carrier_code" => "gls",
    "product_code" => "GLSDK_HD",
    "service_codes" => "EMAIL_NT,SMS_NT",
    "order_id" => "10001",
    "reference" => "Webshop 10001",
    "sender" => array(
      "name" => "Pakkelabels.dk ApS",
      "address1" => "Strandvejen 6",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5240",
      "city" => "Odense NØ",
      "attention" => null,
      "email" => "[email protected]",
      "telephone" => "70400407",
      "mobile" => "70400407"       
    ),
    "receiver" => array(
      "name" => "Lene Jensen",
      "address1" => "Vindegade 112",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5000",
      "city" => "Odense C",
      "attention" => null,
      "email" => "[email protected]",
      "telephone" => "50607080",
      "mobile" => "50607080",
      "instruction" => null
    )
  );
  echo $client->create_imported_shipment($params);
?>

Update imported shipment by id

<?php
  $id = 75545625;
  $params = array(
    "carrier_code" => "gls",
    "product_code" => "GLSDK_HD",
    "service_codes" => "EMAIL_NT,SMS_NT",
    "order_id" => "10001",
    "reference" => "Webshop 10001",
    "sender" => array(
      "name" => "Pakkelabels.dk ApS",
      "address1" => "Strandvejen 6",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5240",
      "city" => "Odense NØ",
      "attention" => null,
      "email" => "[email protected]",
      "telephone" => "70400407",
      "mobile" => "70400407"       
    ),
    "receiver" => array(
      "name" => "Lene Jensen",
      "address1" => "Vindegade 112",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5000",
      "city" => "Odense C",
      "attention" => null,
      "email" => "[email protected]",
      "telephone" => "50607080",
      "mobile" => "50607080",
      "instruction" => null
    )
  );
  echo $client->update_imported_shipment($id, $params);
?>

Delete/archive an imported shipment by id

<?php
  $id = 75545625;
  echo $client->delete_imported_shipment($id);
?>

pakkelabels-php-sdk's People

Contributors

hungor avatar janc89 avatar janmsp avatar maxer001 avatar ml-computopic avatar sebastianweirsoe avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pakkelabels-php-sdk's Issues

Issues with Xampp (latest version)

Hello there.

Does this library require any special PHP extensions?
I made a example with the provided code in your Readme page, and it doesnt work on Localhost.

try {
   $label = new Pakkelabels('**********', '**********');
   $pdk_stores = $label->pdk_droppoints(array(
      'zipcode' => '5240',
      'street' => 'Strandvejen'
   ));
   echo $pdk_stores;
}

catch(PakkelabelsException $e) {
   echo $e->getMessage();
   echo 'something is wrong...';
}

NOTE: This is a simplyfied example, a lot has been trimmed

The getMessage is not returning anything, but i get the message "Something is wrong" meaning that the "try" failed.

The very same code works perfect on a webserver, but my project is developed using GitHub, so i prefer having the library work on localhost.

This is the error message i get:

Fatal error: Uncaught exception 'PakkelabelsException' in C:\xampp\htdocs\pakkelabels\Pakkelabels.php:120 Stack trace:

0 C:\xampp\htdocs\pakkelabels\Pakkelabels.php(18): Pakkelabels->_make_api_call('users/login', true, Array)

1 C:\xampp\htdocs\pakkelabels\Pakkelabels.php(14): Pakkelabels->login()

2 C:\xampp\htdocs\pakkelabels\index.php(7): Pakkelabels->__construct('MIN BRUGER', 'MIN NØGLE')

3 {main} thrown in C:\xampp\htdocs\pakkelabels\Pakkelabels.php on line 120

For security reasons, i have ofcourse removed the API user and key.

Please rename repository

If people choose to fork your repository, it will become e.g. lsolesen/php, which gives no clue what the repository contains. It would be great if you could rename the repository to e.g. pakkelabels/pakkelabels-php-sdk or something similar, because then forks will also be easy to distinguish.

Issues with createShipment($data) example

Hi ! Can you please replace this row

$shipment = $label->createShipment($data);

by this :

$shipment = $label->create_shipment($data);

inside README.md .
The method createShipment() does not exist.


Also, the following example is not valid by itself.
The input array requires additional fields like 'receiver_mobile' and 'receiver_email'. Otherwise, it will throw PakkelabelsException.

$data = array(

'shipping_agent' => 'pdk',
'weight' => '1000',
'receiver_name' => 'John Doe',
'receiver_address1' => 'Some Street 42',
'receiver_zipcode' => '5230',
'receiver_city' => 'Odense M',
'receiver_country' => 'DK',
'sender_name' => 'John Wayne',
'sender_address1' => 'The Batcave 1',
'sender_zipcode' => '5000',
'sender_city' => 'Odense C',
'sender_country' => 'DK',
'shipping_product_id' => '51',
'services' => '11,12',
'test' => 'true' // Change to false when going live
);

$shipment = $label->createShipment($data);
echo 'Track&Trace: ' . $shipment['pkg_no'];

Best regards : )

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.