mollie / PrestaShop

iDEAL, Creditcard, Bancontact, SOFORT, Bank transfer, PayPal & paysafecard for Prestashop
http://www.mollie.com
BSD 2-Clause "Simplified" License
69 stars 42 forks source link

Orders API The amount of the order does not match the total amount from the order lines. #89

Closed FabioReims closed 5 years ago

FabioReims commented 5 years ago

Expected behavior

I expected to be redirected to the payment screen.

Actual behavior

This error message:

Error executing API call (422: Unprocessable Entity): The amount of the order does not match the total amount from the order lines. Expected order amount to be €10.48 but got €6.48. Field: amount. Documentation: https://docs.mollie.com/guides/handling-errors. Cart Dump: { "amount": { "currency": "EUR", "value": "6.48" }, "method": "banktransfer", "redirectUrl": "https:\/\/\/en\/module\/mollie\/return?cart_id=79&utm_nooverride=1&rand=1547598071", "webhookUrl": "https:\/\/\/en\/module\/mollie\/webhook", "metadata": { "cart_id": 79, "order_reference": "HZTFVOTQM", "secure_key": "d48a7db5935c814f09720e29325b6fba" }, "locale": "en_US", "billingAddress": { "givenName": "", "familyName": "", "email": "", "streetAndNumber": "jasdasd 12 ", "city": "", "region": "", "country": "KR", "postalCode": "123-123" }, "shippingAddress": { "givenName": "", "familyName": "", "email": "", "streetAndNumber": "", "city": "", "region": "", "country": "KR", "postalCode": "123-123" }, "orderNumber": "HZTFVOTQM", "lines": [ { "name": "Sweet Pumpkin Muffin", "quantity": 1, "sku": "41\u00a4308\u00a40", "unitPrice": { "currency": "EUR", "value": "5.49" }, "totalAmount": { "currency": "EUR", "value": "5.49" }, "vatAmount": { "currency": "EUR", "value": "0.00" }, "vatRate": "0.00" }, { "name": "Shipping", "quantity": 1, "sku": "", "unitPrice": { "currency": "EUR", "value": "2.99" }, "totalAmount": { "currency": "EUR", "value": "2.99" }, "vatAmount": { "currency": "EUR", "value": "0.00" }, "vatRate": "0.00" }, { "name": "Gift wrapping", "quantity": 1, "sku": "", "unitPrice": { "currency": "EUR", "value": "2.00" }, "totalAmount": { "currency": "EUR", "value": "2.00" }, "vatAmount": { "currency": "EUR", "value": "0.00" }, "vatRate": "0.00" } ] }

Looking at the values in it, I can find: unit price: 5.49€, another unit price: 2.99€ and a random 2.00€ which together would indeed result in a total of 10.48€. The products original price is 4.99€ with a 30% discount dropping it to 3.49€ + 2,99€ shipping = 6.48€. Thus, I can't explain where the 5.49€ are coming from. The last 2.00€ would be the exact same amount that is charged for gift wrapping. Which is also set to "quantity" 1 which is curious, given that gift wrapping is disabled in my store.

Steps to reproduce the behavior

Activate oders API and check out.

Environment

firstred commented 5 years ago

Hi @Apury Thanks for opening this issue!

It is indeed really strange that gift wrapping is being added to the cart even though it is not enabled. Are you using or have you used any gift card modules that could be using the gift wrapping field as a workaround? Looking at this line I think this number is coming from the actual PrestaShop Cart object itself: https://github.com/mollie/PrestaShop/blob/b127fdf32e20d140d96e6fe8e9a165cd0d898a17/mollie.php#L2534 so I think we might be able to find the source if we can track what modules are able to add a gift wrapping price to the cart.

What happens if you comment that line out and instead use:

$wrapping = 0;
FabioReims commented 5 years ago

Hi @Apury Thanks for opening this issue!

It is indeed really strange that gift wrapping is being added to the cart even though it is not enabled. Are you using or have you used any gift card modules that could be using the gift wrapping field as a workaround? Looking at this line I think this number is coming from the actual PrestaShop Cart object itself:

PrestaShop/mollie.php

Line 2534 in b127fdf

     $wrapping = round($cart->getGiftWrappingPrice(), $apiRoundingPrecision); 

so I think we might be able to find the source if we can track what modules are able to add a gift wrapping price to the cart. What happens if you comment that line out and instead use:

$wrapping = 0;

Somehow that results in an Error 500. The backoffice throws this error message at me:

[PrestaShop] Fatal error in module file: /var/www/html/store/app/bootstrap.php.cache:3231 Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Parse error: syntax error, unexpected '$remaining' (T_VARIABLE) in /var/www/html/store/modules/mollie/mollie.php:2535 Stack trace: #0 /var/www/html/store/classes/module/Module.php(1071): ModuleCore::coreLoadModule('mollie') #1 /var/www/html/store/classes/Hook.php(837): ModuleCore::getInstanceByName('mollie') #2 /var/www/html/store/classes/controller/AdminController.php(2811): HookCore::exec('displayBackOffi...', Array) #3 /var/www/html/store/classes/controller/Controller.php(234): AdminControllerCore->init() #4 /var/www/html/store/classes/Dispatcher.php(428): ControllerCore->run() #5 /var/www/html/store/chaeyeonryu/index.php(96): DispatcherCore->dispatch() #6 {main} Next LogicException: Request stack is empty in /var/www/html/store/app/bootstrap.php.cache:3231 Stack trace: #0 [internal function]: Symfony\Component\HttpKernel\HttpKernel->terminateWithException(Object(Symfony\Component\Debug\Exception\FatalThrowableError)) #1 /var/www/html/store/v...

The change I've made to the mollie.php looks like this:

$remaining = round($amount, $apiRoundingPrecision); $shipping = round($cart->getTotalShippingCost(null, true), $apiRoundingPrecision); / $wrapping = round($cart->getGiftWrappingPrice(), $apiRoundingPrecision); / $wrapping = 0 $remaining = round($remaining - $shipping - $wrapping, $apiRoundingPrecision); $cartItems = $cart->getProducts();`

I'm drunk. I forgot the ";" ..

firstred commented 5 years ago

forgot the ; I think:

$remaining = round($amount, $apiRoundingPrecision);
$shipping = round($cart->getTotalShippingCost(null, true), $apiRoundingPrecision);
/* $wrapping = round($cart->getGiftWrappingPrice(), $apiRoundingPrecision); */
$wrapping = 0;
$remaining = round($remaining - $shipping - $wrapping, $apiRoundingPrecision);
$cartItems = $cart->getProducts();`
firstred commented 5 years ago

Yes, correct :slightly_smiling_face:

FabioReims commented 5 years ago

This indeed solves the problem. I now 'fixed' it in a less 'forgettable' way by reducing the price for gift wrapping from 2€ to 0€. Appareantly, albite disabled, the 2€ that would've been charged, if it were disabled, were still being included in the calculation. No idea where the 5€ something came from though. Now it matches perfectly. Thank you. Sincerely.

firstred commented 5 years ago

Does everything match? Can you reach the payment screen?

BTW: has the other thread you opened a while ago been solved by the update(s)? https://github.com/mollie/PrestaShop/issues/76

firstred commented 5 years ago

Marking as solved. Feel free to open a new issue if this returns.

Twabi2 commented 5 years ago

It appears this issue is still present in the current version of this module. I had the exact same error where gift wrapping is added to the total amount, even though this was not set by the customer. The solution by firstred still works and allows charging the customer for wrapping correctly, but requires modification of the module itself. The other solution of disabling gift wrapping in Prestashop does fix the problem temporarily, but of course, we do want to offer our customers the option of having their gifts wrapped. Can the code be changed permanently by the developer to fix this issue in future versions as well?