-
Notifications
You must be signed in to change notification settings - Fork 53
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
MOL-1196: Tracking #607
Merged
boxblinkracer
merged 6 commits into
mollie:master
from
BlackScorp:users/vm/MOL-1196-tracking
Dec 4, 2023
Merged
MOL-1196: Tracking #607
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d548cb8
MOL-1196: Tracking
cfd494e
NTR: Merge branch 'master' into users/vm/MOL-1196-tracking
d5d81db
MOL-1196: fix pipeline
8f63450
MOL-1196: extract to factory
2dbf5af
MOL-1196: check tracking code lenght
c947525
MOL-1196: update comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Service; | ||
|
||
use Kiener\MolliePayments\Struct\MollieApi\ShipmentTrackingInfoStruct; | ||
use Shopware\Core\Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryEntity; | ||
|
||
class TrackingInfoStructFactory | ||
boxblinkracer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
/** | ||
* Mollie throws an error with length >= 100 | ||
*/ | ||
const MAX_TRACKING_CODE_LENGTH = 99; | ||
|
||
public function createFromDelivery(OrderDeliveryEntity $orderDeliveryEntity): ?ShipmentTrackingInfoStruct | ||
{ | ||
$trackingCodes = $orderDeliveryEntity->getTrackingCodes(); | ||
$shippingMethod = $orderDeliveryEntity->getShippingMethod(); | ||
if ($shippingMethod === null) { | ||
return null; | ||
} | ||
/** | ||
* Currently we create one shipping in mollie for one order. one shipping object can have only one tracking code. | ||
* When we have multiple Tracking Codes, we do not know which tracking code we should send to mollie. So we just dont send any tracking information at all | ||
* | ||
* https://docs.mollie.com/reference/v2/shipments-api/create-shipment | ||
*/ | ||
if (count($trackingCodes) !== 1) { | ||
return null; | ||
boxblinkracer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return $this->createInfoStruct((string)$shippingMethod->getName(), $trackingCodes[0], (string)$shippingMethod->getTrackingUrl()); | ||
} | ||
|
||
public function create(string $trackingCarrier, string $trackingCode, string $trackingUrl): ?ShipmentTrackingInfoStruct | ||
{ | ||
return $this->createInfoStruct($trackingCarrier, $trackingCode, $trackingUrl); | ||
} | ||
|
||
private function createInfoStruct(string $trackingCarrier, string $trackingCode, string $trackingUrl): ?ShipmentTrackingInfoStruct | ||
{ | ||
if (empty($trackingCarrier) && empty($trackingCode)) { | ||
return null; | ||
} | ||
|
||
if (empty($trackingCarrier)) { | ||
throw new \InvalidArgumentException('Missing Argument for Tracking Carrier!'); | ||
} | ||
|
||
if (empty($trackingCode)) { | ||
throw new \InvalidArgumentException('Missing Argument for Tracking Code!'); | ||
} | ||
|
||
# we just have to completely remove those codes, so that no tracking happens, but a shipping works. | ||
# still, if we find multiple codes (because separators exist), then we use the first one only | ||
if (mb_strlen($trackingCode) > self::MAX_TRACKING_CODE_LENGTH) { | ||
if (strpos($trackingCode, ',') !== false) { | ||
$trackingCode = trim(explode(',', $trackingCode)[0]); | ||
} elseif (strpos($trackingCode, ';') !== false) { | ||
$trackingCode = trim(explode(';', $trackingCode)[0]); | ||
} | ||
|
||
# if we are still too long, then simply remove the code | ||
if (mb_strlen($trackingCode) > self::MAX_TRACKING_CODE_LENGTH) { | ||
return new ShipmentTrackingInfoStruct($trackingCarrier, '', ''); | ||
} | ||
} | ||
|
||
|
||
$trackingUrl = trim(sprintf($trackingUrl, $trackingCode)); | ||
|
||
if (filter_var($trackingUrl, FILTER_VALIDATE_URL) === false) { | ||
$trackingUrl = ''; | ||
} | ||
|
||
/** | ||
* following characters are not allowed in the tracking URL {,},<,>,# | ||
*/ | ||
if (preg_match_all('/[{}<>#]/m', $trackingUrl)) { | ||
$trackingUrl = ''; | ||
} | ||
|
||
return new ShipmentTrackingInfoStruct($trackingCarrier, $trackingCode, $trackingUrl); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really wondering, this PR is about automating tracking in whatever shipping is being done.
so if we extract tracking from delivery in the constructor....then i would assume its used somewhere, but i only see function arguments being used here, and the calling instance doesnt seem to have changed which means its the old logic? so where is the auto-extracted data then used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the shipment facade is too big and too much things, the tests are too complicated, i wanted to extract some private methods into seperate services in order to write smaller tests. the factory is not used anywhere else but it makes the tests easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesnt really give an answer to the question
i think we should talk about it :)