We are trying to print automatically an order or order receipt when order will be placed by REST APIs from web. We tried almost all the printer related jobs like :- StaticOrderPrintJob StaticReceiptPrintJob StaticOrderBasedPrintJob OrderPrintJob OrderBasedPrintJob
but in all cases it is redirecting us on clover printer app to print manually but we want to print our order or receipt automatically when order will be placed from our online web site. We are testing this on sandbox
So please let us know that 1. what we are missing to print automatically through android sdk or REST api ? 2. do we need to make any setting on merchant side ? 3. is there any other way for auto printing ?
code for print
PrintJob pj = new StaticReceiptPrintJob.Builder().order(order).build();
pj.print(MainActivity.this, account, printer.get(i));
for getting printer
private List<Printer> getPrinter() {
List<String> id = Preferences.getInstance(this).readList(Preferences.ACTIVE_PRINTER_LIST, "");
List<Printer> printList = new ArrayList<Printer>();
if (id == null) {
try {
List<Printer> printers = printerConnector.getPrinters();
if (printers != null && !printers.isEmpty()) {
printList.add(printers.get(0));
return printList;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
try {
for (int i = 0; i < id.size(); i++) {
printList.add(printerConnector.getPrinter(id.get(i)));
}
return printList;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
for getting order
private class MyAsyncTask extends AsyncTask<String, Void, Order> {
CallBackTask callback;
public MyAsyncTask(CallBackTask callback) {
this.callback = callback;
}
@Override
protected final Order doInBackground(String... params) {
String orderId = params[0];
Cursor cursor = null;
try {
// Query the last order
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));
}
return orderConnector.getOrder(orderId);
} catch (RemoteException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} catch (BindingException e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}
return null;
}
@Override
protected final void onPostExecute(Order order) {
callback.setData(order);
}
}
Thanks mKonnekt