setono/post-nord-php-sdk

A PHP SDK for the PostNord API

v1.1.3 2020-08-10 08:33 UTC

This package is auto-updated.

Last update: 2021-04-29 21:00:24 UTC


README

Latest Version Latest Unstable Version Software License Build Status Quality Score

A PHP SDK for the PostNord API.

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this library:

$ composer require setono/post-nord-php-sdk

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Usage

Here is an example showing you can get the nearest service points.

Notice that this example uses two libraries that are not installed by default: The PSR 17 factory and the HTTP client implementation. If you don't have any preferences, you can install these two libraries: $ composer require kriswallsmith/buzz nyholm/psr7.

<?php
use Buzz\Client\Curl;
use Nyholm\Psr7\Factory\Psr17Factory;
use Setono\PostNord\Client\Client;

$psr17Factory = new Psr17Factory();
$httpClient = new Curl($psr17Factory);

$client = new Client($httpClient, $psr17Factory, $psr17Factory, 'INSERT API KEY');
$client->get('/rest/businesslocation/v1/servicepoint/findNearestByAddress.json', [
    'countryCode' => 'DK',
    'postalCode' => '9000',
]);

If you know that you will only use the Location API you could change the base URL when you instantiate the client to make the requests easier to read:

<?php
use Buzz\Client\Curl;
use Nyholm\Psr7\Factory\Psr17Factory;
use Setono\PostNord\Client\Client;

$psr17Factory = new Psr17Factory();
$httpClient = new Curl($psr17Factory);

$client = new Client($httpClient, $psr17Factory, $psr17Factory, 'INSERT API KEY', 'https://api2.postnord.com/rest/businesslocation/v1/servicepoint');
$client->get('findNearestByAddress.json', [
    'countryCode' => 'DK',
    'postalCode' => '9000',
]);

Framework integration