Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hak 172 production readyness #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions StripeNative.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../react-native/React/**",
"$(SRCROOT)/example/node_modules/react-native/React/**",
"$(SRCROOT)/../../ios/Pods/**",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = StripeNative;
Expand All @@ -230,6 +231,7 @@
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../react-native/React/**",
"$(SRCROOT)/example/node_modules/react-native/React/**",
"$(SRCROOT)/../../ios/Pods/**",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = StripeNative;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "A3B345E78B69520AC98822C93DEFACE150C81645",
"DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : {

},
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
"1DF63C5B8814492D030C2A6247051230915D5511" : 9223372036854775807,
"A3B345E78B69520AC98822C93DEFACE150C81645" : 9223372036854775807
},
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "218AAF75-D61D-4ACF-B6A8-C42F40562327",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"1DF63C5B8814492D030C2A6247051230915D5511" : "..",
"A3B345E78B69520AC98822C93DEFACE150C81645" : "react-native-stripe\/"
},
"DVTSourceControlWorkspaceBlueprintNameKey" : "StripeNative",
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "StripeNative.xcodeproj",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "bitbucket.org:flyvictor\/mobile-seats.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "1DF63C5B8814492D030C2A6247051230915D5511"
},
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:flyvictor\/react-native-stripe.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "A3B345E78B69520AC98822C93DEFACE150C81645"
}
]
}
1 change: 1 addition & 0 deletions StripeNative/PaymentViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@interface PaymentViewController : UIViewController

@property (nonatomic) NSString* amount;
@property (nonatomic) NSString* currency;
@property (nonatomic, weak) id<PaymentViewControllerDelegate> delegate;

@end
74 changes: 37 additions & 37 deletions StripeNative/PaymentViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
// See https://github.com/stripe/stripe-ios.
//

#import <Stripe/Stripe.h>
#import <Stripe.h>
#import <QuartzCore/QuartzCore.h>

#import "PaymentViewController.h"

@interface PaymentViewController () <STPPaymentCardTextFieldDelegate>
@property (weak, nonatomic) STPPaymentCardTextField *paymentTextField;
@property (weak, nonatomic) UITextField *emailField;
// @property (weak, nonatomic) UITextField *emailField;
@property (weak, nonatomic) UIActivityIndicatorView *activityIndicator;
@end

Expand All @@ -30,7 +30,7 @@ - (void)viewDidLoad {
}

// Setup save button
NSString *title = [NSString stringWithFormat:@"Pay $%@", self.amount];
NSString *title = [NSString stringWithFormat:@"Pay %@%@", self.currency, self.amount];
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleDone target:self action:@selector(save:)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];
saveButton.enabled = NO;
Expand All @@ -43,23 +43,23 @@ - (void)viewDidLoad {
self.paymentTextField = paymentTextField;
[self.view addSubview:paymentTextField];

// Setup email field: hack it up to look just like the Stripe field
UITextField *emailField = [[UITextField alloc] init];
[emailField setPlaceholder:@"Email address"];
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
emailField.leftView = paddingView;
emailField.leftViewMode = UITextFieldViewModeAlways;
emailField.layer.cornerRadius = 5.0f;
emailField.layer.borderColor = [[UIColor colorWithRed:171.0/255.0
green:171.0/255.0
blue:171.0/255.0
alpha:1.0] CGColor];
emailField.layer.borderWidth = 1.0f;
[emailField addTarget:self
action:@selector(textFieldDidChange)
forControlEvents:UIControlEventEditingChanged];
self.emailField = emailField;
[self.view addSubview:emailField];
// // Setup email field: hack it up to look just like the Stripe field
// UITextField *emailField = [[UITextField alloc] init];
// [emailField setPlaceholder:@"Email address"];
// UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
// emailField.leftView = paddingView;
// emailField.leftViewMode = UITextFieldViewModeAlways;
// emailField.layer.cornerRadius = 5.0f;
// emailField.layer.borderColor = [[UIColor colorWithRed:171.0/255.0
// green:171.0/255.0
// blue:171.0/255.0
// alpha:1.0] CGColor];
// emailField.layer.borderWidth = 1.0f;
// [emailField addTarget:self
// action:@selector(textFieldDidChange)
// forControlEvents:UIControlEventEditingChanged];
// self.emailField = emailField;
// [self.view addSubview:emailField];

// Setup Activity Indicator
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
Expand All @@ -68,34 +68,34 @@ - (void)viewDidLoad {
[self.view addSubview:activityIndicator];
}

- (BOOL)emailFieldIsValid {
NSString *emailRegex =
@"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
@"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
@"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
@"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
@"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
@"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
@"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES[c] %@", emailRegex];
return [emailTest evaluateWithObject:self.emailField.text];
}
// - (BOOL)emailFieldIsValid {
// NSString *emailRegex =
// @"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
// @"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
// @"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
// @"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
// @"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
// @"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
// @"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
// NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES[c] %@", emailRegex];
// return [emailTest evaluateWithObject:self.emailField.text];
// }

- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
CGFloat padding = 15;
CGFloat width = CGRectGetWidth(self.view.frame) - (padding * 2);
self.paymentTextField.frame = CGRectMake(padding, padding, width, 44);
self.emailField.frame = CGRectMake(padding, padding*2+44, width, 44);
// self.emailField.frame = CGRectMake(padding, padding*2+44, width, 44);
self.activityIndicator.center = self.view.center;
}

- (void)paymentCardTextFieldDidChange:(nonnull STPPaymentCardTextField *)textField {
self.navigationItem.rightBarButtonItem.enabled = textField.isValid && [self emailFieldIsValid];
self.navigationItem.rightBarButtonItem.enabled = textField.isValid; // && [self emailFieldIsValid];
}

- (void)textFieldDidChange {
self.navigationItem.rightBarButtonItem.enabled = self.paymentTextField.isValid && [self emailFieldIsValid];
self.navigationItem.rightBarButtonItem.enabled = self.paymentTextField.isValid; // && [self emailFieldIsValid];
}

- (void)cancel:(id)sender {
Expand All @@ -108,7 +108,7 @@ - (void)cancel:(id)sender {
}

- (void)save:(id)sender {
if (!([self.paymentTextField isValid] && [self emailFieldIsValid])) {
if (!([self.paymentTextField isValid])) {
return;
}
if (![Stripe defaultPublishableKey]) {
Expand All @@ -129,7 +129,7 @@ - (void)save:(id)sender {
[self.delegate paymentViewController:self didFinishWithToken:nil email:nil error:error];
}
NSLog(@"Successfully got token: %@", token);
[self.delegate paymentViewController:self didFinishWithToken:token email:self.emailField.text error:nil];
[self.delegate paymentViewController:self didFinishWithToken:token email:nil error:nil];
}];
}

Expand Down
2 changes: 1 addition & 1 deletion StripeNative/StripeNativeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Copyright (c) 2015 Lane Rettig. All rights reserved.
//

#import "RCTViewManager.h"
#import "React/RCTViewManager.h"
#import "PaymentViewController.h"

@interface StripeNativeManager : NSObject <RCTBridgeModule, PKPaymentAuthorizationViewControllerDelegate, PaymentViewControllerDelegate>
Expand Down
20 changes: 12 additions & 8 deletions StripeNative/StripeNativeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Copyright (c) 2015 Lane Rettig. All rights reserved.
//

#import <Stripe/Stripe.h>
#import <Stripe.h>

#import <React/RCTEventDispatcher.h>
#import "RCTUtils.h"
#import "React/RCTEventDispatcher.h"
#import "React/RCTUtils.h"

#import "PaymentViewController.h"
#import "StripeNativeManager.h"
Expand Down Expand Up @@ -161,9 +161,13 @@ -(void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewCo

# pragma mark - Card form

- (void)beginCustomPaymentWithAmount:(NSString *)amount {
- (void)beginCustomPaymentWithAmount:(NSString *)amount args:(NSDictionary *)args {

NSString* currencyCode = args[@"currencySymbol"] ? args[@"currencySymbol"] : @"£";

PaymentViewController *paymentViewController = [[PaymentViewController alloc] initWithNibName:nil bundle:nil];
paymentViewController.amount = amount;
paymentViewController.currency = currencyCode;
paymentViewController.delegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:paymentViewController];
[rootViewController presentViewController:navController animated:YES completion:nil];
Expand All @@ -183,7 +187,7 @@ - (void)paymentViewController:(PaymentViewController *)controller didFinishWithT
// Convert token to string and add additional information.
promiseResolver(@[
token.tokenId,
@{@"emailAddress": email},
@{},
@{},
]);
}
Expand Down Expand Up @@ -228,19 +232,19 @@ - (void)paymentViewController:(PaymentViewController *)controller didFinishWithT
else if (args[@"fallbackOnCardForm"]) {
// The last item for Apple Pay is the "summary" item with the total.
NSString *amount = [[items lastObject][@"amount"] stringValue];
[self paymentRequestWithCardForm:amount resolver:resolve rejector:reject];
[self paymentRequestWithCardForm:amount args:args resolver:resolve rejector:reject];
}
else {
reject(nil, nil, [NSError errorWithDomain:StripeNativeDomain code:SNOtherError userInfo:@{NSLocalizedDescriptionKey:@"Apple Pay not enabled and fallback option false"}]);
}
}

RCT_EXPORT_METHOD(paymentRequestWithCardForm:(NSString *)amount resolver:(RCTPromiseResolveBlock)resolve rejector:(RCTPromiseRejectBlock)reject) {
RCT_EXPORT_METHOD(paymentRequestWithCardForm: (NSString *)amount args:(NSDictionary *)args resolver:(RCTPromiseResolveBlock)resolve rejector:(RCTPromiseRejectBlock)reject) {
promiseResolver = resolve;
promiseRejector = reject;
resolved = FALSE;

[self beginCustomPaymentWithAmount:amount];
[self beginCustomPaymentWithAmount:amount args:args];
}

RCT_EXPORT_METHOD(success: (RCTPromiseResolveBlock)resolve rejector:(RCTPromiseRejectBlock)reject)
Expand Down
6 changes: 4 additions & 2 deletions index.ios.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//TESTING
var React = require('react-native');
var NativeModules = React.NativeModules;
var { StripeNativeManager } = NativeModules;
Expand Down Expand Up @@ -69,8 +70,9 @@ var NativeStripe = {
return StripeNativeManager.paymentRequestWithApplePay(summaryItems, options);
},

paymentRequestWithCardForm(items) {
return StripeNativeManager.paymentRequestWithCardForm(getTotal(items).toFixed(2).toString());
paymentRequestWithCardForm(items, options) {
console.log('paymentRequestWithCardForm', items, options);
return StripeNativeManager.paymentRequestWithCardForm(getTotal(items).toFixed(2).toString(), options);
},

};
Expand Down