Skip to content

Instantly share code, notes, and snippets.

@ademcan
Created March 11, 2020 13:02
Show Gist options
  • Save ademcan/0b1a95ddabeb34dd6956712109241262 to your computer and use it in GitHub Desktop.
Save ademcan/0b1a95ddabeb34dd6956712109241262 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#import "StripeBridge.h"
#import <Stripe/Stripe.h>
#import "CheckoutViewController.h"
@implementation StripeBridge
RCT_EXPORT_MODULE();
// createPaymentIntent
RCT_EXPORT_METHOD(createPayment:(NSString*)clientSecret whitCc:(NSString*)cc withMo:(NSString*)month withYe:(NSString*)year withCvc:(NSString*)cvc callback:(RCTResponseSenderBlock)callback ){
NSNumber *num1 = @([month intValue]);
NSNumber *num2 = @([year intValue]);
STPPaymentMethodCardParams *cardParams = [STPPaymentMethodCardParams new];
cardParams.number = cc;
cardParams.expMonth = num1;
cardParams.expYear = num2;
cardParams.cvc = cvc;
STPPaymentMethodParams *paymentMethodParams = [STPPaymentMethodParams paramsWithCard:cardParams billingDetails:nil metadata:nil];
STPPaymentIntentParams *paymentIntentParams = [[STPPaymentIntentParams alloc] initWithClientSecret:clientSecret ];
paymentIntentParams.paymentMethodParams = paymentMethodParams;
CheckoutViewController *authContext = [[CheckoutViewController alloc] init];
[[STPPaymentHandler sharedHandler] confirmPayment:paymentIntentParams withAuthenticationContext:authContext completion:^(STPPaymentHandlerActionStatus status, STPPaymentIntent * paymentIntent, NSError * error) {
switch (status) {
case STPPaymentHandlerActionStatusSucceeded:
NSLog(@"PAYMENTINTENT: %@", paymentIntent.stripeId);
callback(@[[NSNull null], @"SUCCESS", paymentIntent.stripeId]);
break;
// Payment succeeded
case STPPaymentHandlerActionStatusCanceled:
callback(@[[NSNull null], @"CANCEL" ]);
break;
// Handle cancel
case STPPaymentHandlerActionStatusFailed:
NSLog(@"ERROR: %@", error);
callback(@[[NSNull null], @"ERROR", @"NULL" ]);
break;
// Handle error
}
}];
}
@end
@ademcan
Copy link
Author

ademcan commented Feb 16, 2021

I haven't work on the Android version but you can check the following repo to get some idea: https://github.com/Fitpassu/react-native-stripe-payments. And be aware that Stripe is working on an official RN lib so if you are not in a hurry I would rather wait for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment