PHP code example of wuunder / connector-php

1. Go to this page and download the library: Download wuunder/connector-php 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/ */

    

wuunder / connector-php example snippets


$draftsRequest = $connector->createBulkDrafts();

$draftsConfig = new \Wuunder\Api\Config\DraftConfig();

$booking1 = new \Wuunder\Api\Config\BookingConfig();
$booking1->setWebhookUrl("url");
$booking1->setRedirectUrl("url");

$booking2 = new \Wuunder\Api\Config\BookingConfig();
$booking2->setWebhookUrl("url");
$booking2->setRedirectUrl("url");

$draftsConfig->addBookingConfig(1, $booking1, true);
$draftsConfig->addBookingConfig(2, $booking2, true);

if ($draftsConfig->validate()) {
    $draftsRequest->setConfig($draftsConfig);

    if ($draftsRequest->fire()) {
        var_dump($draftsRequest->getDraftsResponse());
    } else {
        var_dump($draftsRequest->getDraftsResponse()->getError());
    }
} else {
    print("DraftsConfig not valid");
}

$booking = $connector->createBooking();

$bookingConfig = new Wuunder\Api\Config\BookingConfig();
$bookingConfig->setWebhookUrl("url");
$bookingConfig->setRedirectUrl("url");

if ($bookingConfig->validate()) {
    $booking->setConfig($bookingConfig);

    if ($booking->fire()) {
        var_dump($booking->getBookingResponse()->getBookingUrl());
    } else {
        var_dump($booking->getBookingResponse()->getError());
    }
} else {
    print("Bookingconfig not valid");
}

$shipment = $connector->createShipment();

$shipmentConfig = new \Wuunder\Api\Config\ShipmentConfig();
$shipmentConfig->setDescription("Test");
$shipmentConfig->setKind("package");
$shipmentConfig->setValue(200);
$shipmentConfig->setLength(10);
$shipmentConfig->setWidth(10);
$shipmentConfig->setHeight(10);
$shipmentConfig->setWeight(210);
$shipmentConfig->setPreferredServiceLevel("cheapest");

$deliveryAddress = new \Wuunder\Api\Config\AddressConfig();
$deliveryAddress->setEmailAddress("email");
$deliveryAddress->setFamilyName("Lastname");
$deliveryAddress->setGivenName("Firstname");
$deliveryAddress->setLocality("City");
$deliveryAddress->setStreetName("Street");
$deliveryAddress->setHouseNumber("Number");
$deliveryAddress->setZipCode("Zipcode");
$deliveryAddress->setCountry("NL");

$shipmentConfig->setDeliveryAddress($deliveryAddress);

$pickupAddress = new \Wuunder\Api\Config\AddressConfig();
$pickupAddress->setEmailAddress("email");
$pickupAddress->setFamilyName("Lastname");
$pickupAddress->setGivenName("Firstname");
$pickupAddress->setLocality("City");
$pickupAddress->setStreetName("Street");
$pickupAddress->setHouseNumber("Number");
$pickupAddress->setZipCode("Zipcode");
$pickupAddress->setCountry("NL");

$shipmentConfig->setPickupAddress($pickupAddress);

if ($shipmentConfig->validate()) {
    $shipment->setConfig($shipmentConfig);

    if ($shipment->fire()) {
        var_dump($shipment->getShipmentResponse()->getShipmentData());
    } else {
        var_dump($shipment->getShipmentResponse()->getError());
    }
} else {
    print("ShipmentConfig not valid");
}

$parcelshopsRequest = $connector->getParcelshopsByAddress();

$parcelshopsConfig = new \Wuunder\Api\Config\ParcelshopsConfig();
$parcelshopsConfig->setProviders(array("CARRIERCODE"));
$parcelshopsConfig->setAddress("address");
$parcelshopsConfig->setLimit(40);

if ($parcelshopsConfig->validate()) {
    $parcelshopsRequest->setConfig($parcelshopsConfig);

    if ($parcelshopsRequest->fire()) {
        var_dump(json_encode($parcelshopsRequest->getParcelshopsResponse()->getParcelshopsData()));
    } else {
        var_dump($parcelshopsRequest->getParcelshopsResponse()->getError());
    }
} else {
    print("ParcelshopsConfig not valid");
}

$parcelshopRequest = $connector->getParcelshopById();

$parcelshopConfig = new \Wuunder\Api\Config\ParcelshopConfig();
$parcelshopConfig->setId("id");

if ($parcelshopConfig->validate()) {
    $parcelshopRequest->setConfig($parcelshopConfig);

    if ($parcelshopRequest->fire()) {
        var_dump(json_encode($parcelshopRequest->getParcelshopResponse()->getParcelshopData()));
    } else {
        var_dump($parcelshopRequest->getParcelshopResponse()->getError());
    }
} else {
    print("ParcelshopConfig not valid");
}