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
, orexternal
Supported PrinterProviders
Here is a list of supported print providers:
PrinterProvider | Value | Behaviour |
---|---|---|
None (default) | PrinterProvider.none | No print button shown |
SDK | PrinterProvider.sdk | Print button shown if integrated printer available |
External | PrinterProvider.external | Print 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.
Print in charge flow
Set up PrintParameters
when creating a charge:
clientTransactionId: String
- Client transaction id returned when creating chargemerchantInfo: MerchantInfo
- Merchant informationtransactionType: TransactionType
- TransactionType.GOODS for a charge and TransactionType.REFUND for printing of refundssignature: Data
- signature bitmap asData
if availableprintStartListener: ((PaymentResult?, UpdatePrintProgress) -> Void)
- start listener allows control of displaying printing progress using theUpdatePrintProgress
callback. Used withexternal
PrinterProvider.printerStatusListener: ((PrinterStatus) -> Void)
- listens for printer status updates for integrated printersprintResultListener: ((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
})
Print with lookup
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
}