PHP code example of jacobdekeizer / redjepakketje-client

1. Go to this page and download the library: Download jacobdekeizer/redjepakketje-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 / redjepakketje-client example snippets


$client = new \JacobDeKeizer\RedJePakketje\Client();

$client->setApiKey('api_key');

$shipmentsList = $client->shipments()->all(
    new \JacobDeKeizer\RedJePakketje\Parameters\Shipments\All() // optional
);

$shipmentsList = $client->shipments()->allRecentlyCreated();

$shipment = $client->shipments()->get('tracking_code');

// for example check the shipment status
$isDelivered = $shipment->getStatus() === \JacobDeKeizer\RedJePakketje\Models\Shipment\Enums\ShipmentStatus::DELIVERED;

$shipment = (new \JacobDeKeizer\RedJePakketje\Models\Shipment\CreateShipment())
    ->setCompanyName('Boeren BV')
    ->setName('Gijs Boersma')
    ->setStreet('Lange laan')
    ->setHouseNumber(29)
    ->setHouseNumberExtension('a')
    ->setZipcode('9281EM')
    ->setCity('Zevenaar')
    ->setTelephone('0602938172')
    ->setEmail('[email protected]')
    ->setNote('Some note')
    ->setDeliveryDate(date('Y-m-d'))
    ->setProduct(\JacobDeKeizer\RedJePakketje\Models\Shipment\Enums\ShipmentProduct::SAME_DAY_PARCEL_STANDARD)
    ->setReference('reference')
    ->setNote('my_note')
    ->setSender('sender_uuid');
    
// optionally set product options
$shipment->setProductOptions(
    (new \JacobDeKeizer\RedJePakketje\Models\Shipment\ProductOption())
        ->setOption(\JacobDeKeizer\RedJePakketje\Models\Shipment\ProductOption::OPTION_ALLOW_NEIGHBOURS)
        ->setValue(true),
    (new \JacobDeKeizer\RedJePakketje\Models\Shipment\ProductOption())
        ->setOption(\JacobDeKeizer\RedJePakketje\Models\Shipment\ProductOption::OPTION_REQUIRE_SIGNATURE)
        ->setValue(false),
    (new \JacobDeKeizer\RedJePakketje\Models\Shipment\ProductOption())
        ->setOption(\JacobDeKeizer\RedJePakketje\Models\Shipment\ProductOption::OPTION_AGE_CHECK_18)
        ->setValue(false),
    (new \JacobDeKeizer\RedJePakketje\Models\Shipment\ProductOption())
        ->setOption(\JacobDeKeizer\RedJePakketje\Models\Shipment\ProductOption::OPTION_ALLOW_NEIGHBOURS)
        ->setValue(true)
        ->setMaxAttempts(2)
);

$shipmentResponse = $client->shipments()->create(
    $shipment,
    new \JacobDeKeizer\RedJePakketje\Parameters\Shipments\Create() // optional
);

$label = $shipmentResponse->getLabel();


$shipment = $client->shipments()->update(
    'tracking_code',
    (new \JacobDeKeizer\RedJePakketje\Models\Shipment\UpdateShipment())
        ->setProduct(\JacobDeKeizer\RedJePakketje\Models\Shipment\Enums\ShipmentProduct::NEXT_DAY_PARCEL_LARGE)
);

$shipment = $client->shipments()->cancel('tracking_code');

$label = $client->shipments()->getLabel(
    'tracking_code',
    (new \JacobDeKeizer\RedJePakketje\Parameters\Shipments\GetLabel()) // optional
);

$returnShipmentsList = $client->returnShipments()->all(
    new \JacobDeKeizer\RedJePakketje\Parameters\ReturnShipments\All() // optional
);

$returnShipment = $client->returnShipments()->get('return_shipment_uuid');

$returnShipment = (new \JacobDeKeizer\RedJePakketje\Models\ReturnShipment\CreateReturnShipment())
    ->setName('Gijs Boersma')
    ->setStreet('Lange laan')
    ->setHouseNumber(29)
    ->setHouseNumberExtension('a')
    ->setZipcode('9281EM')
    ->setCity('Zevenaar')
    ->setTelephone('0602938172')
    ->setEmail('[email protected]')
    ->setReference('Bestelling 123')
    ->setNote('Some note')
    ->setReceiverName('My company')
    ->setProduct(\JacobDeKeizer\RedJePakketje\Models\ReturnShipment\Enums\ReturnShipmentProduct::SAME_DAY_PARCEL_MEDIUM)
    ->setNote('some text')
    ->setSender('sender_uuid');

$returnShipmentResponse = $client->returnShipments()->create($returnShipment);

$returnShipment = $client->returnShipments()->cancel('return_shipment_uuid');

$senderList = $client->senders()->all();

$sender = $client->senders()->get('sender_uuid');

$sender = $client->senders()->update(
    'sender_uuid',
    (new \JacobDeKeizer\RedJePakketje\Models\Sender\UpdateSender())
        ->setName('My Webshop 123')
        ->setTelephone('+31612345678')
        ->setStreet('Streetname')
        ->setHouseNumber('11')
        ->setZipcode('8327SD')
        ->setCity('Breda')
);

$sender = $client->senders()->create(
    (new \JacobDeKeizer\RedJePakketje\Models\Sender\CreateSender())
        ->setReference('A1234567890Q')
        ->setName('My Webshop')
        ->setTelephone('+31612345678')
        ->setStreet('Streetname')
        ->setHouseNumber('11')
        ->setZipcode('8327SD')
        ->setCity('Breda')
);

$client->senders()->deactivate(
    'sender_uuid',
    (new \JacobDeKeizer\RedJePakketje\Models\Sender\DeactivateSender())
        ->setInactiveFrom(date('Y-m-d', strtotime('+1 day')))
);

$pickUpLocationsList = $client->pickUpLocations()->all(
    new JacobDeKeizer\RedJePakketje\Parameters\PickUpLocation\All() // optional
);

$pickUpLocation = $client->pickUpLocations()->get('pick_up_location_uuid');

$pickUpLocation = $client->pickUpLocations()->create(
    (new JacobDeKeizer\RedJePakketje\Models\PickUpLocation\CreatePickUpLocation())
        ->setName('Warehouse')
        ->setStreet('Streetname')
        ->setHouseNumber('11')
        ->setHouseNumberExtension('a')
        ->setZipcode('8327SD')
        ->setCity('Breda')
        ->setAvailableDays([1, 2, 3, 4, 5])
        ->setTypes([\JacobDeKeizer\RedJePakketje\Models\PickUpLocation\Enums\PickUpLocationType::PICK_UP_POINT])
);

$pickUpLocation = $client->pickUpLocations()->update(
    'pick_up_location_uuid',
    (new \JacobDeKeizer\RedJePakketje\Models\PickUpLocation\UpdatePickUpLocation())
        ->setAvailableDays([1, 2, 3, 4, 5, 6, 7])
);

$pickUpRulesList = $client->pickUpRules()->all('sender_uuid');

$pickUpRule = $client->pickUpRules()->create(
        'sender_uuid',
        (new \JacobDeKeizer\RedJePakketje\Models\PickUpRule\CreatePickUpRule())
            ->setPickUpLocation('pick_up_location_uuid')
            ->setStartDate(date('Y-m-d'))
    );

$pickUpRule = $client->pickUpRules()->update(
    'sender_uuid',
    'pick_up_rule_uuid',
    (new \JacobDeKeizer\RedJePakketje\Models\PickUpRule\UpdatePickUpRule())
        ->setStartDate(date('Y-m-d', strtotime('+1 day')))
);


$client->pickUpRules()->delete(
    'sender_uuid',
    'pick_up_rule_uuid'
);

$contactsList = $client->contacts()->all();

$contact = $client->contacts()->get('contact_uuid');

$contact = $client->contacts()->create(
    (new \JacobDeKeizer\RedJePakketje\Models\Contact\CreateContact())
        ->setFirstName('John')
        ->setLastName('Doe')
        ->setEmail('[email protected]')
        ->setTelephone('+31612345678')
        ->setGender(\JacobDeKeizer\RedJePakketje\Models\Contact\Enums\Gender::MALE)
        ->setReference('reference')
);

$contact = $client->contacts()->update(
    'contact_uuid',
    (new \JacobDeKeizer\RedJePakketje\Models\Contact\UpdateContact())
        ->setFirstName('Jane')
        ->setLastName('Doe')
        ->setEmail('[email protected]')
        ->setTelephone('+31612345678')
        ->setGender(\JacobDeKeizer\RedJePakketje\Models\Contact\Enums\Gender::FEMALE)
        ->setReference('reference')
);

// example bad call
try {
    $shipmentResponse = $client->shipments()->create(
        (new \JacobDeKeizer\RedJePakketje\Models\Shipment\CreateShipment()),
    );
} catch (\JacobDeKeizer\RedJePakketje\Exceptions\RedJePakketjeException $exception) {
    if ($exception->hasResponse()) {
        var_dump($exception->getResponse());
    }

    if ($exception->hasResponseError()) {
        var_dump($exception->getResponseError()->getErrorCode());
        var_dump($exception->getResponseError()->getErrorMessage());
        var_dump($exception->getResponseError()->getErrorDetails());
    }

    if ($exception->isJsonError()) {
        var_dump($exception->getPrevious());
    }
}