question

Danielle Cox avatar image
Danielle Cox asked Danielle Cox commented

Order fully paid - getState shows locked

I am receiving the payment processed intent, and the documentation looks like it should give me the state of the order, yet all I see is locked - is there another way to tell or do I just loop through the payments and add them all up to determine that the order is fully paid?

Thanks again,

Danielle

1 comment
10 |2000

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

Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

I'm working finding some sample code I can give you for this.

0 Likes 0 ·
Jeffrey Blattman avatar image
Jeffrey Blattman answered

Unfortunately there's no simple method to ask if an order is "fully paid". Here's some sample code that should do that trick,

  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);
  }

If the amount left to pay is 0, then it's fully paid.

Locked means that it cannot be modified (it has payments, refunds, or credits). Order state is really for internal use only; please don't rely on it.

10 |2000

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

Jeffrey Blattman avatar image
Jeffrey Blattman answered Danielle Cox commented

I created a sample in our SDK to show how to do this. Until that's released, here's a link to the example activity. In a nutshell you are checking if the payment totals add up to the order total, but you must also consider refunds and tips. http://pastebin.com/2QrDigt1

Hopefully we'll get the sample into our public SDK soon.

1 comment
10 |2000

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

Danielle Cox avatar image Danielle Cox commented ·

Thank You!

0 Likes 0 ·

Welcome to the
Clover Developer Community