Last active
June 21, 2020 20:00
-
-
Save ademcan/6dd706e9debeedff5ef45ff7343e6d87 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
// createPaymentIntent | |
RCT_EXPORT_METHOD(createSetupIntent:(NSString*)intent whitCc:(NSString*)cc withMo:(NSString*)month withYe:(NSString*)year withCvc:(NSString*)cvc withEmail:(NSString*)email withName:(NSString*)name callback:(RCTResponseSenderBlock)callback ){ | |
// convert the month and year values to NSNumber | |
NSNumber *num1 = @([month intValue]); | |
NSNumber *num2 = @([year intValue]); | |
STPPaymentMethodCardParams *cardParams = [STPPaymentMethodCardParams new]; | |
cardParams.number = cc; | |
cardParams.expMonth = num1; | |
cardParams.expYear = num2; | |
cardParams.cvc = cvc; | |
STPPaymentMethodBillingDetails *billingDetails = [STPPaymentMethodBillingDetails new]; | |
// optional: add info to your user | |
billingDetails.email = email; | |
billingDetails.name = name; | |
// Fill in card, billing details | |
STPPaymentMethodParams *paymentMethodParams = [STPPaymentMethodParams paramsWithCard:cardParams billingDetails:billingDetails metadata:nil]; | |
[[STPAPIClient sharedClient] createPaymentMethodWithParams:paymentMethodParams completion:^(STPPaymentMethod *paymentMethod, NSError *error) { | |
STPSetupIntentConfirmParams *setupIntentParams = [[STPSetupIntentConfirmParams alloc] initWithClientSecret:intent]; | |
setupIntentParams.paymentMethodID = paymentMethod.stripeId; | |
MyCheckoutViewController *authContext = [[MyCheckoutViewController alloc] init]; | |
[[STPPaymentHandler sharedHandler] confirmSetupIntent:setupIntentParams withAuthenticationContext:authContext completion:^(STPPaymentHandlerActionStatus status, STPSetupIntent * setupIntent, NSError * error) { | |
switch (status) { | |
case STPPaymentHandlerActionStatusSucceeded: | |
// Setup succeeded and returns a paymentIntent to use when creating your customer in the back-end | |
callback(@[[NSNull null], @"SUCCESS", paymentMethod.stripeId ]); | |
break; | |
case STPPaymentHandlerActionStatusCanceled: | |
// Handle cancel | |
callback(@[[NSNull null], @"CANCEL" ]); | |
break; | |
case STPPaymentHandlerActionStatusFailed: | |
// Handle error | |
NSLog(@"ERROR: %@", error); | |
callback(@[[NSNull null], @"ERROR" ]); | |
break; | |
} | |
}]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
YES, exactly what I did!
Thank you we agree about that, thank you!