We have a US-shop, that needs to use an external tax provider service (in this case Avalara) because of the crazy complex tax rules in the US. There is a problem with Mollie and this external tax provider, but I think this is not only scoped to this specific provider, but more general.
We have for example this case: for the shipping costs, the external tax provider returns this:
taxAmount: 0.0
taxRate: 6.25
This may seem strange on the first look, but is totally valid, because there are tax exemption limits that can come into play. So the general taxRate in this case is 6.25, but because of the tax exemption limit the amount is 0.0.
This is now where the trouble with the Mollie plugin starts, because the plugin calculates the taxAmount for every lineItem again (would be nice to know, why this is necessary in the first place).
See:
|
$price = $this->priceCalculator->calculateLineItemPrice($shippingPrice, $totalPrice, $taxStatus, $isVerticalTaxCalculation); |
and:
|
public function calculateLineItemPrice(CalculatedPrice $price, float $lineItemTotalPrice, string $orderTaxType, bool $isVerticalTaxCalculation = false): LineItemPriceStruct |
Because Mollie calculates the taxAmount again based on the taxRate, of course there is a mismatch which results in the following error during order creation:
[2023-08-22T09:28:11.603351+00:00] Mollie.ERROR: Error when starting Mollie payment: Could not create Mollie order (Session: ...) {"function":"order-prepare","exception":"[object] (RuntimeException(code: 422): Could not create Mollie order at www/vendor/store.shopware.com/molliepayments/src/Service/MollieApi/Order.php:184)\n[previous exception] [object] (Mollie\\Api\\Exceptions\\ApiException(code: 422): [2023-08-22T09:28:11+0000] Error executing API call (422: Unprocessable Entity): Order line 2 is invalid. Total amount is off. Expected total amount to be $37.13 (1 × $37.13), got $34.95. Documentation: https://docs.mollie.com/overview/handling-errors. Field: lines.2.totalAmount at www/vendor/store.shopware.com/molliepayments/src/Service/MollieApi/Client/MollieHttpClient.php:151)","session":"","processors":{"uid":{"uid":"4a686af"},"web":{"url":"....","ip":"...","http_method":"GET","server":"...","referrer":"..."},"introspection":{"file":null,"line":null,"class":"Kiener\\MolliePayments\\Handler\\PaymentHandler","callType":"->","function":"pay"}}} []
Now the question is, how to solve this. Personally, I think the recalculation of the taxAmount in the Mollie plugin is not right, why not use the taxAmount present in the CalculatedTax-Object? But there may of course be good reasons unknown to me why this is necessary.
Nevertheless this will be a problem in the future for such cases, especially in the US and with external tax providers.
We have a US-shop, that needs to use an external tax provider service (in this case Avalara) because of the crazy complex tax rules in the US. There is a problem with Mollie and this external tax provider, but I think this is not only scoped to this specific provider, but more general.
We have for example this case: for the shipping costs, the external tax provider returns this:
This may seem strange on the first look, but is totally valid, because there are tax exemption limits that can come into play. So the general taxRate in this case is 6.25, but because of the tax exemption limit the amount is 0.0.
This is now where the trouble with the Mollie plugin starts, because the plugin calculates the taxAmount for every lineItem again (would be nice to know, why this is necessary in the first place).
See:
Shopware6/src/Service/MollieApi/Builder/MollieShippingLineItemBuilder.php
Line 52 in 7127b7f
and:
Shopware6/src/Service/MollieApi/PriceCalculator.php
Line 27 in 7127b7f
Because Mollie calculates the taxAmount again based on the taxRate, of course there is a mismatch which results in the following error during order creation:
Now the question is, how to solve this. Personally, I think the recalculation of the taxAmount in the Mollie plugin is not right, why not use the taxAmount present in the CalculatedTax-Object? But there may of course be good reasons unknown to me why this is necessary.
Nevertheless this will be a problem in the future for such cases, especially in the US and with external tax providers.