card.io-iOS-SDK/SampleApp/ScanExample/ViewController.m

57 lines
1.7 KiB
Objective-C

//
// ViewController.m
// ScanExample
//
// Copyright (c) 2012 PayPal. All rights reserved.
//
#import "ViewController.h"
#import "CardIO.h"
@interface ViewController () <CardIOPaymentViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
@end
@implementation ViewController
#pragma mark - View Lifecycle
#pragma mark -
- (void)viewDidLoad {
[super viewDidLoad];
self.infoLabel.text = @"";
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[CardIOUtilities preload];
}
#pragma mark - User Actions
- (void)scanCardClicked:(id)sender {
CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
scanViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:scanViewController animated:YES completion:nil];
}
#pragma mark - CardIOPaymentViewControllerDelegate
- (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)info inPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
NSLog(@"Scan succeeded with info: %@", info);
// Do whatever needs to be done to deliver the purchased items.
[self dismissViewControllerAnimated:YES completion:nil];
self.infoLabel.text = [NSString stringWithFormat:@"Received card info. Number: %@, expiry: %02lu/%lu, cvv: %@.", info.redactedCardNumber, (unsigned long)info.expiryMonth, (unsigned long)info.expiryYear, info.cvv];
}
- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
NSLog(@"User cancelled scan");
[self dismissViewControllerAnimated:YES completion:nil];
}
@end