我開始將Stripe整合到我正在製作的iOS應用程序中,並且我已經到了需要驗證卡信息的地步。使用Stripe與iOS驗證信用卡
我想:
#pragma mark - My Actions
- (IBAction)buyButtonTapped:(id)sender {
//Populate STPCard property
self.stripeCard = [[STPCard alloc]init];
self.stripeCard.name = self.txtFieldCardHolderName.text;
self.stripeCard.number = self.txtFieldCardNumber.text;
self.stripeCard.cvc = self.txtFieldCardCvc.text;
self.stripeCard.expMonth = [self.selectedMonth integerValue];
self.stripeCard.expYear = [self.selectedYear integerValue];
//Validate Customer info
if ([self validateCustomerInfo]) {
[self performStripeOperation];
}
}
-(BOOL)validateCustomerInfo{
//Create Alert
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Please, try again!"
message:@"Please, enter all required information."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
//Add some action
}];
//Add its action
[alert addAction:action];
//Validate text fields
if (self.txtFieldCardHolderName.text == 0 || self.txtFieldCardNumber.text == 0 || self.txtFieldCardExpDate.text == 0 || self.txtFieldCardCvc.text == 0) {
[self presentViewController:alert animated:true completion:nil];
return NO;
}
//Validate card number, CVC, expMonth, expYear
NSError *error = nil;
[self.stripeCard validateCardReturningError:&error];
//3
if (error) {
alert.message = [error localizedDescription];
[self presentViewController:alert animated:true completion:nil];
return NO;
}
return YES;
}
我查了幾個其他的問題在這裏StackOverflow上,每個人都似乎使用validateCardReturningError
方法,並且它已經廢棄了iOS9。
Xcode抱怨並要求我改用STPCardValidator。
任何人都可以幫助我一個使用STPCardValidator卡驗證的例子嗎?
我發現我可以使用下面的類方法,以及:
[STPCardValidator validationStateForNumber:self.txtFieldCardNumber.text validatingCardBrand:true];
但我不知道如何使用我的方法validateCustomerInfo裏面。
現在,STPCard沒有這些屬性呢? –