question

LSitio avatar image
LSitio asked ·

Getting wrong "total" of an order depending on the time of query

second.png first.png
Hi,
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.

OrdersPaymentsClover MiniSandboxREST API
second.png (86.4 KiB)
first.png (86.5 KiB)
1 comment
10 |2000 characters needed characters left characters exceeded

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

Did you make the request promptly after adding the line item to the order? It is possible it just hadn't yet been updated in the database. That could be due to a bad network connection.

0 Likes 0 · ·
Jeffrey Blattman avatar image
Jeffrey Blattman answered ·
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.

Original answer:
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.


Share
10 |2000 characters needed characters left characters exceeded

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

LSitio avatar image
LSitio answered ·
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.

line-items.txt (13.1 KiB)
line-items.txt (13.1 KiB)
3 comments Share
10 |2000 characters needed characters left characters exceeded

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

Sorry different responses were saved as drafts but weren't showing when is was writing the last answer. When I submitted the last answer all the answers got mixed in one.
0 Likes 0 · ·

1. Where is the change submitted from (device, web)?

2. How is it submitted (Clover Android SDK, REST)?

3. Where is the order queried from (device, web)?

4. How is it queried (Clover Android SDK, REST)?

0 Likes 0 · ·
1. The change (order creation) is submitted from a Clover Mini.
2. Clover Register App.
3. Is Queried from the web ( GET /v3/merchants/{mId}/orders)
4. REST
0 Likes 0 · ·
Jeffrey Blattman avatar image
Jeffrey Blattman answered ·
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.
Share
10 |2000 characters needed characters left characters exceeded

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

LSitio avatar image
LSitio answered ·
OK, so much thanks for your advice.
Share
10 |2000 characters needed characters left characters exceeded

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