Skip to main content

Printing

Printing configuration

Set up printer configuration after SDK intialisation or before making payment, if printing capabilities are required or external printing is required on press of print button.

Use PrinterConfig class to pass in desired functionality for printing

Parameters

  • printerProvider: PrinterProvider - none, sdk, or external

Supported PrinterProviders

Here is a list of supported print providers:

PrinterProviderValueBehaviour
None (default)PrinterProvider.noneNo print button shown
SDKPrinterProvider.sdkPrint button shown if integrated printer available
ExternalPrinterProvider.externalPrint button shown always, printing handled externally by integator
YocoSDK.setPrinterConfig(
PrinterConfig(
printerProvider = PrinterProvider.sdk
)
)

info

Attached and integrated printers (now supported with NEO plus bundle) are auto-detected presenting the print option on payment receipt screen when PrinterProvider.sdk is configured.

Set up PrintParameters when creating a charge:

  • clientTransactionId: String - Client transaction id returned when creating charge
  • merchantInfo: MerchantInfo - Merchant information
  • transactionType: TransactionType - TransactionType.GOODS for a charge and TransactionType.REFUND for printing of refunds
  • signature: Data - signature bitmap as Data if available
  • printStartListener: ((PaymentResult?, UpdatePrintProgress) -> Void) - start listener allows control of displaying printing progress using the UpdatePrintProgress callback. Used with external PrinterProvider.
  • printerStatusListener: ((PrinterStatus) -> Void) - listens for printer status updates for integrated printers
  • printResultListener: ((PrintResult) -> Void) - listens for print result
// Provide a clientTransactionId when setting up printing for refund or lookup of a transaction
let printParams = PrintParameters(
clientTransactionId: nil,
merchantInfo: merchantInfo,
transactionType: YocoTransactionType.GOODS,
receiptType: ReceiptCopyType.BOTH,
signature: nil,
metadata: ["Meta": "Data"],
printStartListener: { result, printProgress in
printProgress(.inProgress(message: nil))
let seconds = 1.5
DispatchQueue.main
.asyncAfter(deadline: DispatchTime
.now() + seconds)
{
if self.printSuccess {
printProgress(.complete(message: nil))
} else {
printProgress(.error(message: "No printer"))
}
}
}, printerStatusListener: { status in
print("Status: \(status)")
}, printResultListener: { result in
print("Result: \(result)")
})
let transactionID = Yoco.charge(
money,
paymentType: type,
currency: .zar,
tippingConfig: tippingSetting,
paymentParameters: getPaymentParams(),
printParameters: printParams,
completionHandler: { paymentResult in
// Do something once the payment is complete
// and the YocoSDK has dismissed
})

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

let printParams = PrintParameters(
clientTransactionId: transactionId,
merchantInfo: merchantInfo,
transactionType: YocoTransactionType.GOODS,
receiptType: ReceiptCopyType.BOTH,
signature: nil,
metadata: ["Meta": "Data"],
printStartListener: { result, printProgress in
printProgress(.inProgress(message: nil))
let seconds = 1.5
DispatchQueue.main
.asyncAfter(deadline: DispatchTime
.now() + seconds)
{
if self.printSuccess {
printProgress(.complete(message: nil))
} else {
printProgress(.error(message: "No printer"))
}
}

}, printerStatusListener: { status in
print("Status: \(status)")
}, printResultListener: { result in
print("Result: \(result)")
})
...
Yoco.print(rootViewController: self, printParameters: printParams) { result in

}