Created
March 11, 2020 13:02
-
-
Save ademcan/0b1a95ddabeb34dd6956712109241262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Hey ademcan,
Thanks so much for this, they were quite useful for the iOS stripe implementation on the app I'm working on.
Small question, do you happen to have a Java version of these (StripeBridge.m/StripeBridge.h) or any pointers on how to migrate them to Java?, I'm pretty new to these integrations so I'm a little bit lost.
Thanks in advance!
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
Sorry my bad, you are right it's setupIntent and the gist here is correct:
https://gist.github.com/ademcan/6dd706e9debeedff5ef45ff7343e6d87
I just updated the name of the function, as you can see on L26 it creates a SetupIntent :)