question

Danielle Cox avatar image
Danielle Cox asked Jeffrey Blattman answered

Perform a task once when an order is fully paid.

I am using the code provided elsewhere as an example for telling that an order is fully paid.

   public static long getAmountLeftToPay(Order order) {
        long paymentTotal = 0;
        if (order.isNotNullPayments()) {
            for (Payment p : order.getPayments()) {
                paymentTotal += p.getAmount();
            }
        }
        return new OrderCalc(order).getTotal(null) - paymentTotal + amountRefundedWithoutTip(order);
    }

etc

Anyway, I need to perform an action once when the order is fully paid. However, using this logic, if I refund a payment and add a new payment, this code triggers a second time. Any suggestions for how to handle this scenario?

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Jeffrey Blattman avatar image
Jeffrey Blattman answered

You could keep track yourself if you've handled the order previously. We don't have any persistent concept of "order has been fully paid at least once".

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community