Issue #695

Inspect SKPaymentTransaction for error. In Swift, any Error can be safely bridged into NSError there you can check errorDomain and code

private func handleFailure(_ transaction: SKPaymentTransaction) {
    guard let error = transaction.error else { return }
    let nsError = error as NSError
    guard nsError.domain == SKError.errorDomain else { return }

    switch nsError.code {
    case SKError.clientInvalid.rawValue, SKError.paymentNotAllowed.rawValue:
        showAlert(text: "You are not allowed to make payment.")
    case SKError.paymentCancelled.rawValue:
        showAlert(text: "Payment has been cancelled.")
    case SKError.unknown.rawValue, SKError.paymentInvalid.rawValue:
        fallthrough
    default:
        showAlert(text: "Something went wrong making payment.")
    }
}