Getting wrong "total" of an order depending on the time of query
When we register a complex order the REST API interface returns a bad total amount inferior than the real total amount. The error is happening in a Sandbox environment and it is time dependent.
I attach 2 screenshots with evidence. The first one shows an erroneous "total" field and the second one has the same modifiedTime, clientCreatedTime and createdTime but is queried 2 seconds after. In the second capture the "total" field is however correct.
Please let me know there is a field for knowing if the total amount of the order is the final total.
If a change is made to an order on a device, there is no guarantee when that change will appear in the cloud. It's important to understand how the Clover Android SDK Order Service (and many other Clover Android SDK services) work. All queries operate off a local cache of the cloud data. When a mutation occurs, it's written locally immediately then put in a queue to post to the server. There could be other things pending in the queue, or the queue can be blocked because of slow network or other reasons.
Obviously the reverse it true as well. If a mutation is made through the REST API, it takes time for the device to be notified of this and sync it's local state to the cloud state.
Every time a mutation is made to an order on the device, it re-calcs the total and posts the change into the queue. What you are seeing is that total that wasn't the "final" total.
The bottom line is that mixing Order Service and REST calls won't work. You can't assume data consistency between them, in the short term. You also cannot assume consistency between devices for the same reasons.
Our server never calculates the total of an order. The system relies on a client calculating the order total and updating the value on the server. If you are using the REST API, that client is you.
If you are using the Clover Android SDK's Order Service, it will re-calculate the order total as you make changes to the order through the API and post the changes to the server.
As to why the changes eventually show up on the server, I can't explain that without more information. It would have to be your change is trigger some other client to calculate the total and post it to the server.
The order is submitted by a Clover Mini device and after we query the orders via REST API interface. If the query is made to soon we get a fraction of the real total. This only happens in complex orders (The order of the screenshots was of 34 item).
line-items.txt Attached is the json of the line_items. If you need any more information please let me know.
,Sorry, I did not say that we use a Clover Mini for submitting the order to the Clover Cloud. After, we query the information via REST API interface but the amount changes throught the time. The orders on which this happens are complex orders (the order of the screenshots is of 34 normal items). Please let me know if you need any more information.
line-items.txt,Yes, the request was made promptly after selecting "Save" in the register app in a Clover Mini. This saved a complete new order with 34 items, it is not an update of the order. Perhaps it could be the network connection however the WiFi layer is optimal.
So I will need to figure out how to know when the order is fully updated without depending on the rest API?.
Maybe I could place a delay between queries of the order for checking that the amount isn't changing. If the amount doesn't change I will be sure that the amount is final.
See my updated answer. I don't think a delay is correct as you don't know how long to delay, and being that there's no guarantee when changes will make it to the cloud. as I mentioned, I think your approach should be to move the logic that depends on the order state to the device.