Closed gjportegies closed 2 years ago
Kristof here the developer of the above extension. I have had a look at some of the other custom order line implementations for other 3rd party extensions and believe something like the below might work. Please note that I do not have access to an instance with Mollie configured as such the code is not yet tested.
Mollie\Payment\Service\Order\Lines\Generator\FoomanTotals.php
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Mollie\Payment\Service\Order\Lines\Generator;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Framework\Module\Manager;
use Mollie\Payment\Helper\General;
class FoomanTotals implements GeneratorInterface
{
/**
* @var General
*/
private $mollieHelper;
/**
* @var Manager
*/
private $moduleManager;
public function __construct(
General $mollieHelper,
Manager $moduleManager
) {
$this->mollieHelper = $mollieHelper;
$this->moduleManager = $moduleManager;
}
public function process(OrderInterface $order, array $orderLines): array
{
if (!$this->moduleManager->isEnabled('Fooman_Totals')) {
return $orderLines;
}
$extAttr = $order->getExtensionAttributes();
if (!$extAttr) {
return $orderLines;
}
$foomanGroup = $extAttr->getFoomanTotalGroup();
if (empty($foomanGroup)) {
return $orderLines;
}
$totals = $foomanGroup->getItems();
if (empty($totals)) {
return $orderLines;
}
$forceBaseCurrency = (bool)$this->mollieHelper->useBaseCurrency($order->getStoreId());
$currency = $forceBaseCurrency ? $order->getBaseCurrencyCode() : $order->getOrderCurrencyCode();
foreach ($totals as $total) {
$amount = $forceBaseCurrency ? $total->getBaseAmount() : $total->getAmount();
$taxAmount = $forceBaseCurrency ? $total->getBaseTaxAmount() : $total->getTaxAmount();
$vatRate = 0;
if ($taxAmount) {
$vatRate = round(($taxAmount / $amount) * 100, 2);
}
$orderLines[] = [
'type' => 'surcharge',
'name' => $total->getLabel(),
'quantity' => 1,
'unitPrice' => $this->mollieHelper->getAmountArray($currency, $amount + $taxAmount),
'totalAmount' => $this->mollieHelper->getAmountArray($currency, $amount + $taxAmount),
'vatRate' => $vatRate,
'vatAmount' => $this->mollieHelper->getAmountArray($currency, $taxAmount)
];
}
return $orderLines;
}
}
etc/di.xml
<type name="Mollie\Payment\Service\Order\Lines\OrderLinesGenerator">
<arguments>
<argument name="generators" xsi:type="array">
<item name="fooman_totals" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\FoomanTotals</item>
<item name="weee_fee" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\WeeeFeeGenerator</item>
<item name="mageworx_rewardpoints" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\MageWorxRewardPoints</item>
<item name="amasty_extrafee" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\AmastyExtraFee</item>
<item name="mirasvit_rewards" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\MirasvitRewards</item>
<item name="aheadworks_addfreegift" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\AheadworksAddFreeGift</item>
<item name="magento_giftcard" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\MagentoGiftCard</item>
</argument>
</arguments>
</type>
Just made one minor edit, this can go one package lower (Fooman_Totals) so this would theoretically support any extensions we build on top of that package (not just Surcharges).
We just tested the changes @fooman suggested on our test environment and everything worked as expected (Both methods Klarna Pay Later and Klarna Slice It).
HI, @gjportegies and @fooman (Kristof),
We are happy to share that we've just released the new 2.11.0 version where we have fixed this issue.
Thank you for opening this issue, for the detailed issue report, and for your PR contribution!
We are closing this issue now but please feel free to reopen the issue if this still occurs.
Describe the bug We found orders in our backend that hang on the payment status 'Payment Review'. We contacted Mollie and we could not find any of those orders in the Mollie dashboard. After checking the mollie log files we found the following (I've anonimized a lot):
This is followed by the following error:
The user added an extra 'sticker pakket' which is added to the checkout with the Fooman Order Fees extension. Since this is an 'order fee' it is not a separate line on the order. The issue is only appearing when choosing one of the Klarna payment methods.
Used versions
To Reproduce Steps to reproduce the behavior:
Expected behavior The order should be processed and send to Mollie.
Actual behavior The Mollie extension throws an error because the order lines total does not match the total amount.
Additional context Possible related: