PHP code example of accu / postmen-sdk

1. Go to this page and download the library: Download accu/postmen-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

accu / postmen-sdk example snippets


$client = new \Accu\Postmen\Client(
    (new \Accu\Postmen\Configuration('your-api-key', $testMode = true))
        ->setMaxRetries(1)
);

/** @var \Accu\Postmen\Entities\Label $label */
$label = $client->send((new \Accu\Postmen\Requests\Labels\Create())
    ->addReference('Dispatch #1')
    ->setServiceType('dpd-uk_parcel_1d')
    ->setShipperAccount((new \Accu\Postmen\Entities\ShipperAccount())
        ->setId('your-shipper-account-id')
    )
    ->setShipment((new \Accu\Postmen\Entities\Shipment())
        ->setShipTo((new \Accu\Postmen\Entities\Address())
            ->setContactName('Goods In')
            ->setCompanyName('Accu Limited')
            ->setStreet1('Haggwood Stone Quarry')
            ->setStreet2('Woodhead Road')
            ->setCity('Holmfirth')
            ->setPostalCode('HD9 6PW')
            ->setCountry('GBR')
            ->setEmail('[email protected]')
            ->setPhone('0123456789')
        )
        ->setShipFrom((new \Accu\Postmen\Entities\Address())
            ->setContactName('Goods Out')
            ->setCompanyName('Accu Limited')
            ->setStreet1('Haggwood Stone Quarry')
            ->setStreet2('Woodhead Road')
            ->setCity('Holmfirth')
            ->setPostalCode('HD9 6PW')
            ->setCountry('GBR')
            ->setEmail('[email protected]')
            ->setPhone('0123456789')
        )
        ->setDeliveryInstructions('Please ring the bell')
        ->addParcel((new \Accu\Postmen\Entities\Parcel())
            ->setBoxType('custom')
            ->setDimension((new \Accu\Postmen\Entities\Dimension())
                ->setUnit('cm')
                ->setHeight(30)
                ->setWidth(50)
                ->setDepth(30)
            )
            ->addItem((new \Accu\Postmen\Entities\Item())
                ->setSku('APC000001')
                ->setItemId('tiny-screw-1')
                ->setDescription('A small screw')
                ->setWeight((new \Accu\Postmen\Entities\Weight())
                    ->setUnit('kg')
                    ->setValue(0.001)
                )
                ->setQuantity(1000)
                ->setPrice((new \Accu\Postmen\Entities\Money())
                    ->setCurrency('GBP')
                    ->setAmount(0.005)
                )
                ->setOriginCountry('GBR')
                ->setHsCode('7318141090')
            )
            ->setWeight((new \Accu\Postmen\Entities\Weight())
                ->setUnit('kg')
                // Sum of items plus packaging.
                ->setValue(1.2)
            )
        )
    )
);

echo $label->getId(); // the-label-identifier
echo $label->getTrackingNumbers(); // ['tracking-1..', 'tracking-2..', ...]
echo $label->getFiles()->getLabel()->getUrl(); // The shipping labels to be printed