Creating custom receipts with CloverConnector
If your integration requires receipt features beyond those provided by Clover (see Set up payment receipts), you can disable the default receipts Per-Transaction Settings and print your own using the Clover device printer. It is your responsibility to ensure that custom receipts comply with local laws and regulations.
NOTE
Because the default receipt selection screen will not appear during the payment flow, your app should launch a custom activity if customer input is required.
Getting the device's printer
Before you can use the print()
method, you must retrieve information about the device's available printer. Your app can do so after the connection is established and the device is ready for subsequent requests. The following samples from the Remote Pay Android Example POS show how to get the printer information from the connected device.
public static List<Printer> printers;
private Printer printer;
public void onDeviceReady(final MerchantInfo merchantInfo) {
runOnUiThread(new Runnable() {
public void run() {
showMessage("Ready!", Toast.LENGTH_SHORT);
}
});
RetrievePrintersRequest rpr = new RetrievePrintersRequest();
cloverConnector.retrievePrinters(rpr);
}
Next, create a listener to handle the response to the RetrievePrinters()
call and set the printer
for the currently connected device.
@Override
public void onRetrievePrintersResponse(RetrievePrintersResponse response) {
printers = response.getPrinters();
if(printers != null){
printer = printers.get(0);
}
}
You can use this to confirm that the printer
is available before making a print request.
Printing a custom receipt
To send an image to the device printer, use CloverConnector.print(PrintRequest)
. The PrintRequest
's first parameter can take one of three forms: a bitmap image, the URL of an image, or an array of text strings. The following samples from the Remote Pay Android Example POS show how each type of PrintRequest
can be made.
public void printImage(String imgDecodableString){
Bitmap bitmap = BitmapFactory.decodeFile(imgDecodableString);
if(this.printer != null){
PrintRequest pr = new PrintRequest(bitmap);
lastPrintRequestId = String.valueOf(getNextPrintRequestId());
pr.setPrintRequestId(lastPrintRequestId);
pr = new PrintRequest(bitmap, lastPrintRequestId, printer.getId());
cloverConnector.print(pr);
}
}
public void printImageURLClick(View view) {
String URL = ((TextView) findViewById(R.id.PrintImageURLText)).getText().toString();
if(printer != null){
PrintRequest pr = new PrintRequest(URL);
lastPrintRequestId = String.valueOf(getNextPrintRequestId());
pr.setPrintRequestId(lastPrintRequestId);
pr = new PrintRequest(URL, lastPrintRequestId, printer.getId());
cloverConnector.print(pr);
}
}
public void printTextClick(View view) {
String[] textLines = ((TextView) findViewById(R.id.PrintTextText)).getText().toString().split("\n");
List<String> lines = Arrays.asList(textLines);
if(printer != null){
PrintRequest pr = new PrintRequest(lines);
lastPrintRequestId = String.valueOf(getNextPrintRequestId());
pr.setPrintRequestId(lastPrintRequestId);
pr = new PrintRequest(lines, lastPrintRequestId, printer.getId());
cloverConnector.print(pr);
}
Guidelines for receipt images
For the best printing performance, observe the following recommendations when constructing a receipt bitmap to be printed:
- Pre-scale the image to a maximum width of 576 pixels
- Use a purely black-and-white image (where the saturation value is zero). A grey-scaled image will process more slowly because the device will evaluate each pixel.
Updated about 2 years ago