Error recovery

Previous transaction look up

In the event that the app crashes or is terminated during a transaction, it is useful to know what happend to the transaction that was in progress. To look up the state of a previous transaction, call:

Yoco.getPaymentResult(transactionID: transactionID) { paymentResult, error in
}

This will allow you to get the PaymentResult of the transaction so you can determine if it was a success or failure.

Showing the user the result

After receiving the PaymentResult above, you probably want to show the user the result (and allow them to send a receipt). The YocoSDK has a function to allow you to present the result of the payment and send a receipt via the function below:

Yoco.showPaymentResult(paymentResult, paymentParameters: parameters) { paymentResult in
}

You can pass the same PaymentParameters object you normally use with the Yoco.charge() method to pass a YocoReceiptDelegate and other optional parameters.

You can chain both the above methods near your app start to automatically display a previous transaction:

// If something happened during a transaction, attempt to get the transaction status and display the result to the user.
if let transactionID = UserDefaults.standard.value(forKey: "transactionInProgress") as? String {
Yoco.getPaymentResult(transactionID: transactionID) { paymentResult, error in
if let paymentResult = paymentResult {
Yoco.showPaymentResult(paymentResult, paymentParameters: parameters) { paymentResult in
UserDefaults.standard.set(nil, forKey: "transactionInProgress") // Clear the transaction ID we saved, so we dont accidentally show it again.
}
}
}
}