forked from andrewgjohnson-forks/Freetch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a72f19e
Showing
150 changed files
with
11,459 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MVC.xcodeproj/project.xcworkspace/xcuserdata/hamzaouazzanichahdi.xcuserdatad/UserInterfaceState.xcuserstate | ||
*.xcworkspace | ||
xcuserdata | ||
Pods/* |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// PaymentViewController.h | ||
// MVC | ||
// | ||
// Created by Hamza Ouazzani Chahdi on 17/03/2014. | ||
// Copyright (c) 2014 Hamza Ouazzani Chahdi. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "STPView.h" | ||
#import "SWRevealViewController.h" | ||
#import "PaymentViewController.h" | ||
#import "User.h" | ||
#import "AppDelegate.h" | ||
|
||
@interface AddPaymentViewController : UIViewController <STPViewDelegate> | ||
|
||
@property STPView* checkoutView; | ||
|
||
@property (strong, nonatomic) IBOutlet UIButton *saveButton; | ||
@property (strong, nonatomic) IBOutlet UILabel *paymentLabel; | ||
@property (strong, nonatomic) IBOutlet UIButton *cancelButton; | ||
@property BOOL changeCard; | ||
|
||
- (IBAction)save:(id)sender; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
// | ||
// PaymentViewController.m | ||
// MVC | ||
// | ||
// Created by Hamza Ouazzani Chahdi on 17/03/2014. | ||
// Copyright (c) 2014 Hamza Ouazzani Chahdi. All rights reserved. | ||
// | ||
#import "AddPaymentViewController.h" | ||
#import "MBProgressHUD.h" | ||
#import "Mixpanel.h" | ||
#import <Appsee/Appsee.h> | ||
#import "Heap.h" | ||
|
||
@interface AddPaymentViewController () | ||
|
||
- (void)hasError:(NSError *)error; | ||
- (void)hasToken:(STPToken *)token; | ||
|
||
@end | ||
|
||
@implementation AddPaymentViewController | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
|
||
// Setup save button | ||
self.saveButton.enabled = NO; | ||
self.paymentLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"credit_card"]; | ||
|
||
|
||
// Setup checkout | ||
self.checkoutView = [[STPView alloc] initWithFrame:CGRectMake(15,100,290,55) andKey:STRIPE_PUBLISHABLE_KEY]; | ||
self.checkoutView.delegate = self; | ||
[self.view addSubview:self.checkoutView]; | ||
|
||
|
||
} | ||
- (IBAction)cancel:(id)sender { | ||
//If it's coming from AddPayment then go to the ParkVC | ||
if ([self.presentingViewController isKindOfClass:[AddPhoneViewController class]]) { | ||
|
||
// Track event | ||
[Heap track:@"Cancel Card"]; | ||
|
||
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; | ||
[appDelegate userLoggedIn]; | ||
} | ||
//Else dismiss | ||
else{ | ||
[self dismissViewControllerAnimated:YES completion:nil]; | ||
} | ||
} | ||
|
||
- (void)stripeView:(STPView *)view withCard:(PKCard *)card isValid:(BOOL)valid | ||
{ | ||
// Enable save button if the Checkout is valid | ||
self.saveButton.enabled = YES; | ||
} | ||
|
||
- (IBAction)save:(id)sender | ||
{ | ||
[MBProgressHUD showHUDAddedTo:self.view animated:YES]; | ||
self.saveButton.enabled=NO; | ||
|
||
[self.checkoutView createToken:^(STPToken *token, NSError *error) { | ||
[MBProgressHUD hideHUDForView:self.view animated:YES]; | ||
|
||
if (error) { | ||
[self hasError:error]; | ||
Mixpanel *mixpanel = [Mixpanel sharedInstance]; | ||
[mixpanel track:@"Card error"]; | ||
} else { | ||
[self hasToken:token]; | ||
} | ||
}]; | ||
|
||
} | ||
|
||
- (void)hasError:(NSError *)error | ||
{ | ||
UIAlertView *message = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", @"Error") | ||
message:@"Your card is not valid. Call us if you need help" | ||
delegate:self | ||
cancelButtonTitle:@"Retry" | ||
otherButtonTitles:@"Call support",nil]; | ||
[message show]; | ||
} | ||
|
||
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex | ||
{ | ||
if (buttonIndex == 1) { | ||
NSUserDefaults* userDefaults=[NSUserDefaults standardUserDefaults]; | ||
NSString* supportNumber =[userDefaults objectForKey:@"support_number"]; | ||
NSString *phoneNumber = [supportNumber stringByReplacingOccurrencesOfString:@" " withString:@""]; | ||
NSString *phoneURL = [NSString stringWithFormat:@"tel:%@",phoneNumber]; | ||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneURL]]; | ||
} | ||
} | ||
|
||
- (void)hasToken:(STPToken *)token | ||
{ | ||
NSLog(@"Stripe card token %@", token.tokenId); | ||
NSLog(@"Card type %@", token.card.type); | ||
|
||
// Define variables | ||
NSString *cardNumber = [[NSString alloc] initWithFormat:@"•••%@",token.card.last4]; | ||
NSString *cardType = token.card.type; | ||
|
||
// Store last4 digits and card type in phone | ||
[[NSUserDefaults standardUserDefaults] setObject:cardNumber forKey:@"cardNumber"]; | ||
[[NSUserDefaults standardUserDefaults] setObject:cardType forKey:@"cardType"]; | ||
|
||
// Set user properties | ||
User *theUser = [User theUser]; | ||
theUser.cardNumber = cardNumber; | ||
theUser.cardType = cardType; | ||
|
||
// Send card token to back-end | ||
NSDictionary *cardParams = [NSDictionary dictionaryWithObjectsAndKeys:token.tokenId, @"card_token", [User theUser].token,@"auth_token", nil]; | ||
|
||
NSString *baseURL = API_URL; | ||
NSString *path = [NSString stringWithFormat:@"/users/%@",[User theUser].id]; | ||
NSString *url = [baseURL stringByAppendingString:path]; | ||
|
||
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; | ||
manager.requestSerializer = [AFJSONRequestSerializer serializer]; | ||
manager.responseSerializer = [AFJSONResponseSerializer serializer]; | ||
|
||
[manager PUT:url parameters:cardParams success:^(AFHTTPRequestOperation *operation, id JSON) { | ||
|
||
[MBProgressHUD hideHUDForView:self.view animated:YES]; | ||
|
||
if (!theUser.isCustomer) { | ||
|
||
// Track Mixpanel | ||
Mixpanel *mixpanel = [Mixpanel sharedInstance]; | ||
[mixpanel track:@"Save card"]; | ||
[mixpanel.people set:@{@"Card saved": @"1"}]; | ||
|
||
// Send to Appsee | ||
[Appsee addEvent:@"Card saved"]; | ||
|
||
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; | ||
|
||
// The user is now a customer | ||
[userDefaults setObject:JSON[@"user"][@"is_customer"] forKey:@"isCustomer"]; | ||
theUser.isCustomer = [JSON[@"user"][@"is_customer"] boolValue]; | ||
|
||
// Update his credits | ||
[userDefaults setObject:JSON[@"user"][@"credits"] forKey:@"credits"]; | ||
theUser.credits = JSON[@"user"][@"credits"]; | ||
|
||
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; | ||
[appDelegate userLoggedIn]; | ||
} else { | ||
[self.navigationController popViewControllerAnimated:YES]; | ||
} | ||
|
||
|
||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { | ||
|
||
NSLog(@"NSError: %@",error.localizedDescription); | ||
[MBProgressHUD hideHUDForView:self.view animated:YES]; | ||
[self hasError:error]; | ||
|
||
}]; | ||
} | ||
|
||
-(void) popVC | ||
{ | ||
[self.navigationController popViewControllerAnimated:YES]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// AddPhoneViewController.h | ||
// MVC | ||
// | ||
// Created by Thomas on 28/05/2014. | ||
// Copyright (c) 2014 Hamza Ouazzani Chahdi. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "RMPhoneFormat.h" | ||
#import "AppDelegate.h" | ||
#import "User.h" | ||
#import "Mixpanel.h" | ||
|
||
@interface AddPhoneViewController : UIViewController | ||
|
||
@property (strong, nonatomic) IBOutlet UITextField *phoneTextField; | ||
@property (strong, nonatomic) IBOutlet UILabel *phoneLabel; | ||
@property (weak, nonatomic) IBOutlet UIButton *nextButton; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// AddPhoneViewController.m | ||
// MVC | ||
// | ||
// Created by Thomas on 28/05/2014. | ||
// Copyright (c) 2014 Hamza Ouazzani Chahdi. All rights reserved. | ||
// | ||
|
||
#import "AddPhoneViewController.h" | ||
#import <Appsee/Appsee.h> | ||
|
||
@implementation AddPhoneViewController | ||
|
||
#pragma mark - UIViewController | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
self.nextButton.enabled=YES; | ||
|
||
NSString *phoneMessage = [[NSUserDefaults standardUserDefaults] objectForKey:@"phone_message"]; | ||
self.phoneLabel.text = phoneMessage; | ||
} | ||
|
||
- (void)viewDidAppear:(BOOL)animated | ||
{ | ||
[self.phoneTextField becomeFirstResponder]; | ||
} | ||
|
||
#pragma mark - IBAction | ||
|
||
- (IBAction)next:(id)sender { | ||
// Change the UI | ||
self.nextButton.enabled=NO; | ||
|
||
// Validate number | ||
RMPhoneFormat *fmt = [[RMPhoneFormat alloc] init]; | ||
NSString *phoneNumber = self.phoneTextField.text; | ||
BOOL valid = [fmt isPhoneNumberValid:phoneNumber]; | ||
if (valid) { | ||
// Save number in backend | ||
User *theUser = [User theUser]; | ||
theUser.phoneNumber = phoneNumber; | ||
[theUser patchUserWithParameter:@{@"phone":phoneNumber}]; | ||
|
||
// Send to Appsee | ||
[Appsee addEvent:@"Phone saved"]; | ||
|
||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(phoneUpdatedInBackend) name:@"UserUpdatedInBackend" object:nil]; | ||
} else { | ||
[self phoneNumberNotValid]; | ||
} | ||
} | ||
|
||
- (void)phoneNumberNotValid | ||
{ | ||
UIAlertView *error = [[UIAlertView alloc] initWithTitle:@"Invalid Phone Number" | ||
message:@"Your phone number is not valid. Call us if you need help" | ||
delegate:self | ||
cancelButtonTitle:@"Retry" | ||
otherButtonTitles:@"Call support", nil]; | ||
[error show]; | ||
Mixpanel *mixpanel = [Mixpanel sharedInstance]; | ||
[mixpanel track:@"Phone number error"]; | ||
|
||
} | ||
|
||
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex { | ||
if (buttonIndex == 1) { | ||
NSUserDefaults* userDefaults=[NSUserDefaults standardUserDefaults]; | ||
NSString* supportNumber =[userDefaults objectForKey:@"support_number"]; | ||
NSString *phoneNumber = [supportNumber stringByReplacingOccurrencesOfString:@" " withString:@""]; | ||
NSString *phoneURL = [NSString stringWithFormat:@"tel:%@",phoneNumber]; | ||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneURL]]; | ||
} | ||
} | ||
|
||
- (void)phoneUpdatedInBackend | ||
{ | ||
User *theUser = [User theUser]; | ||
if (theUser.isCustomer) { | ||
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; | ||
[appDelegate userLoggedIn]; | ||
} else { | ||
[self performSegueWithIdentifier:@"ShowAddPayment" sender:nil]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// AppDelegate.h | ||
// MVC | ||
// | ||
// Created by Hamza Ouazzani Chahdi on 05/02/2014. | ||
// Copyright (c) 2014 Hamza Ouazzani Chahdi. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <FacebookSDK/FacebookSDK.h> | ||
#import "LoginViewController.h" | ||
#import "AddPhoneViewController.h" | ||
#import "AddPaymentViewController.h" | ||
#import "User.h" | ||
#import "SWRevealViewController.h" | ||
#import "StartViewController.h" | ||
|
||
|
||
|
||
@interface AppDelegate : UIResponder <UIApplicationDelegate> | ||
|
||
@property (strong, nonatomic) UIWindow *window; | ||
@property (strong, nonatomic) UINavigationController* navController; | ||
@property (strong, nonatomic) SWRevealViewController* revealVC; | ||
@property (strong, nonatomic) LoginViewController *loginViewController; | ||
@property (strong, nonatomic) NSDictionary *userParameters; | ||
@property (strong, nonatomic) NSString *deviceToken; | ||
@property (strong, nonatomic) User *user; | ||
@property BOOL newSession; | ||
@property BOOL readyToUpdate; | ||
|
||
- (void)openFbSession; | ||
- (void)userLoggedIn; | ||
@end |
Oops, something went wrong.