diff --git a/Service/Order/Lines/Generator/MagentoRewardPoints.php b/Service/Order/Lines/Generator/MagentoRewardPoints.php new file mode 100644 index 00000000000..66513849a96 --- /dev/null +++ b/Service/Order/Lines/Generator/MagentoRewardPoints.php @@ -0,0 +1,55 @@ +mollieHelper = $mollieHelper; + } + + public function process(OrderInterface $order, array $orderLines): array + { + $extensionAttributes = $order->getExtensionAttributes(); + + if (!method_exists($extensionAttributes, 'getRewardCurrencyAmount')) { + return $orderLines; + } + + $amount = $extensionAttributes->getRewardCurrencyAmount(); + if ($amount === null) { + return $orderLines; + } + + $forceBaseCurrency = (bool)$this->mollieHelper->useBaseCurrency($order->getStoreId()); + if ($forceBaseCurrency) { + $amount = $extensionAttributes->getBaseRewardCurrencyAmount(); + } + + $currency = $forceBaseCurrency ? $order->getBaseCurrencyCode() : $order->getOrderCurrencyCode(); + + $orderLines[] = [ + 'type' => 'surcharge', + 'name' => 'Reward Points', + 'quantity' => 1, + 'unitPrice' => $this->mollieHelper->getAmountArray($currency, -$amount), + 'totalAmount' => $this->mollieHelper->getAmountArray($currency, -$amount), + 'vatRate' => 0, + 'vatAmount' => $this->mollieHelper->getAmountArray($currency, 0.0), + ]; + + return $orderLines; + } +} diff --git a/Service/Order/Lines/OrderLinesProcessor.php b/Service/Order/Lines/OrderLinesProcessor.php index 5f760c3dacd..746585e108c 100644 --- a/Service/Order/Lines/OrderLinesProcessor.php +++ b/Service/Order/Lines/OrderLinesProcessor.php @@ -23,13 +23,7 @@ public function __construct( $this->processors = $processors; } - /** - * @param array $orderLine - * @param OrderInterface $order - * @param OrderItemInterface|null $orderItem - * @return array - */ - public function process(array $orderLine, OrderInterface $order, OrderItemInterface $orderItem = null) + public function process(array $orderLine, OrderInterface $order, OrderItemInterface $orderItem = null): array { foreach ($this->processors as $processor) { $orderLine = $processor->process($orderLine, $order, $orderItem); @@ -37,4 +31,4 @@ public function process(array $orderLine, OrderInterface $order, OrderItemInterf return $orderLine; } -} \ No newline at end of file +} diff --git a/etc/di.xml b/etc/di.xml index e6bff4d3b5f..40b5c5fd2b6 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -161,6 +161,7 @@ Mollie\Payment\Service\Order\Lines\Generator\MagentoGiftWrapping Mollie\Payment\Service\Order\Lines\Generator\GeisswebEuvat Mollie\Payment\Service\Order\Lines\Generator\ShippingDiscount + Mollie\Payment\Service\Order\Lines\Generator\MagentoRewardPoints