Print Receipts API

The Print Receipts API is used to print the charge slip of a transaction for N10 devices only.

Method: POST

🚧

Warning

This API is applicable only for N10 device.

Request parameters

ParameterDescriptionExample
Handler

mandatory
handler Create a handler inner class. This class will return the response message.handler
deviceType

mandatory
string The device type of the POS terminalN910
referenceNumber
mandatory
string The transaction reference number.123-45-8575
receiptImage

Optional
bitmap Pass this parameter to print your company logo in the receipt.
customerCopy

Optional
boolean Determines whether or not to print the customer copy.True

Sample request

PaymentInitialization initialization=new PaymentInitialization(
PaymentDetails.this);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.payswiff);
initialization.initiatePrintReceipt(printHandler,
DeviceType.N910,txnResponse.getReferenceNumber(),null,customerCopy);

Sample response

@SuppressLint("HandlerLeak")
private final Handler printHandler = new Handler()
{
	public void handleMessage(android.os.Message msg)
	{
		if (msg.what == SUCCESS)
		{
			Toast.makeText(PaymentDetails.this, "Success",
				Toast.LENGTH_LONG).show();
		}
		i
		f(msg.what == FAIL)
		{
			Toast.makeText(PaymentDetails.this, (String) msg.obj,
				Toast.LENGTH_LONG).show();
			//finish();
		}
		else if (msg.what == ERROR_MESSAGE)
		{
			Toast.makeText(PaymentDetails.this, (String) msg.obj,
				Toast.LENGTH_LONG).show();
		}
	};
};

Custom printer

Use the custom printer API for customization of print receipt such as the size of the fonts in the receipt, the alignment of the texts in the receipt, etc.

❗️

Warning

This API is applicable only for N910 device.

Custom printer allows you to print the following:

  • Print text
  • Print image
  • Print QR code.
  • Print multi-language and special characters

Custom printer has the following customization options:

Font Size

TypeParameterDescription
Small fontsPrints 48 characters in a row.
Medium fontnPrints 32 characters in a row
Large fontlPrints 24 characters in a row
Small font, width, standard font heightsnPrints small font, small width, and standard font height.
Small font, width and large font heightslPrints small font, small width, and large font height.
Standard font width, large font heightnlPrints standard font, small width, and large font height.

Text Alignment

TypeParameterDescription
LeftlPrints text in the left.
RightrPrints text in the right.
CentercPrint text in the center.

Print Text

Method: POST

Use this API to print text. If you require to print custom text, use PRINT CUSTOM TEXT API instead.

Request parameter

ParameterDescriptionExample
Handler

mandatory
handler Create a handler inner class. This class will return response message.
DeviceType

mandatory
string This parameter is used to Identify the device.
StringBuffer
mandatory
stringBuffer Used to append, concatenate, and manipulate Strings or sequence of characters.StringBuffer sb=newStringBuffer();

Sample request

StringBuffer scriptBuffer = new StringBuffer();
scriptBuffer.append("!hz l\n !asc l\n !gray 5\n");//Set the title font to large
scriptBuffer.append("!yspace 5\n");// Set the line spacing, the value is [0,60], the default is 6
scriptBuffer.append("*text " + alignment + " ++++++++++++++ X ++++++++\n");
scriptBuffer.append("*text " + alignment + " SampleData\n");
scriptBuffer.append("!yspace 10\n");// Set content line spacing
scriptBuffer.append("*text l DATE:25-07-2020 " + "\n");//print text on Right side
scriptBuffer.append("*text l MID:5245678659\n");
scriptBuffer.append("*text l INVOICE:61349\n");
scriptBuffer.append("*text l CARD:441962XXXX1912[CHIP]\n");
scriptBuffer.append("*text l AUTH CODE:61349\n");
scriptBuffer.append("*text r RRN:159566454868\n");//print text on left side
scriptBuffer.append("*text r AID:A0000000031010\n");
scriptBuffer.append("*text l TVR:0000000000\n");
scriptBuffer.append("*text c TC:28EDE192A8837CAA\n");//print text on Center
scriptBuffer.append("*line" + "\n");//Print dotted line
PaymentInitialization initialization = new PaymentInitialization(ScannerViewActivity.this);
initialization.printScript(printerHandler, DeviceType.N910, scriptBuffer);

Sample response

Use this code to fetch the response of this API.

@SuppressLint("HandlerLeak")
private final Handler printerHandler = new Handler()
{
	public void handleMessage(android.os.Message msg)
	{
		if (msg.what == SUCCESS)
		{
			Toast.makeText(N910PrinterActivity.this,
				(String) msg.obj, Toast.LENGTH_SHORT).show();
		}
		else
		{
			Toast.makeText(N910PrinterActivity.this,
				(String) msg.obj, Toast.LENGTH_SHORT).show();
		}
	}
};

Print custom text

Use this API to print custom text.

πŸ“˜

Remember

If print characters are more than 32 ,the text will print in the next line.

Sample request

StringBuffer scriptBuffer = new StringBuffer()
scriptBuffer.append("!hz l\n !asc l\n !gray 5\n");//Set font to large
scriptBuffer.append("*text c " + "Print Sample text " + "\n");//set Text center
scriptBuffer.append("*text l " + "Print Sample text " + "\n");//set Text Left
scriptBuffer.append("*text c " + "Print Sample text " + "\n");//Set Text Right
PaymentInitialization initialization = new PaymentInitialization(ScannerViewActivity.this);
initialization.printScript(printerHandler, DeviceType.N910, scriptBuffer);

Print Image

Use this API to print image.

Request parameter

ParameterDescriptionExample
Handler

mandatory
handler Create a handler inner class. This class will return response message.
DeviceType

mandatory
string This parameter is used to Identify the device.
Map<String,Bitmap>
mandatory
bitmap This parameter stores the data in a pair such
that each element has a key associated with it.
Map<String,Bitmap> map=new Map<String,Bitmap>
StringBuffer
mandatory
stringBuffer Used to append, concatenate, and manipulate Strings or sequence of characters.StringBuffer sb=newStringBuffer();

Sample request

StringBuffer scriptBuffer = new StringBuffer();
scriptBuffer.append("!hz l\n !asc l\n !gray 5\n");//Set the title font to large
scriptBuffer.append("!yspace 5\n");// Set the line spacing, the value is [0,60], the default is 6
scriptBuffer.append("*text " + alignment + " ++++++++++++++ X ++++++++\n");
scriptBuffer.append("*text " + alignment + " SampleData\n");
scriptBuffer.append("!yspace 10\n");// Set content line spacing
scriptBuffer.append("*text l DATE:25-07-2020 " + "\n");//print text on Right side
scriptBuffer.append("*text l MID:5245678659\n");
scriptBuffer.append("*text l INVOICE:61349\n");
scriptBuffer.append("*text l CARD:441962XXXX1912[CHIP]\n");
scriptBuffer.append("*text l AUTH CODE:61349\n");
scriptBuffer.append("*text r RRN:159566454868\n");//print text on left side
scriptBuffer.append("*text r AID:A0000000031010\n");
scriptBuffer.append("*text l TVR:0000000000\n");
scriptBuffer.append("*text c TC:28EDE192A8837CAA\n");//print text on Center
scriptBuffer.append("*line" + "\n");//Print dotted line
PaymentInitialization initialization = new PaymentInitialization(ScannerViewActivity.this);
initialization.printScript(printerHandler, DeviceType.N910, scriptBuffer);

Sample response

Use this code to fetch the response for this API.

@SuppressLint("HandlerLeak")
private final Handler printerHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == SUCCESS) {
Toast.makeText(N910PrinterActivity.this,
(String) msg.obj, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(N910PrinterActivity.this,
(String) msg.obj, Toast.LENGTH_SHORT).show();
}
}
};

Print QR Code

Use this API to print QR code.

Request Parameter

ParameterDescriptionExample
Handler

mandatory
handler Create a handler inner class. This class will return response message.
DeviceType

mandatory
string This parameter is used to Identify the device.
StringBuffer
mandatory
stringBuffer Used to append, concatenate, and manipulate Strings or sequence of characters.StringBuffer sb=newStringBuffer();

Sample request

//Request
StringBuffer scriptBuffer = new StringBuffer();
scriptBuffer.append("!qrcode "+size+" "+width+"\n*qrcode c Your Text goes here\n");
PaymentInitialization initialization = new PaymentInitialization(ScannerViewActivity.

πŸ‘

Callout

In above sample request maximum range of size can be 50 to 350 and maximum range of width can be 1 to 3.

Sample response

Use this code to fetch the response of this API.

@SuppressLint("HandlerLeak")
private final Handler printerHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == SUCCESS) {
Toast.makeText(N910PrinterActivity.this,
(String) msg.obj, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(N910PrinterActivity.this,
(String) msg.obj, Toast.LENGTH_SHORT).show();
}
}
};

Multi-language and Special characters

Use this API to print multi-language and special characters.

Request parameter

ParameterDescriptionExample
Handler

mandatory
handler Create a handler inner class. This class will return response message.
DeviceType

mandatory
string Passed for Identification of the device.
Font
mandatory
string This parameter prints language other than English and special characters.Roboto.ttf
Map<String,Bitmap>
mandatory
bitmap This parameter stores the data in a pair such that each element has a key associated with it.Map<String,Bitmap> map=new Map<String,Bitmap>
StringBuffer
mandatory
stringBuffer Used to append, concatenate, and manipulate Strings or sequence of characters.StringBuffer sb=newStringBuffer();

Notes:

  1. If Image is not required in print you can pass the Map object as null. The specified font must be available in the application assets folder, else it will print boxes instead. Ensure that you are using proper .ttf file which supports both language and special characters. Example: src/main/assets/Roboto.ttf
  2. If you are using Locale to get string resources, ensure that you are setting it to English at the end of print.
    Example, for Hindi: Context context = LocaleHelper.setLocale(context,”hi”);
    Resources resources =context.getResources().getString(R.string.your_string); You need to set Locale again at the end of print, else the device language will get changed. Example, if you want to change the language to english: Context context = LocaleHelper.setLocale(context,”en”);
    Once a transaction is initiated, back button must be disabled until the transaction is completed.

Sample request

Bitmap bitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),
	R.drawable.payswiff);
Map<String, Bitmap> map = new HashMap<String, Bitmap> ();
String bmp0 = "bmp0;";
map.put(bmp0, bitmap);
StringBuffer buffer = new StringBuffer();
buffer.append("*line\n!yspace 5\n");
buffer.append("*line\n!yspace 5\n");
buffer.append("*image c 200 * 300 path:" + bmp0 + "\n");	//Print image in center
buffer.append("*line\n!yspace 5\n");
buffer.append("*text c ΰ€†ΰ€ͺΰ€•ΰ€Ύ ΰ€ͺΰ€Ύΰ€  ΰ€―ΰ€Ήΰ€Ύΰ€ ΰ€œΰ€Ύΰ€€ΰ€Ύ ΰ€Ήΰ₯ˆ\n");
buffer.append("*line\n!yspace 5\n");
buffer.append("!qrcode 200 2\n*qrcode c ABCDEFG\n");	//Print QR in center
buffer.append("*line\n!yspace 5\n");
buffer.append("*text c € Β£ $ Β₯ β‚Ή\n");	//Special characters
buffer.append("*line\n!yspace 5\n");
buffer.append("!barcode 3 100\n*barcode c 1234567\n");	//Print barcode in center

PaymentInitialization initialization = new PaymentInitialization(N910PrinterActivity.this);
initialization.printImage(printerHandler, DeviceType.N910, buffer, map, "Yantramanav-Medium.ttf");

Sample Response

Use this code to fetch the response of this API.

@SuppressLint("HandlerLeak")
private final Handler printerHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == SUCCESS) {
Toast.makeText(N910PrinterActivity.this,
(String) msg.obj, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(N910PrinterActivity.this,
(String) msg.obj, Toast.LENGTH_SHORT).show();
}
}
};