Stripe - 在 Stripe 方法中出错

Stripe - Getting Error in Stripe Method

我正在尝试将 Stripe 集成到我的应用程序中,我遵循的教程似乎已经过时了。这是我的代码的样子:

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
        }
    }

}

我在这段代码中遇到错误:

            var underlyingError: NSError?
        stripCard.validateCardReturningError(&underlyingError)
        if underlyingError != nil {
            self.handleError(underlyingError!)
            return
        }
    }

错误提示 .validateCardReturningError(&underlyingError) 已弃用,我应该改用 STPCardValidator。我尝试这样做但无法修复它。将不胜感激。

根据@jflinter 的说法。你应该这样流动

let cardParams = STPCardParams()
cardParams.number = ...
cardParams.expMonth = ...
cardParams.expYear = ...
cardParams.cvc = ...
if STPCardValidator.validationStateForCard(cardParams) == .Valid {
  // the card is valid.
}