Order balance calculation discrepancy for voided and expired payments.

Created on 27 April 2023, almost 2 years ago
Updated 23 May 2023, almost 2 years ago

Problem/Motivation

When voiding payments on an order, or when an authorization has expired, the amounts are still added to the balance.

Steps to reproduce

Create an order
Add a payment with a payment gateway that supports `authorization_voided` and `authorization_expired` states.
Void the payment
Clear caches
See that the order balance still includes the voided payment.

Proposed resolution

Option 1: Exclude payments with void/expired states in the PaymentOrderUpdater

- if ($payment->isCompleted()) { 
+ if ($payment->isCompleted() && !in_array($payment->getState()->value, ['authorization_voided', 'authorization_expired'])) {

Option 2: Set the payment stated completed value to false whenever a payment is voided/expired.

I prefer something along the lines of option 1. However, it would be helpful to define the balance actions of a payment state since other states may also need to be excluded.

Remaining tasks

Decide how to handle
Implement fix
Update tests to include checking void/expired states

User interface changes

None

🐛 Bug report
Status

Active

Version

2.0

Component

Payment

Created by

🇺🇸United States andyg5000 North Carolina, USA

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

Comments & Activities

  • Issue created by @andyg5000
  • 🇺🇸United States andyg5000 North Carolina, USA
  • 🇺🇸United States andyg5000 North Carolina, USA
  • 🇮🇱Israel jsacksick

    What's confusing me here is... The payment shouldn't have been completed in the first place right? If the payment is simply authorized and the authorization is voided, then $payment->isCompleted() never returns TRUE as the completed time is set whenever the payment state is set to completed?

    Could it be that there's an issue with your payment workflow? Did you define a custom workflow? Custom gateway even?

  • 🇺🇸United States andyg5000 North Carolina, USA

    Hey @jsacksick

    See this issue for how I handle it in Auth.net https://www.drupal.org/project/commerce_authnet/issues/2911837#comment-1... 🐛 Error on refund if payment hasn't been settled Needs review

    The issue was happening when a payment was authorized and captured, but then voided before the payment was settled by the merchant account. With auth.net, to issue a refund, the payment must be voided if it hasn't been settled (~24 hours). It can be refunded once the payment is settled.

    Maybe this should just be handled by the payment module as seen above?

Production build 0.71.5 2024