繁体   English   中英

斯威夫特的条纹

[英]Stripe in Swift

我有一个用于卡支付系统的自定义表格。 表单包含名称为cardNumber,cvcNumber和到期日期的三个文本字段。 我正在使用条纹的支付系统。 条带测试密钥已成功配置。 但是在我的视图控制器中,当我为STPCard()编写代码时,它向我显示了一些错误。 cocoapods安装得很好,但是仍然显示错误,我正在尝试从数据条中获取令牌,但是这没有发生。 我的代码是这样的

 // Initiate the card
    let stripCard = STPCard()

    // Split the expiration date to extract Month & Year
    if self.expieryTxt.text?.isEmpty == false {
        let expirationDate = self.expieryTxt.text?.components( separatedBy: "/")
        let expMonth = UInt(expirationDate![0].toInt()!)
        let expYear = UInt(expirationDate![1].toInt()!)

        // Send the card info to Strip to get the token
        stripCard.nuber = self.cardNumberTxt.text
        stripCard.cvc = self.cvcNumberTxt.text
        stripCard.expMonth = expMonth
        stripCard.expYear = expYear
    }


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

    STPAPIClient.sharedClient().createTokenWithCard(stripCard, completion: { (token, error) -> Void in

        if error != nil {
            self.handleError(error!)
            return
        }

        self.postStripeToken(token!)
    })

错误是'init()' is unavailable: You cannot directly instantiate an STPCard. You should only use one that has been returned from an STPAPIClient callback. 'init()' is unavailable: You cannot directly instantiate an STPCard. You should only use one that has been returned from an STPAPIClient callback.

另一个是这个

Value of type 'String' has no member 'toInt'

类型错误的值,请尝试以下操作:

let expMonth = UInt(Int(expirationDate![0])!)
let expYear = UInt(Int(expirationDate![1])!)

另一个错误表明,您无法创建“空” STPCard,您已经从STPAPIClient获得了一个,然后就可以使用它了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM