Printing Preformatted Receipts
Starting from SDK version 2.50, you can access preformatted receipts that
represent the
required receipt information format. Preformatted
receipts can be printed immediately without additional
formatting. The preformatted receipts are flexible to be
adjusted according to your printer's character limit for each
line.
Setting Preformatted Receipts Line
Limit
In order to define the maximum characters of each
line of preformatted receipts, do the following
method:
transactionProvider.setMaxReceiptLineLength(40);
Note
that
40
is just an example value. The actual
value depends on your printer's limit that it can print on its
paper. Longer lines will be wrapped to their respective next
lines in the returned output.
Printing
Preformatted Receipts
After you have defined the maximum line
length of your preformatted receipts, you can simply print them for
both customer receipt and merchant receipt by calling
receipt.getLines()
. The method returns a list
of strings that you can loop through to easily print
out.
TransactionProcess paymentProcess = transactionProvider.startTransaction(transactionParameters, accessoryParameters,
new TransactionProcessWithRegistrationListener() {
@Override
public void onCompleted(TransactionProcess process,
Transaction transaction,
TransactionProcessDetails processDetails) {
// For merchant Receipt
Receipt merchantReceipt = transaction.getMerchantReceipt();
System.out.println("Merchant Receipt");
for (String line : merchantReceipt.getLines()) {
System.out.println(line);
}
// For customer Receipt
Receipt customerReceipt = transaction.getCustomerReceipt();
System.out.println("Customer Receipt");
for (String line : customerReceipt.getLines()) {
System.out.println(line);
}
}
}
);