Issues while tracking ecommerce events

Hi all,

I hope I’m posting this in the right place…

I am currently integrating Matomo (4.0.5) as an addon into an ERP in order to enable its tracking features through the HTTP tracking API. I’m using what seems to be the offciial java library https://github.com/matomo-org/matomo-java-tracker, mostly for the bean-like class PiwikRequest.
Basically my main concern is when and how the ec_id must be set and passed. From my understanding, I can track cart and order events, meaning that both can be treated differenttly though data is mostly the same. At least the ERP works like that internally and looks Matomo supports that too, at least according to what I gather from API doc:

Use the following values to record a cart and/or an ecommerce order.

  • you must set &idgoal=0 in the request to track an ecommerce interaction: cart update or an ecommerce order.
  • ec_id — The unique string identifier for the ecommerce order (required when tracking an ecommerce order)

Initially I considered that ec_id should be set everytime for cart updates using the same value (cart creation date stored in session) but that turned out to be wrong. I was able to track the first request but the subsequent ones returned an error 400: Bad Request. Then I figured that ec_id was only needed/required for tracking orders, which in our case means a cart that has been successfully checked out. This seems to be wrong as well, as the PiwikRequest class implements this method:

public void verifyEcommerceState(){
        verifyEcommerceEnabled();
        if (getEcommerceId() == null){
            throw new IllegalStateException("EcommerceId must be set before this value can be set.");
        }
        if (getEcommerceRevenue() == null){
            throw new IllegalStateException("EcommerceRevenue must be set before this value can be set.");
        }
    }

So, I don’t really know how exactly this is supposed to work in the sense that carts and orders can be tracked separately or it is just that for Matomo a cart == order so basically not matching our design.

Any help will be really appreciated