xewl/postnl

Library to connect to PostNL's SOAP service called CIF (ex- 'DivideBV/Postnl' v1.2.1 - updated for 2018 switch as 1.2.1.1)

dev-master 2018-11-01 20:21 UTC

This package is auto-updated.

Last update: 2024-04-29 04:09:00 UTC


README

PostNL CIF

Latest Stable Version Total Downloads Latest Unstable Version License

This is a library to interface with the SOAP services offered by PostNL, called CIF.

Installation

Install the latest version with

composer require xewl/postnl

Implementation Status

This library is not complete. This table lists which services are implemented and which aren't. The list of existing services is taken from PostNL's developer center.

ServiceImplementedVersion
Addresses €
Adrescheck NationaalN/A
Adrescheck Basis NationaalN/A
Adrescheck InternationaalN/A
Persoon op Adrescheck BasisN/A
Geo Adrescheck NationaalN/A
Creditworthiness & Business information €
Bedrijfscheck NationaalN/A
Fraudepreventie Check BasisN/A
IBANcheck NationaalN/A
Kredietcheck Consument BasisN/A
Kredietcheck Consument PremiumN/A
Kredietcheck ZakelijkN/A
Send & Track
Barcode webservice1_1
Confirming webservice1_9
Labelling webservice2_0
Shippingstatus webservice1_6
Delivery options
Deliverydate webservice2_1
Location webservice2_1
Timeframe webservice2_0
Mail
Bulkmail webserviceN/A

Example

use Xewl\Postnl\Postnl;
use Xewl\Postnl\ComplexTypes;

// Create client class using credentials received from PostNL.
$client = new Postnl(
    12345678,   // Customer number
    'ABCD',     // Customer code
    'Acme BV',  // Customer name
    'Acme',     // Username
    'Password', // Password
    123456,     // Collection location
    'CD1234',   // Globalpack
    true        // Whether to use PostNL's sandbox environment.
);

/**
 * Jan Smit
 * Smit & Zonen
 * Hoofdstraat 1A
 * 1234 AB Heikant
 * The Netherlands
 */
$receiverAddress = ComplexTypes\Address::create()
    ->setAddressType('01')
    ->setFirstName('Jan')
    ->setName('Smit')
    ->setCompanyName('Smit & Zonen')
    ->setStreet('Hoofdstraat')
    ->setHouseNr('1')
    ->setHouseNrExt('A')
    ->setZipcode('1234AB')
    ->setCity('Heikant')
    ->setCountrycode('NL');

$senderAddress = ComplexTypes\Address::create()
    ->setAddressType('02')
    ->setFirstName('Robert')
    ->setName('Jansen')
    ->setCompanyName('Jansen & Janssen')
    ->setStreet('Hoofdstraat')
    ->setHouseNr('999')
    ->setHouseNrExt('B')
    ->setZipcode('1234AB')
    ->setCity('Heikant')
    ->setCountrycode('NL');

// Request a barcode from PostNL.
$barcode = $client->generateBarcodeByDestination($receiverAddress->getCountryCode());

// Create a shipment.
$shipment = ComplexTypes\Shipment::create()
    ->setAddresses(new ComplexTypes\ArrayOfAddress([
        $receiverAddress,
        $senderAddress,
    ]))
    ->setBarcode($barcode)
    ->setDimension(ComplexTypes\Dimension::create()
        ->setWeight(5000) // Weight in g
        ->setWidth(215)   // Width in mm
        ->setLength(305)  // Length in mm
        ->setHeight(280)  // Height in mm
    )
    ->setProductCodeDelivery('3085');

// Generate label and confirm shipment.
$result = $client->generateLabel($shipment);

// Save the label PDF locally.
$label = $result->getLabels()[0];
$file = new \SplFileObject("label.pdf", 'w');
$file->fwrite($label->getContent());