Stripe error “create token with card(_:completion:

2019-08-06 11:48发布

In this line, the error was Display. Can someone tell me what mistake was made?

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

标签: swift
4条回答
疯言疯语
2楼-- · 2019-08-06 12:19

Thanks, @Shali! Your tip is helpful.

For those who are beginners like me, you might still get an error. In case you experience an error indicating either an extra argument in call before adding sharedClient() or how createTokenWithCard cannot be invoked after sharedClient() is added, it helps to make the completion arguments optional (as in STPToken? and NSError?).

查看更多
放荡不羁爱自由
3楼-- · 2019-08-06 12:34

As mentioned by Christine, the method now uses Optionals so it looks like the following:

    STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token: STPToken?, error: NSError?) -> Void in     
    })
查看更多
Evening l夕情丶
4楼-- · 2019-08-06 12:34

For objective-c using latest 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);

}];
查看更多
神经病院院长
5楼-- · 2019-08-06 12:38

I had the same problem after updating Stripe in pods recently. That method is deprecated. Instead, you can use the following code:

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

It takes the same parameters.

Update

Thanks to @Christine and @Keyhole150

This function in Stripe API has now be changed to

STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token: STPToken?, error: NSError?) -> Void in     
})
查看更多
登录 后发表回答