Printing
Attached printers (now supported with NEO plus bundle) can be detected using a call to isPrinterAvailable
shown in below example usage:
Yoco.isPrinterAvailable { available, error in
// if available proceed with printing
}
Print in charge flow
If .print
receipt type is provided in list of SupportedReceiptTypes
when performing a charge, a Print
button is displayed in list of options on receipt screen. Print button press invokes below
delegate method and gives opportunity to pass in required PrintRequest
and initiate printing:
func printReceipt(canPrintOnTerminal: Bool, message: String?, paymentResult: PaymentResult, progress: @escaping UpdateReceiptProgress) {
if(canPrintOnTerminal) {
if let receiptInfo = paymentResult.receiptInfo {
let merchantInfo = MerchantInfo(
merchantId: "merchant-id",
merchantName: "Your Business",
phone: "0123456789",
address: "Underground Business 1, ZA"
)
let printRequest = PrintRequest(
printRequestId: paymentResult.transactionID,
clientTransactionId: "", // Used for printing a transaction from history
printerConfig: PrinterConfig(), // a class instance of PrinterConfig
receiptInfo: receiptInfo,
merchantInfo: merchantInfo,
transactionType: YocoTransactionType.GOODS,
receiptType: ReceiptCopyType.BOTH,
signature: nil,
metadata: ["Meta" : "Data"]
)
progress(.inProgress(message: "Printing..."))
// Sends print request to SDK to be printed
Yoco.printReceipt(printRequest: printRequest) { printResult in
if (printResult?.completed == true) {
progress(.complete())
} else {
progress(.error(message: printResult?.errorMessage ?? "Print failed"))
}
}
} else {
progress(.error(message: "Payment request is missing receiptInfo"))
}
}
}
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:
let merchantInfo = MerchantInfo(
merchantId: "merchant-id",
merchantName: "Your business",
phone: "0123456789",
address: "Underground Business 1, ZA"
)
...
let printRequest = PrintRequest(
printRequestId: transactionId,
clientTransactionId: transactionId,
printerConfig: PrinterConfig(),
receiptInfo: nil,
merchantInfo: merchantInfo,
transactionType: YocoTransactionType.GOODS,
receiptType: ReceiptCopyType.BOTH,
signature: nil,
metadata: ["Meta" : "Data"]
)
...
Yoco.print(rootViewController: self, printRequest: printRequest) { result in
}