Finishing a payment

The charge and refund functions have a completion handler that has a PaymentResult object as a parameter. You can get info about the result of the transaction from this object. The completion handler will always be called when the payment flow is closing.

The PaymentResult object has a property of type enum called result, which can be any of the following ResultCode values.

ResultCode.swift
1public enum ResultCode: CaseIterable {
2 case success
3 case inProgress
4 case failure(String)
5 case unknownResult(String)
6 case cancelled
7 case permissionDenied
8 case noConnectivity
9 case invalidToken
10 case bluetoothDisabled
11 case cardMachineError
12 case printFailed
13}

The result enum helps identify the state of the payment and if an error has occurred.

Payment result example
1YocoSDK.charge(1000) { paymentResult in
2 switch paymentResult.result {
3 case .success:
4 break
5 default: // all failure cases
6 break
7 }
8}

Handling Tips

The charge function also accepts a parameter askForTip. When this feature is used, you will need to account for any tip amount entered after a payment is started.

You will get back three amounts in the paymentResult:

PropertyDescription
amountInCentsThe initial transaction amount you passed into the charge call (the subtotal).
tipAmountInCentsThe tip amount entered by the cardholder on the card machine.
finalAmountInCentsThe total amount charged to the customer, including the subtotal and the tip.