Printing

Printing configuration

Our SDK exposes APIs to print receipts after a payment. If printing capabilities are required for your use case, ensure you set up printer configuration after SDK initialisation or before making a payment.

Use the PrinterConfig class to pass in desired functionality for printing.

Supported PrinterProvider values

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 integrator.
Basic printing configuration
1YocoSDK.setPrinterConfig(
2 PrinterConfig(
3 printerProvider: PrinterProvider.sdk
4 )
5)

When using PrinterProvider.sdk, the SDK will automatically detect attached and integrated printers, and will show the print option on the payment receipt screen.

Print button

Set up PrintParameters when creating a charge.

Lookup with print in charge flow
1// Provide a clientTransactionId when setting up printing for refund
2// or lookup of a transaction
3let printParams = PrintParameters(
4 clientTransactionId: nil,
5 merchantInfo: merchantInfo,
6 transactionType: YocoTransactionType.GOODS,
7 receiptType: ReceiptCopyType.BOTH,
8 signature: nil,
9 metadata: ["Meta": "Data"],
10 printStartListener: { result, printProgress in
11 printProgress(.inProgress(message: nil))
12 let seconds = 1.5
13 DispatchQueue.main
14 .asyncAfter(
15 deadline:
16 DispatchTime
17 .now() + seconds
18 ) {
19 if self.printSuccess {
20 printProgress(.complete(message: nil))
21 } else {
22 printProgress(.error(message: "No printer"))
23 }
24 }
25 },
26 printerStatusListener: { status in
27 print("Status: \(status)")
28 },
29 printResultListener: { result in
30 print("Result: \(result)")
31 })
32let transactionID = YocoSDK.charge(
33 money,
34 paymentType: type,
35 currency: .zar,
36 tippingConfig: tippingSetting,
37 paymentParameters: getPaymentParams(),
38 printParameters: printParams,
39 completionHandler: { paymentResult in
40 // Do something once the payment is complete
41 // and the YocoSDK has dismissed
42 })

To print receipts for older transactions, a standalone printing flow is provided that takes in a clientTransactionId parameter in PrintParameters to perform both lookup and print.

Lookup with print usage
1let printParams =
2 PrintParameters(
3 clientTransactionId: transactionID,
4 merchantInfo: merchantInfo,
5 transactionType: YocoTransactionType.GOODS,
6 receiptType: ReceiptCopyType.BOTH,
7 signature: nil,
8 metadata: ["Meta": "Data"],
9 printStartListener: { result, printProgress in
10 printProgress(.inProgress(message: nil))
11 let seconds = 1.5
12 DispatchQueue.main
13 .asyncAfter(
14 deadline:
15 DispatchTime
16 .now() + seconds
17 ) {
18 if self.printSuccess {
19 printProgress(.complete(message: nil))
20 } else {
21 printProgress(.error(message: "No printer"))
22 }
23 }
24
25 },
26 printerStatusListener: { status in
27 print("Status: \(status)")
28 },
29 printResultListener: { result in
30 print("Result: \(result)")
31 })
32 ...
33 YocoSDK.print(rootViewController: self, printParameters: printParams) { result in
34 }