GithubHelp home page GithubHelp logo

pakkelabels-php-sdk's Introduction

Pakkelabels.dk's official PHP library

Getting started

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

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

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

To see the current balance:

<?php
    echo $label->balance();
?>

To list all Post Danmark shipments sent to to Denmark:

<?php
    $labels = $label->shipments(array('shipping_agent' => 'pdk', 'receiver_country' => 'DK'));
    print_r($labels);
?>

To display the PDF for the shipment ID with 42 inline in the browser:

<?php
    $base64 = $label->pdf(42);
    $pdf = base64_decode($base64);
    header('Content-type: application/pdf');
    header('Content-Disposition: inline; filename="label.pdf"');
    echo $pdf;
?>

To create a test shipment with Post Danmark, and then output the Track&Trace number of the newly created shipment:

<?php
    $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',
      'receiver_mobile' => '004560708090',
      'receiver_email' => '[email protected]',
      'test' => 'true' // Change to false when going live
    );

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

You’ll notice that we supply a shipping_product_id and a list of services. In this case, 51 is the ID of “Privatpakke u. omdeling” (without delivery) The service with ID 11 is email notification, and 12 is sms notification.

To find the IDs of the products and services:

<?php
    $data = array(
      'country' => 'DK',
    );
    print_r($label->freight_rates($data));
?>

To find pickup point within a zipcode for a certain shipping agent:

<?php
    $data = array(
      'agent' => 'pdk',
      'zipcode' => '5240',
      'country' => 'DK',
    );
    print_r($label->pickup_points($data));
?>

pakkelabels-php-sdk's People

Contributors

hungor avatar janc89 avatar maxer001 avatar ml-computopic avatar

Watchers

 avatar  avatar

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.