Created
June 19, 2019 12:30
-
-
Save lukebrandonfarrell/d9efc7dad5ddcc0f935e8b618fdd6691 to your computer and use it in GitHub Desktop.
This file contains 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
RCT_EXPORT_METHOD( | |
confirmPaymentIntent:(NSString *)payment_intent_client_secret | |
resolvePromise:(RCTPromiseResolveBlock)resolve | |
rejectPromise:(RCTPromiseRejectBlock)reject | |
) | |
{ | |
// Create the payment intent using the payment_intent_client_secret | |
[[STPAPIClient sharedClient] retrievePaymentIntentWithClientSecret:payment_intent_client_secret completion:^(STPPaymentIntent *paymentIntent, NSError *error) { | |
NSLog(@"Intent %@", paymentIntent); | |
if(error == nil){ | |
if (paymentIntent.status == STPPaymentIntentStatusRequiresAction) { | |
STPRedirectContext *redirectContext = [[STPRedirectContext alloc] initWithPaymentIntent:paymentIntent completion:^(NSString *clientSecret, NSError *redirectError) { | |
[[STPAPIClient sharedClient] retrievePaymentIntentWithClientSecret:clientSecret completion:^(STPPaymentIntent *paymentIntent, NSError *error) { | |
// Check paymentIntent.status | |
}]; | |
NSLog(@"Redirect Completed %@", paymentIntent); | |
}]; | |
NSLog(@"Context %@", redirectContext); | |
if (redirectContext) { | |
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController; | |
// opens SFSafariViewController to the necessary URL | |
[redirectContext startRedirectFlowFromViewController:rootViewController]; | |
} else { | |
// This PaymentIntent action is not yet supported by the SDK. | |
} | |
} | |
} else { | |
NSLog(@"SError %@", error); | |
reject(@"payment_intent", @"Issue authenticating payment intent", error); | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment