Skip to content

Commit

Permalink
CardIO branch
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMa-Bambora committed Mar 2, 2018
1 parent 493f23f commit 17b5cca
Show file tree
Hide file tree
Showing 28 changed files with 1,166 additions and 87 deletions.
6 changes: 4 additions & 2 deletions APAC-BNPayment.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "APAC-BNPayment"
spec.version = "1.2.2"
spec.version = "1.3.0"
spec.summary = "The Mobile Payment SDK from Bambora (APAC) makes it simple to accept credit card payments in your app."
build_tag = spec.version
spec.homepage = "http://bambora.com/en/au"
Expand All @@ -16,7 +16,9 @@ Pod::Spec.new do |spec|
spec.header_dir = 'BNPayment'
spec.source_files = 'BNPayment/**/**'
spec.vendored_frameworks = 'Example/VisaCheckoutHybrid.framework'
spec.dependency 'CardIO', '~> 5.4.1'
spec.static_framework = true
spec.resource_bundles = {
'BNPayment' => ['Assets/**/*.{png,bundle,xib,nib,cer,html}']
}
end
end
Binary file added Assets/camera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
146 changes: 146 additions & 0 deletions BNPayment.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions BNPayment/Core/Models/BNCardRegistrationGuiSetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ typedef enum
registrationCardNumberWatermark,
registrationExpiryDateWatermark,
registrationSecurityCodeWatermark,
registrationButtonColor
registrationButtonColor,
registrationCardIODisable,
registrationCardIOColor
} cardRegistrationGuiEnum;


Expand All @@ -47,7 +49,8 @@ typedef enum
@property (nonatomic, strong) NSString *securityCodeWatermark;
//Color Hex Code ie. #00ff00
@property (nonatomic, strong) NSString *registrationButtonColor;

@property (nonatomic) BOOL registrationCardIODisable;
@property (nonatomic, strong) NSString *registrationCardIOColor;

+(NSString *)GetGuiKey:(cardRegistrationGuiEnum)cardRegistrationGuiEnum;

Expand Down
11 changes: 10 additions & 1 deletion BNPayment/Core/Models/BNCardRegistrationGuiSetting.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ + (BNCardRegistrationGuiSetting *)BNCardRegistrationGuiSetting:
expiryDateWatermark:(NSString *)expiryDateWatermark
securityCodeWatermark:(NSString *)securityCodeWatermark
registrationButtonColor:(NSString *)registrationButtonColor
registrationCardIODisable:(BOOL)registrationCardIODisable
registrationCardIOColor:(NSString *)registrationCardIOColor
{
BNCardRegistrationGuiSetting *cardRegistrationGuiSetting = [BNCardRegistrationGuiSetting new];
cardRegistrationGuiSetting.titleText = titleText;
Expand All @@ -44,6 +46,8 @@ + (BNCardRegistrationGuiSetting *)BNCardRegistrationGuiSetting:
cardRegistrationGuiSetting.expiryDateWatermark = expiryDateWatermark;
cardRegistrationGuiSetting.securityCodeWatermark = securityCodeWatermark;
cardRegistrationGuiSetting.registrationButtonColor = registrationButtonColor;
cardRegistrationGuiSetting.registrationCardIODisable = registrationCardIODisable;
cardRegistrationGuiSetting.registrationCardIOColor = registrationCardIOColor;
return cardRegistrationGuiSetting;
}

Expand Down Expand Up @@ -73,7 +77,12 @@ +(NSString *)GetGuiKey:(cardRegistrationGuiEnum)cardRegistrationGuiEnum{
case registrationButtonColor:
guiKey = @"registrationButtonColor";
break;

case registrationCardIODisable:
guiKey = @"registrationCardDisable";
break;
case registrationCardIOColor:
guiKey = @"registrationCardIOColor";
break;
default:
[NSException raise:NSGenericException format:@"Unexpected cardRegistrationGuiEnum."];
}
Expand Down
6 changes: 5 additions & 1 deletion BNPayment/Core/Models/BNSubmitSinglePaymentCardGuiSetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ typedef enum
payButtonText,
payButtonColor,
switchButtonColor,
loadingBarColor
loadingBarColor,
cardIODisable,
cardIOColor
} submitSinglePaymentCardGuiEnum;


Expand All @@ -51,6 +53,8 @@ typedef enum
@property (nonatomic, strong) NSString *switchButtonColor;
@property (nonatomic, strong) NSString *payButtonColor;
@property (nonatomic, strong) NSString *loadingBarColor;
@property (nonatomic, strong) NSString *cardIOColor;
@property (nonatomic) BOOL cardIODisable;
+(NSString *)GetGuiKey:(submitSinglePaymentCardGuiEnum)guiEnum;


Expand Down
7 changes: 6 additions & 1 deletion BNPayment/Core/Models/BNSubmitSinglePaymentCardGuiSetting.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ +(NSString *)GetGuiKey:(submitSinglePaymentCardGuiEnum)guiEnum{
case loadingBarColor:
guiKey = @"loadingBarColor";
break;

case cardIOColor:
guiKey = @"cardIOColor";
break;
case cardIODisable:
guiKey = @"cardIODisable";
break;
default:
[NSException raise:NSGenericException format:@"Unexpected submitSinglePaymentCardGuiEnum."];
}
Expand Down
123 changes: 118 additions & 5 deletions BNPayment/UI/ViewControllers/BNCreditCardRegistrationVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
#import "UIColor+BNColors.h"
#import "UITextField+BNCreditCard.h"
#import "BNLoaderButton.h"

#import "CardIO.h"
#import <AVFoundation/AVCaptureDevice.h>
NSInteger const TextFieldHeight = 50;
NSInteger const ButtonHeight = 50;
NSInteger const Padding = 15;
Expand All @@ -44,16 +45,21 @@ @interface BNCreditCardRegistrationVC ()
@property (nonatomic, strong) BNCreditCardNumberTextField *cardNumberTextField;
@property (nonatomic, strong) BNCreditCardExpiryTextField *cardExpiryTextField;
@property (nonatomic, strong) BNBaseTextField *cardCVCTextField;

@property (nonatomic, strong) UIButton *cardIOButton;
@property (nonatomic, strong) UIColor *cardIOColor;
@property (nonatomic, strong) BNLoaderButton *submitButton;

@property (nonatomic, strong) NSBundle *bundle;
@end

@implementation BNCreditCardRegistrationVC

- (void)viewDidLoad {
[super viewDidLoad];

self.bundle = [BNBundleUtils getBundleFromCocoaPod];
if(!self.bundle)
{
self.bundle=[BNBundleUtils paymentLibBundle];
}
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.backgroundColor = [UIColor whiteColor];

Expand Down Expand Up @@ -113,6 +119,11 @@ - (void)layoutCreditCardForm {
inputWidth,
TextFieldHeight);

self.cardIOButton.frame = CGRectMake(Padding+inputWidth-60-TextFieldHeight*0.6,
CGRectGetMinY(self.cardNumberTextField.frame)+TextFieldHeight*0.2,
TextFieldHeight*0.6,
TextFieldHeight*0.6);

self.cardExpiryTextField.frame = CGRectMake(Padding,
CGRectGetMaxY(self.cardNumberTextField.frame)-1,
ceilf((inputWidth)/2.f),
Expand Down Expand Up @@ -156,6 +167,15 @@ - (void)setupCreditCardForm {
[self.cardNumberTextField addTarget:self action:@selector(validateFields) forControlEvents:UIControlEventEditingChanged];
[self.formScrollView addSubview:self.cardNumberTextField];

self.cardIOButton=[[UIButton alloc] init];
[self.cardIOButton addTarget:self
action:@selector(cardIOLaunch:)
forControlEvents:UIControlEventTouchUpInside];
UIImage *cameraImage = [UIImage loadImageWithName:@"camera"
fromBundle:self.bundle];
[self.cardIOButton setImage:cameraImage forState:UIControlStateNormal];
[self.formScrollView addSubview:self.cardIOButton];

self.cardExpiryTextField = [[BNCreditCardExpiryTextField alloc] init];
self.cardExpiryTextField.placeholder = NSLocalizedString(@"MM/YY", @"Placeholder");
[self.cardExpiryTextField applyStyle];
Expand Down Expand Up @@ -190,6 +210,7 @@ - (void)guiCustomisation {
[self securityCodeCustomisation];
[self securityCodeCustomisation];
[self registerButtonCustomisation];
[self cardIOCustomisation];
}

- (void)titleCustomisation {
Expand Down Expand Up @@ -264,7 +285,26 @@ - (void)registerButtonCustomisation {
}



- (void)cardIOCustomisation{
if(_guiSetting!=nil && _cardIOButton!=nil)
{
if(!_guiSetting.registrationCardIODisable)
{
if(_guiSetting.registrationCardIOColor.length==7)
{
self.cardIOColor=[BNUtils colorFromHexString:_guiSetting.registrationCardIOColor];
}
else
{
self.cardIOColor=[UIColor BNPurpleColor];
}
}
else
{
[_cardIOButton removeFromSuperview];
}
}
}


- (void)showAlertViewWithTitle:(NSString*)title message:(NSString*)message {
Expand Down Expand Up @@ -372,4 +412,77 @@ - (void)resignKeyboard
[self.cardCVCTextField resignFirstResponder];
}

- (void)cardIOLaunch:(UIButton *)sender {
AVAuthorizationStatus AVstatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
switch (AVstatus) {
case AVAuthorizationStatusAuthorized:
[self startCardIO];
break;
case AVAuthorizationStatusDenied:
[self askForCameraPermission];
break;
case AVAuthorizationStatusNotDetermined:
[self startCardIO];
break;
case AVAuthorizationStatusRestricted:
[self askForCameraPermission];
break;
default:
break;
}
}

-(void)askForCameraPermission{
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
message:@"To scan your card, you need to enable the camera access."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {}];
[alert addAction:cancelAction];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
}

-(void)startCardIO{
CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
[scanViewController setCollectCVV:NO];
[scanViewController setCollectCardholderName:NO];
[scanViewController setScanExpiry:YES];
[scanViewController setCollectExpiry:YES];
[scanViewController setHideCardIOLogo:YES];
[scanViewController setDisableManualEntryButtons:YES];
[scanViewController setGuideColor:self.cardIOColor];
[scanViewController setSuppressScannedCardImage:NO];
[self presentViewController:scanViewController animated:YES completion:nil];
}

- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)scanViewController {
[scanViewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)info inPaymentViewController:(CardIOPaymentViewController *)scanViewController {
[self.cardNumberTextField setText:info.cardNumber];
[self.cardNumberTextField sendActionsForControlEvents:UIControlEventEditingChanged];
[self.cardNumberTextField resignFirstResponder];

NSString *expiryMonth=[NSString stringWithFormat:@"%@",@(info.expiryMonth)];
if(expiryMonth.length==1)
{
expiryMonth=[NSString stringWithFormat:@"0%@",@(info.expiryMonth)];
}
NSString *expiryYear=[[NSString stringWithFormat:@"%@", @(info.expiryYear)] substringWithRange:NSMakeRange(2,2)];
[self.cardExpiryTextField setText:[NSString stringWithFormat:@"%@/%@",expiryMonth,expiryYear]];
[self.cardExpiryTextField resignFirstResponder];

[self validateFields];
[scanViewController dismissViewControllerAnimated:YES completion:nil];
}

@end
Loading

0 comments on commit 17b5cca

Please sign in to comment.