CiviCRM Contribution Page, total amount calculation is sometimes off by one or two cents, which causes incorrect amount to be paid or transaction to fail depending on the Payment Processor being used
When using a CiviCRM Contribution Page the total amount calculation is sometimes off by one or two cents, which causes incorrect amount to be paid or transaction to fail depending on the Payment Processor being used.
In the case of Stripe, the correct amount is pre-authorised. When the payment is confirmed the incorrect amount is used and because the two amounts do not match, the transaction fails. As a result this bug prevents payments from working with Stripe as a payment processor for certain amounts.
Steps to reproduce
- Enable tax and invoicing
- Add e.g. a 10% GST account to Member Dues
- Create a membership prices set with one field that has three checkbox options:
- 318.18182 (350 incl tax)
- 22.72727 (25 incl tax)
- 24.54545 (27 after tax - note that this would actually work out to 27.01 with the older premature rounding based off-by one issue)
- Use this price set on a contribution page
- Submit a test using this contribution page.
- Note in the summary that the line totals are 350.00, 25.00, and 27.00
Expected result
Total should be $402
Actual result
Total is $401.99 - which is one cent less than the expect value, and two cents less than the value you would get with premature rounding.
Tested environment
Bug has been confirmed using CiviCRM 5.52.alpha1 on https://wpmaster.demo.civicrm.org/
Workaround
Adjust the amount to account for the rounding error. In this case, change the amount: 24.54545 to 24.5363636364 which then changes the total to $401.99. This is then matches the total on the Thank You page.
Contribution page with membership options selected - correct total is shown
Thank you page - incorrect total is shown
Set up - Membership Types
Set up - Priceset
Agileware Ref: CIVICRM-2007