jacobdekeizer/redjepakketje-client

此软件包已被废弃,不再维护。未建议替代软件包。

PHP 的 Red je Pakketje API 客户端

v2.0.0 2021-11-23 17:46 UTC

This package is auto-updated.

Last update: 2023-11-12 11:26:24 UTC


README

Packagist Version Packagist Packagist Packagist Build

Red je Pakketje API 文档

安装

使用 composer 获取

composer require jacobdekeizer/redjepakketje-client

用法

本说明展示了此软件包的基本用法,有关所有可用选项,请参阅类定义和 API 文档。

创建客户端

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

$client->setApiKey('api_key');

货运

列出货运

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

列出最近创建的货运

检索过去 7 天内的货运。

$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('noreply@example.com')
    ->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('noreply@example.com')
    ->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('john.doe@example.com')
        ->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('jane.doe@example.com')
        ->setTelephone('+31612345678')
        ->setGender(\JacobDeKeizer\RedJePakketje\Models\Contact\Enums\Gender::FEMALE)
        ->setReference('reference')
);

异常

您可以捕获 RedJePakketjeException 并检查是否有响应和响应错误,或者是否为 json 错误。

// 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());
    }
}

代码检查器

检查: composer phpcs

自动修复: composer phpcbf