PHP code example of jacobdekeizer / dpd-shipper-client
1. Go to this page and download the library: Download jacobdekeizer/dpd-shipper-client 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/ */
jacobdekeizer / dpd-shipper-client example snippets
$client = new \JacobDeKeizer\DpdShipper\Client(
authTokenStore: new \JacobDeKeizer\DpdShipper\Stores\JsonFileAuthTokenStore(
__DIR__ . '/auth.json'
), // Or your own implementation of the AuthTokenStore interface
accountConfiguration: new \JacobDeKeizer\DpdShipper\Configuration\AccountConfiguration(
username: 'username',
depotNumber: 'depot number',
password: 'password',
),
locale: 'nl_NL', // optional
staging: false, // optional
);
$result = $client->parcelShopFinder()->findParcelShops(new \JacobDeKeizer\DpdShipper\Entities\ParcelShopFinder\FindParcelShopsRequest(
country: 'NL',
zipCode: '1012NX',
city: 'Amsterdam',
limit: 2
));
$result = $client->parcelShopFinder()->findParcelShopsByGeoData(new \JacobDeKeizer\DpdShipper\Entities\ParcelShopFinder\FindParcelShopsByGeoDataRequest(
latitude: 52.377956,
longitude: 4.897070,
limit: 2
));
$result = $client->shipment()->storeOrders(new \JacobDeKeizer\DpdShipper\Entities\Shipment\StoreOrdersRequest(
[
new \JacobDeKeizer\DpdShipper\Entities\Shipment\Order(
generalShipmentData: new \JacobDeKeizer\DpdShipper\Entities\Shipment\GeneralShipmentData(
sendingDepot: $this->client->login()->session()->depot,
product: \JacobDeKeizer\DpdShipper\Entities\Shipment\ShipmentProduct::CL,
sender: new \JacobDeKeizer\DpdShipper\Entities\Shipment\Address(
name1: 'Ikea',
street: 'Hullenbergweg',
country: 'NL',
zipCode: '1101BL',
city: 'Amsterdam',
houseNo: '2',
phone: '+31612345678',
email: '[email protected] ',
),
recipient: new \JacobDeKeizer\DpdShipper\Entities\Shipment\Address(
name1: 'John Doe',
street: 'Hullenbergweg',
country: 'NL',
zipCode: '1101BL',
city: 'Amsterdam',
name2: 'Company Name',
houseNo: '2',
phone: '+31612345678',
email: '[email protected] ',
),
),
productAndServiceData: new \JacobDeKeizer\DpdShipper\Entities\Shipment\ProductAndServiceData(
orderType: \JacobDeKeizer\DpdShipper\Entities\Shipment\OrderType::Consignment,
saturdayDelivery: true,
predict: new \JacobDeKeizer\DpdShipper\Entities\Shipment\Notification(
channel: \JacobDeKeizer\DpdShipper\Entities\Shipment\NotificationChannel::Sms,
value: '+31612345678',
language: 'NL',
),
),
parcels: [
new \JacobDeKeizer\DpdShipper\Entities\Shipment\Parcel(
customerReferenceNumber1: 'TEST12345',
customerReferenceNumber2: 'A reference', // Optional
volume: 0100202030, // 10cm x 20cm x 30cm, optional
weight: 315, // 3,15 KG, optional
),
new \JacobDeKeizer\DpdShipper\Entities\Shipment\Parcel(
customerReferenceNumber1: 'TEST12',
)
]
)
],
new \JacobDeKeizer\DpdShipper\Entities\Shipment\PrintOptions(
printerLanguage: \JacobDeKeizer\DpdShipper\Entities\Shipment\PrinterLanguage::PDF,
paperFormat: \JacobDeKeizer\DpdShipper\Entities\Shipment\PaperFormat::A6,
)
));
try {
$result = $client->parcelShopFinder()->findParcelShopsByGeoData(...);
var_dump($result);
} catch (\JacobDeKeizer\DpdShipper\Exceptions\AuthenticationFaultException $authenticationFaultException) {
// Catches the specific AuthenticationFaultException
$errorMessage = $authenticationFaultException->detail->authenticationFault->errorMessage;
var_dump($authenticationFaultException->detail);
} catch (\JacobDeKeizer\DpdShipper\Exceptions\DpdShipperException $exception) {
// Catches the rest of the possible exceptions.
var_dump($exception);
}