Skip to content

Receipt printing via bluetooth printer

A number of POS thermal printers are supported.

To take advantage of our Bluetooth printer SDK for your receipt printing purposes, you want to include the following dependency in your app build.gradle file.

dependencies {
    implementation "com.globalaccelerex.printer:bluetooth:1.0.0"
}

Also, ensure the following maven declarations are set in your maven repositories block

repositorries {
    maven {
        url "https://<url-shared-with-you>"
    }
    maven { url 'https://jitpack.io' }
}

You want to construct your receipt print request using the ReceiptRequest class. You can send multiple receipts and they would be printed one after the other.

To print a logo on the receipt, supply a valid internet or publicly accessible uri in the bitmapUri field.

A StringField is a HEADER:BODY kind of formatted print line. If body is omitted (that is blank), the header is printed alone as a single line without the colon. (You don't need to supply the colon otherwise.)

To print a blank line after a StringField set the blanks field to the number of blank lines you wish to print. (Note that a single bank line can be somewhat large. Check that it fits your purpose)

Underline To underline a field, set the underline field of the LineField to true.

Bold Text To print a bold text, set the isBold field to true.

Alignment You can align text to the left, center or right (left by default). Use the FieldAlign enum

Font size Possible font sizes are normal, large, x-large, and small.

QR Code QR CODE can be printed by supplying the qrString parameter of the StringField. In this case, header and body should be left blank (that is empty strings).

Example receipt printing in an Android Activity.

    private val printReceipt = registerForActivityResult(ReceiptPrinterContract()) { success ->
        Timber.d("Receipt printed: $success")
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        findViewById<Button>(R.id.button_print_sample).setOnClickListener {
            val receiptRequest = receiptRequest(sampleResponse)
            printReceipt.launch(receiptRequest)
        }
    }

    private fun receiptRequest(pr: PaymentResponse) = ReceiptRequest(
        receipts = listOf(
            Receipt(
                bitmapUri = pr.bankLogo, // Bank logo should be an internet or publicly accessible uri of the logo. 
                stringFields = listOf(
                    StringFields(
                        header = LineField(text = pr.merchantName ?: ""),
                        body = LineField(text = "")
                    ),
                    StringFields(
                        isMultiline = true,
                        header = LineField(text = "LOCATION"),
                        body = LineField(text = pr.merchantAddress ?: "", underline = true)
                    ),
                    StringFields(
                        header = LineField(text = "TERMINAL ID"),
                        body = LineField(text = pr.terminalId ?: "")
                    ),
                    StringFields(
                        header = LineField(
                            text = pr.transactionType.uppercase(),
                            align = FieldAlign.center,
                            isBold = true,
                            size = "large"
                        ),
                        body = LineField(text = "")
                    ),
                    StringFields(
                        header = LineField(text = "STAN", isBold = true, size = FONT_SIZE_LARGE),
                        body = LineField(text = pr.stan ?: "")
                    ),
                    StringFields(
                        header = LineField(text = "DATE/TIME"),
                        body = LineField(text = pr.datetime ?: "")
                    ),
                    StringFields(
                        header = LineField(
                            text = "AMOUNT",
                            isBold = true,
                            size = FONT_SIZE_LARGE,
                            blanks = 1
                        ),
                        body = LineField(text = pr.amount ?: "")
                    ),
                    StringFields(
                        header = LineField(text = pr.appLabel ?: "Debit Card"),
                        body = LineField(text = "")
                    ),
                    StringFields(
                        header = LineField(text = pr.maskedPan ?: "", align = FieldAlign.center),
                        body = LineField(text = "")
                    ),
                    StringFields(
                        header = LineField(text = pr.cardHolderName ?: "Cardholder"),
                        body = LineField(text = "")
                    ),
                    StringFields(
                        header = LineField(text = "EXP. DATE."),
                        body = LineField(text = pr.cardExpireDate ?: "")
                    ),

                    StringFields(
                        header = LineField(
                            text = if (pr.approved()) "APPROVED" else "DECLINED",
                            align = FieldAlign.center,
                            isBold = true
                        ),
                        body = LineField(text = "")
                    ),
                    StringFields(
                        header = LineField(text = "RRN"),
                        body = LineField(text = pr.rrn ?: "")
                    ),
                    StringFields(
                        header = LineField(text = "AUTHCODE"),
                        body = LineField(text = pr.authcode ?: "")
                    ),
                    StringFields(
                        header = LineField(text = "STATUS CODE"),
                        body = LineField(text = pr.statusCode ?: "")
                    ),
                    StringFields(
                        header = LineField(text = "RESPONSE STATUS"),
                        body = LineField(text = pr.message ?: "")
                    ),
                    StringFields(
                        header = LineField(text = "AID"),
                        body = LineField(text = pr.aid ?: "")
                    ),
                    StringFields(
                        header = LineField(text = pr.footerMessage ?: ""),
                        body = LineField(text = "")
                    ),
                )
            )
        )
    )