Skip to content

Commit

Permalink
Merge branch 'main' into feat/remove-src-from-namespace-and-deprecate…
Browse files Browse the repository at this point in the history
…d-items
  • Loading branch information
joerivanveen authored Jan 30, 2025
2 parents 070259d + e7eee72 commit fe17108
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file. See
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [7.22.0](https://github.com/myparcelnl/sdk/compare/v7.21.0...v7.22.0) (2025-01-15)


### :sparkles: New Features

* allow sender with feature header ([#517](https://github.com/myparcelnl/sdk/issues/517)) ([ce6d623](https://github.com/myparcelnl/sdk/commit/ce6d623e808fceac04941d8102bae2e768086fb6))

## [7.21.0](https://github.com/myparcelnl/sdk/compare/v7.20.1...v7.21.0) (2025-01-02)


Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "myparcelnl/sdk",
"version": "7.21.0",
"version": "7.22.0",
"description": "This package is designed to send and receive data from MyParcel by means of an API.",
"keywords": [
"MyParcel",
Expand Down
13 changes: 11 additions & 2 deletions src/Helper/MyParcelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,24 @@ public function createConcepts(): self
$newConsignments = $this->where('consignment_id', '!=', null)->toArray();
$this->addMissingReferenceId();

$grouped = $this->where('consignment_id', null)->groupBy(function(AbstractConsignment $item) {
return $item->getApiKey() . ($item->hasSender() ? '-sender' : '');
});

/* @var MyParcelCollection $consignments */
foreach ($this->where('consignment_id', null)->groupBy('api_key') as $consignments) {
foreach ($grouped as $consignments) {
$headers = MyParcelRequest::HEADER_CONTENT_TYPE_SHIPMENT;
if ($consignments->first()->hasSender()) {
$headers += MyParcelRequest::HEADER_SET_CUSTOM_SENDER;
}

$data = (new CollectionEncode($consignments))->encode();
$request = (new MyParcelRequest())
->setUserAgents($this->getUserAgent())
->setRequestParameters(
$consignments->first()->apiKey,
$data,
MyParcelRequest::HEADER_CONTENT_TYPE_SHIPMENT
$headers
)
->sendRequest();

Expand Down
1 change: 1 addition & 0 deletions src/Model/MyParcelRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MyParcelRequest
];
public const HEADER_ACCEPT_APPLICATION_PDF = ['Accept' => 'application/pdf'];
public const HEADER_CONTENT_TYPE_RETURN_SHIPMENT = ['Content-Type' => 'application/vnd.return_shipment+json; charset=utf-8'];
public const HEADER_SET_CUSTOM_SENDER = ['x-dmp-set-custom-sender' => 'true'];

/* @deprecated use HEADER_CONTENT_TYPE_SHIPMENT, HEADER_ACCEPT_APPLICATION_PDF or HEADER_CONTENT_TYPE_RETURN_SHIPMENT */
public const REQUEST_HEADER_SHIPMENT = 'Content-Type: application/vnd.shipment+json;charset=utf-8;version=1.1';
Expand Down
4 changes: 2 additions & 2 deletions src/Services/CollectionEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ private function groupMultiColloConsignments()
{
return $this->consignments->groupBy(function (AbstractConsignment $consignment) {
if ($consignment->isPartOfMultiCollo()) {
return $consignment->getReferenceId();
return $consignment->getReferenceIdentifier();
}

return 'random_to_prevent_multi_collo_' . uniqid();
return 'random_to_prevent_multi_collo_' . uniqid('', true);
})->toArray();
}
}
13 changes: 9 additions & 4 deletions src/Services/ConsignmentEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,17 @@ private function encodeBase(): self
'carrier' => $consignment->getCarrierId(),
];

if ($consignment->getReferenceId()) {
$this->consignmentEncoded['reference_identifier'] = $consignment->getReferenceId();

if (($sender = $consignment->getSender())) {
$this->consignmentEncoded['sender'] = $sender->toArrayWithoutNull();
}

if (($id = $consignment->getReferenceIdentifier())) {
$this->consignmentEncoded['reference_identifier'] = $id;
}

if ($consignment->getCompany()) {
$this->consignmentEncoded['recipient']['company'] = $consignment->getCompany();
if (($company = $consignment->getCompany())) {
$this->consignmentEncoded['recipient']['company'] = $company;
}

return $this;
Expand Down

0 comments on commit fe17108

Please sign in to comment.