Sum of purchase item amounts does not match total amount

Created on 23 June 2025, 13 days ago

Payments fail with both versions 3.1 and 4.0 ALPHA with an error message:

Paytrail API failure #8645: Update module for new _menu() hook : [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.

🐛 Bug report
Status

Active

Version

3.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @kaipipek
  • 🇫🇮Finland tuutti

    Hi! 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.

  • Hi! 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.

  • Paytrail proposed this kind of approach:

    The description field can be used to convey information about the contents of the order item. This could also include the quantity, for example: "1.5 meters" or "1.5 kg".

    In this case:

    The units field should always be set to 1, if the quantity is provided in the description field.

    The unitPrice field should contain the total price of the sold product (not price per unit, but the full price for the quantity).

    This way, the Paytrail interface would display both the sold quantity (e.g. 1.5 meters or 1.5 kg) via the description field and its price via the unitPrice field.

    Could the module handle this in case of decimal quantities?

  • Merge request !5Resolve #3531710 "Support decimal quantity" → (Merged) created by tuutti
  • 🇫🇮Finland tuutti

    tuutti changed the visibility of the branch 3531710-support-decimal-quantity to hidden.

  • 🇫🇮Finland tuutti

    tuutti changed the visibility of the branch 3531710-support-decimal-quantity to active.

  • 🇫🇮Finland tuutti

    tuutti changed the visibility of the branch 3531710-sum-of-purchase to hidden.

  • 🇫🇮Finland tuutti

    tuutti changed the visibility of the branch 3531710-sum-of-purchase to active.

  • Merge request !6Support decimal quantities → (Merged) created by tuutti
  • 🇫🇮Finland tuutti

    This should be fixed in the latest 3.x and 4.x releases.

  • Thank 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)?

  • 🇫🇮Finland tuutti

    It 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.

  • ApplePay 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.

  • The 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 213

Production build 0.71.5 2024