Skip to content

Instantly share code, notes, and snippets.

@lukebrandonfarrell
Created June 19, 2019 12:30
Show Gist options
  • Save lukebrandonfarrell/d9efc7dad5ddcc0f935e8b618fdd6691 to your computer and use it in GitHub Desktop.
Save lukebrandonfarrell/d9efc7dad5ddcc0f935e8b618fdd6691 to your computer and use it in GitHub Desktop.
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