Payments fail with both versions 3.1 and 4.0 ALPHA with an error message:
Paytrail API failure [400] Client error: `POST https://services.paytrail.com/payments` resulted in a `400 Bad Request` response: @"status":"error","message":"Sum of purchase item amounts does not match total amount."
I assume the issue is caused by the module's inability to properly handle order items with decimal quantities. Supporting the sale of items in decimal quantities (such as weight-based or measurement-based products) has been a core feature of Drupal Commerce for years, so this should work out of the box.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 2025-06-24_20-53.png | 62.57 KB | tuutti |
Issue fork commerce_paytrail-3531710
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
tuutti commentedHi! As far as I known, Paytrail doesn't support decimal quantities.
I guess we could just check for any decimal quantities and skip including the order items in the payload.
Comment #3
kaipipek commentedHi! We have had decimal quantities for ten years now and we have used Xocovis' Paytrail module where this has been handled also with the current Paytrail API.
Comment #4
kaipipek commentedComment #5
kaipipek commentedPaytrail proposed this kind of approach:
Could the module handle this in case of decimal quantities?
Comment #13
tuutti commentedThis should be fixed in the latest 3.x and 4.x releases.
There's no easy way to figure out what is being sold, so the description field just shows a hard-coded "X units" message instead of "X kg" etc.
It should be easy enough to tailor it for your needs if needed by creating an event subscriber and override the description field there.
Comment #14
kaipipek commentedThank you for very quick response and fix! A purchase with decimal quantities was successfully processed.
By the way, I am missing ApplePay which we have enabled if we use Paytrail's payment page. Is there some additional configuration to enable ApplePay (which I can see in test mode)?
Comment #15
tuutti commentedIt should be listed under "Mobile payment methods" when using test credentials:
If you're using real credentials then you might have to enable it somewhere in Paytrail's merchant panel.
Comment #16
kaipipek commentedApplePay is enabled and domain listed in the merchand's panel because we have had it available in the Paytrail payment page, but I will ask help from Paytrail if they need to do something so that ApplePay becomes available with your module.
Comment #17
kaipipek commentedThe issue does not seem to be fixed in the latest beta and dev releases:
Uncaught PHP Exception Paytrail\\SDK\\Exception\\ValidationException: "Amount doesnt match ItemsTotal" at vendor/paytrail/paytrail-php-sdk/src/PaytrailClient.php line 213Comment #18
tuutti commentedHmmm. Do you have some other module that modifies the total price, like promotions, shipping + shipping taxes, giftcards etc.
Comment #19
kaipipek commentedThe error surfaced after upgrading Commerce Core to 3.1 and it is caused by order items with decimal quantities only.
Comment #20
tuutti commentedWeird. I just upgraded Commerce Core to 3.1 and it seems to work. Are you using 3.x or 4.x version?
Comment #21
kaipipek commented4.0.0-beta2 because 3.1.2 requires Commerce ^2
Comment #22
kaipipek commentedI restored the site so that there was again Commerce 2.40 and Commerce Paytrail 3.1.2 and then I upgraded Commerce Paytrail to 4.0.0-beta2 and tested buying and after that I upgraded Commerce to 3.1 and tested buying again and now it seems to work. I honestly don't know anymore why I got the error message previously. Sorry!
Comment #23
tuutti commentedDid you ever figure out why the ApplePay didn't work?
Comment #24
kaipipek commentedI found out that with production credentials, Apple Pay is only visible when using Safari. Unfortunately, I don’t have a device with Apple Pay to verify this. It’s a bit confusing that Apple Pay is always visible when using test credentials.
Comment #25
kaipipek commentedGod, now we got WSOD in production with two order items with quantities of 4 and 2 and neither of them have decimal quantities:
Paytrail\SDK\Exception\ValidationException: Amount doesnt match ItemsTotal funktiossa Paytrail\SDK\PaytrailClient->validateRequestItem() (line 213 vendor/paytrail/paytrail-php-sdk/src/PaytrailClient.php).
Commerce version was 3.1 and Paytrail 4.0@beta2. I had to downgrade them to 2.4 and 3.1.2.
Comment #26
kaipipek commentedThe issue is related to free shipping for orders over 100 eur because the request has one item with value -590 which clearly affects Amount vs. ItemsTotal matching. If I decrease the units to 3 and total value is under 100 eur without shipping discount, I get no error.
But this error is introduced with 4.0@beta2 version (or Commerce 3.1).
Comment #27
tuutti commentedLooks like shipping promotions apply order level discounts even tho
$shipping->getAdjustedAmount()returns the adjusted unit price 🤔Comment #29
tuutti commentedCan you test if https://git.drupalcode.org/project/commerce_paytrail/-/merge_requests/9 fixes this?
Comment #30
kaipipek commentedUnfortunately I don't know how to install a merge request. We are using Composer for installing updates.
Comment #31
tuutti commentedOkay, it should be merged in 4.x branch now. You can install it with
composer require drupal/commerce_paytrail:4.x-devComment #32
kaipipek commentedPayment is processed successfully now. Shipping unit price is now the same as the discount and the Amount matches.
Comment #33
kaipipek commentedWhen is the 4.x version scheduled for production?
Comment #34
tuutti commented4.x@beta3 should be available now