question

ondrej avatar image
ondrej asked Jeffrey Blattman commented

Syncing server and device order data

Hello,

is there any way to invoke 'sync' in the code so that the synchronization between the server state of the order and the device state is done more 'on demand'?

Use case:

  1. During the order flow, the cashier selects our custom tender in the payments screen
  2. In the custom tender activity we need to create more than one payment (a gift card payment). We do it using the v3 web API since it is not possible using the OrderConnector (it fails with ForbiddenException).
  3. Application waits until the order (and the new payment) is synchronized to the device
  4. The flow returns to the payments screen

In the step 3 we currently have to wait in a loop for the sync. We are waiting for the sync so that the payment is shown in the step 4 immediately after the screen opening. Is there any method to initiate this sync to speed things up ?

Thank you.

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.

1 Answer

Jacob Abrams avatar image
Jacob Abrams answered Jeffrey Blattman commented

This code should force orders to sync:

private static void forceSync(Context context) {
    Bundle extras = new Bundle();
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    context.getContentResolver().requestSync(CloverAccount.getAccount(context), OrderContract.AUTHORITY, extras);
}
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.

Even if you do this, you still need to wait in a loop for the sync. The above starts an asynchronous operation and you still don't know when it's going to complete. In general it's a bad idea to force sync. The software on Clover devices does it's best to keep the server and device state in sync with push messages indicating when the device should sync to the server. Adding code to force this can put unreasonable strain on our servers and is redundant since the device will end up syncing twice.

0 Likes 0 ·

Welcome to the
Clover Developer Community