-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
55 changed files
with
608 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ | |
}, | ||
"tracked": { | ||
"enum": [0, 1] | ||
}, | ||
"receiptCode": { | ||
"enum": [-1] | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ | |
500000, | ||
null | ||
] | ||
}, | ||
"receiptCode": { | ||
"enum": [-1, 0, 1] | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,9 @@ | |
}, | ||
"tracked": { | ||
"enum": [0, 1] | ||
}, | ||
"receiptCode": { | ||
"enum": [0, 1] | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\App\Options\Definition; | ||
|
||
use MyParcelNL\Pdk\App\Options\Contract\OrderOptionDefinitionInterface; | ||
use MyParcelNL\Pdk\Settings\Model\CarrierSettings; | ||
use MyParcelNL\Pdk\Settings\Model\ProductSettings; | ||
use MyParcelNL\Pdk\Shipment\Model\ShipmentOptions; | ||
use MyParcelNL\Pdk\Validation\Validator\CarrierSchema; | ||
|
||
final class ReceiptCodeDefinition implements OrderOptionDefinitionInterface | ||
{ | ||
public function getCarrierSettingsKey(): ?string | ||
{ | ||
return CarrierSettings::EXPORT_RECEIPT_CODE; | ||
} | ||
|
||
public function getProductSettingsKey(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function getShipmentOptionsKey(): ?string | ||
{ | ||
return ShipmentOptions::RECEIPT_CODE; | ||
} | ||
|
||
public function validate(CarrierSchema $carrierSchema): bool | ||
{ | ||
return $carrierSchema->canHaveReceiptCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/App/Order/Calculator/PostNl/PostNLReceiptCodeCalculator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\App\Order\Calculator\PostNl; | ||
|
||
use MyParcelNL\Pdk\App\Order\Calculator\AbstractPdkOrderOptionCalculator; | ||
use MyParcelNL\Pdk\Base\Service\CountryCodes; | ||
use MyParcelNL\Pdk\Types\Service\TriStateService; | ||
use MyParcelNL\Pdk\Validation\Validator\CarrierSchema; | ||
use MyParcelNL\Pdk\Facade\Pdk; | ||
|
||
/** | ||
* When receipt code is enabled, insurance is required. | ||
*/ | ||
final class PostNLReceiptCodeCalculator extends AbstractPdkOrderOptionCalculator | ||
{ | ||
/** | ||
* Calculates the receipt code options for PostNL shipments. | ||
* When receipt code is enabled: | ||
* - Shipment must be to the Netherlands | ||
* - Receipt code will be disabled if age check is active | ||
* - Signature and only recipient will be disabled | ||
* - Large format will be disabled | ||
* - Return will be disabled | ||
* - Insurance will be enabled (minimum €100) when no insurance is active | ||
*/ | ||
public function calculate(): void | ||
{ | ||
$shipmentOptions = $this->order->deliveryOptions->shipmentOptions; | ||
|
||
if (TriStateService::ENABLED !== $shipmentOptions->receiptCode) { | ||
return; | ||
} | ||
|
||
if ($this->order->shippingAddress->cc !== CountryCodes::CC_NL) { | ||
$shipmentOptions->receiptCode = TriStateService::DISABLED; | ||
return; | ||
} | ||
|
||
if (TriStateService::ENABLED === $shipmentOptions->ageCheck) { | ||
$shipmentOptions->receiptCode = TriStateService::DISABLED; | ||
return; | ||
} | ||
|
||
$shipmentOptions->signature = TriStateService::DISABLED; | ||
$shipmentOptions->onlyRecipient = TriStateService::DISABLED; | ||
$shipmentOptions->largeFormat = TriStateService::DISABLED; | ||
$shipmentOptions->return = TriStateService::DISABLED; | ||
|
||
if ($shipmentOptions->insurance === TriStateService::DISABLED) { | ||
/** @var \MyParcelNL\Pdk\Validation\Validator\CarrierSchema $schema */ | ||
$schema = Pdk::get(CarrierSchema::class); | ||
$allowedInsuranceAmounts = $schema | ||
->setCarrier($this->order->deliveryOptions->carrier) | ||
->getAllowedInsuranceAmounts(); | ||
|
||
$shipmentOptions->insurance = $this->getLowestInsuranceAmount($allowedInsuranceAmounts); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the lowest allowed insurance amount that is greater than 0. | ||
* | ||
* @param int[] $insuranceAmount | ||
* | ||
* @return int | ||
*/ | ||
private function getLowestInsuranceAmount(array $insuranceAmount): int | ||
{ | ||
$lowestAmount = null; | ||
|
||
foreach ($insuranceAmount as $allowedInsuranceAmount) { | ||
if ($allowedInsuranceAmount <= 0) { | ||
continue; | ||
} | ||
|
||
if (null === $lowestAmount || $allowedInsuranceAmount < $lowestAmount) { | ||
$lowestAmount = $allowedInsuranceAmount; | ||
} | ||
} | ||
|
||
return $lowestAmount ?? 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.