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
}

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, .inProgress:
break
default: // all failure cases
break
}
}