-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NTR: PISHPS-393: send delivery on cancel item (#916)
Co-authored-by: Vitalij Mik <[email protected]>
- Loading branch information
1 parent
517bc02
commit d3fcc72
Showing
9 changed files
with
113 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Event; | ||
|
||
use Mollie\Api\Resources\Order; | ||
|
||
class OrderLinesUpdatedEvent | ||
{ | ||
private Order $mollieOrder; | ||
|
||
public function __construct(Order $mollieOrder) | ||
{ | ||
$this->mollieOrder = $mollieOrder; | ||
} | ||
|
||
public function getMollieOrder(): Order | ||
{ | ||
return $this->mollieOrder; | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Subscriber; | ||
|
||
use Kiener\MolliePayments\Event\OrderLinesUpdatedEvent; | ||
use Mollie\Api\Resources\OrderLine; | ||
use Mollie\Api\Types\OrderLineType; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class OrderLinesUpdatedSubscriber implements EventSubscriberInterface | ||
{ | ||
private LoggerInterface $logger; | ||
|
||
public function __construct(LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
OrderLinesUpdatedEvent::class => 'onOrderLinesUpdated', | ||
]; | ||
} | ||
|
||
public function onOrderLinesUpdated(OrderLinesUpdatedEvent $event): void | ||
{ | ||
$mollieOrder = $event->getMollieOrder(); | ||
|
||
$shippingOptions = []; | ||
|
||
$mollieLines = $mollieOrder->lines(); | ||
|
||
/** | ||
* @var OrderLine $line | ||
*/ | ||
foreach ($mollieLines as $line) { | ||
if ($line->type === OrderLineType::TYPE_SHIPPING_FEE && $line->shippableQuantity > 0) { | ||
$shippingOptions[] = [ | ||
'id' => $line->id, | ||
'quantity' => $line->quantity, | ||
]; | ||
} | ||
} | ||
|
||
if (count($shippingOptions) === 0) { | ||
return; | ||
} | ||
try { | ||
$mollieOrder->createShipment(['lines' => $shippingOptions]); | ||
} catch (\Exception $exception) { | ||
$this->logger->error("Failed to update shipping costs", ['message' => $exception->getMessage(), 'options' => $shippingOptions]); | ||
} | ||
} | ||
} |
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