Skip to content

Commit

Permalink
fix layout glitch on cc payment view controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jukiginanjar committed Oct 13, 2016
1 parent 898be22 commit 5e354f9
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 156 deletions.
4 changes: 4 additions & 0 deletions Demo/VTDirectDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[VTConfig setClientKey:@"VT-client-wRhLUazn8LGHLP6Q"
merchantServerURL:@"https://vt-merchant.coralshop.top/api"
serverEnvironment:VTServerEnvironmentSandbox];

// [VTConfig setClientKey:@"VT-client-wCSALF27ZAHMVa2U"
// merchantServerURL:@"http://tapri.ayopop.com/payments/ccPayment"
// serverEnvironment:VTServerEnvironmentSandbox];
#endif

BOOL enableOneclick = [[[NSUserDefaults standardUserDefaults] objectForKey:@"enable_oneclick"] boolValue];
Expand Down
6 changes: 4 additions & 2 deletions Demo/VTDirectDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ - (IBAction)settingPressed:(UIBarButtonItem *)sender {
}

- (IBAction)checkoutPressed:(UIBarButtonItem *)sender {
[[VTCardControllerConfig sharedInstance] setEnableOneClick:YES];
[[VTCardControllerConfig sharedInstance] setEnable3DSecure:YES];

NSData *encoded = [[NSUserDefaults standardUserDefaults] objectForKey:@"vt_customer"];
VTCustomerDetails *customerDetails = [NSKeyedUnarchiver unarchiveObjectWithData:encoded];
VTTransactionDetails *transactionDetails = [[VTTransactionDetails alloc] initWithOrderID:[NSString randomWithLength:20] andGrossAmount:[self grossAmountOfItemDetails:self.itemDetails]];

if (customerDetails) {
VTAddCardController *vc = [[VTAddCardController alloc] initWithCustomerDetails:customerDetails itemDetails:self.itemDetails transactionDetails:transactionDetails];
// VTCardListController *vc = [[VTCardListController alloc] initWithCustomerDetails:customerDetails itemDetails:self.itemDetails transactionDetails:transactionDetails];
// VTAddCardController *vc = [[VTAddCardController alloc] initWithCustomerDetails:customerDetails itemDetails:self.itemDetails transactionDetails:transactionDetails];
VTCardListController *vc = [[VTCardListController alloc] initWithCustomerDetails:customerDetails itemDetails:self.itemDetails transactionDetails:transactionDetails];
[vc presentOnViewController:self];

// [[VTCardControllerConfig sharedInstance] setEnableOneClick:YES];
Expand Down
8 changes: 8 additions & 0 deletions MidtransKit/MidtransKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
E5591A481CEF0DB0005A2DB1 /* VTVASuccessStatusController.h in Headers */ = {isa = PBXBuildFile; fileRef = E5591A451CEF0DB0005A2DB1 /* VTVASuccessStatusController.h */; };
E5591A491CEF0DB0005A2DB1 /* VTVASuccessStatusController.m in Sources */ = {isa = PBXBuildFile; fileRef = E5591A461CEF0DB0005A2DB1 /* VTVASuccessStatusController.m */; };
E5591A4A1CEF0DB7005A2DB1 /* VTVASuccessStatusController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E5591A471CEF0DB0005A2DB1 /* VTVASuccessStatusController.xib */; };
E573CE451DAF75B5007531E0 /* VTNavigationViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = E573CE431DAF75B5007531E0 /* VTNavigationViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
E573CE461DAF75B5007531E0 /* VTNavigationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E573CE441DAF75B5007531E0 /* VTNavigationViewController.m */; };
E578DD061CFBED7A0091760A /* vaother@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = E578DD051CFBED7A0091760A /* vaother@2x.png */; };
E578DD0A1CFBF6480091760A /* UIView+Toast.h in Headers */ = {isa = PBXBuildFile; fileRef = E578DD081CFBF6480091760A /* UIView+Toast.h */; };
E578DD0B1CFBF6480091760A /* UIView+Toast.m in Sources */ = {isa = PBXBuildFile; fileRef = E578DD091CFBF6480091760A /* UIView+Toast.m */; };
Expand Down Expand Up @@ -423,6 +425,8 @@
E5591A451CEF0DB0005A2DB1 /* VTVASuccessStatusController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VTVASuccessStatusController.h; sourceTree = "<group>"; };
E5591A461CEF0DB0005A2DB1 /* VTVASuccessStatusController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VTVASuccessStatusController.m; sourceTree = "<group>"; };
E5591A471CEF0DB0005A2DB1 /* VTVASuccessStatusController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VTVASuccessStatusController.xib; sourceTree = "<group>"; };
E573CE431DAF75B5007531E0 /* VTNavigationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VTNavigationViewController.h; sourceTree = "<group>"; };
E573CE441DAF75B5007531E0 /* VTNavigationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VTNavigationViewController.m; sourceTree = "<group>"; };
E578DD051CFBED7A0091760A /* vaother@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "vaother@2x.png"; path = "../MidtransResources/vaother@2x.png"; sourceTree = "<group>"; };
E578DD081CFBF6480091760A /* UIView+Toast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Toast.h"; sourceTree = "<group>"; };
E578DD091CFBF6480091760A /* UIView+Toast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Toast.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -838,6 +842,8 @@
children = (
3068387F1C7EE7220064A305 /* VTPaymentViewController.h */,
306838801C7EE7220064A305 /* VTPaymentViewController.m */,
E573CE431DAF75B5007531E0 /* VTNavigationViewController.h */,
E573CE441DAF75B5007531E0 /* VTNavigationViewController.m */,
30E77E831C8401DC0090D228 /* Payment */,
00F61AE61D1459F300C93DA0 /* Payment List */,
);
Expand Down Expand Up @@ -1013,6 +1019,7 @@
E525E12A1CFD75D1009448A5 /* UIViewController+Modal.h in Headers */,
E503AECD1C8E889C00F097FF /* VTVAListController.h in Headers */,
E517C2D81C96B610009AE6AA /* VTHudView.h in Headers */,
E573CE451DAF75B5007531E0 /* VTNavigationViewController.h in Headers */,
30BB9C811C7DA6410012BB2A /* VTTextField.h in Headers */,
3005E2A81C7C239A00064169 /* VTClassHelper.h in Headers */,
E583AFF51C8D6DD300C04512 /* VTSuccessStatusController.h in Headers */,
Expand Down Expand Up @@ -1267,6 +1274,7 @@
30E713231C859D6100AFB7B4 /* MBXPageViewController_vt.m in Sources */,
30BB9C821C7DA6410012BB2A /* VTTextField.m in Sources */,
E50D86081D0ECBC500F26D2E /* VTIndomaretSuccessController.m in Sources */,
E573CE461DAF75B5007531E0 /* VTNavigationViewController.m in Sources */,
3056A21E1C7EA3660015B3CC /* VTItemViewModel.m in Sources */,
00F61AEA1D145A2B00C93DA0 /* VTPaymentListView.m in Sources */,
30E7131A1C85816B00AFB7B4 /* VTDetailedTitleController.m in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion MidtransKit/MidtransKit/VTAddCardController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "VTCvvInfoController.h"
#import "VTCCFrontView.h"
#import "VTSuccessStatusController.h"
#import "VTNavigationViewController.h"
#import "VTErrorStatusController.h"
#import "IHKeyboardAvoiding_vt.h"
#import "UIViewController+Modal.h"
Expand Down Expand Up @@ -60,7 +61,7 @@ - (void)dealloc {
}

- (void)presentOnViewController:(UIViewController *)viewController {
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:self];
VTNavigationViewController *nvc = [[VTNavigationViewController alloc] initWithRootViewController:self];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(closePressed:)];
[viewController presentViewController:nvc animated:YES completion:nil];
}
Expand Down
154 changes: 45 additions & 109 deletions MidtransKit/MidtransKit/VTCardListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,30 @@
#import "VTErrorStatusController.h"
#import "VTConfirmPaymentController.h"
#import "UIViewController+Modal.h"
#import "VTNavigationViewController.h"

#import <MidtransCoreKit/MidtransCoreKit.h>

//#import <CardIO.h>

@interface VTCardListController () <VTCardCellDelegate, VTAddCardControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate/*, CardIOPaymentViewControllerDelegate*/>
@property (strong, nonatomic) IBOutlet UIPageControl *pageControl;
@property (strong, nonatomic) IBOutlet UIView *emptyCardView;
@property (strong, nonatomic) IBOutlet UIView *cardsView;
@property (strong, nonatomic) IBOutlet UILabel *amountLabel;
@property (strong, nonatomic) IBOutlet UIButton *addCardButton;
@property (nonatomic) IBOutlet NSLayoutConstraint *addCardButtonHeight;
@property (nonatomic) NSMutableArray *cards;
@property (nonatomic) BOOL editingCell;
@end
@property (strong, nonatomic) IBOutlet UIPageControl *pageControl;

@property (strong, nonatomic) IBOutlet UIView *emptyCardView;
@property (strong, nonatomic) IBOutlet UIView *cardsView;
@property (strong, nonatomic) IBOutlet UILabel *amountLabel;
@property (strong, nonatomic) IBOutlet UIButton *addCardButton;

@property (nonatomic) IBOutlet NSLayoutConstraint *addCardButtonHeight;

@property (nonatomic) NSMutableArray *cards;
@property (nonatomic) BOOL editingCell;
@end

@implementation VTCardListController {
VTHudView *_hudView;
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
Expand Down Expand Up @@ -78,21 +79,21 @@ - (void)viewDidLoad {
}

- (void)presentOnViewController:(UIViewController *)viewController {
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:self];
VTNavigationViewController *nvc = [[VTNavigationViewController alloc] initWithRootViewController:self];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(closePressed:)];
[viewController presentViewController:nvc animated:YES completion:nil];
}

- (void)closePressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)setEditingCell:(BOOL)editingCell {
_editingCell = editingCell;

[_collectionView reloadData];
}

- (void)startEditing:(id)sender {
self.editingCell = true;
}
Expand All @@ -118,8 +119,8 @@ - (void)reloadMaskedCards {
[self updateView];
}];
}


- (void)updateView {
if (self.cards.count) {
_addCardButton.hidden = true;
Expand All @@ -133,59 +134,59 @@ - (void)updateView {
_cardsView.hidden = true;
}
}

- (void)cardsUpdated:(id)sender {
[self reloadMaskedCards];
}

- (void)setCards:(NSMutableArray *)cards {
_cards = cards;

[_pageControl setNumberOfPages:[cards count]];
[_collectionView reloadData];
}

- (IBAction)addCardPressed:(id)sender {
VTAddCardController *vc = [[VTAddCardController alloc] initWithCustomerDetails:self.customerDetails itemDetails:self.itemDetails transactionDetails:self.transactionDetails];
vc.delegate = self;
[self.navigationController pushViewController:vc animated:YES];
}

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController*)fromVC
toViewController:(UIViewController*)toVC
{
if (operation == UINavigationControllerOperationPush) {
return [PushAnimator new];;
}

return nil;
{
if (operation == UINavigationControllerOperationPush) {
return [PushAnimator new];;
}

return nil;
}

#pragma mark - UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [_cards count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
VTCardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VTCardCell" forIndexPath:indexPath];
cell.delegate = self;
cell.maskedCard = _cards[indexPath.row];
cell.editing = self.editingCell;
return cell;
}

#pragma mark - UICollectionViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat pageWidth = scrollView.frame.size.width; // you need to have a **iVar** with getter for scrollView
float fractionalPage = scrollView.contentOffset.x / pageWidth;
NSInteger page = lround(fractionalPage);
self.pageControl.currentPage = page; // you need to have a **iVar** with getter for pageControl
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (self.editingCell) {
self.editingCell = false; return;
Expand All @@ -206,9 +207,9 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
[self.navigationController pushViewController:vc animated:YES];
}
}

#pragma mark - Helper

- (void)payWithToken:(NSString *)token {
[_hudView showOnView:self.navigationController.view];

Expand All @@ -230,16 +231,16 @@ - (void)payWithToken:(NSString *)token {
}
}];
}

#pragma mark - VTAddCardControllerDelegate

- (void)viewController:(VTAddCardController *)viewController didRegisterCard:(VTMaskedCreditCard *)registeredCard {
[self.navigationController popViewControllerAnimated:YES];
[self reloadMaskedCards];
}

#pragma mark - VTCardCellDelegate

- (void)cardCellShouldRemoveCell:(VTCardCell *)cell {
NSIndexPath *indexPath = [_collectionView indexPathForCell:cell];
VTMaskedCreditCard *card = _cards[indexPath.row];
Expand All @@ -263,76 +264,11 @@ - (void)cardCellShouldRemoveCell:(VTCardCell *)cell {
[self updateView];
}];
}

#pragma MARK - UICollectionViewDelegateFlowLayout

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(self.view.frame.size.width, 200);
}

/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

/*
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
VTAddCardController *vc = [[VTAddCardController alloc] initWithCustomerDetails:self.customerDetails itemDetails:self.itemDetails transactionDetails:self.transactionDetails];
vc.delegate = self;
[self.navigationController pushViewController:vc animated:YES];
} else if (buttonIndex == 1) {
CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
[self presentViewController:scanViewController animated:YES completion:nil];
}
}
*/

/*
#pragma mark - CardIOPaymentViewControllerDelegate
/// This method will be called if the user cancels the scan. You MUST dismiss paymentViewController.
/// @param paymentViewController The active CardIOPaymentViewController.
- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
/// This method will be called when there is a successful scan (or manual entry). You MUST dismiss paymentViewController.
/// @param cardInfo The results of the scan.
/// @param paymentViewController The active CardIOPaymentViewController.
- (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)cardInfo inPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
NSString *year = cardInfo.expiryYear < 10 ? [NSString stringWithFormat:@"0%lu", (unsigned long)cardInfo.expiryYear] : [NSString stringWithFormat:@"%lu", (unsigned long)cardInfo.expiryYear];
NSString *month = cardInfo.expiryMonth < 10 ? [NSString stringWithFormat:@"0%lu", (unsigned long)cardInfo.expiryMonth] : [NSString stringWithFormat:@"%lu", (unsigned long)cardInfo.expiryMonth];
VTCreditCard *creditCard = [[VTCreditCard alloc] initWithNumber:cardInfo.cardNumber
expiryMonth:month
expiryYear:year
cvv:cardInfo.cvv];
[[VTClient sharedClient] registerCreditCard:creditCard completion:^(VTMaskedCreditCard *maskedCreditCard, NSError *error) {
[_hudView hide];
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
[alert show];
} else {
[[VTMerchantClient sharedClient] saveRegisteredCard:maskedCreditCard completion:^(id result, NSError *error) {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
[alert show];
} else {
[self reloadMaskedCards];
[self dismissViewControllerAnimated:YES completion:nil];
}
}];
}
}];
}
*/
@end

@end
13 changes: 13 additions & 0 deletions MidtransKit/MidtransKit/VTNavigationViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// VTNavigationViewController.h
// MidtransKit
//
// Created by Nanang Rafsanjani on 10/13/16.
// Copyright © 2016 Veritrans. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface VTNavigationViewController : UINavigationController

@end
Loading

0 comments on commit 5e354f9

Please sign in to comment.