Finishing a payment

The charge and refund function 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. Alternatively you can also get a payment result returned to you inside any of the ReceiptDelegate methods.

The PaymentResult object has a property called result which is one of the following ResultCode

public enum ResultCode: CaseIterable {
case success
case inProgress
case failure(String)
case cancelled
case permissionDenied
case noConnectivity
case invalidToken
case bluetoothDisabled
case cardMachineError
}

This result is useful to know if the payment was successful or not and why it may have been unsuccessful.

Yoco.charge(1000) { paymentResult in
switch paymentResult.result {
case .success:
break
default: // all failure cases
break
}
}

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 started.

You will get back 3 amounts in the paymentResult:

paymentResult.amountInCents // This is the initial value you passed into the charge call
paymentResult.tipAmountInCents // The tip amount that the cardholder entered on the card machine
paymentResult.finalAmountInCents // The final amount obtained from: tipAmountInCents + amountInCents