diff --git a/StripeNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/StripeNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/StripeNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/StripeNative/PaymentViewController.h b/StripeNative/PaymentViewController.h index 7743f51..612ffaf 100644 --- a/StripeNative/PaymentViewController.h +++ b/StripeNative/PaymentViewController.h @@ -21,6 +21,8 @@ @interface PaymentViewController : UIViewController @property (nonatomic) NSString* amount; +@property (nonatomic) NSString* email; +@property (nonatomic) NSString* currencySymbol; @property (nonatomic, weak) id delegate; @end diff --git a/StripeNative/PaymentViewController.m b/StripeNative/PaymentViewController.m index 7c2490a..d087c18 100644 --- a/StripeNative/PaymentViewController.m +++ b/StripeNative/PaymentViewController.m @@ -30,7 +30,14 @@ - (void)viewDidLoad { } // Setup save button - NSString *title = [NSString stringWithFormat:@"Pay $%@", self.amount]; + float num = [self.amount floatValue]; + num = num/100; + NSString *title; + if (self.currencySymbol != nil){ + title = [NSString stringWithFormat:@"Pay %@%.2f", self.currencySymbol, num ]; + } else { + title = [NSString stringWithFormat:@"Pay $%.2f", num ]; + } 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; @@ -45,6 +52,9 @@ - (void)viewDidLoad { // Setup email field: hack it up to look just like the Stripe field UITextField *emailField = [[UITextField alloc] init]; + if (self.email != nil){ + emailField.text=self.email; + } [emailField setPlaceholder:@"Email address"]; UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 44)]; emailField.leftView = paddingView; diff --git a/StripeNative/StripeNativeManager.h b/StripeNative/StripeNativeManager.h index c241c64..ad20a59 100644 --- a/StripeNative/StripeNativeManager.h +++ b/StripeNative/StripeNativeManager.h @@ -5,7 +5,7 @@ // Copyright (c) 2015 Lane Rettig. All rights reserved. // -#import "RCTViewManager.h" +#import #import "PaymentViewController.h" @interface StripeNativeManager : NSObject diff --git a/StripeNative/StripeNativeManager.m b/StripeNative/StripeNativeManager.m index 51b710a..2f8ecca 100644 --- a/StripeNative/StripeNativeManager.m +++ b/StripeNative/StripeNativeManager.m @@ -7,8 +7,8 @@ #import -#import "RCTEventDispatcher.h" -#import "RCTUtils.h" +#import +#import #import "PaymentViewController.h" #import "StripeNativeManager.h" @@ -161,14 +161,20 @@ -(void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewCo # pragma mark - Card form -- (void)beginCustomPaymentWithAmount:(NSString *)amount { +- (void)beginCustomPaymentWithAmount:(NSString *)amount email:(NSString *)email currencySymbol:(NSString *)currencySymbol { PaymentViewController *paymentViewController = [[PaymentViewController alloc] initWithNibName:nil bundle:nil]; paymentViewController.amount = amount; paymentViewController.delegate = self; + paymentViewController.email = email; + paymentViewController.currencySymbol = currencySymbol; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:paymentViewController]; [rootViewController presentViewController:navController animated:YES completion:nil]; } +- (void)beginCustomPaymentWithAmount:(NSString *)amount email:(NSString *)email { + [self beginCustomPaymentWithAmount:amount email:email currencySymbol:nil]; +} + - (void)paymentViewController:(PaymentViewController *)controller didFinishWithToken:(STPToken *)token email:(NSString *)email error:(NSError *)error { [rootViewController dismissViewControllerAnimated:YES completion:^{ resolved = TRUE; @@ -228,19 +234,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 email:nil currencySymbol:nil 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 email:(NSString *)email currencySymbol:(NSString *) currencySymbol resolver:(RCTPromiseResolveBlock)resolve rejector:(RCTPromiseRejectBlock)reject) { promiseResolver = resolve; promiseRejector = reject; resolved = FALSE; - [self beginCustomPaymentWithAmount:amount]; + [self beginCustomPaymentWithAmount:amount email:email currencySymbol:currencySymbol]; } RCT_EXPORT_METHOD(success: (RCTPromiseResolveBlock)resolve rejector:(RCTPromiseRejectBlock)reject) diff --git a/index.ios.js b/index.ios.js index 74ef076..a8cb742 100644 --- a/index.ios.js +++ b/index.ios.js @@ -69,8 +69,8 @@ var NativeStripe = { return StripeNativeManager.paymentRequestWithApplePay(summaryItems, options); }, - paymentRequestWithCardForm(items) { - return StripeNativeManager.paymentRequestWithCardForm(getTotal(items).toFixed(2).toString()); + paymentRequestWithCardForm(items, email, currencySymbol) { + return StripeNativeManager.paymentRequestWithCardForm(getTotal(items).toFixed(2).toString(), email, currencySymbol); }, };