-
Notifications
You must be signed in to change notification settings - Fork 10
Token PreAuth
Albert Mata edited this page Nov 3, 2016
·
6 revisions
func repeatPreAuthOperation() {
if let cardDetails = self.cardDetails, let payToken = self.paymentToken, let ref = Reference(consumerRef: self.reference) {
try! self.judoKitSession.invokeTokenPreAuth(judoId, amount: Amount(decimalNumber: 0.01, currency: currentCurrency), reference: ref, cardDetails: cardDetails, paymentToken: payToken, completion: { (response, error) -> () in
self.dismiss(animated: true, completion: nil)
if let error = error {
if error.code == .userDidCancel {
self.dismiss(animated: true, completion: nil)
return
}
var errorTitle = "Error"
if let errorCategory = error.category {
errorTitle = errorCategory.stringValue()
}
self.alertController = UIAlertController(title: errorTitle, message: error.message, preferredStyle: .alert)
self.alertController!.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.dismiss(animated: true, completion:nil)
return // BAIL
}
if let resp = response, let transactionData = resp.items.first {
self.cardDetails = transactionData.cardDetails
self.paymentToken = transactionData.paymentToken()
}
let sb = UIStoryboard(name: "Main", bundle: nil)
let viewController = sb.instantiateViewController(withIdentifier: "detailviewcontroller") as! DetailViewController
viewController.response = response
self.navigationController?.pushViewController(viewController, animated: true)
})
} else {
let alert = UIAlertController(title: "Error", message: "you need to create a card token before making a repeat payment or preauth operation", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
Note: Please make sure that the Consumer Reference used and the card token matches the ones used when the card token was originally generated.