DivideBV / Postnl

Library to connect to PostNL's SOAP service called CIF
GNU General Public License v2.0
31 stars 40 forks source link

Implement PostNL location EasyReturn Webservice #41

Closed BBrunekreeft closed 2 years ago

BBrunekreeft commented 7 years ago

Added support for PostNL EasyReturn Webservice. This webservice generates return labels in PDF format for use with return shipments from outside the Netherlands. I've created: ComplexTypes/GenerateReturnLabelRequest.php ComplexTypes/GenerateReturnLabelResponse.php Modified Postnl.nl, added generateReturnLabel() function.

Easyreturn label is created like this:

$barcode = '3SXXXX123456';
$receiverAddress = \DivideBV\Postnl\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 = \DivideBV\Postnl\ComplexTypes\Address::create()
    ->setAddressType('02')
    ->setFirstName('John')
    ->setName('Doe')
    ->setCompanyName('')
    ->setStreet('Wiertzstraat')
    ->setHouseNr('60')
    ->setHouseNrExt('')
    ->setZipcode('1047')
    ->setCity('Brussel')
    ->setCountrycode('BE');

$contact = \DivideBV\Postnl\ComplexTypes\Contact::create()
    ->setContactType('01')
    ->setEmail('info@example.com');

$shipment = \DivideBV\Postnl\ComplexTypes\Shipment::create()
    ->setAddresses(new \DivideBV\Postnl\ComplexTypes\ArrayOfAddress([
        $receiverAddress,
        $senderAddress,
    ]))
    ->setContacts(new \DivideBV\Postnl\ComplexTypes\ArrayOfContact([
        $contact,
    ]))
    ->setBarcode($barcode)
    ->setDimension(\DivideBV\Postnl\ComplexTypes\Dimension::create()
        ->setWeight(1000) // Weight in g
    );

$shipment->setProductCodeDelivery('04910');
$result = $client->generateReturnLabel($shipment, 'Jan Smit', 'info@example.com');
$label = $result->getLabels()[0];
$file = new \SplFileObject("label.pdf", 'w');
$file->fwrite($label->getContent());
ameenross commented 7 years ago

Also a final point: add the supported version of this service to the readme