-
Notifications
You must be signed in to change notification settings - Fork 0
Add setup intents #2
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
489b61e
ad2460e
317a1da
8d0e1f9
77310b0
5e17a24
3be33db
84759a7
9ce2185
d7f55b1
d961509
02ef228
203ac38
6671024
3464a7e
ccaf265
89db3f3
77e283b
9963e40
f860eaa
2e3f809
323ae60
a521ae3
959438f
0341443
3ae94ed
0cc9397
86603e3
83d6410
cf21b32
42fa50c
5dddeb2
0ac9578
740148f
ba35163
0310ec9
6ff4597
ee419a2
3842941
2c4aec2
a361c3c
f07cffa
3087599
4d2910c
ca35981
1034bf7
9fd58eb
23f6af5
2c7014a
420058e
7618193
ef8512f
ca7ba25
c1be5a0
f815bd3
7ccb975
16bb8aa
ee115f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #import "GatewayManager.h" | ||
| #import <React/RCTConvert.h> | ||
|
|
||
| #if __has_include(<Stripe/Stripe.h>) | ||
| #import <Stripe/Stripe.h> | ||
|
|
@@ -64,6 +65,45 @@ - (void)configureStripeGateway:(NSDictionary *_Nonnull)gatewayParameters | |
| #endif | ||
| } | ||
|
|
||
|
|
||
| - (void)savePaymentMethod:(NSString *)clientSecret cardParams:(NSDictionary *)cardParams completion:(void (^)(NSString * _Nullable, NSError * _Nullable))completion | ||
| { | ||
| #if __has_include(<Stripe/Stripe.h>) | ||
| // Collect card details | ||
| STPPaymentMethodCardParams *card = [[STPPaymentMethodCardParams alloc] init]; | ||
| card.number = [RCTConvert NSString:cardParams[@"number"]]; | ||
| card.expYear = [RCTConvert NSNumber:cardParams[@"expYear"]]; | ||
| card.expMonth = [RCTConvert NSNumber:cardParams[@"expMonth"]]; | ||
| card.cvc = [RCTConvert NSString:cardParams[@"cvc"]]; | ||
| STPPaymentMethodParams *paymentMethodParams = [STPPaymentMethodParams paramsWithCard:card billingDetails:nil metadata:nil]; | ||
|
||
| STPSetupIntentConfirmParams *setupIntentParams = [[STPSetupIntentConfirmParams alloc] initWithClientSecret:clientSecret]; | ||
| setupIntentParams.paymentMethodParams = paymentMethodParams; | ||
|
|
||
| // Confirm setup intent (authorize use of paymend method for future payments) | ||
| STPPaymentHandler *paymentHandler = [STPPaymentHandler sharedHandler]; | ||
| [paymentHandler confirmSetupIntent:(STPSetupIntentConfirmParams *)setupIntentParams withAuthenticationContext:self completion:^(STPPaymentHandlerActionStatus status, STPSetupIntent *setupIntent, NSError *error) { | ||
| dispatch_async(dispatch_get_main_queue(), ^{ | ||
| switch (status) { | ||
| case STPPaymentHandlerActionStatusFailed: { | ||
| completion(nil, error); | ||
| break; | ||
| } | ||
| case STPPaymentHandlerActionStatusCanceled: { | ||
| completion(nil, error); | ||
| break; | ||
| } | ||
| case STPPaymentHandlerActionStatusSucceeded: { | ||
| completion(setupIntent.paymentMethodID, nil); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, so we have validated that we can get the method ID out of this method |
||
| break; | ||
| } | ||
| default: | ||
| break; | ||
| } | ||
| }); | ||
| }]; | ||
| #endif | ||
| } | ||
|
|
||
| - (void)createStripeTokenWithPayment:(PKPayment *)payment completion:(void (^)(NSString * _Nullable, NSError * _Nullable))completion | ||
| { | ||
| #if __has_include(<Stripe/Stripe.h>) | ||
|
|
@@ -111,4 +151,9 @@ - (void)createBraintreeTokenWithPayment:(PKPayment *_Nonnull)payment | |
| #endif | ||
| } | ||
|
|
||
| - (UIViewController *)authenticationPresentingViewController | ||
nabilfreeman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return RCTPresentedViewController(); | ||
| } | ||
|
|
||
| @end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,37 @@ - (NSDictionary *)constantsToExport | |
| callback(@[[NSNull null]]); | ||
| } | ||
|
|
||
|
|
||
| RCT_EXPORT_METHOD(savePaymentMethod: (NSDictionary *)methodData | ||
| cardParams: (NSDictionary *)cardParams | ||
| callback: (RCTResponseSenderBlock)callback) | ||
| { | ||
| NSString *merchantId = methodData[@"merchantIdentifier"]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| NSDictionary *gatewayParameters = methodData[@"paymentMethodTokenizationParameters"][@"parameters"]; | ||
|
|
||
| NSLog(@"%@", gatewayParameters); | ||
|
|
||
| if (gatewayParameters) { | ||
| self.hasGatewayParameters = true; | ||
| self.gatewayManager = [GatewayManager new]; | ||
| [self.gatewayManager configureGateway:gatewayParameters merchantIdentifier:merchantId]; | ||
| } | ||
|
|
||
| if (self.hasGatewayParameters) { | ||
| [self.gatewayManager savePaymentMethod:methodData[@"clientSecret"] cardParams:cardParams completion:^(NSString * _Nullable token, NSError * _Nullable error) { | ||
| if (error) { | ||
| NSLog(@"Failed"); | ||
| NSLog(@"%@", error); | ||
| NSString *message = error.localizedDescription; | ||
| callback(@[message, [NSNull null]]); | ||
| return; | ||
| } | ||
|
|
||
| callback(@[[NSNull null], token]); | ||
| }]; | ||
| } | ||
| } | ||
|
|
||
| RCT_EXPORT_METHOD(show:(RCTResponseSenderBlock)callback) | ||
| { | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { NativeModules, Platform } from 'react-native'; | ||
|
|
||
| const { ReactNativePayments } = NativeModules; | ||
|
|
||
| const IS_ANDROID = Platform.OS === 'android'; | ||
|
|
||
| const Intents = { | ||
| savePaymentMethod(methodData, cardParams) { | ||
| return new Promise((resolve, reject) => { | ||
| if (IS_ANDROID) { | ||
| return resolve(); | ||
| } | ||
|
|
||
| ReactNativePayments.savePaymentMethod( | ||
| methodData, | ||
nabilfreeman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cardParams, | ||
| (err, data) => { | ||
| if (err) return reject(err); | ||
|
|
||
| resolve(data); | ||
| } | ||
| ); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| export { Intents }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export { default as PaymentRequest } from './PaymentRequest'; | ||
| export { PKPaymentButton } from './PKPaymentButton'; | ||
| export { Intents } from './Intents'; | ||
|
||
Uh oh!
There was an error while loading. Please reload this page.