简体   繁体   English

快速创建createTokenWithCard完成块

[英]createTokenWithCard completion block in swift

I have got the number,cvc,expmonth,expyear and now I am trying to run a closure to get a token. 我已经有了数字,cvc,expmonth,expyear,现在我正在尝试关闭以获取令牌。 So far I have code like this : 到目前为止,我有这样的代码:

card.number = PaymentView.card.number
        card.cvc = PaymentView.card.cvc
        card.expMonth = PaymentView.card.expMonth
        card.expYear = PaymentView.card.expYear


        Stripe.createTokenWithCard(card: card, completion: {(token : STPToken, error : NSError) in


        })

    }

So I am then going to add an IF statement in there to check everything is cool and if so create the token. 因此,我将在其中添加IF语句以检查一切是否正常,如果是,则创建令牌。 but I am getting an error at the closure saying "Missing argument for parameter 'publishableKey' in call. 但是我在关闭时遇到错误,说“调用中缺少参数'publishableKey'的参数。

Any ideas ? 有任何想法吗 ?

At first glance I'd say the problem is that your parameters in the closure need to be optional, since that was defined in Objective-C: 乍一看,我想说的问题是,闭包中的参数必须是可选的,因为这是在Objective-C中定义的:

Stripe.createTokenWithCard(card: card, completion: {
    (token: STPToken!, error: NSError!) in
    // ...
})

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

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