Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add carrier dhl #428

Merged
merged 27 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1f2413f
feat: add carrier dhl for you
Mark-Ernst Sep 9, 2022
c059ed0
wip
Mark-Ernst Sep 9, 2022
8a03857
fix: add extra_assurance and change hide_sender
wthijmen Nov 21, 2022
42547b4
fix: hide sender constant
joerivanveen Nov 21, 2022
289e1b6
wip
wthijmen Nov 21, 2022
14885da
wip
wthijmen Nov 21, 2022
f6b9cfd
fix: correct options for dhlforyou consignment
joerivanveen Nov 21, 2022
9ec7e52
fix(dhl): remove unsupported options
joerivanveen Nov 21, 2022
418ed4e
fix(dhl): remove unsupported pickup options
joerivanveen Nov 21, 2022
d1fab69
fix(dhl): remove unsupported options, add hide sender and extra assur…
joerivanveen Nov 21, 2022
b39cf8f
fix: add hide_sender to shipment options in encode
Mark-Ernst Nov 22, 2022
439d0ec
fix(dhlforyou): prevent export of faulty combinations
Mark-Ernst Nov 22, 2022
54c1791
refactor: instabox to dhlforyou consignmenttest
wthijmen Nov 22, 2022
4a7fa33
refactor: updated coverage
wthijmen Nov 22, 2022
ddc8d3a
refactor: updated coverage
wthijmen Nov 22, 2022
4d24908
fix(dhlforyou): add pickup to allowed delivery types
Mark-Ernst Nov 22, 2022
c5a85ad
refactor: remove dead code
Mark-Ernst Nov 22, 2022
e7d5c36
fix(dhl): coverage
joerivanveen Nov 24, 2022
489cb75
fix(dhl): remove todo
joerivanveen Nov 24, 2022
e211f59
fix: updated coverage
wthijmen Nov 25, 2022
ffc7d53
Update src/Model/Consignment/AbstractConsignment.php
wthijmen Nov 25, 2022
c762ef5
fix: implement feedback
wthijmen Nov 25, 2022
8648c1b
fix:
Mark-Ernst Nov 28, 2022
b82ef32
refactor: change dhl for you human string
Mark-Ernst Nov 28, 2022
eda885d
refactor: add same day delivery
Mark-Ernst Nov 28, 2022
cc6bcab
fix(dhl): wip
joerivanveen Dec 5, 2022
1ea0caf
test: fix dhl tests
EdieLemoine Dec 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Adapter/ConsignmentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ private function setExtraOptions(): self
'package_type' => $options['package_type'] ?? AbstractConsignment::PACKAGE_TYPE_PACKAGE,
'delivery_date' => $options['delivery_date'] ?? null,
'delivery_type' => $options['delivery_type'] ?? AbstractConsignment::DEFAULT_DELIVERY_TYPE,
'only_recipient' => (bool) ($options['only_recipient'] ?? false),
'large_format' => (bool) ($options['large_format'] ?? false),
'age_check' => (bool) ($options['age_check'] ?? false),
'signature' => (bool) ($options['signature'] ?? false),
'extra_assurance' => (bool) ($options['extra_assurance'] ?? false),
'hide_sender' => (bool) ($options['hide_sender'] ?? false),
'large_format' => (bool) ($options['large_format'] ?? false),
'only_recipient' => (bool) ($options['only_recipient'] ?? false),
'return' => (bool) ($options['return'] ?? false),
'same_day_delivery' => (bool) ($options['same_day_delivery'] ?? false),
'signature' => (bool) ($options['signature'] ?? false),
'insurance' => $options['insurance']['amount'] ?? 0,
'label_description' => $options['label_description'] ?? null,
]);
Expand Down
68 changes: 61 additions & 7 deletions src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Adapter\DeliveryOptions;

Expand All @@ -24,6 +25,11 @@ abstract class AbstractShipmentOptionsAdapter
*/
protected $same_day_delivery;

/**
* @var bool|null
*/
protected $hide_sender;

/**
* @var bool|null
*/
Expand All @@ -44,6 +50,11 @@ abstract class AbstractShipmentOptionsAdapter
*/
protected $label_description;

/**
* @var null|bool
*/
protected $extra_assurance;

/**
* @return bool|null
*/
Expand Down Expand Up @@ -76,6 +87,22 @@ public function hasLargeFormat(): ?bool
return $this->large_format;
}

/**
* @return null|bool
*/
public function hasHideSender(): ?bool
{
return $this->hide_sender;
}

/**
* @return null|bool
*/
public function hasExtraAssurance(): ?bool
{
return $this->extra_assurance;
}

/**
* Return the package if the recipient is not home
*
Expand Down Expand Up @@ -113,7 +140,7 @@ public function setLabelDescription(string $labelDescription): void
}

/**
* @param null|bool $signature
* @param null|bool $signature
*
* @return void
*/
Expand All @@ -123,7 +150,7 @@ public function setSignature(?bool $signature): void
}

/**
* @param null|int $insurance
* @param null|int $insurance
*
* @return void
*/
Expand All @@ -133,7 +160,7 @@ public function setInsurance(?int $insurance): void
}

/**
* @param null|bool $ageCheck
* @param null|bool $ageCheck
*
* @return void
*/
Expand All @@ -143,7 +170,7 @@ public function setAgeCheck(?bool $ageCheck): void
}

/**
* @param null|bool $onlyRecipient
* @param null|bool $onlyRecipient
*
* @return void
*/
Expand All @@ -153,7 +180,7 @@ public function setOnlyRecipient(?bool $onlyRecipient): void
}

/**
* @param null|bool $return
* @param null|bool $return
*
* @return void
*/
Expand All @@ -162,13 +189,28 @@ public function setReturn(?bool $return): void
$this->return = $return;
}

/**
* @param null|bool $sameDayDelivery
*
* @return void
*/
public function setSameDayDelivery(?bool $sameDayDelivery): void
{
$this->same_day_delivery = $sameDayDelivery;
}

/**
* @param null|bool $largeFormat
* @param null|bool $hideSender
*
* @return void
*/
public function setHideSender(?bool $hideSender): void
{
$this->hide_sender = $hideSender;
}

/**
* @param null|bool $largeFormat
*
* @return void
*/
Expand All @@ -177,6 +219,16 @@ public function setLargeFormat(?bool $largeFormat): void
$this->large_format = $largeFormat;
}

/**
* @param null|bool $extraAssurance
*
* @return void
*/
public function setExtraAssurance(?bool $extraAssurance): void
{
$this->extra_assurance = $extraAssurance;
}

/**
* @return array
*/
Expand All @@ -191,6 +243,8 @@ public function toArray(): array
'same_day_delivery' => $this->isSameDayDelivery(),
'large_format' => $this->hasLargeFormat(),
'label_description' => $this->getLabelDescription(),
'hide_sender' => $this->hasHideSender(),
'extra_assurance' => $this->hasExtraAssurance(),
];
}
}
10 changes: 6 additions & 4 deletions src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ class ShipmentOptionsV3Adapter extends AbstractShipmentOptionsAdapter
*/
public function __construct(array $shipmentOptions)
{
$this->signature = $shipmentOptions['signature'] ?? null;
$this->only_recipient = $shipmentOptions['only_recipient'] ?? null;
$this->insurance = $shipmentOptions['insurance'] ?? null;
$this->age_check = $shipmentOptions['age_check'] ?? null;
$this->extra_assurance = $shipmentOptions['extra_assurance'] ?? null;
$this->hide_sender = $shipmentOptions['hide_sender'] ?? null;
$this->insurance = $shipmentOptions['insurance'] ?? null;
$this->label_description = $shipmentOptions['label_description'] ?? null;
$this->large_format = $shipmentOptions['large_format'] ?? null;
$this->only_recipient = $shipmentOptions['only_recipient'] ?? null;
$this->return = $shipmentOptions['return'] ?? null;
$this->same_day_delivery = $shipmentOptions['same_day_delivery'] ?? null;
$this->label_description = $shipmentOptions['label_description'] ?? null;
$this->signature = $shipmentOptions['signature'] ?? null;
}
}
1 change: 1 addition & 0 deletions src/Helper/MyParcelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ private function apiEncodeReturnShipments(array $consignments): string
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException
* @throws \Exception
*/
private function getNewCollectionFromResult($result): self
{
Expand Down
35 changes: 35 additions & 0 deletions src/Model/Carrier/CarrierDHLForYou.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Carrier;

use MyParcelNL\Sdk\src\Model\Consignment\DHLForYouConsignment;

class CarrierDHLForYou extends AbstractCarrier
{
public const CONSIGNMENT = DHLForYouConsignment::class;
public const HUMAN = 'DHL For You Vandaag';
public const ID = 9;
public const NAME = 'dhlforyou';

/**
* @var class-string
*/
protected $consignmentClass = self::CONSIGNMENT;

/**
* @var string
*/
protected $human = self::HUMAN;

/**
* @var int
*/
protected $id = self::ID;

/**
* @var string
*/
protected $name = self::NAME;
}
1 change: 1 addition & 0 deletions src/Model/Carrier/CarrierFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CarrierFactory
CarrierDPD::class,
CarrierPostNL::class,
CarrierInstabox::class,
CarrierDHLForYou::class,
];

/**
Expand Down
54 changes: 53 additions & 1 deletion src/Model/Consignment/AbstractConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ abstract class AbstractConsignment
use HasApiKey;

public const SHIPMENT_OPTION_AGE_CHECK = 'age_check';
public const SHIPMENT_OPTION_HIDE_SENDER = 'hide_sender';
public const SHIPMENT_OPTION_INSURANCE = 'insurance';
public const SHIPMENT_OPTION_LARGE_FORMAT = 'large_format';
public const SHIPMENT_OPTION_ONLY_RECIPIENT = 'only_recipient';
public const SHIPMENT_OPTION_RETURN = 'return';
public const SHIPMENT_OPTION_SIGNATURE = 'signature';
public const SHIPMENT_OPTION_SAME_DAY_DELIVERY = 'same_day_delivery';
public const SHIPMENT_OPTION_SIGNATURE = 'signature';
public const SHIPMENT_OPTION_EXTRA_ASSURANCE = 'extra_assurance';

public const EXTRA_OPTION_DELIVERY_DATE = 'delivery_date';
public const EXTRA_OPTION_DELIVERY_MONDAY = 'delivery_monday';
Expand Down Expand Up @@ -423,6 +425,16 @@ abstract class AbstractConsignment
*/
private $carrier;

/**
* @var bool
*/
private $hide_sender;

/**
* @var bool
*/
private $extra_assurance;

/**
* @var bool
*/
Expand Down Expand Up @@ -1489,6 +1501,46 @@ public function setLargeFormat(bool $largeFormat): self
return $this;
}

/**
* @param bool $hideSender
* @codeCoverageIgnore
* @return $this
*/
public function setHideSender(bool $hideSender): self
{
$this->hide_sender = $hideSender;

return $this;
}

/**
* @return null|bool
*/
public function hasHideSender(): ?bool
{
return $this->hide_sender;
}

/**
* @param bool $extraAssurance
* @codeCoverageIgnore
* @return $this
*/
public function setExtraAssurance(bool $extraAssurance): self
{
$this->extra_assurance = $extraAssurance;

return $this;
}

/**
* @return null|bool
*/
public function hasExtraAssurance(): ?bool
{
return $this->extra_assurance;
}

/**
* Age check
* Required: No.
Expand Down
66 changes: 66 additions & 0 deletions src/Model/Consignment/DHLForYouConsignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Consignment;

use MyParcelNL\Sdk\src\Model\Carrier\CarrierDHLForYou;
use MyParcelNL\Sdk\src\Validator\Consignment\DHLForYouConsignmentValidator;

class DHLForYouConsignment extends AbstractConsignment
{
/**
* @var string
*/
protected $carrierClass = CarrierDHLForYou::class;

/**
* @var string
*/
protected $validatorClass = DHLForYouConsignmentValidator::class;

/**
* @return string[]
*/
public function getAllowedDeliveryTypes(): array
{
return [
self::DELIVERY_TYPE_STANDARD_NAME,
self::DELIVERY_TYPE_PICKUP_NAME,
];
}

/**
* @return string[]
*/
public function getAllowedPackageTypes(): array
{
return [
self::PACKAGE_TYPE_PACKAGE_NAME,
self::PACKAGE_TYPE_MAILBOX_NAME,
];
}

/**
* @return string[]
*/
public function getAllowedShipmentOptions(): array
{
return [
self::SHIPMENT_OPTION_AGE_CHECK,
self::SHIPMENT_OPTION_HIDE_SENDER,
self::SHIPMENT_OPTION_EXTRA_ASSURANCE,
self::SHIPMENT_OPTION_ONLY_RECIPIENT,
self::SHIPMENT_OPTION_SIGNATURE,
self::SHIPMENT_OPTION_SAME_DAY_DELIVERY,
];
}

/**
* @return string
*/
public function getLocalCountryCode(): string
{
return self::CC_NL;
}
}
Loading