条带错误"用卡创建令牌(_:完成:)不可用"

时间:2015-01-22 06:04:27

标签: swift

在此行中,错误为显示。有人能告诉我犯了什么错误吗?

 Stripe.createTokenWithCard(card, completion: { (token: STPToken!, error: NSError!) -> Void in
        self.handleToken(token)

3 个答案:

答案 0 :(得分:9)

我最近在pods中更新Stripe后遇到了同样的问题。该方法已弃用。相反,您可以使用以下代码:

STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token: STPToken!, error: NSError!) -> Void in     
})

它采用相同的参数。

更新

感谢@Christine和@ Keyhole150

Stripe API中的此功能现在已更改为

STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token: STPToken?, error: NSError?) -> Void in     
})

答案 1 :(得分:4)

谢谢,@莎莉!你的提示很有帮助。

对于像我这样的初学者,你可能仍会收到错误。如果您在添加sharedClient()之前遇到调用中的额外参数或者在添加createTokenWithCard后无法调用sharedClient()时出现错误,则有助于使完成参数可选(如STPToken?NSError?)。

答案 2 :(得分:1)

对于使用最新条纹广告的Objective-c

#import "Stripe.h"

STPCardParams *cardParams = [[STPCardParams alloc] init];
cardParams.number = @"4242424242424242";
cardParams.expMonth = 10;
cardParams.expYear = 2018;
cardParams.cvc = @"123";

[[STPAPIClient sharedClient] createTokenWithCard:cardParams completion:^(STPToken *token, NSError *error) {
    if (token == nil || error != nil) {
        // Present error to user...
        NSLog(@"%@",error.description);
        return;
    }

NSLog(@"token.tokenId :: %@",token.tokenId);

}];
相关问题