Reputation: 153
I am trying to integrate Stripe into my app and I followed a tutorial that seems to be out of date. This is how my code looks:
import Foundation
import UIKit
import Stripe
import AFNetworking
class PaymentViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var cardNumberTextField: UITextField!
@IBOutlet weak var expirationDateTextField: UITextField!
@IBOutlet weak var cvcTextField: UITextField!
@IBAction func payButton(_ sender: Any) {
// Initiate the card
let stripCard = STPCardParams()
// Split the expiration date to extract Month & Year
if self.expirationDateTextField.text?.isEmpty == false {
let expirationDate = self.expirationDateTextField.text?.components(separatedBy: "/")
let expMonth = UInt((expirationDate?[0])!)
let expYear = UInt((expirationDate?[1])!)
// Send the card info to Strip to get the token
stripCard.number = self.cardNumberTextField.text
stripCard.cvc = self.cvcTextField.text
stripCard.expMonth = expMonth!
stripCard.expYear = expYear!
}
var underlyingError: NSError?
stripCard.validateCardReturningError(&underlyingError)
if underlyingError != nil {
self.handleError(underlyingError!)
return
}
}
}
I am getting an error in this block of code:
var underlyingError: NSError?
stripCard.validateCardReturningError(&underlyingError)
if underlyingError != nil {
self.handleError(underlyingError!)
return
}
}
The error says that .validateCardReturningError(&underlyingError)
is deprecated and that I should use STPCardValidator instead. I tried doing so but could not fix it. Help will be greatly appreciated.
Upvotes: 1
Views: 444
Reputation: 10590
according to @jflinter . you should flowing this way
let cardParams = STPCardParams()
cardParams.number = ...
cardParams.expMonth = ...
cardParams.expYear = ...
cardParams.cvc = ...
if STPCardValidator.validationStateForCard(cardParams) == .Valid {
// the card is valid.
}
Upvotes: 1