cdcilley avatar image
cdcilley asked Raymond Lee Deactivated commented

Printed receipt line numbering

Using Secure Pay, when the customer is done and chooses to "Print Receipt", all of the line items on the receipt are numbered "1" on the left hand side, see image. How can I get either no numbering or have it number the lines sequentially, 1 - 2 - 3 - etc...?

I'm building a custom Android application. I build the Order with a call to
mOrder = orderConnector.createOrder();
I create the LineItems and set the values, then add them to the order using
tmpItem = new LineItem();
orderConnector.addCustomLineItem(mOrder.getId(), tmpItem, false);
Everything works fine - the order is created, has the correct line items, total, etc.

I call Secure Pay using
Intent intent = new Intent(Intents.ACTION_SECURE_PAY);
intent.putExtra(Intents.EXTRA_AMOUNT, 1030);
intent.putExtra(Intents.EXTRA_ORDER_ID, mOrder.getId());
startActivityForResult(intent, CSPConstants.SECURE_PAY_REQUEST_CODE);

As a bonus question... You may notice I've added text in the "item name" that includes the unit name and quantity. I've tried tmpItem.setUnitName but that does not show up on the receipt and tmpItem.setUnitQty only accepts integers which doesn't work for stuff sold by the pound.
PrintDevKitsecure network pay display
receipt.jpg (284.1 KiB)
1 comment
10 |2000

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

The list of 1's is the quantity of each item. The order has 1 item of "Grain Quinoa Organic" with the units lb, with 3.15 lb at $3.15 per lb and so on.

I don't know if this is configurable.

0 Likes 0 ·
Raymond Lee avatar image
Raymond Lee Deactivated answered Raymond Lee Deactivated commented
Hi @cdcilley,

As Dan mentioned, The 1's are the quantity of each item. Normally you would not want to hide this, in the case of someone ordering multiple of a LineItem.

For tmpItem.setUnitQty, it accepts integers, but it translates to a quantity with 3 digit precision.
For example:
A unitQty of 25608 would be 25.608.
A unitQty of 34 would be 0.034.

As for the tmpItem.setUnitName, it does not show up as we currently do not support creating custom PerUnitLineItems through Android SDK. It has to be an existing per unit inventory item for you to make a PerUnitLineItem through Android SDK.

However you can still make a custom PerUnitLineItem through our REST API.

Here is how:

private RequestQueue mRequestQueue;

// In onCreate():
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap
Network network = new BasicNetwork(new HurlStack());
mRequestQueue = new RequestQueue(cache, network);
CloverAuth.AuthResult authResult = CloverAuth.authenticate(getApplicationContext(), mAccount);
final String authToken = authResult.authToken;
String baseUrl = authResult.authData.getString(CloverAccount.KEY_BASE_URL);
String merchantId = authResult.merchantId;
String orderId = "F2AYBT5DX0E20"; // Just for example; get your orderId from OrderConnector.

if (authToken != null && baseUrl != null) {
    String url = baseUrl + "/v3/merchants/" + merchantId + "/orders/" + orderId + "/line_items";

    JSONObject params = new JSONObject();
    params.put("name", "Avocados");
    params.put("unitName", "lb");
    params.put("unitQty", 500);     // 0.5 lb
    params.put("price", 100);       // $1 per lb

    JsonObjectRequest jsObjRequest = new JsonObjectRequest(
            Request.Method.POST, url, params, new Response.Listener<JSONObject>() {
        public void onResponse(JSONObject response) {
            try {
                // You can get any info you want from the response 
		// using response.getJSONObject() or response.getJSONArray()

            catch (JSONException e) {
    }, new Response.ErrorListener() {
        public void onErrorResponse(VolleyError error) {
    }) {
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Authorization", "Bearer " + authToken);

            return headers;


Give it a try, it should show up with the unitQty and unitName on the device and receipt, so you don't have to add it to the LineItem note.

Hope that helps,

10 |2000

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

I tried the Volley RequestQueue.

I use an AsyncTask to get the authToken, merchantId, orderId and baseUrl. I return those values (orderBundle) to my activity for use in the RequestQueue. I copied your code and added some debug logging...

merchantId = YCJRNJV7WK61Y : orderId = 7SJWJGRJ7B4MW
orderURL =
headers = {Authorization=Bearer 3d455bc9-xxx-xxx-xxx-618760993b26}
onErrorResponse() : No authentication challenges found

Can't seem to get past the No authentication challenges found error.

Any ideas? I vaguely remember seeing something about use the REST API in the sandbox...

0 Likes 0 ·

I believe that the No authentication challenges found error is due to a 401 unauthorized error sent by our server, without WWW-Authenticate in the response header. A 401 unauthorized error is due to either incorrectly sending the API token (incorrect format, or token itself), or due to app permissions.

In this case I think it is due to app permissions; can you verify if you have write permissions for Orders in your App's required permissions?

If not, could you set write permissions for your app? Then you will need to do an uninstall/reinstall of your app for your test merchant, as that is required in order for the new permissions to be applied.

0 Likes 0 ·

The permission would seem to be it - didn't have order permissions for the app. I talked with the customer and since the current receipts (all 1's) has 100% of the content and 90% look right, we're going to go with that for the moment and update to the REST API later (kind of time constrained right now ;-).

0 Likes 0 ·

Sounds good, glad the permissions fixed it for you!

0 Likes 0 ·
cdcilley avatar image
cdcilley answered Raymond Lee Deactivated commented
I set the Unit Qty as you suggested...
LineItem tmpItem = new LineItem();
tmpItem.setUnitQty((int) (2.2 * 1000));
Log.d("CloverTAG", "unitQty = " + tmpItem.getUnitQty()); // Returns 2200 in Logcat
tmpItem.setPrice(195); // $1.95/lb
orderConnector.addCustomLineItem(mOrder.getId(), tmpItem, false);
Still prints a "1" for each and every line item on the receipt.
I feel this may have something to do with not being able to set the payType for a custom LineItem...

I'll give the REST option a try, but it seems overkill for something that should be set-able in the SDK.

As an aside... I'm stuck creating these as custom LineItems. My client has a robust and in-house built order/inventory system (over 7000 items that are in flux). They currently use Clover to process card transactions, but just hand enter a single line item with an invoice number and total cost. They are keen (especially after I showed them these test printed receipts) to have the detail show up on the invoice.
1 comment
10 |2000

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

Yes, the 1 will still be printed, as that represents the quantity of that line item. You can have multiple of the same line item, which would result in a different number being printed.

Here is an example I made with Avocados and Peaches:

Yes, for now the REST option is the only option, as we currently do not have a method of creating a custom per unit line item through Android SDK. I will submit an enhancement request to be able to do so, but for now REST API is the only option.

0 Likes 0 ·
line-item-example.jpg (490.7 KiB)

Welcome to the
Clover Developer Community