条纹错误 "create token with card(_:completion:) is unavailable"

Stripe error "create token with card(_:completion:) is unavailable"

在这一行中,错误是显示。谁能告诉我哪里出错了?

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

我最近在 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     
})

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

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

正如 Christine 所提到的,该方法现在使用 Optionals,因此它看起来像下面这样:

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

对于 objective-c 使用最新的 stripe pod

#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);

}];