question

blueleaves avatar image
blueleaves asked blueleaves answered

Retrieve Current Order ID

Hello, all.

How can I retrieve the current order ID that is open in the Register application on a specific device (from outside the Register Application)?

The code I used to implement the latest order retrieval is this:

    cursor = MainActivity.this.getContentResolver().query(OrderContract.Summaries
           .contentUriWithAccount(account), new String[]{OrderContract.Summaries.ID}, null, null,
           OrderContract.Summaries.LAST_MODIFIED + " DESC LIMIT 1");

    if (cursor != null && cursor.moveToFirst()) {
      orderId = cursor.getString(cursor.getColumnIndex(OrderContract.Summaries.ID));
    }

    if (orderId == null) {
      return orderConnector.createOrder(new Order());
    } else {
      return orderConnector.getOrder(orderId);
    }

First impressions might make this seem like a good solution. The only problem is that this code it is not specific to a particular device. So, if an order is created on a separate device in the meantime, then it will choose that order ID instead of the one on the current device.

To elaborate further with an example:

Given two different end users using two different devices (device A and device B) tied to the same merchant account....

  • An end user creates an order on device A.
  • This end user starts adding items to that order.
  • While this is happening, the end user on device B creates an order was well.
  • The end user on device A now goes to my app, runs this code, and instead of retrieving the order ID from the order s/he was working on, instead, the ID is retrieved from the order that the user on device B created.

This scenario is what is occurring, and, logically, it makes sense because this snippet of code gets the 'last_modified' order ID, which would be the the order created on device B.

So my questions then are:

  • Does anyone know of a method or implementation to retrieve the current order ID on the specific device (the one open in the Register Application)?
  • OR can anyone think of a clever workout-around to this? (Maybe use a broadcast listener to intercept when an Order is created and go from there?)

Any help would be much appreciated! Thanks!

Orders
10 |2000

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

1 Answer

blueleaves avatar image
blueleaves answered

As it turns out, I was able to achieve what I needed by using this line of code:

orderId = getIntent().getStringExtra(Intents.EXTRA_ORDER_ID);

Of course, this is only if you are implementing your application flow to start after an end user clicks an 'Other' button in the Payments Activity.

Also, make sure you add this intent filter in the manifest:

<intent-filter>
            <action android:name="clover.intent.action.MODIFY_ORDER" />

            <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
10 |2000

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