Skip to content

Commit

Permalink
feat: add receipt code (#507)
Browse files Browse the repository at this point in the history
* feat: add receipt code

* chore: formatting(1)

* feat: add receipt code

* feat: add receipt code
  • Loading branch information
joerivanveen authored Oct 23, 2024
1 parent 1e01ce2 commit e794021
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 252 deletions.
5 changes: 3 additions & 2 deletions src/Adapter/ConsignmentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ConsignmentAdapter
/**
* ConsignmentDecode constructor.
*
* @param array $data
* @param \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment $consignment
* @param array $data
* @param \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment $consignment
*
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException
*/
Expand Down Expand Up @@ -103,6 +103,7 @@ private function setExtraOptions(): self
'return' => (bool) ($options['return'] ?? false),
'same_day_delivery' => (bool) ($options['same_day_delivery'] ?? false),
'signature' => (bool) ($options['signature'] ?? false),
'receipt_code' => (bool) ($options['receipt_code'] ?? false),
'insurance' => $options['insurance']['amount'] ?? 0,
'label_description' => $options['label_description'] ?? null,
]);
Expand Down
42 changes: 33 additions & 9 deletions src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ abstract class AbstractShipmentOptionsAdapter
*/
protected $signature;

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

/**
* @var bool|null
*/
Expand Down Expand Up @@ -63,6 +68,14 @@ public function hasSignature(): ?bool
return $this->signature;
}

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

/**
* @return bool|null
*/
Expand Down Expand Up @@ -140,7 +153,7 @@ public function setLabelDescription(string $labelDescription): void
}

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

/**
* @param null|int $insurance
* @param bool|null $receiptCode
*
* @return void
*/
public function setReceiptCode(?bool $receiptCode): void
{
$this->receipt_code = $receiptCode;
}

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

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

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

/**
* @param null|bool $return
* @param null|bool $return
*
* @return void
*/
Expand All @@ -190,7 +213,7 @@ public function setReturn(?bool $return): void
}

/**
* @param null|bool $sameDayDelivery
* @param null|bool $sameDayDelivery
*
* @return void
*/
Expand All @@ -200,7 +223,7 @@ public function setSameDayDelivery(?bool $sameDayDelivery): void
}

/**
* @param null|bool $hideSender
* @param null|bool $hideSender
*
* @return void
*/
Expand All @@ -210,7 +233,7 @@ public function setHideSender(?bool $hideSender): void
}

/**
* @param null|bool $largeFormat
* @param null|bool $largeFormat
*
* @return void
*/
Expand All @@ -220,7 +243,7 @@ public function setLargeFormat(?bool $largeFormat): void
}

/**
* @param null|bool $extraAssurance
* @param null|bool $extraAssurance
*
* @return void
*/
Expand All @@ -236,6 +259,7 @@ public function toArray(): array
{
return [
'signature' => $this->hasSignature(),
'receipt_code' => $this->hasReceiptCode(),
'insurance' => $this->getInsurance(),
'age_check' => $this->hasAgeCheck(),
'only_recipient' => $this->hasOnlyRecipient(),
Expand Down
1 change: 1 addition & 0 deletions src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public function __construct(array $shipmentOptions)
$this->return = $shipmentOptions['return'] ?? null;
$this->same_day_delivery = $shipmentOptions['same_day_delivery'] ?? null;
$this->signature = $shipmentOptions['signature'] ?? null;
$this->receipt_code = $shipmentOptions['receipt_code'] ?? null;
}
}
13 changes: 7 additions & 6 deletions src/Collection/Fulfilment/OrderCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class OrderCollection extends Collection
use HasCountry;

/**
* @param string $apiKey
* @param array $parameters
* @param string $apiKey
* @param array $parameters
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException
Expand Down Expand Up @@ -62,8 +62,8 @@ public function save(): self
$request = (new MyParcelRequest())
->setUserAgents($this->getUserAgent())
->setRequestParameters(
$this->ensureHasApiKey(),
$requestBody
$this->ensureHasApiKey(),
$requestBody
)
->sendRequest('POST', MyParcelRequest::REQUEST_TYPE_ORDERS);

Expand Down Expand Up @@ -125,6 +125,7 @@ private function getShipmentOptions(AbstractDeliveryOptionsAdapter $deliveryOpti
'delivery_type' => $deliveryOptions->getDeliveryTypeId(),
'delivery_date' => $deliveryDate ?: null,
'signature' => (int) $shipmentOptions->hasSignature(),
'receipt_code' => (int) $shipmentOptions->hasReceiptCode(),
'only_recipient' => (int) $shipmentOptions->hasOnlyRecipient(),
'age_check' => (int) $shipmentOptions->hasAgeCheck(),
'large_format' => (int) $shipmentOptions->hasLargeFormat(),
Expand All @@ -143,7 +144,7 @@ private function getShipmentOptions(AbstractDeliveryOptionsAdapter $deliveryOpti
}

/**
* @param \MyParcelNL\Sdk\src\Model\Consignment\DropOffPoint $dropOffPoint
* @param \MyParcelNL\Sdk\src\Model\Consignment\DropOffPoint $dropOffPoint
*
* @return array
*/
Expand All @@ -162,7 +163,7 @@ private function getDropOffPointAsArray(DropOffPoint $dropOffPoint): array
}

/**
* @param \MyParcelNL\Sdk\src\Model\MyParcelRequest $request
* @param \MyParcelNL\Sdk\src\Model\MyParcelRequest $request
*
* @return self
*/
Expand Down
52 changes: 26 additions & 26 deletions src/Helper/MyParcelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function getLinkOfLabels()
}

/**
* @param AbstractConsignment $consignment
* @param AbstractConsignment $consignment
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException
Expand All @@ -193,8 +193,8 @@ public function addConsignment(AbstractConsignment $consignment): self
}

/**
* @param int[] $ids
* @param string $apiKey
* @param int[] $ids
* @param string $apiKey
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException
Expand All @@ -213,8 +213,8 @@ public function addConsignmentByConsignmentIds($ids, $apiKey): self
}

/**
* @param string[] $ids
* @param string $apiKey
* @param string[] $ids
* @param string $apiKey
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException
Expand Down Expand Up @@ -337,7 +337,7 @@ public function deleteConcepts(): self
* Get all current data
* Set id and run this function to update all the information about this shipment
*
* @param int $size
* @param int $size
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException
Expand Down Expand Up @@ -373,7 +373,7 @@ public function setLatestData($size = 300): self
* Get all the information about the last created shipments
*
* @param $key
* @param int $size
* @param int $size
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException
Expand All @@ -391,7 +391,7 @@ public function setLatestDataWithoutIds($key, $size = 300): self
/**
* Get link of labels
*
* @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet.
* @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet.
* Positioning is only applied on the first page with labels. All subsequent pages will use the default positioning `[1,2,3,4]`.
* Pass an array to specify the positions on an A4 sheet, e.g. `[2,3,4]`.
* Pass a number to specify the starting position on an A4 sheet, e.g. `2`. The following labels will fill the subsequent positions.
Expand Down Expand Up @@ -439,7 +439,7 @@ public function setLinkOfLabels($positions = self::DEFAULT_A4_POSITION): self
* Receive label PDF
* After setPdfOfLabels() apiId and barcode is present
*
* @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet.
* @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet.
* Positioning is only applied on the first page with labels. All subsequent pages will use the default positioning `[1,2,3,4]`.
* Pass an array to specify the positions on an A4 sheet, e.g. `[2,3,4]`.
* Pass a number to specify the starting position on an A4 sheet, e.g. `2`. The following labels will fill the subsequent positions.
Expand Down Expand Up @@ -478,7 +478,7 @@ public function setPdfOfLabels($positions = self::DEFAULT_A4_POSITION): self
/**
* Download labels
*
* @param bool $inline_download
* @param bool $inline_download
*
* @return void
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException
Expand All @@ -505,8 +505,8 @@ public function downloadPdfOfLabels($inline_download = false): void
/**
* Send return label to customer. The customer can pay and download the label.
*
* @param bool $sendMail
* @param \Closure|null $modifier
* @param bool $sendMail
* @param \Closure|null $modifier
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException
Expand All @@ -521,8 +521,8 @@ public function generateReturnConsignments(bool $sendMail, Closure $modifier = n
$parentConsignments = $this->getConsignments(false);
$returnConsignments = $this->getReturnConsignments($parentConsignments, $modifier);

$data = $this->apiEncodeReturnShipments($returnConsignments);
$apiKey = $returnConsignments[0]->getApiKey();
$data = $this->apiEncodeReturnShipments($returnConsignments);
$apiKey = $returnConsignments[0]->getApiKey();

$request = (new MyParcelRequest())
->setUserAgents($this->getUserAgent())
Expand Down Expand Up @@ -610,8 +610,8 @@ public function clearConsignmentsCollection(): void
/**
* To search and filter consignments by certain values
*
* @param string $apiKey
* @param mixed $parameters May be an array or object containing properties.
* @param string $apiKey
* @param mixed $parameters May be an array or object containing properties.
* If query_data is an array, it may be a simple one-dimensional structure,
* or an array of arrays (which in turn may contain other arrays).
* If query_data is an object, then only public properties will be incorporated
Expand Down Expand Up @@ -651,8 +651,8 @@ public static function query(string $apiKey, $parameters): self
}

/**
* @param int $id
* @param string $apiKey
* @param int $id
* @param string $apiKey
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException
Expand All @@ -665,8 +665,8 @@ public static function find(int $id, string $apiKey): self
}

/**
* @param array $consignmentIds
* @param string $apiKey
* @param array $consignmentIds
* @param string $apiKey
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException
Expand All @@ -691,8 +691,8 @@ public static function findMany(array $consignmentIds, string $apiKey): self
}

/**
* @param string $id
* @param string $apiKey
* @param string $id
* @param string $apiKey
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException
Expand All @@ -705,8 +705,8 @@ public static function findByReferenceId(string $id, string $apiKey): self
}

/**
* @param array $referenceIds
* @param string $apiKey
* @param array $referenceIds
* @param string $apiKey
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException
Expand Down Expand Up @@ -755,7 +755,7 @@ public function sortByCollection(MyParcelCollection $sortedCollection): self
/**
* Sets label format settings
*
* @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet.
* @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet.
* Positioning is only applied on the first page with labels. All subsequent pages will use the default positioning `[1,2,3,4]`.
* Pass an array to specify the positions on an A4 sheet, e.g. `[2,3,4]`.
* Pass a number to specify the starting position on an A4 sheet, e.g. `2`. The following labels will fill the subsequent positions.
Expand Down Expand Up @@ -854,7 +854,7 @@ private function getNewCollectionFromResult($result): self
private function addMissingReferenceId(): void
{
$this->transform(function (AbstractConsignment $consignment) {
if (!$consignment->getReferenceId()) {
if (! $consignment->getReferenceId()) {
$consignment->setReferenceId('random_' . uniqid('', true));
}

Expand Down
Loading

0 comments on commit e794021

Please sign in to comment.