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

Changes in the Payment Card Form #25

Open
wants to merge 4 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

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

2 changes: 2 additions & 0 deletions StripeNative/PaymentViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
@interface PaymentViewController : UIViewController

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

@end
12 changes: 11 additions & 1 deletion StripeNative/PaymentViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
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
18 changes: 12 additions & 6 deletions StripeNative/StripeNativeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#import <Stripe/Stripe.h>

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

#import "PaymentViewController.h"
#import "StripeNativeManager.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

};
Expand Down