Printing

Attached printers (now supported with NEO plus bundle) can be detected using a call to isPrinterAvailable shown in below example usage:

YocoSDK.isPrinterAvailable { available, error ->
if (available) {
// Do printing
}
}

Print in charge flow

A print button is shown when a printer is available with the card reader. Set up PrintParameters after a charge is initiated and a clientTransactionId has been returned, these paramters are used to configure

Parameters

  • printRequestId: String - A unique UUID for this print job
  • clientTransactionId: String - Client transaction id returned when creating charge
  • pritnerConfig: PrinterConfig - Configuration for printer such as autoprinting when transaction completes
  • merchantInfo: MerchantInfo - Merchant information
  • transactionType: TransactionType - TransactionType.GOODS for a charge and TransactionType.REFUND for printing of refunds
  • signature: Bitmap - signature bitmap if available
import com.yoco.payments.sdk.data.params.MerchantInfo
import com.yoco.payments.sdk.data.params.PrintParameters
import com.yoco.payments.sdk.data.params.PrinterConfig
...
// A charge was created here
YocoSDK.setPrintParamters(
PrintParameters(
printRequestId = UUID.randomUUID().toString(),
clientTransactionId = clientTransactionId,
printerConfig = PrinterConfig(
autoPrint = false
),
merchantInfo = MerchantInfo("merchant-id", "merchant-name", "123-456-789", "business address"),
transactionType = TransactionType.GOODS,
signature = null,
metadata = null
)
)
}

Print with lookup

In order to print receipts for older transactions, a standalone printing flow is provided that takes in clientTransactionId param in PrintRequest to perform lookup and print. Example usage is given below:

Parameters

  • context: Context - activity/fragment context
  • params: PrintParameters - parameters required to complete print job
  • result: ActivityResultLauncher<Intent> - activity result handler to receive activity result
import com.yoco.payments.sdk.data.result.PrintResult
import com.yoco.payments.sdk.data.params.MerchantInfo
import com.yoco.payments.sdk.data.params.PrintParameters
import com.yoco.payments.sdk.data.params.PrinterConfig
import com.yoco.payments.sdk.data.delegates.UpdateReceiptProgress
import com.yoco.payments.sdk.data.enums.ReceiptState
import com.yoco.payments.sdk.data.enums.SupportedReceiptType
...
private val printResult: ActivityResultLauncher<Intent> =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
System.err.println("Result Code: ${result.resultCode}") // PaymentSDK.Response.ResultCode
val printResult: PrintResult? =
result.data?.getSerializableExtra(PaymentResultInfo.ResultKeys.Print) as PrintResult?
System.err.println("Print Result: $printResult")
}
...
YocoSDK.print(
requireContext(),
PrintParameters(
printRequestId = UUID.randomUUID().toString(),
clientTransactionId = transactionIdStr,
printerConfig = PrinterConfig(
autoPrint = false
),
merchantInfo = MerchantInfo("merchant-id", "merchant-name", "123-456-789", "business address"),
transactionType = TransactionType.GOODS,
signature = null,
metadata = null
),
result = printResult
)